mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kairui Song <ryncsn@gmail.com>
To: "T.J. Mercier" <tjmercier@google.com>
Cc: roman.gushchin@linux.dev, muchun.song@linux.dev,
	 Andrew Morton <akpm@linux-foundation.org>,
	Kairui Song <kasong@tencent.com>, Qi Zheng <qi.zheng@linux.dev>,
	 Shakeel Butt <shakeel.butt@linux.dev>,
	Barry Song <baohua@kernel.org>,
	 Axel Rasmussen <axelrasmussen@google.com>,
	Yuanchu Xie <yuanchu@google.com>, Wei Xu <weixugc@google.com>,
	 Baoquan He <baoquan.he@linux.dev>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	 David Hildenbrand <david@kernel.org>,
	Lorenzo Stoakes <ljs@kernel.org>,
	 "Liam R. Howlett" <liam@infradead.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	 Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	 Michal Hocko <mhocko@suse.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	cgroups@vger.kernel.org,  linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] mm/vmscan: remove redundant !mem_cgroup_online() checks
Date: Wed, 28 Oct 2026 18:19:59 +0800	[thread overview]
Message-ID: <auHLzLazLr4iA_Pn@KASONG-MC4> (raw)
In-Reply-To: <20261028010611.3929937-2-tjmercier@google.com>

