Skip to content

Commit 4dec192

Browse files
Pavithraacerv
authored andcommitted
memcg/memcontrol04: Fix race in pagecache allocation measurement
The test was failing with memory.current values much lower than expected: TFAIL: (A/B/C memory.current=6684672) ~= 34603008 TFAIL: (A/B/D memory.current=5373952) ~= 17825792 Child processes allocating pagecache were exiting immediately after allocation (via tst_reap_children()), causing the pagecache to be freed before the test could measure memory.current values. Signed-off-by: Sachin Sant <sachinp@linux.ibm.com> Signed-off-by: Pavithra <pavrampu@linux.ibm.com> Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com>
1 parent e20f825 commit 4dec192

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

testcases/kernel/controllers/memcg/memcontrol04.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@
4545
static struct tst_cg_group *trunk_cg[3];
4646
static struct tst_cg_group *leaf_cg[4];
4747
static int fd = -1;
48+
static unsigned int num_children_spawned;
4849

4950
enum checkpoints {
50-
CHILD_IDLE
51+
CHILD_IDLE,
52+
TEST_DONE,
5153
};
5254

5355
enum trunk_cg {
@@ -67,6 +69,12 @@ static void cleanup_sub_groups(void)
6769
{
6870
size_t i;
6971

72+
if (num_children_spawned > 0) {
73+
TST_CHECKPOINT_WAKE2(TEST_DONE, num_children_spawned);
74+
tst_reap_children();
75+
num_children_spawned = 0;
76+
}
77+
7078
for (i = ARRAY_SIZE(leaf_cg); i > 0; i--) {
7179
if (!leaf_cg[i - 1])
7280
continue;
@@ -88,7 +96,7 @@ static void alloc_anon_in_child(const struct tst_cg_group *const cg,
8896
const pid_t pid = SAFE_FORK();
8997

9098
if (pid) {
91-
tst_reap_children();
99+
SAFE_WAITPID(pid, NULL, 0);
92100
return;
93101
}
94102

@@ -107,7 +115,8 @@ static void alloc_pagecache_in_child(const struct tst_cg_group *const cg,
107115
const pid_t pid = SAFE_FORK();
108116

109117
if (pid) {
110-
tst_reap_children();
118+
num_children_spawned++;
119+
TST_CHECKPOINT_WAIT(CHILD_IDLE);
111120
return;
112121
}
113122

@@ -117,6 +126,11 @@ static void alloc_pagecache_in_child(const struct tst_cg_group *const cg,
117126
getpid(), tst_cg_group_name(cg), size);
118127
alloc_pagecache(fd, size);
119128

129+
SAFE_FSYNC(fd);
130+
131+
TST_CHECKPOINT_WAKE(CHILD_IDLE);
132+
TST_CHECKPOINT_WAIT(TEST_DONE);
133+
120134
exit(0);
121135
}
122136

@@ -125,6 +139,7 @@ static void test_memcg_low(void)
125139
long c[4];
126140
unsigned int i;
127141

142+
num_children_spawned = 0;
128143
fd = SAFE_OPEN(TMPDIR"/tmpfile", O_RDWR | O_CREAT, 0600);
129144
trunk_cg[A] = tst_cg_group_mk(tst_cg, "trunk_A");
130145

0 commit comments

Comments
 (0)