[LTP] [PATCH v2] swapon04: Settle udev after mkswap on kernels < 5.18
Wei Gao
wegao@suse.com
Fri Nov 13 04:08:22 CET 2026
When mkswap formats and closes the loop device, systemd-udevd
asynchronously runs blkid probing on the device. On kernels prior to
5.18, tmpfs shmem_file_read_iter() treats non-iovec read iterators
(!iter_is_iovec(to)) as stacking filesystem reads, allocating real
zero-filled pages into holes (this behavior get fixed by commit
56a8c8eb1eaf ("tmpfs: do not allocate pages on read")).
When a udev worker reads the loop device after swapon-time discard
has punched holes in the tmpfs backing file, the probing reads
re-allocate up to 84 zero-filled pages (672 blocks), causing
blocks_after to exceed max_header_blocks and failing the test
intermittently on tmpfs (e.g. observed on SLE 15-SP4 aarch64):
swapon04.c:167: TFAIL: blocks_after (672) > max_header_blocks (16)
Tracing block:block_rq_issue confirms that udev-worker reads the loop
device after discard has punched the holes:
# mkswap writes swap header
mkswap-703 [000] ..... 2100.340705: block_rq_issue: 7,1 WS 4096 () 0 + 8 [mkswap]
# sys_swapon reads swap header
swapon04-701 [000] ..... 2100.345665: block_rq_issue: 7,1 R 4096 () 0 + 8 [swapon04]
# swapon-time discard punches holes across sectors 8..32767
kworker/0:1H-31[000] ..... 2100.345715: block_rq_issue: 7,1 DS 16773120 () 8 + 32760 [kworker/0:1H]
# udev-worker probes loop device 5.5ms after discard, re-allocating tmpfs pages
(udev-worker)-655 [001] .. 2100.351255: block_rq_issue: 7,1 RA 4096 () 32640 + 8 [(udev-worker)]
(udev-worker)-655 [000] .. 2100.351302: block_rq_issue: 7,1 RA 4096 () 32752 + 8 [(udev-worker)]
(udev-worker)-655 [000] .. 2100.352286: block_rq_issue: 7,1 RA 126976 () 264 + 248 [(udev-worker)]
On kernels prior to 5.18, wait for udev to settle after mkswap so that
probing completes before swapon discards the area. On 5.18+, skip settling
so that any regression causing tmpfs to allocate pages on loop reads
is not masked.
Fixes: aabccf0a0117 ("swapon04: Add test for discard flags")
Signed-off-by: Wei Gao <wegao@suse.com>
---
v1->v2:
- Add udevadm to .needs_cmds
- Skip udevadm settling on 5.18+
testcases/kernel/syscalls/swapon/swapon04.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/testcases/kernel/syscalls/swapon/swapon04.c b/testcases/kernel/syscalls/swapon/swapon04.c
index de95849e3..e0d59d042 100644
--- a/testcases/kernel/syscalls/swapon/swapon04.c
+++ b/testcases/kernel/syscalls/swapon/swapon04.c
@@ -138,6 +138,7 @@ static void verify_swapon(unsigned int n)
struct stat st;
blkcnt_t blocks_before, blocks_after;
const char *const mkswap_argv[] = {"mkswap", loop_dev, NULL};
+ const char *const udevadm_argv[] = {"udevadm", "settle", NULL};
tst_res(TINFO, "Testing swapon(%s, %s)", loop_dev, tc->desc);
@@ -148,6 +149,8 @@ static void verify_swapon(unsigned int n)
SAFE_CLOSE(fd);
tst_cmd(mkswap_argv, "/dev/null", "/dev/null", 0);
+ if (tst_kvercmp(5, 18, 0) < 0)
+ tst_cmd(udevadm_argv, "/dev/null", "/dev/null", 0);
SAFE_STAT(BACKING_FILE, &st);
blocks_before = st.st_blocks;
@@ -195,6 +198,7 @@ static struct tst_test test = {
},
.needs_cmds = (struct tst_cmd[]) {
{.cmd = "mkswap"},
+ {.cmd = "udevadm"},
{}
},
.needs_kconfigs = (const char *[]) {
--
2.55.0
More information about the ltp
mailing list