[LTP] memcg/memcontrol04: Fix race in pagecache allocation measurement

linuxtestproject.agent@gmail.com linuxtestproject.agent@gmail.com
Mon May 25 19:12:03 CEST 2026


Hi Pavithra,

On Mon, 25 May 2026, Pavithra wrote:
> memcg/memcontrol04: Fix race in pagecache allocation measurement

> +static unsigned int num_children_spawned;

> +enum checkpoints {
> -	CHILD_IDLE
> +	CHILD_IDLE,
> +	TEST_DONE,
>  };

> +	if (num_children_spawned > 0) {
> +		TST_CHECKPOINT_WAKE2(TEST_DONE, num_children_spawned);
> +		tst_reap_children();
> +		num_children_spawned = 0;
> +	}

Correct. Waking all pagecache children before tst_reap_children() and
resetting the counter is safe since cleanup_sub_groups() is idempotent
(called both from test_memcg_low() and cleanup()).

> -		tst_reap_children();
> +		SAFE_WAITPID(pid, NULL, 0);

Good catch. The old tst_reap_children() would have reaped the still-
waiting pagecache children prematurely.

> +	num_children_spawned++;
> +	TST_CHECKPOINT_WAIT(CHILD_IDLE);

Sequential fork+wait pairs mean CHILD_IDLE is always at zero before
the next child is forked, so there's no ambiguity in who signals it.

> +	SAFE_FSYNC(fd);
> +
> +	TST_CHECKPOINT_WAKE(CHILD_IDLE);
> +	TST_CHECKPOINT_WAIT(TEST_DONE);

fsync before signalling the parent ensures the pagecache is durably
accounted before memory.current is read.

> +	num_children_spawned = 0;
>  	fd = SAFE_OPEN(TMPDIR"/tmpfile", O_RDWR | O_CREAT, 0600);

Explicit reset at the start of each test_all invocation is the right
place; handles repeated runs correctly.

Reviewed-by: LTP AI Reviewer <ltp-ai@noreply.github.com>

---
Note:

Our agent completed the review of the patch. The full review can be
found at: https://github.com/linux-test-project/ltp-agent/actions/runs/26411599009

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
```


More information about the ltp mailing list