Linux filesystem development
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Matthew Wilcox <willy@infradead.org>
Cc: Zi Yan <ziy@nvidia.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	"Liam R. Howlett" <liam@infradead.org>,
	Nico Pache <nico.pache@linux.dev>,
	Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
	Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
	Usama Arif <usama.arif@linux.dev>,
	Kiryl Shutsemau <kas@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	William Kucharski <william.kucharski@oracle.com>,
	Heiko Carstens <hca@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Claudio Imbrenda <imbrenda@linux.ibm.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	"Lorenzo Stoakes (ARM)" <ljs@kernel.org>,
	Matthew Brost <matthew.brost@intel.com>,
	Joshua Hahn <joshua.hahnjy@gmail.com>,
	Byungchul Park <byungchul@sk.com>,
	Gregory Price <gourry@gourry.net>,
	Ying Huang <ying.huang@linux.alibaba.com>,
	Alistair Popple <apopple@nvidia.com>,
	Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
	Miklos Szeredi <miklos@szeredi.hu>,
	Joanne Koong <joannelkoong@gmail.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, stable@vger.kernel.org,
	Chris Mason <mason@kernel.org>
Subject: Re: [PATCH 1/2] mm/huge_memory: use NOFS when allocating while splitting folios
Date: Mon, 23 Nov 2026 21:44:45 +0100	[thread overview]
Message-ID: <2cb3ddae-9ece-4d91-afcd-9adc3251fa35@kernel.org> (raw)
In-Reply-To: <awSgk1VTUsiVQOAT@casper.infradead.org>

On 11/23/26 21:22, Matthew Wilcox wrote:
> On Sun, Nov 22, 2026 at 01:42:17PM +0100, David Hildenbrand (Arm) wrote:
>> Various callers (migration, memory-failure, s390_wiggle_split_folio) split
>> locked folios without holding a reference on the folio's inode.
>>
>> Splitting a file folio might allocate memory for the xarray and call
>> filemap_release_folio(). If either ends up in direct reclaim with
>> __GFP_FS, reclaim can evict the inode through the dcache shrinker, and
>> wait in truncate_inode_pages_final() for the folio that we hold locked:
>>
>>     try_split_folio()
>>       folio_lock(A)
>>       split_folio_to_list(A)
>>         xas_split_alloc()
>>           try_to_free_pages()
>>             super_cache_scan()
>>               prune_dcache_sb()
>>                 iput_final()
>>                   evict()
>>                     truncate_inode_pages_final()
>>                       folio_lock(A)
> 
> The "holding a reference to the inode" piece is a red herring.  We can
> deadlock even without it (although maybe the AI can't see it).  If we
> don't remove __GFP_FS, we can hit this path:
> 
>   folio_lock(A)
>   kmalloc
>     alloc_pages
>       try_to_compact_pages
> 	compact_zone_order
> 	  compact_zone(MIGRATE_SYNC_LIGHT)
> 	    migrate_pages
> 	      migrate_pages_sync
> 		migrate_pages_batch
> 		  try_split_folio
> 		    folio_lock(A)

Quite nasty, thanks for these details. I was aware that memcg v1 would run into
deadlocks whenever we would perform a charged allocation, but sync compaction
triggering it is even worse.

> 
> See this discussion:
> https://lore.kernel.org/all/20200214065504.GK31689@dhcp22.suse.cz/
> which led to patch f2c817bed58d in June 2020.

Thanks for the pointer.

> 
> So yes, anywhere we're allocating memory with a file folio locked, we
> should enter nofs scope.  Perhaps we can teach the AI that rule?

I have a couple of reports here regarding memcg v1 deadlocks, so it's not
completely aware of the issues yet.

We should document the rules of what you can or can't do while holding the folio
lock somewhere, yes!

-- 
Cheers,

David

  reply	other threads:[~2026-11-23 20:44 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22 12:42 [PATCH 0/2] mm: fix deadlock on the folio lock due to inode eviction David Hildenbrand (Arm)
2026-11-22 12:42 ` [PATCH 1/2] mm/huge_memory: use NOFS when allocating while splitting folios David Hildenbrand (Arm)
2026-11-22 17:16   ` Jose A. Perez de Azpillaga
2026-11-22 18:45   ` Gregory Price (Meta)
2026-11-23  1:14     ` Barry Song
2026-11-23  8:12       ` Gregory Price (Meta)
2026-11-23  8:19   ` Baolin Wang
2026-11-23 16:47   ` Zi Yan
2026-11-23 17:26   ` Lorenzo Stoakes (ARM)
2026-11-23 20:22   ` Matthew Wilcox
2026-11-23 20:44     ` David Hildenbrand (Arm) [this message]
2026-11-22 12:42 ` [PATCH 2/2] mm/migrate: allocate destination folios before locking a batch David Hildenbrand (Arm)
2026-11-22 19:02   ` Gregory Price (Meta)
2026-11-23 17:24   ` Zi Yan
2026-11-23 20:45     ` David Hildenbrand (Arm)
2026-11-23  5:53 ` [PATCH 0/2] mm: fix deadlock on the folio lock due to inode eviction Chris Down
2026-11-23 16:27   ` David Hildenbrand (Arm)
2026-11-23 16:27 ` David Hildenbrand

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=2cb3ddae-9ece-4d91-afcd-9adc3251fa35@kernel.org \
    --to=david@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=apopple@nvidia.com \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=brauner@kernel.org \
    --cc=byungchul@sk.com \
    --cc=dev.jain@arm.com \
    --cc=gourry@gourry.net \
    --cc=hannes@cmpxchg.org \
    --cc=hca@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=jack@suse.cz \
    --cc=joannelkoong@gmail.com \
    --cc=joshua.hahnjy@gmail.com \
    --cc=kas@kernel.org \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mason@kernel.org \
    --cc=matthew.brost@intel.com \
    --cc=miklos@szeredi.hu \
    --cc=nico.pache@linux.dev \
    --cc=ryan.roberts@arm.com \
    --cc=stable@vger.kernel.org \
    --cc=usama.arif@linux.dev \
    --cc=william.kucharski@oracle.com \
    --cc=willy@infradead.org \
    --cc=ying.huang@linux.alibaba.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