From: Joshua Hahn <joshua.hahnjy@gmail.com>
To: shakeel.butt@linux.dev
Cc: hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev,
muchun.song@linux.dev, akpm@linux-foundation.org, sj@kernel.org,
cgroups@vger.kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, kernel-team@meta.com
Subject: [v3 PATCH 0/3] memcg/hugetlb: Rework memcg hugetlb charging
Date: Wed, 11 Dec 2024 12:39:48 -0800 [thread overview]
Message-ID: <20241211203951.764733-1-joshua.hahnjy@gmail.com> (raw)
This series cleans up memcg's hugetlb charging logic by deprecating the
current memcg hugetlb try-charge + {commit, cancel} logic present in
alloc_hugetlb_folio. A single function mem_cgroup_charge_hugetlb takes
its place instead. This makes the code more maintainable by simplifying
the error path and reduces memcg's footprint in hugetlb logic.
This patch introduces a few changes in the hugetlb folio allocation
error path:
(a) Instead of having multiple return points, we consolidate them to
two: one for reaching the memcg limit or running out of memory
(-ENOMEM) and one for hugetlb allocation fails / limit being
reached (-ENOSPC).
(b) Previously, the memcg limit was checked before the folio is acquired,
meaning the hugeTLB folio isn't acquired if the limit is reached.
This patch performs the charging after the folio is reached, meaning
if memcg's limit is reached, the acquired folio is freed right away.
This patch builds on two earlier patch series: [2] which adds memcg
hugeTLB counters, and [3] which deprecates charge moving and removes the
last references to mem_cgroup_cancel_charge. The request for this cleanup
can be found in [2].
Suggested-by: Shakeel Butt <shakeel.butt@linux.dev>
Signed-off-by: Joshua Hahn <joshua.hahnjy@gmail.com>
[1] https://lore.kernel.org/all/20231006184629.155543-1-nphamcs@gmail.com/
[2] https://lore.kernel.org/all/20241101204402.1885383-1-joshua.hahnjy@gmail.com/
[3] https://lore.kernel.org/linux-mm/20241025012304.2473312-1-shakeel.butt@linux.dev/
---
Changelog
v3:
* Fixed build error where mem_cgroup_charge_hugetlb was defined inside
an #ifdef CONFIG_MEMCG. It is now defined in the #else case as well.
* memcg_accounts_hugetlb is no longer forward-declared, just
statically defined earlier.
* The #ifdef is moved outside memcg_accounts_hugetlb's definition.
* lruvec_stat_mod_folio() is now called only except when memcg
charging fails. That is, even when memcg is not supported or memcg
does not account hugetlb, we still update the (global) stats.
* For this to happen, memcg_charge_hugetlb no longer returns
-EOPNOTSUPP, just returns 0 when it is not supported.
* kernel-doc comment added for mem_cgroup_charge_hugetlb
* s/deprecate/remove in commit messages for clarity.
* Thank you Shakeel, Yosry, and SJ for your input!
v2:
* Removed declaration of memcg_accounts_hugetlb from memcontrol.h
* Moved second call to memcg_accounts_hugetlb from 2nd patch to 1st
* Changed error behavior in alloc_hugetlb_folio: v1 included a bug
that uncharged hugetlb_cgroup twice when memecg's limit was reached
* mem_cgroup_charge_hugetlb no longer called with hugetlb_lock held
* Moved mem_cgroup_hugetlb_{try, charge} deprecation to patch 3
* mem_cgroup_charge_hugetlb always decrements memcg's refcount
* Fully cleaned up mem_cgroup_{cancel,commit}_charge
* Fixed typos
Joshua Hahn (3):
memcg/hugetlb: Introduce memcg_accounts_hugetlb
memcg/hugetlb: Introduce mem_cgroup_charge_hugetlb
memcg/hugetlb: Remove memcg hugetlb try-commit-cancel protocol
include/linux/memcontrol.h | 21 ++-------
mm/hugetlb.c | 35 ++++++---------
mm/memcontrol.c | 92 ++++++++++++++++----------------------
3 files changed, 56 insertions(+), 92 deletions(-)
--
base-commit: 9f16d5e6f220661f73b36a4be1b21575651d8833
2.43.5
next reply other threads:[~2024-12-11 20:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-11 20:39 Joshua Hahn [this message]
2024-12-11 20:39 ` [v3 PATCH 1/3] memcg/hugetlb: Introduce memcg_accounts_hugetlb Joshua Hahn
2024-12-11 22:05 ` Shakeel Butt
2024-12-14 1:28 ` Nhat Pham
2024-12-11 20:39 ` [v3 PATCH 2/3] memcg/hugetlb: Introduce mem_cgroup_charge_hugetlb Joshua Hahn
2024-12-11 22:06 ` Shakeel Butt
2024-12-14 1:29 ` Nhat Pham
2024-12-11 20:39 ` [PATCH 3/3] memcg/hugetlb: Remove memcg hugetlb try-commit-cancel protocol Joshua Hahn
2024-12-14 1:30 ` Nhat Pham
2024-12-16 3:03 ` Joshua Hahn
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=20241211203951.764733-1-joshua.hahnjy@gmail.com \
--to=joshua.hahnjy@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=sj@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox