From: Amir Goldstein <amir73il@gmail.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v5] syscalls/readahead02: test readahead using posix_fadvise()
Date: Tue, 4 Dec 2018 17:35:28 +0200 [thread overview]
Message-ID: <20181204153528.26176-1-amir73il@gmail.com> (raw)
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 <amir73il@gmail.com>
---
.../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;
}
--
2.17.1
next reply other threads:[~2018-12-04 15:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-04 15:35 Amir Goldstein [this message]
2018-12-14 18:18 ` [LTP] [PATCH v5] syscalls/readahead02: test readahead using posix_fadvise() Amir Goldstein
2018-12-18 13:01 ` Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181204153528.26176-1-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox