From patchwork Tue Dec 4 15:35:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 1007710 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="BqfcOBeB"; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 438QtP4cY7z9s7W for ; Wed, 5 Dec 2018 02:35:41 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E536A3E7648 for ; Tue, 4 Dec 2018 16:35:38 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) by picard.linux.it (Postfix) with ESMTP id EC6E83E62C2 for ; Tue, 4 Dec 2018 16:35:36 +0100 (CET) Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id 7596F140145A for ; Tue, 4 Dec 2018 16:35:36 +0100 (CET) Received: by mail-wr1-x444.google.com with SMTP id r10so16398149wrs.10 for ; Tue, 04 Dec 2018 07:35:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=1VmSk+enqjhTFrDJiu0z5AIjBwOFrlSI0esj9w2UgH4=; b=BqfcOBeBZBkx5TBBZYjxeFAv145kFQd8eaPTlwQqbIO+rYTHZktEpzNPzHXMePu9Zj 8hX5SLaDp+dyKIHVUtT1vaCFLKqu6tkChIq0n5v7uSaL0LlAhKBfP9rAp9pGLaQyUbKK UL0jT2oqmwqGS8hEkrs38U2NBZYN2xNWe4fuR+VbHec0/lo+ufZjb44rkAqBbANmZFw7 0BijkyzMW3P9PmUPbDKH2RcIAMLkDILARZJfJN6fAm4CeVzV5JwiT8mfsKXS+txWSx2a il/adlxRsZYYBmcK1TsYzISjzdlrPjeOGmNUlIoz+DuuVy9bz/XhRQJ4GQf4u5JJCHDM dn3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=1VmSk+enqjhTFrDJiu0z5AIjBwOFrlSI0esj9w2UgH4=; b=Pl41IX6tSRAYTDHOKtj6an3DJpulrxFSWTEuhO8O3SdAo6TYRTt7zo8FQ24vBgY19K c5xFcISiHtQXdYA1a8EtqQR40pZ0oGfU5evEt5Jj/jgA9iWfhaE4U/QwZL6JSEJNfqIE BILOPJTM9vdZRJyoFcrGcxtGvz4E+atPDFEoJFJZ7LAV8favNKH4hdAaql87m0PcQelr ggRbOxhMe6sfDsb7bhBXSAMLzNC+THA4MmiD++VSvIdnYq899mRXJuJWiO7iM8sUwlwy 2nFjJVWV6VgeF6ccEkWF0dJCMuNAHXZEB2uPFfYfUGZUmKkFmJAXYD0ELaI2RSXzWvE/ PEkw== X-Gm-Message-State: AA+aEWZwc+X9VsvW9WNsZDsI5kHIzGvN2sizGsLQ/F6ovs+YBWuTlD5Q OgaIS2rf62sSghH3zQTZmrc= X-Google-Smtp-Source: AFSGD/WhUxATZnhFqV3IGs6iXDQAbx23E7/wHSZSA+16Q1QN4kwNjoq29gk944pZgqJhbqQGgyQp2Q== X-Received: by 2002:adf:a78a:: with SMTP id j10mr18906313wrc.191.1543937735866; Tue, 04 Dec 2018 07:35:35 -0800 (PST) Received: from localhost.localdomain ([37.46.46.74]) by smtp.gmail.com with ESMTPSA id g188sm10243204wmf.32.2018.12.04.07.35.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Dec 2018 07:35:35 -0800 (PST) From: Amir Goldstein To: Cyril Hrubis Date: Tue, 4 Dec 2018 17:35:28 +0200 Message-Id: <20181204153528.26176-1-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Cc: linux-unionfs@vger.kernel.org, ltp@lists.linux.it Subject: [LTP] [PATCH v5] syscalls/readahead02: test readahead using posix_fadvise() X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" The call to posix_fadvise(POSIX_FADV_WILLNEED) should have the same effect as the call to readahead() syscall. Repeat the test cases for local file and overlayfs file with posix_fadvise(). Signed-off-by: Amir Goldstein --- .../kernel/syscalls/readahead/readahead02.c | 61 ++++++++++++++----- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/testcases/kernel/syscalls/readahead/readahead02.c b/testcases/kernel/syscalls/readahead/readahead02.c index de12ba114..d74753dcf 100644 --- a/testcases/kernel/syscalls/readahead/readahead02.c +++ b/testcases/kernel/syscalls/readahead/readahead02.c @@ -58,15 +58,34 @@ static struct tst_option options[] = { {NULL, NULL, NULL} }; +static int libc_readahead(int fd, off_t offset, size_t len) +{ + return readahead(fd, offset, len); +} + +static int fadvise_willneed(int fd, off_t offset, size_t len) +{ + /* Should have the same effect as readahead() syscall */ + errno = posix_fadvise(fd, offset, len, POSIX_FADV_WILLNEED); + /* posix_fadvise returns error number (not in errno) */ + return errno ? -1 : 0; +} + static struct tcase { const char *tname; int use_overlay; + int use_fadvise; + /* Use either readahead() syscall or POSIX_FADV_WILLNEED */ + int (*readahead)(int, off_t, size_t); } tcases[] = { - { "readahead on file", 0 }, - { "readahead on overlayfs file", 1 }, + { "readahead on file", 0, 0, libc_readahead }, + { "readahead on overlayfs file", 1, 0, libc_readahead }, + { "POSIX_FADV_WILLNEED on file", 0, 1, fadvise_willneed }, + { "POSIX_FADV_WILLNEED on overlayfs file", 1, 1, fadvise_willneed }, }; static int readahead_supported = 1; +static int fadvise_supported = 1; static int has_file(const char *fname, int required) { @@ -126,7 +145,6 @@ static void create_testfile(int use_overlay) free(tmp); } - /* read_testfile - mmap testfile and read every page. * This functions measures how many I/O and time it takes to fully * read contents of test file. @@ -138,7 +156,8 @@ static void create_testfile(int use_overlay) * @usec: returns how many microsecond it took to go over fsize bytes * @cached: returns cached kB from /proc/meminfo */ -static int read_testfile(int do_readahead, const char *fname, size_t fsize, +static int read_testfile(struct tcase *tc, int do_readahead, + const char *fname, size_t fsize, unsigned long *read_bytes, long long *usec, unsigned long *cached) { @@ -154,7 +173,7 @@ static int read_testfile(int do_readahead, const char *fname, size_t fsize, if (do_readahead) { cached_start = get_cached_size(); do { - TEST(readahead(fd, offset, fsize - offset)); + TEST(tc->readahead(fd, offset, fsize - offset)); if (TST_RET != 0) { SAFE_CLOSE(fd); return TST_ERR; @@ -233,7 +252,8 @@ static void test_readahead(unsigned int n) create_testfile(tc->use_overlay); /* find out how much can cache hold if we read whole file */ - read_testfile(0, testfile, testfile_size, &read_bytes, &usec, &cached); + read_testfile(tc, 0, testfile, testfile_size, &read_bytes, &usec, + &cached); cached_high = get_cached_size(); sync(); drop_caches(); @@ -241,7 +261,8 @@ static void test_readahead(unsigned int n) cached_max = MAX(cached_max, cached_high - cached_low); tst_res(TINFO, "read_testfile(0)"); - read_testfile(0, testfile, testfile_size, &read_bytes, &usec, &cached); + read_testfile(tc, 0, testfile, testfile_size, &read_bytes, &usec, + &cached); if (cached > cached_low) cached = cached - cached_low; else @@ -251,20 +272,28 @@ static void test_readahead(unsigned int n) drop_caches(); cached_low = get_cached_size(); tst_res(TINFO, "read_testfile(1)"); - ret = read_testfile(1, testfile, testfile_size, &read_bytes_ra, + ret = read_testfile(tc, 1, testfile, testfile_size, &read_bytes_ra, &usec_ra, &cached_ra); - if (ret == EINVAL && - (!tc->use_overlay || !readahead_supported)) { - readahead_supported = 0; - tst_res(TCONF, "readahead not supported on %s", - tst_device->fs_type); - return; + if (ret == EINVAL) { + if (tc->use_fadvise && + (!tc->use_overlay || !fadvise_supported)) { + fadvise_supported = 0; + tst_res(TCONF, "CONFIG_ADVISE_SYSCALLS not configured " + "in kernel?"); + return; + } else if (!tc->use_overlay || !readahead_supported) { + readahead_supported = 0; + tst_res(TCONF, "readahead not supported on %s", + tst_device->fs_type); + return; + } } if (ret) { - tst_res(TFAIL | TTERRNO, "readahead failed on %s%s", - tc->use_overlay ? "overlayfs on " : "", + tst_res(TFAIL | TTERRNO, "%s failed on %s", + tc->use_fadvise ? "fadvise" : "readahead", + tc->use_overlay ? "overlayfs" : tst_device->fs_type); return; }