From: sashiko-bot@kernel.org
To: "Harshal Patil" <harpatil@redhat.com>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Hocko" <mhocko@kernel.org>,
"Roman Gushchin" <roman.gushchin@linux.dev>,
"Shakeel Butt" <shakeel.butt@linux.dev>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Tejun Heo" <tj@kernel.org>
Cc: "Muchun Song" <muchun.song@linux.dev>,
"Michal Koutný" <mkoutny@suse.com>,
"Nhat Pham" <nphamcs@gmail.com>,
"Frank van der Linden" <fvdl@google.com>,
"Yosry Ahmed" <yosry@kernel.org>,
"Waiman Long" <longman@redhat.com>,
"Oscar Salvador" <osalvador@suse.de>,
"David Hildenbrand" <david@kernel.org>,
"Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Randy Dunlap" <rdunlap@infradead.org>,
linux-mm@kvack.org
Subject: Re: [RFC PATCH] mm: memcontrol: let a cgroup opt out of HugeTLB accounting
Date: Wed, 25 Nov 2026 00:32:29 +0000 [thread overview]
Message-ID: <sashiko-outbox-232294@kernel.org> (raw)
In-Reply-To: <20261124003145.80705-1-harpatil@redhat.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] selftests: cgroup: unflushed root hugetlb stat in
hugetlb_opt_out_program()
- [Low] selftests: cgroup: silent skip in test_hugetlb_memcg_opt_out()
--
commit 7608afc552161fa7f74ef34d7e8ac3bc7ba49d98
Author: Harshal Patil <harpatil@redhat.com>
mm: memcontrol: let a cgroup opt out of HugeTLB accounting
This commit adds a non-root cgroup v2 control file,
memory.hugetlb_accounting, that allows a cgroup and its descendants to
opt out of HugeTLB memory accounting so that HugeTLB folios are charged
to the parent of the topmost ancestor that opted out, and extends the
hugetlb memcg selftest to cover it.
Link: https://lore.kernel.org/all/CAPTztWY8eDSa1qKx35hTm5ef+e13SDnRHDrevc-1V1v7-pEP3w@mail.gmail.com/ [1]
Link: https://lore.kernel.org/all/ZRQQMABiVIcXXcrg@dhcp22.suse.cz/ [2]
Link: https://github.com/systemd/systemd/pull/39486 [3]
Link: https://lore.kernel.org/all/ZRrI90KcRBwVZn%2Fr@dhcp22.suse.cz/ [4]
Link: https://lore.kernel.org/all/20231002162133.GC5054@cmpxchg.org/ [5]
Link: https://lore.kernel.org/all/CAKEwX=OwrMNMAvve9a965mBJm8as+njtXE993VcnKXdccd5GEw@mail.gmail.com/ [6]
Link: https://github.com/kubernetes/kubernetes/issues/144131#issuecomment-7104174643 [7]
> diff --git a/tools/testing/selftests/cgroup/test_hugetlb_memcg.c b/tools/testing/selftests/cgroup/test_hugetlb_memcg.c
> index 8c5aced813b62..54e34ee79131b 100644
> --- a/tools/testing/selftests/cgroup/test_hugetlb_memcg.c
> +++ b/tools/testing/selftests/cgroup/test_hugetlb_memcg.c
[ ... ]
> @@ -196,13 +201,197 @@ static int test_hugetlb_memcg(char *root)
> +static int hugetlb_opt_out_program(const char *cgroup, void *arg)
> +{
> + struct opt_out_args *args = arg;
> + long root, child, parent, grandparent, cur;
> + int ret = EXIT_FAILURE;
> + void *addr;
> +
> + root = root_hugetlb(args->root);
[ ... ]
> + /* memory.stat is flushed lazily, give the root time to catch up */
> + cur = cg_read_key_long_poll(args->root, "memory.stat", "hugetlb ",
> + root + LENGTH, 30, DEFAULT_WAIT_INTERVAL_US);
> + if (cur < 0 || !opt_out_charged("root", cur - root, true))
> + goto out;
> +
> + munmap(addr, LENGTH);
> + cur = cg_read_long(args->grandparent, "memory.current");
> + if (cur < 0 || cur - grandparent >= MB(2)) {
> + ksft_print_msg("memory usage should go back down.\n");
> + ksft_print_msg("grandparent memory is now %ld, was %ld\n",
> + cur, grandparent);
> + return ret;
> + }
> +
> + return EXIT_SUCCESS;
[Severity: Medium]
Should hugetlb_opt_out_program() also poll args->root memory.stat after
munmap() until "hugetlb " returns to root?
test_hugetlb_memcg_opt_out() runs hugetlb_opt_out_program() four times
back to back. Reading memory.stat only flushes rstat synchronously when
pending updates exceed MEMCG_CHARGE_BATCH * num_online_cpus():
mm/memcontrol.c:memcg_vmstats_needs_flush() {
return atomic_long_read(&vmstats->stats_updates) >
MEMCG_CHARGE_BATCH * num_online_cpus();
}
Unmapping 8 MB (2048 base pages) does not exceed that threshold on
machines with 32 or more online CPUs, so the next run's non-polling
root_hugetlb(args->root) can snapshot the stale pre-munmap value. Once
rstat flushes both the -8 MB unmap and the new +8 MB fault, "hugetlb "
settles back at root instead of root + LENGTH and
cg_read_key_long_poll() times out. In the fourth run where grandparent
also opts out, grandparent memory.current is never charged, so polling
root memory.stat after munmap() is also needed to verify that the
uncharge took effect.
[ ... ]
> +static int test_hugetlb_memcg_opt_out(char *root)
> +{
[ ... ]
> + if (cg_read_long(child, "memory.hugetlb_accounting") < 0) {
> + ret = KSFT_SKIP;
> + goto out;
> + }
[Severity: Low]
Could this log a message with ksft_print_msg() before returning
KSFT_SKIP, so the skip output explains that memory.hugetlb_accounting is
not available?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124003145.80705-1-harpatil@redhat.com?part=1
prev parent reply other threads:[~2026-11-25 0:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 0:31 [RFC PATCH] mm: memcontrol: let a cgroup opt out of HugeTLB accounting Harshal Patil
2026-11-25 0:32 ` sashiko-bot [this message]
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=sashiko-outbox-232294@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=corbet@lwn.net \
--cc=david@kernel.org \
--cc=fvdl@google.com \
--cc=hannes@cmpxchg.org \
--cc=harpatil@redhat.com \
--cc=linux-mm@kvack.org \
--cc=longman@redhat.com \
--cc=mhocko@kernel.org \
--cc=mkoutny@suse.com \
--cc=muchun.song@linux.dev \
--cc=nphamcs@gmail.com \
--cc=osalvador@suse.de \
--cc=rdunlap@infradead.org \
--cc=roman.gushchin@linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=skhan@linuxfoundation.org \
--cc=tj@kernel.org \
--cc=yosry@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