[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241106221434.2029328-2-joshua.hahnjy@gmail.com>
Date: Wed, 6 Nov 2024 14:14:33 -0800
From: Joshua Hahn <joshua.hahnjy@...il.com>
To: shakeel.butt@...ux.dev
Cc: hannes@...xchg.org,
mhocko@...nel.org,
roman.gushchin@...ux.dev,
muchun.song@...ux.dev,
akpm@...ux-foundation.org,
cgroups@...r.kernel.org,
linux-mm@...ck.org,
linux-kernel@...r.kernel.org,
kernel-team@...a.com
Subject: [PATCH 1/2] memcg/hugetlb: Introduce memcg_accounts_hugetlb
This patch isolates the check for whether memcg accounts hugetlb.
This condition can only be true if the memcg mount option
memory_hugetlb_accounting is on, which includes hugetlb usage
in memory.current.
Signed-of-by: Joshua Hahn <joshua.hahnjy@...il.com>
---
include/linux/memcontrol.h | 2 ++
mm/memcontrol.c | 12 ++++++++++--
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 34d2da05f2f1..25761d55799e 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -694,6 +694,8 @@ static inline int mem_cgroup_charge(struct folio *folio, struct mm_struct *mm,
return __mem_cgroup_charge(folio, mm, gfp);
}
+bool memcg_accounts_hugetlb(void);
+
int mem_cgroup_hugetlb_try_charge(struct mem_cgroup *memcg, gfp_t gfp,
long nr_pages);
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 5444d0e7bb64..59dea0122579 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4497,6 +4497,15 @@ int __mem_cgroup_charge(struct folio *folio, struct mm_struct *mm, gfp_t gfp)
return ret;
}
+bool memcg_accounts_hugetlb(void)
+{
+#ifdef CONFIG_HUGETLB_PAGE
+ return cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_HUGETLB_ACCOUNTING;
+#else
+ return false;
+#endif
+}
+
/**
* mem_cgroup_hugetlb_try_charge - try to charge the memcg for a hugetlb folio
* @memcg: memcg to charge.
@@ -4522,8 +4531,7 @@ int mem_cgroup_hugetlb_try_charge(struct mem_cgroup *memcg, gfp_t gfp,
* but do not attempt to commit charge later (or cancel on error) either.
*/
if (mem_cgroup_disabled() || !memcg ||
- !cgroup_subsys_on_dfl(memory_cgrp_subsys) ||
- !(cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_HUGETLB_ACCOUNTING))
+ !cgroup_subsys_on_dfl(memory_cgrp_subsys) || !memcg_accounts_hugetlb())
return -EOPNOTSUPP;
if (try_charge(memcg, gfp, nr_pages))
--
2.43.5
Powered by blists - more mailing lists