syscalls/preadv203: Add basic RWF_NOWAIT test
Subsystems (2)
PATCH 1/1 syscalls/preadv203: Add basic RWF_NOWAIT test
From: Cyril Hrubis <[email protected]>
We are attempting to trigger the EAGAIN path for the RWF_NOWAIT flag.
In order to do so the test runs three threads:
* nowait_reader: reads from a random offset from a random file with RWF_NOWAIT flag and expects to get EAGAIN and short read sooner or later
* writer_thread: rewrites random file in order to keep the underlying device bussy so that pages evicted from cache cannot be faulted immediatelly
* cache_dropper: attempts to evict pages from a cache in order for reader to hit evicted page sooner or later
---
I was wondering if we can do a better job at flushing the caches. Is there an interface for flusing caches just for the device we are using for the test?
Also the RWF_NOWAIT should probably be benchmarked as well but that is completely out of scope for LTP.
runtest/syscalls | 2 + testcases/kernel/syscalls/preadv2/.gitignore | 2 + testcases/kernel/syscalls/preadv2/Makefile | 4 + testcases/kernel/syscalls/preadv2/preadv203.c | 266 ++++++++++++++++++ 4 files changed, 274 insertions(+) create mode 100644 testcases/kernel/syscalls/preadv2/preadv203.c
runtest/syscalls +2 -0
@@ -853,6 +853,8 @@ preadv201 preadv201 preadv201_64 preadv201_64 preadv202 preadv202 preadv202_64 preadv202_64 +preadv203 preadv203 +preadv203_64 preadv203_64 profil01 profil01
testcases/kernel/syscalls/preadv2/.gitignore +2 -0
@@ -2,3 +2,5 @@ /preadv201_64 /preadv202 /preadv202_64 +/preadv203 +/preadv203_64
testcases/kernel/syscalls/preadv2/Makefile +4 -0
@@ -11,4 +11,8 @@ include $(abs_srcdir)/../utils/newer_64.mk %_64: CPPFLAGS += -D_FILE_OFFSET_BITS=64 +preadv203: CFLAGS += -pthread +preadv203_64: CFLAGS += -pthread +preadv203_64: LDFLAGS += -pthread + include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/preadv2/preadv203.c new file +266 -0
266 lines not on this page · raw message
Signature · 1 line
2.19.2
PATCH 1/1 syscalls/preadv203: Add basic RWF_NOWAIT test
Hi Cyril,
Quoted 1 line
From: Cyril Hrubis <[email protected]>
Quoted 10 lines
We are attempting to trigger the EAGAIN path for the
RWF_NOWAITflag.In order to do so the test runs three threads:
*
nowait_reader: reads from a random offset from a random file withRWF_NOWAITflag and expects to get EAGAIN and short read sooner or later*
writer_thread: rewrites random file in order to keep the underlying device bussy so that pages evicted from cache cannot be faulted
typo => busy
Quoted 1 line
immediatelly
typo => immediately
...
testcases/kernel/syscalls/preadv2/preadv203.c line 9
Quoted 11 lines
+++
b/testcases/kernel/syscalls/preadv2/preadv203.ctestcases/kernel/syscalls/preadv2/preadv203.c new file +9
-0@@ -0,0 +1,266 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2019 Cyril Hrubis <[email protected]> +*/ + +/* +* This is a basic functional test for RWF_NOWAIT flag, we are attempting to +* force preadv2() either to return a short read or EAGAIN with three +* concurelntly running threads:
typo => concurrently
testcases/kernel/syscalls/preadv2/preadv203.c line 16
Quoted 7 lines
testcases/kernel/syscalls/preadv2/preadv203.c new file +7
-0+* +* nowait_reader: reads from a random offset from a random file with +* RWF_NOWAIT flag and expects to get EAGAIN and short +* read sooner or later +* +* writer_thread: rewrites random file in order to keep the underlying device +* bussy so that pages evicted from cache cannot be faulted
typo => busy
testcases/kernel/syscalls/preadv2/preadv203.c line 17
Quoted 1 line
testcases/kernel/syscalls/preadv2/preadv203.c new file +1
-0+* immediatelly
typo => immediately
Quoted 7 lines
testcases/kernel/syscalls/preadv2/preadv203.c new file +7
-0+* +* cache_dropper: attempts to evict pages from a cache in order for reader to +* hit evicted page sooner or later +*/ + +/* +* If test fails with EOPNOTSUPP you have likely hit a glibc bug:
testcases/kernel/syscalls/preadv2/preadv203.c line 34
Quoted 10 lines
testcases/kernel/syscalls/preadv2/preadv203.c new file +10
-0+* +* https://sourceware.org/bugzilla/show_bug.cgi?id=23579 +* +* Which can be worked around by calling preadv2() directly by syscall() such as: +* +* static ssize_t sys_preadv2(int fd, const struct iovec *iov, int iovcnt, +* off_t offset, int flags) +* { +* return syscall(SYS_preadv2, fd, iov, iovcnt, offset, offset>>32, flags); +* }
I wonder if we want either warn user or run it both via (g)libc wrapper and directly the syscall.
BTW testing on kernel 4.20.0, glibc 2.28 with sys_preadv2() and still get TBROK EOPNOTSUPP. I tried to test on ext[2-4], btrfs. I wonder what I'm missing.
Kind regards,
Petr
PATCH 1/1 syscalls/preadv203: Add basic RWF_NOWAIT test
Hi!
Quoted 2 lines
I wonder if we want either warn user or run it both via (g)libc wrapper and directly the syscall.
I guess that we may drop a hint in the error message.
Quoted 2 lines
BTW testing on kernel 4.20.0, glibc 2.28 with
sys_preadv2()and still get TBROK EOPNOTSUPP. I tried to test on ext[2-4], btrfs. I wonder what I'm missing.
That's strange, are you sure that the test was calling the wrapper instead of the glibc call?
This should really work unless the support in kernel has been disabled in distribution kernel for some reason. I was testing it on vanilla kernel where it worked as expected.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/1 syscalls/preadv203: Add basic RWF_NOWAIT test
Hi Cyril,
Quoted 10 lines
Quoted 2 lines
I wonder if we want either warn user or run it both via (g)libc wrapper and directly the syscall.
I guess that we may drop a hint in the error message.
Quoted 2 lines
BTW testing on kernel 4.20.0, glibc 2.28 with
sys_preadv2()and still get TBROK EOPNOTSUPP. I tried to test on ext[2-4], btrfs. I wonder what I'm missing.That's strange, are you sure that the test was calling the wrapper instead of the glibc call?
See diff below, but I guess it's what you meant :).
Quoted 3 lines
This should really work unless the support in kernel has been disabled in distribution kernel for some reason. I was testing it on vanilla kernel where it worked as expected.
What config option is needed?
It does not work on both my machines (glibc 2.27 and 2.28) and it's working on various VMs with these versions.
Kind regards,
Petr
+++ testcases/kernel/syscalls/preadv2/preadv203.c
@@ -95,6 +95,12 @@ static int verify_short_read(struct iovec *iov, size_t iov_cnt,
return 0;
}
+ static ssize_t sys_preadv2(int fd, const struct iovec *iov, int iovcnt,
+ off_t offset, int flags)
+ {
+ return syscall(SYS_preadv2, fd, iov, iovcnt, offset, offset>>32, flags);
+ }
+
static void *nowait_reader(void *unused LTP_ATTRIBUTE_UNUSED)
{
char buf1[CHUNK_SZ/2];
@@ -115,7 +121,7 @@ static void *nowait_reader(void *unused LTP_ATTRIBUTE_UNUSED)
off_t off = random() % ((CHUNKS - 2) * CHUNK_SZ); int fd = fds[random() % FILES];
- TEST(preadv2(fd, rd_iovec, 2, off, RWF_NOWAIT));
+ TEST(sys_preadv2(fd, rd_iovec, 2, off, RWF_NOWAIT));
if (TST_RET < 0) {
if (TST_ERR != EAGAIN)
PATCH 1/1 syscalls/preadv203: Add basic RWF_NOWAIT test
In reply to Cyril HrubisHi Cyril,
Quoted 1 line
+static void *nowait_reader(void *unused
LTP_ATTRIBUTE_UNUSED)
...
testcases/kernel/syscalls/preadv2/preadv203.c line 118
Quoted 1 line
testcases/kernel/syscalls/preadv2/preadv203.c new file +1
-0+TEST (preadv2 (fd, rd_iovec,2 , off,RWF_NOWAIT ));
RWF_NOWAIT needs to be declared in lapi for old distros.
Kind regards,
Petr
PATCH 1/1 syscalls/preadv203: Add basic RWF_NOWAIT test
Hi!
Quoted 4 lines
Quoted 1 line
+static void *nowait_reader(void *unused
LTP_ATTRIBUTE_UNUSED)...
testcases/kernel/syscalls/preadv2/preadv203.c line 118
Quoted 1 line
testcases/kernel/syscalls/preadv2/preadv203.c new file +1
-0+TEST (preadv2 (fd, rd_iovec,2 , off,RWF_NOWAIT ));
RWF_NOWAITneeds to be declared in lapi for old distros.
Right and we should as well return TCONF on older kernels, I haven't tested that properly yet but I guess that we should check for EOPNOTSUPP and EINVAL. I will do that later on, I just didn't want to delay the initial test patch because it seem that kernel developers wanted to have it ASAP.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/1 syscalls/preadv203: Add basic RWF_NOWAIT test
Quoted 4 lines · Cyril Hrubis
Hi!
Quoted 2 lines
Quoted 1 line
+static void *nowait_reader(void *unused
LTP_ATTRIBUTE_UNUSED)...
Quoted 8 lines
Quoted 2 lines
Quoted 1 line
+
TEST(preadv2(fd, rd_iovec, 2, off, RWF_NOWAIT));
RWF_NOWAITneeds to be declared in lapi for old distros.Right and we should as well return TCONF on older kernels, I haven't tested that properly yet but I guess that we should check for EOPNOTSUPP and EINVAL. I will do that later on, I just didn't want to delay the initial test patch because it seem that kernel developers wanted to have it ASAP.
LTP syscalls test preadv201 and preadv201_64 failed on 4.4 branch kernel on all devices.
PASS 4.9, 4.14, 4.20 kernel versions.
OTOH,
preadv202 and preadv202_64 PASS on 4.4, 4.9, 4.14 and 4.20 kernel versions.
Test output log,
tst_test.c:1085: INFO: Timeout per run is 0h 15m 00s preadv201.c:91: PASS: preadv2() read 64 bytes with content 'a' expectedly preadv201.c:91: PASS: preadv2() read 64 bytes with content 'a' expectedly preadv201.c:91: PASS: preadv2() read 32 bytes with content 'b' expectedly preadv201.c:64: FAIL: preadv2() failed: EINVAL preadv201.c:64: FAIL: preadv2() failed: EINVAL preadv201.c:64: FAIL: preadv2() failed: EINVAL
Summary:
passed 3 failed 3 skipped 0
warnings 0
tst_test.c:1085: INFO: Timeout per run is 0h 15m 00s preadv201.c:91: PASS: preadv2() read 64 bytes with content 'a' expectedly preadv201.c:91: PASS: preadv2() read 64 bytes with content 'a' expectedly preadv201.c:91: PASS: preadv2() read 32 bytes with content 'b' expectedly preadv201.c:64: FAIL: preadv2() failed: EINVAL preadv201.c:64: FAIL: preadv2() failed: EINVAL preadv201.c:64: FAIL: preadv2() failed: EINVAL
Summary:
passed 3 failed 3 skipped 0
warnings 0
Full test log from 4.4 branch kernel x86_64,
https://lkft.validation.linaro.org/scheduler/job/614534#L7922
https://qa-reports.linaro.org/lkft/linux-stable-rc-4.4-oe/tests/ltp-syscalls-tests/preadv201
- Naresh
PATCH 1/1 syscalls/preadv203: Add basic RWF_NOWAIT test
In reply to Cyril HrubisQuoted 23 lines · Cyril Hrubis
From: Cyril Hrubis <[email protected]>
We are attempting to trigger the EAGAIN path for the
RWF_NOWAITflag.In order to do so the test runs three threads:
*
nowait_reader: reads from a random offset from a random file withRWF_NOWAITflag and expects to get EAGAIN and short read sooner or later*
writer_thread: rewrites random file in order to keep the underlying device bussy so that pages evicted from cache cannot be faulted immediatelly*
cache_dropper: attempts to evict pages from a cache in order for reader to hit evicted page sooner or laterSigned-off-by Cyril Hrubis <[email protected]>CC Jiri Kosina <[email protected]>CC Linux-MM <[email protected]>CC kernel list <[email protected]>CC Linux API <[email protected]>
Quoted 6 lines
---
I was wondering if we can do a better job at flushing the caches. Is there an interface for flusing caches just for the device we are using for the test?
Will the BLKFLSBUF ioctl be suitable for this purpose?
Regards,
Vijay