On Tue, Oct 27, 2026 at 06:06:05PM +0800, T.J. Mercier wrote:
> Since commit f1cf8d2f36dc ("mm: memcontrol: eliminate the problem of
> dying memory cgroup for LRU folios") and commit 0e0ac326c511 ("memcg:
> move LRU size accounting on reparenting instead of copying it"),
> mem_cgroup_css_offline() reparents all LRU folios to the parent memcg
> and zeroes the child's lrugen->nr_pages and lru_zone_size before the
> memcg is offlined. Nothing can repopulate the offlined memcg's lruvec
> afterwards. A folio that is off the LRU during reparenting looks up its
> lruvec through its objcg, which now points to the parent so it is put
> back on the parent's LRU.
> 
> As a result, lruvec_lru_size() and lruvec_evictable_size() are always 0
> when !mem_cgroup_online(memcg) is true, making the offlined memcg special
> cases in get_scan_count(), lruvec_is_sizable(), and shrink_one() dead
> code. Remove them.
> 
> With the get_nr_to_scan() special case removed, an offlined memcg that
> still has stale effective protection now has
> apply_proportional_protection() applied like get_scan_count() does, so
> the MGLRU and traditional LRU behavior is now the same.
> 
> Signed-off-by: T.J. Mercier <tjmercier@google.com>
> ---
>  include/linux/mmzone.h |  8 ++++----
>  mm/vmscan.c            | 28 +++++-----------------------
>  2 files changed, 9 insertions(+), 27 deletions(-)

Nice!

> 
> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> index 3b96d6c7123b..7f078ff0dd76 100644
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -638,10 +638,10 @@ struct lru_gen_mm_walk {
>   * The events that trigger the above operations are:
>   * 1. The first attempt to reclaim a memcg below low, which triggers
>   *    MEMCG_LRU_TAIL;
> - * 2. The first attempt to reclaim a memcg offlined or below reclaimable size
> - *    threshold, which triggers MEMCG_LRU_TAIL;
> - * 3. The second attempt to reclaim a memcg offlined or below reclaimable size
> - *    threshold, which triggers MEMCG_LRU_YOUNG;
> + * 2. The first attempt to reclaim a memcg below reclaimable size threshold,
> + *    which triggers MEMCG_LRU_TAIL;
> + * 3. The second attempt to reclaim a memcg below reclaimable size threshold,
> + *    which triggers MEMCG_LRU_YOUNG;
>   * 4. Attempting to reclaim a memcg below min, which triggers MEMCG_LRU_YOUNG;
>   * 5. Finishing the aging on the eviction path, which triggers MEMCG_LRU_YOUNG;
>   * 6. Offlining a memcg, which triggers MEMCG_LRU_OLD.
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 9959ca158ce8..636152d8c94d 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -2754,13 +2754,6 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc,
>  		scan = apply_proportional_protection(memcg, sc, lruvec_size);
>  		scan >>= sc->priority;
>  
> -		/*
> -		 * If the cgroup's already been deleted, make sure to
> -		 * scrape out the remaining cache.
> -		 */
> -		if (!scan && !mem_cgroup_online(memcg))
> -			scan = min(lruvec_size, SWAP_CLUSTER_MAX);
> -
>  		switch (scan_balance) {
>  		case SCAN_EQUAL:
>  			/* Scan lists relative to size */
> @@ -2769,14 +2762,8 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc,
>  			/*
>  			 * Scan types proportional to swappiness and
>  			 * their relative recent reclaim efficiency.
> -			 * Make sure we don't miss the last page on
> -			 * the offlined memory cgroups because of a
> -			 * round-off error.
>  			 */
> -			scan = mem_cgroup_online(memcg) ?
> -			       div64_u64(scan * fraction[file], denominator) :
> -			       DIV64_U64_ROUND_UP(scan * fraction[file],
> -						  denominator);
> +			scan = div64_u64(scan * fraction[file], denominator);
>  			break;
>  		case SCAN_FILE:
>  		case SCAN_ANON:
> @@ -4355,12 +4342,11 @@ static bool lruvec_is_sizable(struct lruvec *lruvec, struct scan_control *sc)
>  {
>  	unsigned long total;
>  	int swappiness = get_swappiness(lruvec, sc);
> -	struct mem_cgroup *memcg = lruvec_memcg(lruvec);
>  
>  	total = lruvec_evictable_size(lruvec, swappiness);
>  
>  	/* whether the size is big enough to be helpful */
> -	return mem_cgroup_online(memcg) ? (total >> sc->priority) : total;
> +	return total >> sc->priority;
>  }
>  
>  static bool lruvec_is_reclaimable(struct lruvec *lruvec, struct scan_control *sc,
> @@ -5199,10 +5185,6 @@ static long get_nr_to_scan(struct lruvec *lruvec, struct scan_control *sc,
>  
>  	evictable = lruvec_evictable_size(lruvec, swappiness);
>  
> -	/* try to scrape all its memory if this memcg was deleted */
> -	if (!mem_cgroup_online(memcg))
> -		return evictable;
> -
>  	nr_to_scan = apply_proportional_protection(memcg, sc, evictable);
>  	nr_to_scan >>= sc->priority;
>  
> @@ -5325,13 +5307,13 @@ static int shrink_one(struct lruvec *lruvec, struct scan_control *sc)
>  
>  	flush_reclaim_state(sc);
>  
> -	if (need_rotate && mem_cgroup_online(memcg))
> +	if (need_rotate)
>  		return MEMCG_LRU_YOUNG;
>  
> -	if (!need_rotate && lruvec_is_sizable(lruvec, sc))
> +	if (lruvec_is_sizable(lruvec, sc))
>  		return 0;
>  
> -	/* one retry if offlined or too small */
> +	/* one retry if too small */
>  	return READ_ONCE(lruvec->lrugen.seg) != MEMCG_LRU_TAIL ?
>  	       MEMCG_LRU_TAIL : MEMCG_LRU_YOUNG;
>  }

This part looks much cleaner, thanks!

Reviewed-by: Kairui Song <kasong@tencent.com>

  parent reply	other threads:[~2026-10-28 10:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28  1:06 [PATCH 0/2] mm/vmscan: remove obsolete offlined memcg reclaim handling T.J. Mercier
2026-10-28  1:06 ` [PATCH 1/2] mm/vmscan: remove redundant !mem_cgroup_online() checks T.J. Mercier
2026-10-28  2:32   ` Balbir Singh
2026-10-28 10:19   ` Kairui Song [this message]
2026-10-28  1:06 ` [PATCH 2/2] mm/mglru: stop rotating offlined memcgs to the old generation T.J. Mercier
2026-10-28  2:42   ` Balbir Singh
2026-10-28 10:43   ` Kairui Song

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=auHLzLazLr4iA_Pn@KASONG-MC4 \
    --to=ryncsn@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=baoquan.he@linux.dev \
    --cc=cgroups@vger.kernel.org \
    --cc=david@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=kasong@tencent.com \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=muchun.song@linux.dev \
    --cc=qi.zheng@linux.dev \
    --cc=roman.gushchin@linux.dev \
    --cc=rppt@kernel.org \
    --cc=shakeel.butt@linux.dev \
    --cc=surenb@google.com \
    --cc=tjmercier@google.com \
    --cc=vbabka@kernel.org \
    --cc=weixugc@google.com \
    --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®