Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@suse.com>
To: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Muchun Song <muchun.song@linux.dev>,
	Joshua Hahn <joshua.hahnjy@gmail.com>,
	Jakub Kicinski <kuba@kernel.org>,
	Meta kernel team <kernel-team@meta.com>,
	linux-mm@kvack.org, cgroups@vger.kernel.org,
	linux-kernel@vger.kernel.org, Joy Chaoyue Xiong <cxiong@meta.com>
Subject: Re: [PATCH v2] memcg: trim the per-cpu charge stock instead of draining it
Date: Fri, 21 Aug 2026 09:45:38 +0200	[thread overview]
Message-ID: <aogCIs5-MCpo9loo@tiehlicka> (raw)
In-Reply-To: <aodk640QxaSa0gVK@linux.dev>

On Thu 20-08-26 13:50:32, Shakeel Butt wrote:
> On Thu, Aug 20, 2026 at 08:44:34PM +0200, Michal Hocko wrote:
> > On Thu 20-08-26 09:06:29, Shakeel Butt wrote:
> > > On Thu, Aug 20, 2026 at 09:06:18AM +0200, Michal Hocko wrote:
> > > > On Wed 19-08-26 18:20:10, Shakeel Butt wrote:
> > > > > @@ -2254,9 +2264,12 @@ static void refill_stock(struct mem_cgroup *memcg, unsigned int nr_pages)
> > > > >  			empty_slot = i;
> > > > >  		if (memcg == READ_ONCE(stock->cached[i])) {
> > > > >  			stock_pages = READ_ONCE(stock->nr_pages[i]) + nr_pages;
> > > > > +			if (stock_pages > MEMCG_STOCK_HIGH) {
> > > > > +				memcg_uncharge(memcg,
> > > > > +					       stock_pages - MEMCG_STOCK_LOW);
> > > > > +				stock_pages = MEMCG_STOCK_LOW;
> > > > 
> > > > I would find it easier to read to keep the update in sync with
> > > > memcg_uncharge, i.e.
> > > > 				stock_pages = WRITE_ONCE(stock_pages - MEMCG_STOCK_LOW)
> > > 
> > > Sorry I am not sure I understand your suggestion. The WRITE_ONCE() is throwing
> > > me off.
> > 
> > Sorry, brainfarth on my end. I meant to say that stock_pages should be
> > updated by the uncharged decrement rather than capping it at MEMCG_STOCK_LOW.
> > So in fact I meant this
> > 				stock_pages = stock_pages - MEMCG_STOCK_LOW;
> > but then shortcuted it to a nonsense.
> 
> To fully understand your suggestion, let me walkthrough the code:
> 
> Let's suppose stock_pages = 65
> 
> 	// Original code does
> 	memcg_uncharge(memcg, stock_pages-MEMCG_STOCK_LOW); // uncharge 33 pages
> 	stock_pages = MEMCG_STOCK_LOW;			    // stock 32 pages
> 
> -----
> 	// You want instead
> 	memcg_uncharge(memcg, MEMCG_STOCK_LOW); 	// uncharge 32 pages
> 	stock_pages = stock_pages-MEMCG_STOCK_LOW	// stock 33 pages
> 	
> 
> Am I understanding you correctly?

Nope you are right, I was clearly not thinking straight.
Sorry about the noise.

-- 
Michal Hocko
SUSE Labs


      reply	other threads:[~2026-08-21  7:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-20  1:20 [PATCH v2] memcg: trim the per-cpu charge stock instead of draining it Shakeel Butt
2026-08-20  7:06 ` Michal Hocko
2026-08-20 16:06   ` Shakeel Butt
2026-08-20 18:44     ` Michal Hocko
2026-08-20 20:50       ` Shakeel Butt
2026-08-21  7:45         ` Michal Hocko [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=aogCIs5-MCpo9loo@tiehlicka \
    --to=mhocko@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=cgroups@vger.kernel.org \
    --cc=cxiong@meta.com \
    --cc=hannes@cmpxchg.org \
    --cc=joshua.hahnjy@gmail.com \
    --cc=kernel-team@meta.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=muchun.song@linux.dev \
    --cc=roman.gushchin@linux.dev \
    --cc=shakeel.butt@linux.dev \
    /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