* [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* Re: [LTP] swapon04: Settle udev after mkswap to prevent tmpfs hole filling
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 ` linuxtestproject.agent
2026-11-12 10:44 ` [LTP] [PATCH v1] " Cyril Hrubis
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: linuxtestproject.agent @ 2026-11-11 8:30 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi Wei,
On Wed Nov 11 08:09:10 2026 +0000, Wei Gao wrote:
> swapon04: Settle udev after mkswap to prevent tmpfs hole filling
Verdict - Reviewed
---
Note:
The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [LTP] [PATCH v1] swapon04: Settle udev after mkswap to prevent tmpfs hole filling
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 ` 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
3 siblings, 0 replies; 5+ messages in thread
From: Cyril Hrubis @ 2026-11-12 10:44 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi!
> 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;
The udevadm has to be added to .needs_cmds as well:
diff --git a/testcases/kernel/syscalls/swapon/swapon04.c b/testcases/kernel/syscalls/swapon/swapon04.c
index de95849e3..15a7c1063 100644
--- a/testcases/kernel/syscalls/swapon/swapon04.c
+++ b/testcases/kernel/syscalls/swapon/swapon04.c
@@ -195,6 +195,7 @@ static struct tst_test test = {
},
.needs_cmds = (struct tst_cmd[]) {
{.cmd = "mkswap"},
+ {.cmd = "udevadm"},
{}
},
.needs_kconfigs = (const char *[]) {
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [LTP] [PATCH v1] swapon04: Settle udev after mkswap to prevent tmpfs hole filling
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
3 siblings, 0 replies; 5+ messages in thread
From: Cyril Hrubis @ 2026-11-12 10:49 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi!
> 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")).
Also when this has been fixed by 5.18 we shouldn't apply the fix for
5.18+ otherwise this would mask regressions.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 5+ messages in thread* [LTP] [PATCH v2] swapon04: Settle udev after mkswap on kernels < 5.18
2026-11-11 8:09 [LTP] [PATCH v1] swapon04: Settle udev after mkswap to prevent tmpfs hole filling Wei Gao via ltp
` (2 preceding siblings ...)
2026-11-12 10:49 ` Cyril Hrubis
@ 2026-11-13 3:08 ` Wei Gao via ltp
3 siblings, 0 replies; 5+ messages in thread
From: Wei Gao via ltp @ 2026-11-13 3:08 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)]
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
--
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