Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests: cgroup: Replace sleep with cg_read_key_long_poll() for waiting on nr_dying_descendants

Replace the manual sleep-and-retry logic in test_kmem_dead_cgroups()
with the new helper `cg_read_key_long_poll()`. This change improves
the robustness of the test by polling the "nr_dying_descendants"
counter in `cgroup.stat` until it reaches 0 or the timeout is exceeded.

Additionally, increase the retry timeout to 8 seconds (from 5 seconds)
based on testing results:
- With 5-second timeout: 4/20 runs passed.
- With 8-second timeout: 20/20 runs passed.

The 8 second timeout is based on stress testing of test_kmem_dead_cgroups()
under load: 5 seconds was occasionally not enough for reclaim of dying
descendants to complete, whereas 8 seconds consistently covered the observed
latencies. This value is intended as a generous upper bound for the
asynchronous reclaim and is not tied to any specific kernel constant, so it
can be adjusted in the future if reclaim behavior changes.

Signed-off-by: Guopeng Zhang <zhangguopeng@kylinos.cn>
Reviewed-by: Shakeel Butt <shakeel.butt@linux.dev>
Acked-by: Michal Koutný <mkoutny@suse.com>
Signed-off-by: Tejun Heo <tj@kernel.org>

authored by

Guopeng Zhang and committed by
Tejun Heo
50133c09 6360d444

+15 -18
+15 -18
tools/testing/selftests/cgroup/test_kmem.c
··· 26 26 */ 27 27 #define MAX_VMSTAT_ERROR (4096 * 64 * get_nprocs()) 28 28 29 + #define KMEM_DEAD_WAIT_RETRIES 80 29 30 30 31 static int alloc_dcache(const char *cgroup, void *arg) 31 32 { ··· 307 306 { 308 307 int ret = KSFT_FAIL; 309 308 char *parent; 310 - long dead; 311 - int i; 312 - int max_time = 20; 309 + long dead = -1; 313 310 314 311 parent = cg_name(root, "kmem_dead_cgroups_test"); 315 312 if (!parent) ··· 322 323 if (cg_run_in_subcgroups(parent, alloc_dcache, (void *)100, 30)) 323 324 goto cleanup; 324 325 325 - for (i = 0; i < max_time; i++) { 326 - dead = cg_read_key_long(parent, "cgroup.stat", 327 - "nr_dying_descendants "); 328 - if (dead == 0) { 329 - ret = KSFT_PASS; 330 - break; 331 - } 332 - /* 333 - * Reclaiming cgroups might take some time, 334 - * let's wait a bit and repeat. 335 - */ 336 - sleep(1); 337 - if (i > 5) 338 - printf("Waiting time longer than 5s; wait: %ds (dead: %ld)\n", i, dead); 339 - } 326 + /* 327 + * Allow up to ~8s for reclaim of dying descendants to complete. 328 + * This is a generous upper bound derived from stress testing, not 329 + * from a specific kernel constant, and can be adjusted if reclaim 330 + * behavior changes in the future. 331 + */ 332 + dead = cg_read_key_long_poll(parent, "cgroup.stat", 333 + "nr_dying_descendants ", 0, KMEM_DEAD_WAIT_RETRIES, 334 + DEFAULT_WAIT_INTERVAL_US); 335 + if (dead) 336 + goto cleanup; 337 + 338 + ret = KSFT_PASS; 340 339 341 340 cleanup: 342 341 cg_destroy(parent);