From patchwork Fri Sep 28 13:06:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 976290 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="ul0A/kau"; 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 42MBll2Pcxz9s1x for ; Fri, 28 Sep 2018 23:06:59 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id A6D7E3E791D for ; Fri, 28 Sep 2018 15:06:55 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) by picard.linux.it (Postfix) with ESMTP id B81123E7815 for ; Fri, 28 Sep 2018 15:06:34 +0200 (CEST) Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 5583C201350 for ; Fri, 28 Sep 2018 15:06:34 +0200 (CEST) Received: by mail-wm1-x342.google.com with SMTP id 206-v6so2156107wmb.5 for ; Fri, 28 Sep 2018 06:06:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=l/fIH4JMETaUfgORMNfvxbo5LGTu0qglN5wAoaYWWm0=; b=ul0A/kauILaWRHYum/Lkhx/aCRu9W8MLjZubjocV5qCqsD2T15P16rNwmkTChcFtur eEH4cwV/Q6hcHCEcl427I4jAolfB17FEZ3d692Tb8TLY6bPDHR6TJs7I6zzRZnCtxJbb Mus/Bd/jng4N0+E7m9AKizOUU2UmYe8sXxAY311vDBn5hial6dA0qwhwZVHsBVrRXmag KacvTZ2SZIeDHLR06Ud6TZ+liOzAVC2/icO5qlCyI0x2SbJn+BLu35eApeaEF+yoYAqg 57q9u+Qyi0bsueC+eSrKmhPtnE13Zp7qHIJyMpgSXs3b5GhPnd5OYZv7jPLf2ucGDepW iDbA== 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:in-reply-to :references; bh=l/fIH4JMETaUfgORMNfvxbo5LGTu0qglN5wAoaYWWm0=; b=U69gplNepabfihO2ncOZDqUJ602AG/qea/BzcaxYkKpkqMI1nI8XALjUx9wRbVAw1w 8I8vKKW+5N4pYAGnnis5f3iLMJ1gRELHIsTlOku6gbZvLQh0bAAQn3tZ9A4U+GfMMvRu FA/CYbWjvWcoQNTcr8sBowaaMAaXsZwxxtN8oU5pROlvrQCOpzUNKN1DSxiaSvFMxrTw l6Y/LnQjC9Wqtelxl6hAWjWPguvDXbDGuBs+tl5jSS/qIl3ZqujFqRhxZlOkDdcTh1Wu uwSG8WIAMGidsZtYKK56dK0lrLtNnXbEP1h7AdlGd8479R88yihYrDUPCsbbM+VaOCba VKNg== X-Gm-Message-State: ABuFfojjVFeIjrHmld5KIRAQ3cy3tivyG+Q4A/wyQrIfwNyOXN5EdV+v LY1OqIw9/VxrFqGH8oTd0r7bVUln X-Google-Smtp-Source: ACcGV60AeEpaMwls4npaRg/7XOP6alePQQW/gGHCcOAiF7kDenz6C7jXvnVC8VkWBnNVyabOwbIBhQ== X-Received: by 2002:a1c:318b:: with SMTP id x133-v6mr1819219wmx.145.1538139993770; Fri, 28 Sep 2018 06:06:33 -0700 (PDT) Received: from localhost.localdomain ([141.226.14.107]) by smtp.gmail.com with ESMTPSA id o12-v6sm4616415wrj.58.2018.09.28.06.06.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Sep 2018 06:06:33 -0700 (PDT) From: Amir Goldstein To: Cyril Hrubis Date: Fri, 28 Sep 2018 16:06:21 +0300 Message-Id: <20180928130621.28932-5-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180928130621.28932-1-amir73il@gmail.com> References: <20180928130621.28932-1-amir73il@gmail.com> X-Virus-Scanned: clamav-milter 0.99.2 at in-7.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-7.smtp.seeweb.it Cc: linux-unionfs@vger.kernel.org, ltp@lists.linux.it, Miklos Szeredi Subject: [LTP] [PATCH 4/4] 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(). The new test case is a regression test for kernel commit b833a3660394 ("ovl: add ovl_fadvise()") which fixes a regression of fadvise() on an overlay file that was introduced by kernel commit 5b910bd615ba ("ovl: fix GPF in swapfile_activate of file from overlayfs over xfs"). Signed-off-by: Amir Goldstein --- .../kernel/syscalls/readahead/readahead02.c | 57 +++++++++++++++++-- 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/testcases/kernel/syscalls/readahead/readahead02.c b/testcases/kernel/syscalls/readahead/readahead02.c index 191116f62..9ebed359d 100644 --- a/testcases/kernel/syscalls/readahead/readahead02.c +++ b/testcases/kernel/syscalls/readahead/readahead02.c @@ -51,6 +51,42 @@ static struct tst_option options[] = { {NULL, NULL, NULL} }; +#ifndef _FILE_OFFSET_BITS +#define _FILE_OFFSET_BITS 32 +#endif + +#ifndef __NR_fadvise64 +#define __NR_fadvise64 0 +#endif + +static struct tcase { + const char *tname; + int use_overlay; + int use_fadvise; +} tcases[] = { + { "readahead on file", 0, 0 }, + { "readahead on overlayfs file", 1, 0 }, +/* Check this system has fadvise64 system which is used in posix_fadvise. */ +#if ((_FILE_OFFSET_BITS == 64) || (__NR_fadvise64 != 0)) + { "POSIX_FADV_WILLNEED on file", 0, 1 }, + { "POSIX_FADV_WILLNEED on overlayfs file", 1, 1 }, +#endif +}; + +static int fadvise_willneed(int fd, off_t offset, size_t len) +{ + /* Should have the same effect as readahead() syscall */ + return posix_fadvise(fd, offset, len, POSIX_FADV_WILLNEED); +} + +static int libc_readahead(int fd, off_t offset, size_t len) +{ + return readahead(fd, offset, len); +} + +typedef int (*readahead_func_t)(int, off_t, size_t); +static readahead_func_t readahead_func = libc_readahead; + static int check_ret(long expected_ret) { if (expected_ret == TST_RET) { @@ -120,6 +156,9 @@ static int setup_overlay(void) { int ret; + if (ovl_mounted) + return 0; + /* Setup an overlay mount with lower dir and file */ SAFE_MKDIR(OVL_LOWER, 0755); SAFE_MKDIR(OVL_UPPER, 0755); @@ -139,7 +178,7 @@ static int setup_overlay(void) return 0; } -static int create_testfile(unsigned int use_overlay) +static int create_testfile(int use_overlay) { int fd; char *tmp; @@ -164,7 +203,6 @@ static int create_testfile(unsigned int use_overlay) return 0; } - /* 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. @@ -194,7 +232,7 @@ static void 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(readahead_func(fd, offset, fsize - offset)); if (TST_RET != 0) { check_ret(0); break; @@ -256,17 +294,24 @@ static void read_testfile(int do_readahead, const char *fname, size_t fsize, SAFE_CLOSE(fd); } -static void test_readahead(unsigned int use_overlay) +static void test_readahead(unsigned int n) { unsigned long read_bytes, read_bytes_ra; long usec, usec_ra; unsigned long cached_max, cached_low, cached, cached_ra; char proc_io_fname[128]; + struct tcase *tc = &tcases[n]; + + tst_res(TINFO, "Test #%d: %s", n, tc->tname); + sprintf(proc_io_fname, "/proc/%u/io", getpid()); - if (create_testfile(use_overlay) != 0) + if (create_testfile(tc->use_overlay) != 0) return; + /* Use either readahead() syscall or POSIX_FADV_WILLNEED */ + readahead_func = tc->use_fadvise ? fadvise_willneed : libc_readahead; + /* find out how much can cache hold if we read whole file */ read_testfile(0, testfile, testfile_size, &read_bytes, &usec, &cached); cached_max = get_cached_size(); @@ -357,7 +402,7 @@ static struct tst_test test = { .cleanup = cleanup, .options = options, .test = test_readahead, - .tcnt = 2, /* Repeat with overlayfs */ + .tcnt = ARRAY_SIZE(tcases), }; #else /* __NR_readahead */