[LTP] [PATCH v4] memcg/memcontrol04: Fix judgment for recursive_protection
Jin Guojie
guojie.jin@gmail.com
Fri Feb 14 10:32:19 CET 2025
When recursive_protection is enabled, skip the check for low events of group F.
Signed-off-by: Jin Guojie <guojie.jin@gmail.com>
Suggested-by: Richard Palethorpe <rpalethorpe@suse.com>
Suggested-by: Michal Koutný <mkoutny@suse.com>
Suggested-by: Wei Gao <wegao@suse.com>
Suggested-by: Li Wang <liwang@redhat.com>
---
include/tst_cgroup.h | 2 ++
lib/tst_cgroup.c | 14 +++++++++++++-
testcases/kernel/controllers/memcg/memcontrol04.c | 6 +++++-
3 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/include/tst_cgroup.h b/include/tst_cgroup.h
index d23a8e652..068ff8306 100644
--- a/include/tst_cgroup.h
+++ b/include/tst_cgroup.h
@@ -256,4 +256,6 @@ int safe_cg_occursin(const char *file, const int lineno,
const char *const file_name,
const char *const needle);
+int tst_cg_memory_recursiveprot(struct tst_cg_group *cg);
+
#endif /* TST_CGROUP_H */
diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index aa13ac8ec..61ee3da48 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -76,6 +76,7 @@ struct cgroup_root {
unsigned int we_mounted_it:1;
/* cpuset is in compatability mode */
unsigned int no_cpuset_prefix:1;
+ unsigned int memory_recursiveprot:1;
};
/* Controller sub-systems */
@@ -575,7 +576,8 @@ static void cgroup_root_scan(const char *const mnt_type,
struct cgroup_ctrl *ctrl;
uint32_t ctrl_field = 0;
int no_prefix = 0;
- int nsdelegate = 0;
+ unsigned int nsdelegate = 0;
+ unsigned int memory_recursiveprot = 0;
char buf[BUFSIZ];
char *tok;
const int mnt_dfd = SAFE_OPEN(mnt_dir, O_PATH | O_DIRECTORY);
@@ -592,6 +594,7 @@ static void cgroup_root_scan(const char *const mnt_type,
}
for (tok = strtok(mnt_opts, ","); tok; tok = strtok(NULL, ",")) {
nsdelegate |= !strcmp("nsdelegate", tok);
+ memory_recursiveprot |= !strcmp("memory_recursiveprot", tok);
}
if (root->ver && ctrl_field == root->ctrl_field)
@@ -644,6 +647,7 @@ backref:
root->ctrl_field = ctrl_field;
root->no_cpuset_prefix = no_prefix;
root->nsdelegate = nsdelegate;
+ root->memory_recursiveprot = memory_recursiveprot;
for_each_ctrl(ctrl) {
if (has_ctrl(root->ctrl_field, ctrl))
@@ -1509,3 +1513,11 @@ int safe_cg_occursin(const char *const file,
const int lineno,
return !!strstr(buf, needle);
}
+
+int tst_cg_memory_recursiveprot(struct tst_cg_group *cg)
+{
+ if (cg && cg->dirs_by_ctrl[0]->dir_root)
+ return cg->dirs_by_ctrl[0]->dir_root->memory_recursiveprot;
+ return 0;
+}
+
diff --git a/testcases/kernel/controllers/memcg/memcontrol04.c
b/testcases/kernel/controllers/memcg/memcontrol04.c
index 1b8d115f8..705bf2ebb 100644
--- a/testcases/kernel/controllers/memcg/memcontrol04.c
+++ b/testcases/kernel/controllers/memcg/memcontrol04.c
@@ -210,7 +210,11 @@ static void test_memcg_low(void)
if (i < E) {
TST_EXP_EXPR(low > 0,
"(%c low events=%ld) > 0", id, low);
- } else {
+ } else if (i == E) {
+ TST_EXP_EXPR(low == 0,
+ "(%c low events=%ld) == 0", id, low);
+ } else if (!tst_cg_memory_recursiveprot(leaf_cg[F])) {
+ /* dont not check F when recursive_protection enabled */
TST_EXP_EXPR(low == 0,
"(%c low events=%ld) == 0", id, low);
}
--
2.34.1
More information about the ltp
mailing list