All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wei Gao via ltp <ltp@lists.linux.it>
To: Jin Guojie <guojie.jin@gmail.com>
Cc: "Michal Koutný" <mkoutny@suse.com>, ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v2] memcg/memcontrol04: Fix judgment for recursive_protection
Date: Mon, 23 Dec 2024 21:40:41 -0500	[thread overview]
Message-ID: <Z2ofKS5Aqytyp1d1@wegao> (raw)
In-Reply-To: <CA+B+MYSO4HM9aBWEyCszC3-VrYvyv5DCs2ofaheHpsw0j7jiXQ@mail.gmail.com>

On Thu, Dec 19, 2024 at 02:08:59PM +0800, Jin Guojie wrote:
> V2:
> * Change the expected events in F depending on memory_recursiveprot
> 
> In Patch v1[1], the role of recursive_protection in cgoup v2 was not considered.
> 
> By carefully reading the algorithm in the kernel function
> effective_protection(). When memory_recursiveprot is enabled, a
> subgroup with usage > 0 can get unclaimed greater than 0.
> 
> The purpose of doing this should be to achieve the essential purpose
> of recursive_protection: the sum of all subgroups' unprotected values
> is equal to parent's unprotected values.
> 
> Even though the documentation does not give an explicit description
> for recursive_memoryprot, it looks like the kernel's processing
> algorithm is reasonable.
> 
> Based on the idea of [2], Patch v2 is rewritten to determine whether
> memory_recursiveprot is enabled.
> 
> On distributions with memory_recursiveprot enabled by default (from
> Ubuntu 22.04 to 24.10), running this passes:
> 
> memcontrol04.c:208: TPASS: Expect: (C oom events=0) == 0
> memcontrol04.c:211: TPASS: Expect: (C low events=966) > 0
> memcontrol04.c:208: TPASS: Expect: (D oom events=0) == 0
> memcontrol04.c:211: TPASS: Expect: (D low events=966) > 0
> memcontrol04.c:208: TPASS: Expect: (E oom events=0) == 0
> memcontrol04.c:214: TPASS: Expect: (E low events=0) == 0
> memcontrol04.c:208: TPASS: Expect: (F oom events=0) == 0
> memcontrol04.c:211: TPASS: Expect: (F low events=874) > 0
> 
> [1] https://lists.linux.it/pipermail/ltp/2024-November/040946.html
> [2] https://lore.kernel.org/ltp/20220222144511.GA12037@blackbody.suse.cz/
> 
> Signed-off-by: Jin Guojie <guojie.jin@gmail.com>
> Suggested-by: Richard Palethorpe <rpalethorpe@suse.com>
> Suggested-by: Michal Koutný <mkoutny@suse.com>
> ---
>  include/tst_cgroup.h                              |  2 ++
>  lib/tst_cgroup.c                                  | 12 ++++++++++++
>  testcases/kernel/controllers/memcg/memcontrol04.c |  2 +-
>  3 files changed, 15 insertions(+), 1 deletion(-)
> 
> 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 6055015eb..9e3b21ed0 100644
> --- a/lib/tst_cgroup.c
> +++ b/lib/tst_cgroup.c
> @@ -76,6 +76,8 @@ struct cgroup_root {
>         int we_mounted_it:1;
>         /* cpuset is in compatability mode */
>         int no_cpuset_prefix:1;
> +
> +       int memory_recursiveprot:1;
>  };
> 
>  /* Controller sub-systems */
> @@ -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);
> +               root->memory_recursiveprot |=
> !strcmp("memory_recursiveprot", tok);
>         }
> 
>         if (root->ver && ctrl_field == root->ctrl_field)
> @@ -718,6 +721,7 @@ mount:
>                 tst_res(TINFO, "Mounted V2 CGroups on %s", mnt_path);
>                 tst_cg_scan();
>                 roots[0].we_mounted_it = 1;
> +               roots[0].memory_recursiveprot = 1;
>                 return;
>         }
> 
> @@ -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..9e9d6ab6e 100644
> --- a/testcases/kernel/controllers/memcg/memcontrol04.c
> +++ b/testcases/kernel/controllers/memcg/memcontrol04.c
> @@ -207,7 +207,7 @@ static void test_memcg_low(void)
> 
>                 TST_EXP_EXPR(oom == 0, "(%c oom events=%ld) == 0", id, oom);
> 
> -               if (i < E) {
> +               if (i < E || ((i == F) &&
> tst_cg_memory_recursiveprot(leaf_cg[F]))) {
>                         TST_EXP_EXPR(low > 0,
>                                      "(%c low events=%ld) > 0", id, low);
>                 } else {
> --
Maybe just give a warning instead of error if event of F > 0, since event of F > 0 has no
real impact on end user, at the same time maybe we will get a fix in kernel side to correct
this behavior.
> 2.34.1
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2024-12-24  2:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <31564d54-4fea-4450-997d-45e14c4957f4.jinguojie.jgj@alibaba-inc.com>
2024-12-19  6:08 ` [LTP] [PATCH v2] memcg/memcontrol04: Fix judgment for recursive_protection Jin Guojie
2024-12-24  2:40   ` Wei Gao via ltp [this message]
2024-12-25 11:38   ` Li Wang
2024-12-25 11:56     ` Li Wang
2025-01-09  6:53     ` Li Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z2ofKS5Aqytyp1d1@wegao \
    --to=ltp@lists.linux.it \
    --cc=guojie.jin@gmail.com \
    --cc=mkoutny@suse.com \
    --cc=wegao@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.