Re: [PATCH 2/3] memcg/hugetlb: Introduce mem_cgroup_charge_hugetlb

From: SeongJae Park
Date: Fri Nov 08 2024 - 20:03:28 EST


Hi Joshua,

On Fri, 8 Nov 2024 13:29:45 -0800 Joshua Hahn <joshua.hahnjy@xxxxxxxxx> wrote:

> This patch introduces mem_cgroup_charge_hugetlb, which combines the
> logic of mem_cgroup{try,commit}_hugetlb. This reduces the footprint of

Nit. Seems the regular expression is not technically correct?

> memcg in hugetlb code, and also consolidates the error path that memcg
> can take into just one point.
>
> Signed-off-by: Joshua Hahn <joshua.hahnjy@xxxxxxxxx>
>
> ---
> include/linux/memcontrol.h | 2 ++
> mm/hugetlb.c | 34 ++++++++++++----------------------
> mm/memcontrol.c | 19 +++++++++++++++++++
> 3 files changed, 33 insertions(+), 22 deletions(-)
[...]
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 97f63ec9c9fb..95ee77fe27af 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -4529,6 +4529,25 @@ int mem_cgroup_hugetlb_try_charge(struct mem_cgroup *memcg, gfp_t gfp,
> return 0;
> }
>
> +int mem_cgroup_charge_hugetlb(struct folio *folio, gfp_t gfp)

Can we add a kernel-doc comment for this function? Maybe that for
mem_cgroup_hugetlb_try_charge() can be stolen with only small updates?

> +{
> + struct mem_cgroup *memcg = get_mem_cgroup_from_current();
> + int ret = 0;
> +
> + if (mem_cgroup_disabled() || !memcg_accounts_hugetlb() ||
> + !memcg || !cgroup_subsys_on_dfl(memory_cgrp_subsys)) {
> + ret = -EOPNOTSUPP;
> + goto out;
> + }
> +
> + if (charge_memcg(folio, memcg, gfp))
> + ret = -ENOMEM;
> +
> +out:
> + mem_cgroup_put(memcg);
> + return ret;
> +}
> +
> /**
> * mem_cgroup_swapin_charge_folio - Charge a newly allocated folio for swapin.
> * @folio: folio to charge.
> --
> 2.43.5


Thanks,
SJ