Linux Test Project
 help / color / mirror / Atom feed
* [LTP] [PATCH v1] swapon04: Settle udev after mkswap to prevent tmpfs hole filling
@ 2026-11-11  8:09 Wei Gao via ltp
  2026-11-11  8:30 ` [LTP] " linuxtestproject.agent
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Wei Gao via ltp @ 2026-11-11  8:09 UTC (permalink / raw)
  To: ltp

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)]

Wait for udev to settle after mkswap so that probing completes before
swapon discards the area.

Fixes: aabccf0a0117 ("swapon04: Add test for discard flags")
Signed-off-by: Wei Gao <wegao@suse.com>
---
 testcases/kernel/syscalls/swapon/swapon04.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/testcases/kernel/syscalls/swapon/swapon04.c b/testcases/kernel/syscalls/swapon/swapon04.c
index de95849e3..141456442 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,7 @@ static void verify_swapon(unsigned int n)
 	SAFE_CLOSE(fd);
 
 	tst_cmd(mkswap_argv, "/dev/null", "/dev/null", 0);
+	tst_cmd(udevadm_argv, "/dev/null", "/dev/null", TST_CMD_PASS_RETVAL);
 
 	SAFE_STAT(BACKING_FILE, &st);
 	blocks_before = st.st_blocks;
-- 
2.55.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-13  3:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-11  8:09 [LTP] [PATCH v1] swapon04: Settle udev after mkswap to prevent tmpfs hole filling Wei Gao via ltp
2026-11-11  8:30 ` [LTP] " linuxtestproject.agent
2026-11-12 10:44 ` [LTP] [PATCH v1] " Cyril Hrubis
2026-11-12 10:49 ` Cyril Hrubis
2026-11-13  3:08 ` [LTP] [PATCH v2] swapon04: Settle udev after mkswap on kernels < 5.18 Wei Gao via ltp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox