Linux cgroups development
 help / color / mirror / Atom feed
From: Johannes Weiner <hannes@cmpxchg.org>
To: Usama Arif <usama.arif@linux.dev>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@kernel.org>,
	Lorenzo Stoakes <ljs@kernel.org>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	Michal Hocko <mhocko@kernel.org>,
	Dave Chinner <david@fromorbit.com>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Muchun Song <muchun.song@linux.dev>,
	Qi Zheng <qi.zheng@linux.dev>,
	Yosry Ahmed <yosry.ahmed@linux.dev>, Zi Yan <ziy@nvidia.com>,
	"Liam R . Howlett" <liam@infradead.org>,
	Kiryl Shutsemau <kas@kernel.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	Kairui Song <ryncsn@gmail.com>,
	Mikhail Zaslonko <zaslonko@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	Barry Song <baohua@kernel.org>, Dev Jain <dev.jain@arm.com>,
	Lance Yang <lance.yang@linux.dev>, Nico Pache <npache@redhat.com>,
	Ryan Roberts <ryan.roberts@arm.com>,
	cgroups@vger.kernel.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 8/8] mm: switch deferred split shrinker to list_lru
Date: Tue, 26 May 2026 16:10:36 -0400	[thread overview]
Message-ID: <ahX-PHlOwAn5whdi@cmpxchg.org> (raw)
In-Reply-To: <20260526120923.2331056-1-usama.arif@linux.dev>

On Tue, May 26, 2026 at 05:09:22AM -0700, Usama Arif wrote:
> On Thu, 21 May 2026 11:02:14 -0400 Johannes Weiner <hannes@cmpxchg.org> wrote:
> > @@ -4446,36 +4377,20 @@ void deferred_split_folio(struct folio *folio, bool partially_mapped)
> >  				count_vm_event(THP_DEFERRED_SPLIT_PAGE);
> >  			count_mthp_stat(folio_order(folio), MTHP_STAT_SPLIT_DEFERRED);
> >  			mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_ANON_PARTIALLY_MAPPED, 1);
> > -
> >  		}
> >  	} else {
> >  		/* partially mapped folios cannot become non-partially mapped */
> >  		VM_WARN_ON_FOLIO(folio_test_partially_mapped(folio), folio);
> >  	}
> > -	if (list_empty(&folio->_deferred_list)) {
> > -		struct mem_cgroup *memcg;
> > -
> > -		memcg = folio_split_queue_memcg(folio, ds_queue);
> > -		list_add_tail(&folio->_deferred_list, &ds_queue->split_queue);
> > -		ds_queue->split_queue_len++;
> > -		if (memcg)
> > -			set_shrinker_bit(memcg, folio_nid(folio),
> > -					 shrinker_id(deferred_split_shrinker));
> > -	}
> > -	split_queue_unlock_irqrestore(ds_queue, flags);
> > +	__list_lru_add(&deferred_split_lru, lru, &folio->_deferred_list, nid, memcg);
> > +	list_lru_unlock_irqrestore(lru, &flags);
> > +	rcu_read_unlock();
> 
> Can the shrinker bit end up on the wrong memcg here?
> 
> deferred_split_folio() takes the lock via list_lru_lock_irqsave() with
> the original folio_memcg() of the folio. If that memcg is dying and
> already reparented, lock_list_lru_of_memcg() walks up parent_mem_cgroup()
> until it finds a live sublist and locks it (lru), but the memcg local
> variable still points at the dying child.
> 
> __list_lru_add() then calls set_shrinker_bit(memcg, ...) with the
> original (dying / reparented) memcg, not the parent that actually owns
> the locked sublist where the folio was queued.

I think you're right. Good catch.

This looks like an existing list_lru issue, actually. Even before,
list_lru_add() would call lock_list_lru_of_memcg() which might do the
hierarchy walk. But then set_shrinker_bit() on the passed in memcg.

I'll fix this in list_lru first. It's a likely backport
candidate. Then rebase my patches on top.

> > @@ -1301,6 +1301,9 @@ static enum scan_result collapse_huge_page(struct mm_struct *mm, unsigned long s
> >  	if (result != SCAN_SUCCEED)
> >  		goto out_nolock;
> >  
> > +	if (folio_memcg_alloc_deferred(folio))
> > +		goto out_nolock;
> > +
> 
> Over here, you will end up reporting success on allocation failure.
> 
> Maybe set result to SCAN_ALLOC_HUGE_PAGE_FAIL?

Good point. Sashiko pointed that out as well. I have a follow-up fix.

Thanks for taking a look.

      reply	other threads:[~2026-05-26 20:10 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-21 15:02 [PATCH v4 0/8] mm: switch THP shrinker to list_lru Johannes Weiner
2026-05-21 15:02 ` [PATCH v4 1/8] mm: list_lru: lock_list_lru_of_memcg() cannot return NULL if !skip_empty Johannes Weiner
2026-05-21 17:16   ` Liam R . Howlett
2026-05-21 15:02 ` [PATCH v4 2/8] mm: list_lru: deduplicate unlock_list_lru() Johannes Weiner
2026-05-21 17:16   ` Liam R . Howlett
2026-05-21 15:02 ` [PATCH v4 3/8] mm: list_lru: move list dead check to lock_list_lru_of_memcg() Johannes Weiner
2026-05-21 17:17   ` Liam R . Howlett
2026-05-21 15:02 ` [PATCH v4 4/8] mm: list_lru: deduplicate lock_list_lru() Johannes Weiner
2026-05-21 17:18   ` Liam R . Howlett
2026-05-21 15:02 ` [PATCH v4 5/8] mm: list_lru: introduce caller locking for additions and deletions Johannes Weiner
2026-05-21 17:30   ` Liam R . Howlett
2026-05-21 15:02 ` [PATCH v4 6/8] mm: list_lru: introduce folio_memcg_list_lru_alloc() Johannes Weiner
2026-05-21 15:02 ` [PATCH v4 7/8] mm/memory: flatten folio allocation retry loops Johannes Weiner
2026-05-21 17:09   ` Shakeel Butt
2026-05-26 12:12   ` Usama Arif
2026-05-21 15:02 ` [PATCH v4 8/8] mm: switch deferred split shrinker to list_lru Johannes Weiner
2026-05-26 12:09   ` Usama Arif
2026-05-26 20:10     ` Johannes Weiner [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=ahX-PHlOwAn5whdi@cmpxchg.org \
    --to=hannes@cmpxchg.org \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=cgroups@vger.kernel.org \
    --cc=david@fromorbit.com \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=gor@linux.ibm.com \
    --cc=kas@kernel.org \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@kernel.org \
    --cc=muchun.song@linux.dev \
    --cc=npache@redhat.com \
    --cc=qi.zheng@linux.dev \
    --cc=roman.gushchin@linux.dev \
    --cc=ryan.roberts@arm.com \
    --cc=ryncsn@gmail.com \
    --cc=shakeel.butt@linux.dev \
    --cc=usama.arif@linux.dev \
    --cc=vbabka@kernel.org \
    --cc=yosry.ahmed@linux.dev \
    --cc=zaslonko@linux.ibm.com \
    --cc=ziy@nvidia.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