All of 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>, Tejun Heo <tj@kernel.org>,
	Meta kernel team <kernel-team@meta.com>,
	cgroups@vger.kernel.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH for-7.5 3/5] memcg: use high_work for remote charges
Date: Wed, 14 Oct 2026 13:29:26 +0200	[thread overview]
Message-ID: <as9nlkBxzFZSLd5K@tiehlicka> (raw)
In-Reply-To: <20261010210957.1350874-4-shakeel.butt@linux.dev>

On Sat 10-10-26 14:09:55, Shakeel Butt wrote:
> Some charges go to a cgroup outside the current mm's cgroup and its
> ancestors. The high handler uses current->mm, so it cannot handle these
> overages. Filesystem notifications and remote page faults can take
> this path.

Hmm, you made me look at other places in the charge path where we are
assuming current->memcg == memcg. We have reclaim recursion and oom
checks. The former makes sense, for the latter it is likely not
harmful.

> Use mm_match_cgroup() before checking the high limits. If it does not
> match, use high_work instead of recording task overage or doing
> synchronous reclaim and throttling. Charges to the same cgroup or an
> ancestor keep their current handling. Tasks without an mm also use the
> worker.
> 
> Like kernel threads, remote chargers skip memory.swap.high throttling
> and its high-event reporting, and a fast allocator can outrun the worker.
> The memory.max and memory.swap.max checks stay the same.

Makes sense.

> Suggested-by: Tejun Heo <tj@kernel.org>
> Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>

Acked-by: Michal Hocko <mhocko@suse.com>
Thanks!

> ---
>  mm/memcontrol.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 8116fce6ab96..3456960cbe68 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -2705,7 +2705,8 @@ static void memcg_enforce_high(struct mem_cgroup *memcg, unsigned int nr_pages,
>  			       gfp_t gfp_mask)
>  {
>  	bool allow_spinning = gfpflags_allow_spinning(gfp_mask);
> -	bool use_worker = !in_task() || (current->flags & PF_KTHREAD);
> +	bool use_worker = !in_task() || (current->flags & PF_KTHREAD) ||
> +		!current->mm || !mm_match_cgroup(current->mm, memcg);
>  
>  	/*
>  	 * If the hierarchy is above the normal consumption range, schedule
> @@ -2728,6 +2729,7 @@ static void memcg_enforce_high(struct mem_cgroup *memcg, unsigned int nr_pages,
>  		 * Don't make an unrelated interrupted task handle this charge.
>  		 * Kernel threads may be working for other tasks, so let a worker
>  		 * reclaim instead.
> +		 * Remote charges need reclaim from their charged hierarchy.
>  		 */
>  		if (use_worker) {
>  			if (mem_high) {
> @@ -2756,7 +2758,7 @@ static void memcg_enforce_high(struct mem_cgroup *memcg, unsigned int nr_pages,
>  		}
>  	} while ((memcg = parent_mem_cgroup(memcg)));
>  
> -	/* Interrupts and kernel threads stop here. */
> +	/* Interrupts, kernel threads, and remote chargers stop here. */
>  	if (use_worker)
>  		return;
>  
> -- 
> 2.53.0-Meta

-- 
Michal Hocko
SUSE Labs

  reply	other threads:[~2026-10-14 11:29 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-10 21:09 [PATCH for-7.5 0/5] memcg: clean up memory.high enforcement Shakeel Butt
2026-10-10 21:09 ` [PATCH for-7.5 1/5] memcg: move memory.high enforcement out of try_charge_memcg() Shakeel Butt
2026-10-12 13:22   ` Harry Yoo
2026-10-12 17:13     ` Shakeel Butt
2026-10-14 11:13   ` Michal Hocko
2026-10-10 21:09 ` [PATCH for-7.5 2/5] memcg: use high_work for kernel threads Shakeel Butt
2026-10-14 11:21   ` Michal Hocko
2026-10-10 21:09 ` [PATCH for-7.5 3/5] memcg: use high_work for remote charges Shakeel Butt
2026-10-14 11:29   ` Michal Hocko [this message]
2026-10-10 21:09 ` [PATCH for-7.5 4/5] memcg: avoid queuing high_work from reclaim Shakeel Butt
2026-10-14 11:39   ` Michal Hocko
2026-10-14 16:06     ` Shakeel Butt
2026-10-10 21:09 ` [PATCH for-7.5 5/5] memcg: simplify high limit handling after a charge Shakeel Butt
2026-10-14 11:46   ` Michal Hocko

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=as9nlkBxzFZSLd5K@tiehlicka \
    --to=mhocko@suse.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=muchun.song@linux.dev \
    --cc=roman.gushchin@linux.dev \
    --cc=shakeel.butt@linux.dev \
    --cc=tj@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.