controllers/memcg: Add testcase for kmem_limit_in_bytes of memory cgroup
PATCH v2 1/1 controllers/memcg: Add testcase for kmem_limit_in_bytes of memory cgroup
Hi Richard,
Calling setpgid in this testcase is aim to make the task group be controlled by memory.kmem.limit_in_bytes since we have set the pgid to cgroup.procs.
In this testcase, memory cgroup is just effective for the task group of cgroup.procs. it is no affection for the parent process as expect.
So if fork success, we can use tst_* and would not be failed, otherwise, we can use tst_* since it is in parent process.
I don't know if I express it clearly.
Thanks very much!
Best Regards,
Gongyi
Quoted 71 lines
Hello,
Quoted 11 lines · zhaogongyi
Hi Richard,
Thanks so much for your review!
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Review
Quoted 7 lines
(quoted diff) +7
-0+ pid = SAFE_FORK(); + if (!pid) { + SAFE_SETPGID(0, 0); + + SAFE_FILE_PRINTF(KMEM_LIMIT_IN_BYTES, "%d", 0); + + SAFE_FILE_PRINTF(CGROUP_PROCS, "%d",getpgid(getpid()));
Quoted 11 lines
Quoted 11 lines
Quoted 8 lines
Quoted 5 lines
After setting this we should avoid doing any work in this process except calling fork. AFAIK there is no guarantee that some other syscall or tasklet etc. Won't try to allocate memory and also fail.
It seems that we would not be afraid since there is no asynchronous operation in the test process.
IIRC one of the problems with tasklets is they can run in any process. Also, in theory stdout can point to anything. So
write()mightallocate memory.
Quoted 9 lines
Quoted 9 lines
Why not do something like:
SAFE_FILE_PRINTF(CGROUP_PROCS, "%d", getpgid(getpid())); errno = 0;fork(); exit(errno);Then check that errno == ENOMEM, in the parent process?
Quoted 10 lines
Quoted 7 lines
Quoted 7 lines
Review
Quoted 7 lines
(quoted diff) +7
-0+ TEST(fork()); + if (TST_RET == -1) { + if (TST_ERR == ENOMEM) + tst_res(TPASS, "fork fail as expected"); + else + tst_brk(TFAIL | TTERRNO, + "fork fail as unexpected");As far as my personal understanding, after setpgid, the controlled process is the sub process whose process id is pid, excluded from the
parent process, and the functions
tst_resortst_brkIs executed in its parent process.
setpgid(0, 0)sets the process group id (pgid) to be the same as the (pid), which creates a new process group. This probably has the effect that the calling process will not recieve signals from the terminal. Also it should receive SIGTTOU when callingtst_resandtst_brk, if stdout/stderr point to a terminal with the right configuration.AFAICT process groups are for shells and affect where signals are sent. Nothing else.
Quoted 6 lines
In this case, is it no affection to this test?
Best Regards,
Gongyi--
Thank you,
Richard.
PATCH v2 1/1 controllers/memcg: Add testcase for kmem_limit_in_bytes of memory cgroup
Hello,
Quoted 4 lines · zhaogongyi
Hi Richard,
Calling setpgid in this testcase is aim to make the task group be controlled by memory.kmem.limit_in_bytes since we have set the pgid to cgroup.procs.
Please see cgroup_procs_write_start in cgroup/cgroup.c. It calls find_task_by_vpid which interprets pid as PIDTYPE_PID not PIDTYPE_PGID.
Signature · 2 lines
Thank you, Richard.