mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joshua Hahn <joshua.hahnjy@gmail.com>
To: Alexandre Ghiti <alex@ghiti.fr>
Cc: alexandre@ghiti.fr, Andrew Morton <akpm@linux-foundation.org>,
	Barry Song <baohua@kernel.org>, Ben Segall <bsegall@google.com>,
	cgroups@vger.kernel.org,
	Chengming Zhou <chengming.zhou@linux.dev>,
	Christoph Lameter <cl@gentwo.org>,
	David Hildenbrand <david@kernel.org>,
	Dennis Zhou <dennis@kernel.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Ingo Molnar <mingo@redhat.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Kairui Song <kasong@tencent.com>,
	Kent Overstreet <kent.overstreet@linux.dev>,
	K Prateek Nayak <kprateek.nayak@amd.com>,
	"Liam R. Howlett" <liam@infradead.org>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	Lorenzo Stoakes <ljs@kernel.org>, Mel Gorman <mgorman@suse.de>,
	Michal Hocko <mhocko@kernel.org>, Mike Rapoport <rppt@kernel.org>,
	Minchan Kim <minchan@kernel.org>,
	Muchun Song <muchun.song@linux.dev>,
	Nhat Pham <nphamcs@gmail.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Qi Zheng <qi.zheng@linux.dev>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	Steven Rostedt <rostedt@goodmis.org>,
	Suren Baghdasaryan <surenb@google.com>, Tejun Heo <tj@kernel.org>,
	Valentin Schneider <vschneid@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Vlastimil Babka <vbabka@kernel.org>, Wei Xu <weixugc@google.com>,
	Yosry Ahmed <yosry@kernel.org>, Yuanchu Xie <yuanchu@google.com>
Subject: Re: [PATCH v2 4/9] mm: percpu: Split memcg charging and kmem accounting
Date: Mon, 29 Jun 2026 12:10:26 -0700	[thread overview]
Message-ID: <20260629191026.2124952-1-joshua.hahnjy@gmail.com> (raw)
In-Reply-To: <20260626102358.1603618-5-alex@ghiti.fr>

> This is preparatory patch for upcoming per-memcg-per-node kmem
> accounting.

Hi Alex, I hope you are doing well. Thank you for the series!
And sorry that I took so long to review. I'm slowly going through the
series, so I expect to leave more comments in the future. 

> Percpu allocations charge memory before knowing which NUMA nodes the
> pages will land on. So we need to decouple the memcg charging from the
> kmem accounting:
> 
> 1. In the pre-alloc hook, obj_cgroup_precharge() reserves pages for
>    memcg limit enforcement without updating kmem stats.
> 2. In the post-alloc hook, obj_cgroup_account_kmem() accounts kmem
>    and places the sub-page remainder into the obj stock after the
>    allocation succeeds.
> 
> Because of that decoupling, we must not rely on the stock in the
> precharge function and always charge the necessary pages that will
> be accounted after the allocations happened.

I was thinking about this, I think the reality of the sitaution is
actually a bit better than the description makes it seem. We're still
using stock, just a different level so we're not losing any
fastpath at all. Previously we would use the objcg stock to do the
charge quickly, but if we're going straight to memcg charging, we'll
be using the memcg stock instead. Maybe a clarification here that
we're not relying on the obj_stock would help your case here : -)

> That means we may
> temporarily overcharge the memcg but the obj_stock draining will get
> things back to normal.

Nice, this is quite clean. We might hit memcg limits faster because
we overcharge up to PAGE_SIZE bytes but... I'm not sure if this is even
worth noting since the window is so small. 

I think in all the places where you use PAGE_ALIGN(x) >> PAGE_SHIFT
we can instead use PFN_UP(x)? Or maybe DIV_ROUND_UP(x, PAGE_SIZE)?
Just thought that this way we could avoid some of the two-line function
calls ; -)

> Signed-off-by: Alexandre Ghiti <alex@ghiti.fr>

Anyways I think the split looks clean and makes sense to me. Sashiko
raised no concerns either, just wanted to note some nits. I imagine
there will be a v3 in the future? I think this patch looks good but
I will wait until the next version to leave my signatures in case
some of the context changes.

Thanks again, Alex! I hope you have a great day,
Joshua

  reply	other threads:[~2026-06-29 19:10 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-26 10:20 [RESEND PATCH v2 0/9] per-memcg-per-node " Alexandre Ghiti
2026-06-26 10:20 ` [PATCH v2 1/9] memcg: convert task->objcg to a per-node objcgs array Alexandre Ghiti
2026-06-26 10:20 ` [PATCH v2 2/9] memcg: charge kmem pages and slab objects against per-node objcg Alexandre Ghiti
2026-06-26 10:20 ` [PATCH v2 3/9] mm: percpu: fix obj_exts metadata charge size Alexandre Ghiti
2026-06-26 10:20 ` [PATCH v2 4/9] mm: percpu: Split memcg charging and kmem accounting Alexandre Ghiti
2026-06-29 19:10   ` Joshua Hahn [this message]
2026-06-26 10:20 ` [PATCH v2 5/9] mm: memcontrol: track MEMCG_KMEM per NUMA node Alexandre Ghiti
2026-06-26 10:20 ` [PATCH v2 6/9] mm: percpu: per-node kmem accounting Alexandre Ghiti
2026-06-26 10:20 ` [PATCH v2 7/9] mm: percpu: per-node kmem accounting for obj_exts metadata Alexandre Ghiti
2026-06-26 10:20 ` [PATCH v2 8/9] mm: percpu: skip the per-cpu node walk on single-node systems Alexandre Ghiti
2026-06-26 10:20 ` [PATCH v2 9/9] mm: zswap: per-node kmem accounting for zswap/zsmalloc Alexandre Ghiti
2026-06-26 14:32   ` Usama Arif
2026-06-26 18:36     ` Nhat Pham
2026-06-29 13:38       ` Alexandre Ghiti
2026-06-29 18:08         ` Nhat Pham
2026-06-29 13:14     ` Alexandre Ghiti
2026-06-29 18:14       ` Nhat Pham

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=20260629191026.2124952-1-joshua.hahnjy@gmail.com \
    --to=joshua.hahnjy@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=alex@ghiti.fr \
    --cc=alexandre@ghiti.fr \
    --cc=baohua@kernel.org \
    --cc=bsegall@google.com \
    --cc=cgroups@vger.kernel.org \
    --cc=chengming.zhou@linux.dev \
    --cc=cl@gentwo.org \
    --cc=david@kernel.org \
    --cc=dennis@kernel.org \
    --cc=dietmar.eggemann@arm.com \
    --cc=hannes@cmpxchg.org \
    --cc=juri.lelli@redhat.com \
    --cc=kasong@tencent.com \
    --cc=kent.overstreet@linux.dev \
    --cc=kprateek.nayak@amd.com \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mgorman@suse.de \
    --cc=mhocko@kernel.org \
    --cc=minchan@kernel.org \
    --cc=mingo@redhat.com \
    --cc=muchun.song@linux.dev \
    --cc=nphamcs@gmail.com \
    --cc=peterz@infradead.org \
    --cc=qi.zheng@linux.dev \
    --cc=roman.gushchin@linux.dev \
    --cc=rostedt@goodmis.org \
    --cc=rppt@kernel.org \
    --cc=senozhatsky@chromium.org \
    --cc=shakeel.butt@linux.dev \
    --cc=surenb@google.com \
    --cc=tj@kernel.org \
    --cc=vbabka@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    --cc=weixugc@google.com \
    --cc=yosry@kernel.org \
    --cc=yuanchu@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®