Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jose A. Perez de Azpillaga" <azpijr@gmail.com>,
	"David Hildenbrand" <david@kernel.org>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	"Jan Kara" <jack@suse.cz>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Zi Yan" <ziy@nvidia.com>, "Zach O'Keefe" <zokeefe@google.com>,
	"Lorenzo Stoakes" <ljs@kernel.org>, "Dev Jain" <dev.jain@arm.com>,
	"Baolin Wang" <baolin.wang@linux.alibaba.com>,
	"Hugh Dickins" <hughd@google.com>,
	"Kiryl Shutsemau" <kas@kernel.org>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Rik van Riel" <riel@surriel.com>,
	"Song Liu" <songliubraving@fb.com>
Cc: "Liam R. Howlett" <liam@infradead.org>,
	"Vlastimil Babka" <vbabka@kernel.org>,
	"Mike Rapoport" <rppt@kernel.org>,
	"Michal Hocko" <mhocko@suse.com>,
	"Nico Pache" <nico.pache@linux.dev>,
	"Ryan Roberts" <ryan.roberts@arm.com>,
	"Barry Song" <baohua@kernel.org>,
	"Lance Yang" <lance.yang@linux.dev>,
	"Usama Arif" <usama.arif@linux.dev>,
	linux-mm@kvack.org
Subject: Re: [PATCH 4/4] mm/khugepaged: use NOFS while collapse_file() holds folio locks
Date: Thu, 26 Nov 2026 10:01:39 +0000	[thread overview]
Message-ID: <sashiko-outbox-235223@kernel.org> (raw)
In-Reply-To: <20261125100058.15200-5-azpijr@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mm/khugepaged: filemap_release_folio() still gets __GFP_FS in
  collapse_file()
--

commit eca7ae08f59655cebfe256885070eec102a63325
Author: Jose A. Perez de Azpillaga <azpijr@gmail.com>

mm/khugepaged: use NOFS while collapse_file() holds folio locks

This commit wraps the folio-locked section of collapse_file() in a
memalloc_nofs_save() scope to avoid __GFP_FS allocations and filesystem
waits while holding folio locks.

> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index 6d2431a20bc98..c3c733d3a32b0 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -2302,6 +2302,7 @@ static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr,
>  	LIST_HEAD(pagelist);
>  	XA_STATE_ORDER(xas, &mapping->i_pages, start, HPAGE_PMD_ORDER);
>  	enum scan_result result = SCAN_SUCCEED;
> +	unsigned int nofs_flags;
>  	int nr_none = 0;
>  	bool do_readahead = false;
>  	bool readahead_done = false;
> @@ -2320,6 +2321,13 @@ static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr,
>  		goto out;
>  	new_pfn = folio_pfn(new_folio);
>  
> +	/*
> +	 * We allocate while holding folio locks below, when swapping in shmem
> +	 * folios and in filemap_release_folio(). Allocating with __GFP_FS
> +	 * there can deadlock in reclaim or compaction.
> +	 */
> +	nofs_flags = memalloc_nofs_save();

[Severity: Medium]
Does filemap_release_folio() in collapse_file() still receive __GFP_FS
despite memalloc_nofs_save()?

collapse_file() passes a literal GFP_KERNEL to
filemap_release_folio(folio, GFP_KERNEL), and filemap_release_folio()
forwards that mask unmodified to mapping->a_ops->release_folio(folio, gfp)
without applying current_gfp_context():

fs/netfs/misc.c:netfs_release_folio() {
	if (unlikely(folio_test_private_2(folio))) { /* [DEPRECATED] */
		if (current_is_kswapd() || !(gfp & __GFP_FS))
			return false;
		folio_wait_private_2(folio);
	}
	return fscache_release_folio(folio, gfp);
}

Callbacks such as netfs_release_folio() and nfs_fscache_release_folio()
test gfp & __GFP_FS directly, so they will still see __GFP_FS set and wait
in folio_wait_private_2() while collapse_file() holds folio locks.
Compare with __folio_freeze_split_file(), which passes
current_gfp_context() (or GFP_NOFS) to filemap_release_folio().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125100058.15200-1-azpijr@gmail.com?part=4


      parent reply	other threads:[~2026-11-26 10:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  9:59 [PATCH 0/4] mm: don't allocate page tables with the folio locked Jose A. Perez de Azpillaga
2026-11-25  9:59 ` [PATCH 1/4] mm/khugepaged: allocate page tables before locking the folio Jose A. Perez de Azpillaga
2026-11-25  9:59 ` [PATCH 2/4] mm/memory: don't allocate in finish_fault() with the folio locked Jose A. Perez de Azpillaga
2026-11-25  9:59 ` [PATCH 3/4] mm/memory: never allocate a page table in do_set_pmd() Jose A. Perez de Azpillaga
2026-11-25  9:59 ` [PATCH 4/4] mm/khugepaged: use NOFS while collapse_file() holds folio locks Jose A. Perez de Azpillaga
2026-11-25 10:55   ` David Hildenbrand (Arm)
2026-11-25 11:12     ` Jose A. Perez de Azpillaga
2026-11-25 11:15       ` David Hildenbrand (Arm)
2026-11-25 11:34         ` Jose A. Perez de Azpillaga
2026-11-25 11:59           ` David Hildenbrand (Arm)
2026-11-26 10:01   ` sashiko-bot [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=sashiko-outbox-235223@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=azpijr@gmail.com \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=hannes@cmpxchg.org \
    --cc=hughd@google.com \
    --cc=jack@suse.cz \
    --cc=kas@kernel.org \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=nico.pache@linux.dev \
    --cc=riel@surriel.com \
    --cc=rppt@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=songliubraving@fb.com \
    --cc=usama.arif@linux.dev \
    --cc=vbabka@kernel.org \
    --cc=willy@infradead.org \
    --cc=ziy@nvidia.com \
    --cc=zokeefe@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