memcontrol04 and s/cgroup/cg/
Subsystems (2)
v2 cover memcontrol04 and s/cgroup/cg/
Hello,
This adds another test from kselftest and tries to improve the readability of the cgroup API.
This is probably the last test I will copy for now. However I may rewrite the tests to clone child processes into a CGroup when the feature is available.
V2:
* Add more debugging info to the test output
Richard Palethorpe (3):
API/cgroup: Add memory.{events, low} API/cgroup: Shorten cgroup to cg in most symbols
memcontrol04: Copy from kselftest
doc/c-test-api.txt | 52 ++-- include/tst_cgroup.h | 112 ++++---- include/tst_test.h | 2 +- lib/newlib_tests/tst_cgroup01.c | 18 +- lib/newlib_tests/tst_cgroup02.c | 54 ++-- lib/tst_cgroup.c | 112 ++++---- lib/tst_test.c | 8 +- runtest/controllers | 1 + scripts/coccinelle/cgroup-ver.cocci | 16 +- .../coccinelle/kselftest-cgroup-to-ltp.cocci | 16 +- testcases/kernel/controllers/memcg/.gitignore | 1 + .../kernel/controllers/memcg/memcontrol01.c | 36 +-- .../kernel/controllers/memcg/memcontrol02.c | 28 +- .../kernel/controllers/memcg/memcontrol03.c | 60 ++--- .../kernel/controllers/memcg/memcontrol04.c | 243 ++++++++++++++++++ testcases/kernel/mem/cpuset/cpuset01.c | 14 +- testcases/kernel/mem/include/mem.h | 2 +- testcases/kernel/mem/ksm/ksm02.c | 6 +- testcases/kernel/mem/ksm/ksm03.c | 4 +- testcases/kernel/mem/ksm/ksm04.c | 6 +- testcases/kernel/mem/lib/mem.c | 8 +- testcases/kernel/mem/oom/oom03.c | 18 +- testcases/kernel/mem/oom/oom04.c | 8 +- testcases/kernel/mem/oom/oom05.c | 24 +- .../sched/cfs-scheduler/cfs_bandwidth01.c | 40 +-- testcases/kernel/syscalls/madvise/madvise06.c | 16 +- 26 files changed, 576 insertions(+), 329 deletions(-) create mode 100644 testcases/kernel/controllers/memcg/memcontrol04.c
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/3 API/cgroup: Add memory.{events, low}
--- lib/tst_cgroup.c | 2 ++ 1 file changed, 2 insertions(+)
lib/tst_cgroup.c +2 -0
@@ -159,6 +159,8 @@ static const struct cgroup_file cgroup_ctrl_files[] = {static const struct cgroup_file memory_ctrl_files[] = { {"memory.current" ,"memory.usage_in_bytes" ,CTRL_MEMORY }, + {"memory.events" ,NULL ,CTRL_MEMORY }, + {"memory.low" ,NULL ,CTRL_MEMORY }, {"memory.min" ,NULL ,CTRL_MEMORY }, {"memory.max" ,"memory.limit_in_bytes" ,CTRL_MEMORY }, {"memory.stat" ,"memory.stat" ,CTRL_MEMORY },
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 2/3 API/cgroup: Shorten cgroup to cg in most symbols
In reply to Richard Palethorpe via ltpWith the current naming it is common to have 'group' repeated 3 or even 4 times in one line. This causes a number of readability problems. Renaming it to cg reduces the amount of repetition.
The one place it is not renamed is in tst_test because it won't cause repetition there. Meanwhile it is easier to search the internet for 'linux cgroup' than 'linux cg'.
Li Wang suggested renaming tst_cg to tst_cg_test because it is consistent with tst_cg_drain. However I think tst_cg is used so often that it is more important to have shorter lines.
--- doc/c-test-api.txt | 52 ++++---- include/tst_cgroup.h | 112 +++++++++--------- include/tst_test.h | 2 +- lib/newlib_tests/tst_cgroup01.c | 18 +-- lib/newlib_tests/tst_cgroup02.c | 54 ++++----- lib/tst_cgroup.c | 110 ++++++++--------- lib/tst_test.c | 8 +- scripts/coccinelle/cgroup-ver.cocci | 16 +-- .../coccinelle/kselftest-cgroup-to-ltp.cocci | 16 +-- .../kernel/controllers/memcg/memcontrol01.c | 36 +++--- .../kernel/controllers/memcg/memcontrol02.c | 28 ++--- .../kernel/controllers/memcg/memcontrol03.c | 60 +++++----- testcases/kernel/mem/cpuset/cpuset01.c | 14 +-- testcases/kernel/mem/include/mem.h | 2 +- testcases/kernel/mem/ksm/ksm02.c | 6 +- testcases/kernel/mem/ksm/ksm03.c | 4 +- testcases/kernel/mem/ksm/ksm04.c | 6 +- testcases/kernel/mem/lib/mem.c | 8 +- testcases/kernel/mem/oom/oom03.c | 18 +-- testcases/kernel/mem/oom/oom04.c | 8 +- testcases/kernel/mem/oom/oom05.c | 24 ++-- .../sched/cfs-scheduler/cfs_bandwidth01.c | 40 +++---- testcases/kernel/syscalls/madvise/madvise06.c | 16 +-- 23 files changed, 329 insertions(+), 329 deletions(-)
doc/c-test-api.txt +26 -26
@@ -2084,10 +2084,10 @@ static void run(void) static void setup(void) { - SAFE_CGROUP_PRINTF(tst_cgroup, "cgroup.procs", "%d", getpid()); - SAFE_CGROUP_PRINTF(tst_cgroup, "memory.max", "%lu", MEMSIZE); - if (SAFE_CGROUP_HAS(tst_cgroup, "memory.swap.max")) - SAFE_CGROUP_PRINTF(tst_cgroup, "memory.swap.max", "%zu", memsw); + SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid()); + SAFE_CG_PRINTF(tst_cg, "memory.max", "%lu", MEMSIZE); + if (SAFE_CG_HAS(tst_cg, "memory.swap.max")) + SAFE_CG_PRINTF(tst_cg, "memory.swap.max", "%zu", memsw); } struct tst_test test = {
@@ -2101,7 +2101,7 @@ struct tst_test test = { Above, we first ensure the memory controller is available on the test's CGroup with '.needs_cgroup_controllers'. This populates a structure, -'tst_cgroup', which represents the test's CGroup. +'tst_cg', which represents the test's CGroup. We then write the current processes PID into 'cgroup.procs', which moves the current process into the test's CGroup. After which we set
@@ -2112,7 +2112,7 @@ on both CGroup versions, then we use the V2 naming. Some controller features, such as 'memory.swap', can be disabled. Therefor we need to check if they exist before accessing -them. This can be done with 'SAFE_CGROUP_HAS' which can be called on +them. This can be done with 'SAFE_CG_HAS' which can be called on any control file or feature. Most tests only require setting a few limits similar to the above. In
@@ -2121,29 +2121,29 @@ cleanup is also mostly hidden. However things can get much worse. [source,c] ------------------------------------------------------------------------------- -static struct tst_cgroup_group *cg_child; +static struct tst_cg_group *cg_child; static void run(void) { char buf[BUFSIZ]; size_t mem = 0; - cg_child = tst_cgroup_group_mk(tst_cgroup, "child"); - SAFE_CGROUP_PRINTF(cg_child, "cgroup.procs", "%d", getpid()); + cg_child = tst_cg_group_mk(tst_cg, "child"); + SAFE_CG_PRINTF(cg_child, "cgroup.procs", "%d", getpid()); - if (!TST_CGROUP_VER_IS_V1(tst_cgroup, "memory")) - SAFE_CGROUP_PRINT(tst_cgroup, "cgroup.subtree_control", "+memory"); - if (!TST_CGROUP_VER_IS_V1(tst_cgroup, "cpuset")) - SAFE_CGROUP_PRINT(tst_cgroup, "cgroup.subtree_control", "+cpuset"); + if (!TST_CG_VER_IS_V1(tst_cg, "memory")) + SAFE_CG_PRINT(tst_cg, "cgroup.subtree_control", "+memory"); + if (!TST_CG_VER_IS_V1(tst_cg, "cpuset")) + SAFE_CG_PRINT(tst_cg, "cgroup.subtree_control", "+cpuset"); if (!SAFE_FORK()) { - SAFE_CGROUP_PRINTF(cg_child, "cgroup.procs", "%d", getpid()); + SAFE_CG_PRINTF(cg_child, "cgroup.procs", "%d", getpid()); - if (SAFE_CGROUP_HAS(cg_child, "memory.swap")) { - SAFE_CGROUP_SCANF(cg_child, + if (SAFE_CG_HAS(cg_child, "memory.swap")) { + SAFE_CG_SCANF(cg_child, "memory.swap.current", "%zu", &mem); } - SAFE_CGROUP_READ(cg_child, "cpuset.mems", buf, sizeof(buf)); + SAFE_CG_READ(cg_child, "cpuset.mems", buf, sizeof(buf)); // Do something with cpuset.mems and memory.current values ...
@@ -2152,15 +2152,15 @@ static void run(void) } tst_reap_children(); - SAFE_CGROUP_PRINTF(tst_cgroup_drain, "cgroup.procs", "%d", getpid()); - cg_child = tst_cgroup_group_rm(cg_child); + SAFE_CG_PRINTF(tst_cg_drain, "cgroup.procs", "%d", getpid()); + cg_child = tst_cg_group_rm(cg_child); } static void cleanup(void) { if (cg_child) { - SAFE_CGROUP_PRINTF(tst_cgroup_drain, "cgroup.procs", "%d", getpid()); - cg_child = tst_cgroup_group_rm(cg_child); + SAFE_CG_PRINTF(tst_cg_drain, "cgroup.procs", "%d", getpid()); + cg_child = tst_cg_group_rm(cg_child); } }
@@ -2183,12 +2183,12 @@ and these should not be changed by the test. It can be used to remove processes from other CGroups incase the hierarchy root is not accessible. -Note that 'tst_cgroup_get_drain_group' should not be called many times, +Note that 'tst_cg_get_drain_group' should not be called many times, as it is allocated in a guarded buffer (See section 2.2.31). Therefor it is best to call it once in 'setup' and not 'run' because 'run' may be repeated with the '-i' option. -In 'run', we first create a child CGroup with 'tst_cgroup_mk'. As we +In 'run', we first create a child CGroup with 'tst_cg_mk'. As we create this CGroup in 'run' we should also remove it at the end of run. We also need to check if it exists and remove it in cleanup as well. Because there are 'SAFE_' functions which may jump to cleanup.
@@ -2223,10 +2223,10 @@ Another example of a behavioral difference between versions is shown below. [source,c] ------------------------------------------------------------------------------- - if (TST_CGROUP_VER_IS_V1(tst_cgroup, "memory")) - SAFE_CGROUP_PRINTF(tst_cgroup, "memory.swap.max", "%lu", ~0UL); + if (TST_CG_VER_IS_V1(tst_cg, "memory")) + SAFE_CG_PRINTF(tst_cg, "memory.swap.max", "%lu", ~0UL); else - SAFE_CGROUP_PRINT(tst_cgroup, "memory.swap.max", "max"); + SAFE_CG_PRINT(tst_cg, "memory.swap.max", "max"); ------------------------------------------------------------------------------- CGroups V2 introduced a feature where 'memory[.swap].max' could be set to
include/tst_cgroup.h +56 -56
190 lines not on this page · raw message
include/tst_test.h +1 -1
@@ -286,7 +286,7 @@ struct tst_test {const char *const *needs_cmds;/* Requires a particular CGroup API version. */ -const enum tst_cgroup_ver needs_cgroup_ver; +const enum tst_cg_ver needs_cgroup_ver;/* {} terminated array of required CGroup controllers */ const char *const *needs_cgroup_ctrls;
lib/newlib_tests/tst_cgroup01.c +9 -9
@@ -12,7 +12,7 @@ static struct tst_option opts[] = { {"n", &no_cleanup, "-n\tLeave CGroups created by test"}, {NULL, NULL, NULL}, }; -struct tst_cgroup_opts cgopts; +struct tst_cg_opts cgopts;static void do_test (void ) {
@@ -21,15 +21,15 @@ static void do_test(void)static void setup (void ) { - cgopts.needs_ver = !!only_mount_v1 ?TST_CGROUP_V1 :0 ; + cgopts.needs_ver = !!only_mount_v1 ?TST_CG_V1 :0 ; -tst_cgroup_scan (); -tst_cgroup_print_config (); +tst_cg_scan (); +tst_cg_print_config (); -tst_cgroup_require ("memory" , &cgopts); -tst_cgroup_print_config (); -tst_cgroup_require ("cpuset" , &cgopts); -tst_cgroup_print_config (); +tst_cg_require ("memory" , &cgopts); +tst_cg_print_config (); +tst_cg_require ("cpuset" , &cgopts); +tst_cg_print_config (); }static void cleanup (void )
@@ -38,7 +38,7 @@ static void cleanup(void)tst_res (TINFO ,"no cleanup" ); }else {tst_res (TINFO ,"cleanup" ); -tst_cgroup_cleanup (); +tst_cg_cleanup (); } }
lib/newlib_tests/tst_cgroup02.c +27 -27
96 lines not on this page · raw message
lib/tst_cgroup.c +55 -55
337 lines not on this page · raw message
lib/tst_test.c +4 -4
@@ -1015,15 +1015,15 @@ static void prepare_device(void)static void do_cgroup_requires (void ) { -const struct tst_cgroup_opts cg_opts = { +const struct tst_cg_opts cg_opts = { .needs_ver = tst_test->needs_cgroup_ver, };const char *const *ctrl_names = tst_test->needs_cgroup_ctrls;for (; *ctrl_names; ctrl_names++) -tst_cgroup_require (*ctrl_names, &cg_opts); +tst_cg_require (*ctrl_names, &cg_opts); -tst_cgroup_init (); +tst_cg_init (); }static void do_setup (int argc,char *argv[])
@@ -1220,7 +1220,7 @@ static void do_test_setup(void)static void do_cleanup (void ) {if (tst_test->needs_cgroup_ctrls) -tst_cgroup_cleanup (); +tst_cg_cleanup ();if (ovl_mounted)SAFE_UMOUNT (OVL_MNT );
scripts/coccinelle/cgroup-ver.cocci +8 -8
@@ -4,26 +4,26 @@ virtual fix expression cg, ctrl; @@ -- TST_CGROUP_VER(cg, ctrl) == TST_CGROUP_V1 -+ TST_CGROUP_VER_IS_V1(cg, ctrl) +- TST_CG_VER(cg, ctrl) == TST_CG_V1 ++ TST_CG_VER_IS_V1(cg, ctrl) @@ expression cg, ctrl; @@ -- TST_CGROUP_VER(cg, ctrl) != TST_CGROUP_V1 -+ !TST_CGROUP_VER_IS_V1(cg, ctrl) +- TST_CG_VER(cg, ctrl) != TST_CG_V1 ++ !TST_CG_VER_IS_V1(cg, ctrl) @@ expression cg, ctrl; @@ -- TST_CGROUP_VER(cg, ctrl) == TST_CGROUP_V2 -+ !TST_CGROUP_VER_IS_V1(cg, ctrl) +- TST_CG_VER(cg, ctrl) == TST_CG_V2 ++ !TST_CG_VER_IS_V1(cg, ctrl) @@ expression cg, ctrl; @@ -- TST_CGROUP_VER(cg, ctrl) != TST_CGROUP_V2 -+ TST_CGROUP_VER_IS_V1(cg, ctrl) +- TST_CG_VER(cg, ctrl) != TST_CG_V2 ++ TST_CG_VER_IS_V1(cg, ctrl)
scripts/coccinelle/kselftest-cgroup-to-ltp.cocci +8 -8
@@ -3,7 +3,7 @@ expression cgn, cgns; @@ - cgn = cg_name(..., cgns); -+ cgn = tst_cgroup_group_mk(cg_test, cgns); ++ cgn = tst_cg_group_mk(cg_test, cgns); @@ expression cg, fname, data;
@@ -12,24 +12,24 @@ expression cg, fname, data; - if (cg_write(cg, fname, data)) { - ... - } -+ SAFE_CGROUP_PRINT(cg, fname, data); ++ SAFE_CG_PRINT(cg, fname, data); @@ expression cg; @@ -... when != TST_CGROUP_VER(...) +... when != TST_CG_VER(...) -- SAFE_CGROUP_PRINT(cg, "cgroup.subtree_control", "+memory"); -+ if (TST_CGROUP_VER(cg, "memory") != TST_CGROUP_V1) -+ SAFE_CGROUP_PRINT(cg, "cgroup.subtree_control", "+memory"); +- SAFE_CG_PRINT(cg, "cgroup.subtree_control", "+memory"); ++ if (TST_CG_VER(cg, "memory") != TST_CG_V1) ++ SAFE_CG_PRINT(cg, "cgroup.subtree_control", "+memory"); @@ expression cg, fname, needle; @@ - cg_read_strstr(cg, fname, needle) -+ !SAFE_CGROUP_OCCURSIN(cg, fname, needle) ++ !SAFE_CG_OCCURSIN(cg, fname, needle) @@ identifier l;
@@ -37,4 +37,4 @@ expression cg, fname; @@ - l = cg_read_long(cg, fname); -+ SAFE_CGROUP_SCANF(cg, fname, "%ld", &l); ++ SAFE_CG_SCANF(cg, fname, "%ld", &l);
testcases/kernel/controllers/memcg/memcontrol01.c +18 -18
@@ -17,46 +17,46 @@#include "tst_test.h" -static struct tst_cgroup_group *parent, *child; -static struct tst_cgroup_group *parent2, *child2; +static struct tst_cg_group *parent, *child; +static struct tst_cg_group *parent2, *child2;static void test_memcg_subtree_control (void ) { - parent =tst_cgroup_group_mk (tst_cgroup,"memcg_test_0" ); - child =tst_cgroup_group_mk (parent,"memcg_test_1" ); - parent2 =tst_cgroup_group_mk (tst_cgroup,"memcg_test_2" ); - child2 =tst_cgroup_group_mk (parent2,"memcg_test_3" ); + parent =tst_cg_group_mk (tst_cg,"memcg_test_0" ); + child =tst_cg_group_mk (parent,"memcg_test_1" ); + parent2 =tst_cg_group_mk (tst_cg,"memcg_test_2" ); + child2 =tst_cg_group_mk (parent2,"memcg_test_3" ); -SAFE_CGROUP_PRINT (parent2,"cgroup.subtree_control" ,"-memory" ); +SAFE_CG_PRINT (parent2,"cgroup.subtree_control" ,"-memory" );TST_EXP_POSITIVE ( -SAFE_CGROUP_OCCURSIN (child,"cgroup.controllers" ,"memory" ), +SAFE_CG_OCCURSIN (child,"cgroup.controllers" ,"memory" ),"child should have memory controller" );TST_EXP_POSITIVE ( - !SAFE_CGROUP_OCCURSIN (child2,"cgroup.controllers" ,"memory" ), + !SAFE_CG_OCCURSIN (child2,"cgroup.controllers" ,"memory" ),"child2 should not have memory controller" ); - child2 =tst_cgroup_group_rm (child2); - parent2 =tst_cgroup_group_rm (parent2); - child =tst_cgroup_group_rm (child); - parent =tst_cgroup_group_rm (parent); + child2 =tst_cg_group_rm (child2); + parent2 =tst_cg_group_rm (parent2); + child =tst_cg_group_rm (child); + parent =tst_cg_group_rm (parent); }static void cleanup (void ) {if (child2) - child2 =tst_cgroup_group_rm (child2); + child2 =tst_cg_group_rm (child2);if (parent2) - parent2 =tst_cgroup_group_rm (parent2); + parent2 =tst_cg_group_rm (parent2);if (child) - child =tst_cgroup_group_rm (child); + child =tst_cg_group_rm (child);if (parent) - parent =tst_cgroup_group_rm (parent); + parent =tst_cg_group_rm (parent); }static struct tst_test test = { .cleanup = cleanup, .test_all = test_memcg_subtree_control, - .needs_cgroup_ver =TST_CGROUP_V2 , + .needs_cgroup_ver =TST_CG_V2 , .needs_cgroup_ctrls = (const char *const []){"memory" ,NULL }, };
testcases/kernel/controllers/memcg/memcontrol02.c +14 -14
@@ -26,7 +26,7 @@#include "memcontrol_common.h" static size_t page_size; -static struct tst_cgroup_group *cg_child; +static struct tst_cg_group *cg_child;static int fd;static int file_to_all_error =10 ;
@@ -36,17 +36,17 @@ static void alloc_anon_50M_check(void)char *buf, *ptr;ssize_t anon, current;const char *const anon_key_fmt = -TST_CGROUP_VER_IS_V1 (tst_cgroup,"memory" ) ?"rss %zd" :"anon %zd" ; +TST_CG_VER_IS_V1 (tst_cg,"memory" ) ?"rss %zd" :"anon %zd" ; buf =SAFE_MALLOC (size);for (ptr = buf; ptr < buf + size; ptr += page_size) *ptr =0 ; -SAFE_CGROUP_SCANF (cg_child,"memory.current" ,"%zd" , ¤t); +SAFE_CG_SCANF (cg_child,"memory.current" ,"%zd" , ¤t);TST_EXP_EXPR (current >= size,"(memory.current=%zd) >= (size=%zd)" , current, size); -SAFE_CGROUP_LINES_SCANF (cg_child,"memory.stat" , anon_key_fmt, &anon); +SAFE_CG_LINES_SCANF (cg_child,"memory.stat" , anon_key_fmt, &anon);TST_EXP_EXPR (anon >0 ,"(memory.stat.anon=%zd) > 0" , anon); TST_EXP_EXPR(values_close(size, anon, 3),
@@ -61,20 +61,20 @@ static void alloc_pagecache_50M_check(void)const size_t size =MB (50 );size_t current, file;const char *const file_key_fmt = -TST_CGROUP_VER_IS_V1 (tst_cgroup,"memory" ) ?"cache %zd" :"file %zd" ; +TST_CG_VER_IS_V1 (tst_cg,"memory" ) ?"cache %zd" :"file %zd" ; fd =SAFE_OPEN (TMPDIR "/tmpfile" ,O_RDWR |O_CREAT ,0600 ); -SAFE_CGROUP_SCANF (cg_child,"memory.current" ,"%zu" , ¤t); +SAFE_CG_SCANF (cg_child,"memory.current" ,"%zu" , ¤t);tst_res (TINFO ,"Created temp file: memory.current=%zu" , current);alloc_pagecache (fd, size); -SAFE_CGROUP_SCANF (cg_child,"memory.current" ,"%zu" , ¤t); +SAFE_CG_SCANF (cg_child,"memory.current" ,"%zu" , ¤t);TST_EXP_EXPR (current >= size,"(memory.current=%zu) >= (size=%zu)" , current, size); -SAFE_CGROUP_LINES_SCANF (cg_child,"memory.stat" , file_key_fmt, &file); +SAFE_CG_LINES_SCANF (cg_child,"memory.stat" , file_key_fmt, &file);TST_EXP_EXPR (file >0 ,"(memory.stat.file=%zd) > 0" , file); TST_EXP_EXPR(values_close(file, current, file_to_all_error),
@@ -88,14 +88,14 @@ static void test_memcg_current(unsigned int n) {size_t current; - cg_child =tst_cgroup_group_mk (tst_cgroup,"child" ); -SAFE_CGROUP_SCANF (cg_child,"memory.current" ,"%zu" , ¤t); + cg_child =tst_cg_group_mk (tst_cg,"child" ); +SAFE_CG_SCANF (cg_child,"memory.current" ,"%zu" , ¤t);TST_EXP_EXPR (current ==0 ,"(current=%zu) == 0" , current);if (!SAFE_FORK ()) { -SAFE_CGROUP_PRINTF (cg_child,"cgroup.procs" ,"%d" ,getpid ()); +SAFE_CG_PRINTF (cg_child,"cgroup.procs" ,"%d" ,getpid ()); -SAFE_CGROUP_SCANF (cg_child,"memory.current" ,"%zu" , ¤t); +SAFE_CG_SCANF (cg_child,"memory.current" ,"%zu" , ¤t);tst_res (TINFO ,"Added proc to memcg: memory.current=%zu" , current);
@@ -105,7 +105,7 @@ static void test_memcg_current(unsigned int n)alloc_pagecache_50M_check (); }else {tst_reap_children (); - cg_child =tst_cgroup_group_rm (cg_child); + cg_child =tst_cg_group_rm (cg_child); } }
@@ -125,7 +125,7 @@ static void setup(void)static void cleanup (void ) {if (cg_child) - cg_child =tst_cgroup_group_rm (cg_child); + cg_child =tst_cg_group_rm (cg_child); }static struct tst_test test = {
testcases/kernel/controllers/memcg/memcontrol03.c +30 -30
150 lines not on this page · raw message
testcases/kernel/mem/cpuset/cpuset01.c +7 -7
@@ -51,10 +51,10 @@ static void test_cpuset(void)unsigned long nmask[MAXNODES /BITS_PER_LONG ] = {0 };char buf[BUFSIZ ]; -SAFE_CGROUP_READ (tst_cgroup,"cpuset.cpus" , buf,sizeof (buf)); -SAFE_CGROUP_PRINT (tst_cgroup,"cpuset.cpus" , buf); -SAFE_CGROUP_READ (tst_cgroup,"cpuset.mems" , buf,sizeof (buf)); -SAFE_CGROUP_PRINT (tst_cgroup,"cpuset.mems" , buf); +SAFE_CG_READ (tst_cg,"cpuset.cpus" , buf,sizeof (buf)); +SAFE_CG_PRINT (tst_cg,"cpuset.cpus" , buf); +SAFE_CG_READ (tst_cg,"cpuset.mems" , buf,sizeof (buf)); +SAFE_CG_PRINT (tst_cg,"cpuset.mems" , buf); child =SAFE_FORK ();if (child ==0 ) {
@@ -68,8 +68,8 @@ static void test_cpuset(void)exit (mem_hog_cpuset (ncpus >1 ? ncpus :1 )); } -SAFE_CGROUP_PRINTF (tst_cgroup,"cpuset.mems" ,"%d" , nodes[0 ]); -SAFE_CGROUP_PRINTF (tst_cgroup,"cpuset.mems" ,"%d" , nodes[1 ]); +SAFE_CG_PRINTF (tst_cg,"cpuset.mems" ,"%d" , nodes[0 ]); +SAFE_CG_PRINTF (tst_cg,"cpuset.mems" ,"%d" , nodes[1 ]);tst_reap_children ();
@@ -84,7 +84,7 @@ static void setup(void)if (nnodes <=1 )tst_brk (TCONF ,"requires a NUMA system." ); -SAFE_CGROUP_PRINTF (tst_cgroup,"cgroup.procs" ,"%d" ,getpid ()); +SAFE_CG_PRINTF (tst_cg,"cgroup.procs" ,"%d" ,getpid ()); } static void sighandler(int signo LTP_ATTRIBUTE_UNUSED)
testcases/kernel/mem/include/mem.h +1 -1
@@ -65,7 +65,7 @@ void check_hugepage(void);void write_memcg (void );/* cpuset/memcg - include/tst_cgroup.h */ -void write_cpusets (const struct tst_cgroup_group *cg,long nd); +void write_cpusets (const struct tst_cg_group *cg,long nd);/* shared */ unsigned int get_a_numa_node (void );
testcases/kernel/mem/ksm/ksm02.c +3 -3
@@ -76,10 +76,10 @@ static void verify_ksm(void) }create_same_memory (size, num, unit); -write_cpusets (tst_cgroup, node); -SAFE_CGROUP_PRINTF (tst_cgroup,"cgroup.procs" ,"%d" ,getpid ()); +write_cpusets (tst_cg, node); +SAFE_CG_PRINTF (tst_cg,"cgroup.procs" ,"%d" ,getpid ());create_same_memory (size, num, unit); -SAFE_CGROUP_PRINTF (tst_cgroup_drain,"cgroup.procs" ,"%d" ,getpid ()); +SAFE_CG_PRINTF (tst_cg_drain,"cgroup.procs" ,"%d" ,getpid ()); }static void cleanup (void )
testcases/kernel/mem/ksm/ksm03.c +2 -2
@@ -77,8 +77,8 @@ static void setup(void)parse_ksm_options (opt_sizestr, &size, opt_numstr, &num, opt_unitstr, &unit); -SAFE_CGROUP_PRINTF (tst_cgroup,"cgroup.procs" ,"%d" ,getpid ()); -SAFE_CGROUP_PRINTF (tst_cgroup,"memory.max" ,"%lu" ,TESTMEM ); +SAFE_CG_PRINTF (tst_cg,"cgroup.procs" ,"%d" ,getpid ()); +SAFE_CG_PRINTF (tst_cg,"memory.max" ,"%lu" ,TESTMEM ); }static void cleanup (void )
testcases/kernel/mem/ksm/ksm04.c +3 -3
@@ -67,7 +67,7 @@ static void verify_ksm(void) node =get_a_numa_node ();set_node (nmask, node); -SAFE_CGROUP_PRINTF (tst_cgroup,"memory.max" ,"%lu" ,TESTMEM ); +SAFE_CG_PRINTF (tst_cg,"memory.max" ,"%lu" ,TESTMEM );if (set_mempolicy (MPOL_BIND , nmask,MAXNODES ) ==-1 ) {if (errno !=ENOSYS )
@@ -78,7 +78,7 @@ static void verify_ksm(void) }create_same_memory (size, num, unit); -write_cpusets (tst_cgroup, node); +write_cpusets (tst_cg, node);create_same_memory (size, num, unit); }
@@ -102,7 +102,7 @@ static void setup(void)parse_ksm_options (opt_sizestr, &size, opt_numstr, &num, opt_unitstr, &unit); -SAFE_CGROUP_PRINTF (tst_cgroup,"cgroup.procs" ,"%d" ,getpid ()); +SAFE_CG_PRINTF (tst_cg,"cgroup.procs" ,"%d" ,getpid ()); }static struct tst_test test = {
testcases/kernel/mem/lib/mem.c +4 -4
@@ -632,11 +632,11 @@ static void gather_node_cpus(char *cpus, long nd) cpus[strlen (cpus) -1 ] ='\0' ; } -void write_cpusets (const struct tst_cgroup_group *cg,long nd) +void write_cpusets (const struct tst_cg_group *cg,long nd) {char cpus[BUFSIZ ] ="" ; -SAFE_CGROUP_PRINTF (cg,"cpuset.mems" ,"%ld" , nd); +SAFE_CG_PRINTF (cg,"cpuset.mems" ,"%ld" , nd);gather_node_cpus (cpus, nd);/*
@@ -645,11 +645,11 @@ void write_cpusets(const struct tst_cgroup_group *cg, long nd)* the value of cpuset.cpus. */ if (strlen (cpus) !=0 ) { -SAFE_CGROUP_PRINT (cg,"cpuset.cpus" , cpus); +SAFE_CG_PRINT (cg,"cpuset.cpus" , cpus); }else {tst_res (TINFO ,"No CPUs in the node%ld; " "using only CPU0" , nd); -SAFE_CGROUP_PRINT (cg,"cpuset.cpus" ,"0" ); +SAFE_CG_PRINT (cg,"cpuset.cpus" ,"0" ); } }
testcases/kernel/mem/oom/oom03.c +9 -9
@@ -43,7 +43,7 @@ static void verify_oom(void)#endif testoom (0 ,0 ,ENOMEM ,1 ); -if (SAFE_CGROUP_HAS (tst_cgroup,"memory.swap.max" )) { +if (SAFE_CG_HAS (tst_cg,"memory.swap.max" )) {tst_res (TINFO ,"OOM on MEMCG with special memswap limitation:" );/* * Cgroup v2 tracks memory and swap in separate, which splits
@@ -55,17 +55,17 @@ static void verify_oom(void)* let's scale down the value of 'memory.swap.max' to only * 1MB for CGroup v2. */ -if (!TST_CGROUP_VER_IS_V1 (tst_cgroup,"memory" )) -SAFE_CGROUP_PRINTF (tst_cgroup,"memory.swap.max" ,"%lu" ,MB ); +if (!TST_CG_VER_IS_V1 (tst_cg,"memory" )) +SAFE_CG_PRINTF (tst_cg,"memory.swap.max" ,"%lu" ,MB );else -SAFE_CGROUP_PRINTF (tst_cgroup,"memory.swap.max" ,"%lu" ,TESTMEM +MB ); +SAFE_CG_PRINTF (tst_cg,"memory.swap.max" ,"%lu" ,TESTMEM +MB );testoom (0 ,1 ,ENOMEM ,1 ); -if (TST_CGROUP_VER_IS_V1 (tst_cgroup,"memory" )) -SAFE_CGROUP_PRINTF (tst_cgroup,"memory.swap.max" ,"%lu" , ~0UL ); +if (TST_CG_VER_IS_V1 (tst_cg,"memory" )) +SAFE_CG_PRINTF (tst_cg,"memory.swap.max" ,"%lu" , ~0UL );else -SAFE_CGROUP_PRINT (tst_cgroup,"memory.swap.max" ,"max" ); +SAFE_CG_PRINT (tst_cg,"memory.swap.max" ,"max" ); }/* OOM for MEMCG with mempolicy */
@@ -82,8 +82,8 @@ static void setup(void) overcommit =get_sys_tune ("overcommit_memory" );set_sys_tune ("overcommit_memory" ,1 ,1 ); -SAFE_CGROUP_PRINTF (tst_cgroup,"cgroup.procs" ,"%d" ,getpid ()); -SAFE_CGROUP_PRINTF (tst_cgroup,"memory.max" ,"%lu" ,TESTMEM ); +SAFE_CG_PRINTF (tst_cg,"cgroup.procs" ,"%d" ,getpid ()); +SAFE_CG_PRINTF (tst_cg,"memory.max" ,"%lu" ,TESTMEM ); }static void cleanup (void )
testcases/kernel/mem/oom/oom04.c +4 -4
@@ -45,13 +45,13 @@ static void verify_oom(void)testoom (0 ,0 ,ENOMEM ,1 );if (is_numa (NULL ,NH_MEMS ,2 ) && -SAFE_CGROUP_HAS (tst_cgroup,"cpuset.memory_migrate" )) { +SAFE_CG_HAS (tst_cg,"cpuset.memory_migrate" )) {/* * Under NUMA system, the migration of cpuset's memory * is in charge of cpuset.memory_migrate, we can write * 1 to cpuset.memory_migrate to enable the migration. */ -SAFE_CGROUP_PRINT (tst_cgroup,"cpuset.memory_migrate" ,"1" ); +SAFE_CG_PRINT (tst_cg,"cpuset.memory_migrate" ,"1" );tst_res (TINFO ,"OOM on CPUSET with mem migrate:" );testoom (0 ,0 ,ENOMEM ,1 );
@@ -78,8 +78,8 @@ static void setup(void)if (ret <0 )tst_brk (TBROK ,"Failed to get a memory node " "using get_allowed_nodes()" ); -write_cpusets (tst_cgroup, memnode); -SAFE_CGROUP_PRINTF (tst_cgroup,"cgroup.procs" ,"%d" ,getpid ()); +write_cpusets (tst_cg, memnode); +SAFE_CG_PRINTF (tst_cg,"cgroup.procs" ,"%d" ,getpid ()); }static void cleanup (void )
testcases/kernel/mem/oom/oom05.c +12 -12
@@ -51,29 +51,29 @@ static void verify_oom(void)* 1 to cpuset.memory_migrate to enable the migration. */ if (is_numa (NULL ,NH_MEMS ,2 ) && -SAFE_CGROUP_HAS (tst_cgroup,"cpuset.memory_migrate" )) { -SAFE_CGROUP_PRINT (tst_cgroup,"cpuset.memory_migrate" ,"1" ); +SAFE_CG_HAS (tst_cg,"cpuset.memory_migrate" )) { +SAFE_CG_PRINT (tst_cg,"cpuset.memory_migrate" ,"1" );tst_res (TINFO ,"OOM on CPUSET & MEMCG with " "cpuset.memory_migrate=1" );testoom (0 ,0 ,ENOMEM ,1 ); } -if (SAFE_CGROUP_HAS (tst_cgroup,"memory.swap.max" )) { +if (SAFE_CG_HAS (tst_cg,"memory.swap.max" )) {tst_res (TINFO ,"OOM on CPUSET & MEMCG with " "special memswap limitation:" ); -if (!TST_CGROUP_VER_IS_V1 (tst_cgroup,"memory" )) -SAFE_CGROUP_PRINTF (tst_cgroup,"memory.swap.max" ,"%lu" ,MB ); +if (!TST_CG_VER_IS_V1 (tst_cg,"memory" )) +SAFE_CG_PRINTF (tst_cg,"memory.swap.max" ,"%lu" ,MB );else -SAFE_CGROUP_PRINTF (tst_cgroup,"memory.swap.max" ,"%lu" ,TESTMEM +MB ); +SAFE_CG_PRINTF (tst_cg,"memory.swap.max" ,"%lu" ,TESTMEM +MB );testoom (0 ,1 ,ENOMEM ,1 );tst_res (TINFO ,"OOM on CPUSET & MEMCG with " "disabled memswap limitation:" ); -if (TST_CGROUP_VER_IS_V1 (tst_cgroup,"memory" )) -SAFE_CGROUP_PRINTF (tst_cgroup,"memory.swap.max" ,"%lu" , ~0UL ); +if (TST_CG_VER_IS_V1 (tst_cg,"memory" )) +SAFE_CG_PRINTF (tst_cg,"memory.swap.max" ,"%lu" , ~0UL );else -SAFE_CGROUP_PRINT (tst_cgroup,"memory.swap.max" ,"max" ); +SAFE_CG_PRINT (tst_cg,"memory.swap.max" ,"max" );testoom (0 ,0 ,ENOMEM ,1 ); } }
@@ -99,9 +99,9 @@ void setup(void)tst_brk (TBROK ,"Failed to get a memory node " "using get_allowed_nodes()" ); -write_cpusets (tst_cgroup, memnode); -SAFE_CGROUP_PRINTF (tst_cgroup,"cgroup.procs" ,"%d" ,getpid ()); -SAFE_CGROUP_PRINTF (tst_cgroup,"memory.max" ,"%lu" ,TESTMEM ); +write_cpusets (tst_cg, memnode); +SAFE_CG_PRINTF (tst_cg,"cgroup.procs" ,"%d" ,getpid ()); +SAFE_CG_PRINTF (tst_cg,"memory.max" ,"%lu" ,TESTMEM ); }void cleanup (void )
testcases/kernel/sched/cfs-scheduler/cfs_bandwidth01.c +20 -20
@@ -31,37 +31,37 @@#include "tst_test.h" #include "tst_timer.h" -static struct tst_cgroup_group *cg_level2, *cg_level3a, *cg_level3b; -static struct tst_cgroup_group *cg_workers[3 ]; +static struct tst_cg_group *cg_level2, *cg_level3a, *cg_level3b; +static struct tst_cg_group *cg_workers[3 ];static int may_have_waiters =0 ; -static void set_cpu_quota (const struct tst_cgroup_group *const cg, +static void set_cpu_quota (const struct tst_cg_group *const cg,const float quota_percent) {const unsigned int period_us =10000 ;const unsigned int quota_us = (quota_percent /100 ) * (float )period_us; -if (!TST_CGROUP_VER_IS_V1 (cg,"cpu" )) { -SAFE_CGROUP_PRINTF (cg,"cpu.max" , +if (!TST_CG_VER_IS_V1 (cg,"cpu" )) { +SAFE_CG_PRINTF (cg,"cpu.max" ,"%u %u" , quota_us, period_us); }else { -SAFE_CGROUP_PRINTF (cg,"cpu.cfs_period_us" , +SAFE_CG_PRINTF (cg,"cpu.cfs_period_us" ,"%u" , period_us); -SAFE_CGROUP_PRINTF (cg,"cpu.max" , +SAFE_CG_PRINTF (cg,"cpu.max" ,"%u" , quota_us); }tst_res (TINFO ,"Set '%s/cpu.max' = '%d %d'" , -tst_cgroup_group_name (cg), quota_us, period_us); +tst_cg_group_name (cg), quota_us, period_us); } -static void mk_cpu_cgroup (struct tst_cgroup_group **cg, -const struct tst_cgroup_group *const cg_parent, +static void mk_cpu_cgroup (struct tst_cg_group **cg, +const struct tst_cg_group *const cg_parent,const char *const cg_child_name,const float quota_percent) { - *cg =tst_cgroup_group_mk (cg_parent,"%s" , cg_child_name); + *cg =tst_cg_group_mk (cg_parent,"%s" , cg_child_name);set_cpu_quota (*cg, quota_percent); }
@@ -83,7 +83,7 @@ static void busy_loop(const unsigned int sleep_ms) } } -static void fork_busy_procs_in_cgroup (const struct tst_cgroup_group *const cg) +static void fork_busy_procs_in_cgroup (const struct tst_cg_group *const cg) {const unsigned int sleeps_ms[] = {3000 ,1000 ,10 };const pid_t worker_pid =SAFE_FORK ();
@@ -98,7 +98,7 @@ static void fork_busy_procs_in_cgroup(const struct tst_cgroup_group *const cg)if (!busy_pid)busy_loop (sleeps_ms[i]); -SAFE_CGROUP_PRINTF (cg,"cgroup.procs" ,"%d" , busy_pid); +SAFE_CG_PRINTF (cg,"cgroup.procs" ,"%d" , busy_pid); }tst_reap_children ();
@@ -131,13 +131,13 @@ static void do_test(void)static void setup (void ) { - cg_level2 =tst_cgroup_group_mk (tst_cgroup,"level2" ); + cg_level2 =tst_cg_group_mk (tst_cg,"level2" ); - cg_level3a =tst_cgroup_group_mk (cg_level2,"level3a" ); + cg_level3a =tst_cg_group_mk (cg_level2,"level3a" );mk_cpu_cgroup (&cg_workers[0 ], cg_level3a,"worker1" ,30 );mk_cpu_cgroup (&cg_workers[1 ], cg_level3a,"worker2" ,20 ); - cg_level3b =tst_cgroup_group_mk (cg_level2,"level3b" ); + cg_level3b =tst_cg_group_mk (cg_level2,"level3b" );mk_cpu_cgroup (&cg_workers[2 ], cg_level3b,"worker3" ,30 ); }
@@ -153,15 +153,15 @@ static void cleanup(void)for (i =0 ; i <ARRAY_SIZE (cg_workers); i++) {if (cg_workers[i]) - cg_workers[i] =tst_cgroup_group_rm (cg_workers[i]); + cg_workers[i] =tst_cg_group_rm (cg_workers[i]); }if (cg_level3a) - cg_level3a =tst_cgroup_group_rm (cg_level3a); + cg_level3a =tst_cg_group_rm (cg_level3a);if (cg_level3b) - cg_level3b =tst_cgroup_group_rm (cg_level3b); + cg_level3b =tst_cg_group_rm (cg_level3b);if (cg_level2) - cg_level2 =tst_cgroup_group_rm (cg_level2); + cg_level2 =tst_cg_group_rm (cg_level2); }static struct tst_test test = {
testcases/kernel/syscalls/madvise/madvise06.c +8 -8
@@ -70,10 +70,10 @@ static void print_cgmem(const char *name) {long ret; -if (!SAFE_CGROUP_HAS (tst_cgroup, name)) +if (!SAFE_CG_HAS (tst_cg, name))return ; -SAFE_CGROUP_SCANF (tst_cgroup, name,"%ld" , &ret); +SAFE_CG_SCANF (tst_cg, name,"%ld" , &ret);tst_res (TINFO ,"\t%s: %ld Kb" , name, ret /1024 ); }
@@ -118,18 +118,18 @@ static void setup(void)check_path ("/proc/self/oom_score_adj" );SAFE_FILE_PRINTF ("/proc/self/oom_score_adj" ,"%d" ,-1000 ); -SAFE_CGROUP_PRINTF (tst_cgroup,"memory.max" ,"%ld" ,MEM_LIMIT ); -if (SAFE_CGROUP_HAS (tst_cgroup,"memory.swap.max" )) -SAFE_CGROUP_PRINTF (tst_cgroup,"memory.swap.max" ,"%ld" ,MEMSW_LIMIT ); +SAFE_CG_PRINTF (tst_cg,"memory.max" ,"%ld" ,MEM_LIMIT ); +if (SAFE_CG_HAS (tst_cg,"memory.swap.max" )) +SAFE_CG_PRINTF (tst_cg,"memory.swap.max" ,"%ld" ,MEMSW_LIMIT ); -if (SAFE_CGROUP_HAS (tst_cgroup,"memory.swappiness" )) { -SAFE_CGROUP_PRINT (tst_cgroup,"memory.swappiness" ,"60" ); +if (SAFE_CG_HAS (tst_cg,"memory.swappiness" )) { +SAFE_CG_PRINT (tst_cg,"memory.swappiness" ,"60" ); }else {check_path ("/proc/sys/vm/swappiness" );SAFE_FILE_PRINTF ("/proc/sys/vm/swappiness" ,"%d" ,60 ); } -SAFE_CGROUP_PRINTF (tst_cgroup,"cgroup.procs" ,"%d" ,getpid ()); +SAFE_CG_PRINTF (tst_cg,"cgroup.procs" ,"%d" ,getpid ());meminfo_diag ("Initial meminfo, later values are relative to this (except memcg)" ); init_swap =SAFE_READ_MEMINFO ("SwapTotal:" ) -SAFE_READ_MEMINFO ("SwapFree:" );
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 3/3 memcontrol04: Copy from kselftest
In reply to Richard Palethorpe via ltpAt first glance this test looks the same as memcontrol03. However there are some significant changes which complicate combining the two.
--- runtest/controllers | 1 + testcases/kernel/controllers/memcg/.gitignore | 1 + .../kernel/controllers/memcg/memcontrol04.c | 243 ++++++++++++++++++ 3 files changed, 245 insertions(+) create mode 100644 testcases/kernel/controllers/memcg/memcontrol04.c
runtest/controllers +1 -0
@@ -20,6 +20,7 @@ memcg_control memcg_control_test.sh memcontrol01 memcontrol01 memcontrol02 memcontrol02 memcontrol03 memcontrol03 +memcontrol04 memcontrol04 cgroup_fj_function_debug cgroup_fj_function.sh debug cgroup_fj_function_cpuset cgroup_fj_function.sh cpuset
testcases/kernel/controllers/memcg/.gitignore +1 -0
@@ -8,3 +8,4 @@ memcontrol01 memcontrol02 memcontrol03 +memcontrol04
testcases/kernel/controllers/memcg/memcontrol04.c new file +243 -0
243 lines not on this page · raw message
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp