[LTP] [PATCH] mmap22: Improve MAP_DROPPABLE test stability using mincore()

Petr Vorel pvorel@suse.cz
Tue Sep 23 13:07:32 CEST 2025


Hi Li,

> The current mmap22 test validates MAP_DROPPABLE by writing to the
> allocated memory and checking for zero-filled pages under memory
> pressure. However, this approach is unreliable because:

>   - Child process memory pressure (malloc + single writes) may not
>     reliably trigger cgroup memory reclaim.
>   - Checking memory content (alloc[i] == 0) is insufficient to
>     confirm kernel reclamation, as pages may remain resident but not
>     overwritten.
>   - Race conditions during child cleanup could leave residual cgroup
>     processes.

Thanks for the investigation.

> Error logs:

>    command: mmap22
>    tst_tmpdir.c:316: TINFO: Using /tmp/LTP_mmaxrtyKb as tmpdir (xfs filesystem)
>    tst_test.c:1953: TINFO: LTP version: 20250530
>    tst_kconfig.c:88: TINFO: Parsing kernel config '/lib/modules/6.12.0-130.1445_2041086229.el10.x86_64+rt/build/.config'
>    tst_test.c:1774: TINFO: Overall timeout per run is 0h 05m 54s
>    tst_test.c:1837: TINFO: Killed the leftover descendant processes
>    tst_test.c:1846: TINFO: If you are running on slow machine, try exporting LTP_TIMEOUT_MUL > 1
>    tst_test.c:1848: TBROK: Test killed! (timeout?)
>    tst_cgroup.c:1043: TBROK: unlinkat(5</sys/fs/cgroup/ltp>, 'test-92902', AT_REMOVEDIR): EBUSY (16)
>    ...

> This patch improves the test in the following ways:

>   * Use mincore() to precisely detect if MAP_DROPPABLE pages have
>     been reclaimed by the kernel.
>   * Replace the old child loop with a stronger memory pressure loop
>     (malloc + memset), ensuring cgroup limits are hit quickly.
>   * Use SAFE_KILL + SAFE_WAITPID for robust child cleanup.
nit: SAFE_KILL + SAFE_WAITPID were used before, the change you did is to check
with 'if (child > 0)' if it's meaningful to attempt to kill child.

>   * Extend runtime and add short sleeps to reduce busy looping and
>     stabilize test results.
>   * Record page size during setup for consistent use across functions.

> As a result, the test becomes more stable, deterministic, and easier
> to reproduce under different kernels and configurations.

+1

...
> +static void stress_child(void)
> +{
> +	for (;;) {
> +		char *buf = malloc(page_size);
nit: Please insert a blank line here to keep checkpatch.pl quiet.
mmap22.c:39: WARNING: Missing a blank line after declarations

> +		if (!buf)
> +			exit(1);
> +		memset(buf, 'B', page_size);
> +	}
> +}

...
> +	for (;;) {
> +		if (!tst_remaining_runtime()) {
> +			tst_res(TFAIL, "MAP_DROPPABLE did not drop pages within timeout");
> +			goto cleanup;
> +		}
> +
> +		if (mincore(alloc, ALLOC_SIZE, vec) == -1)
> +			tst_brk(TBROK | TERRNO, "mincore failed");
NOTE: we have SAFE_MINCORE() (can be fixed during merge).

The rest LGTM.

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr


More information about the ltp mailing list