From: "Jose A. Perez de Azpillaga" <azpijr@gmail.com>
To: "David Hildenbrand (Arm)" <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, linux-fsdevel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH 1/4] mm/khugepaged: allocate page tables before locking the folio
Date: Thu, 26 Nov 2026 21:23:18 +0100 [thread overview]
Message-ID: <c5bc383d-fd32-455a-b946-e5f232c7fdf3@gmail.com> (raw)
In-Reply-To: <042ab922-4707-4c96-80a2-83a0378646d1@kernel.org>
On 11/26/26 5:24 PM, David Hildenbrand (Arm) wrote:
> On 11/25/26 10:59, Jose A. Perez de Azpillaga wrote:
>> try_collapse_pte_mapped_thp() calls set_huge_pmd() with the folio
>> locked. set_huge_pmd() allocates the missing p4d/pud/pmd tables there,
>> and on ppc64 with the hash MMU do_set_pmd() also allocates the page
>> table to deposit.
>>
>> Allocating with __GFP_FS while holding a folio lock can deadlock in
>> reclaim. For example, memcg reclaim on cgroup v1 waits for writeback
>> that may be waiting for the folio lock we hold.
>>
>> Allocate these page tables before locking the folio. The mmap lock
>> keeps the upper levels around, and an unused deposit table is freed
>> after unlocking the folio.
>>
>> Fixes: 34488399fa08 ("mm/madvise: add file and shmem support to MADV_COLLAPSE")
>> Fixes: f8a01513f574 ("mm/khugepaged: do not fail collapse_pte_mapped_thp() on SCAN_PMD_NULL")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Jose A. Perez de Azpillaga <azpijr@gmail.com>
>> ---
>> mm/khugepaged.c | 79 +++++++++++++++++++++++++++++++++++--------------
>> 1 file changed, 56 insertions(+), 23 deletions(-)
>>
>
> That's a lot of churn for a corner case (powerpc with hash MMU).
>
> What about simply running in NOFS context when allcoating that page table?
>
> Apparently pte_alloc_one() doesn't consume GFP flags ... but we could add NOFS
> around the allocation.
>
> Any reason you went for this more complicated solution?
>
no reason, it was just the solution I came up with. I'll rework it with
NOFS then, it's a lot less churn.
--
cheers,
jose a. p-a
next prev parent reply other threads:[~2026-11-26 20:23 UTC|newest]
Thread overview: 15+ 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-26 16:24 ` David Hildenbrand (Arm)
2026-11-26 20:23 ` Jose A. Perez de Azpillaga [this message]
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-26 16:29 ` David Hildenbrand (Arm)
2026-11-26 20:27 ` 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
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=c5bc383d-fd32-455a-b946-e5f232c7fdf3@gmail.com \
--to=azpijr@gmail.com \
--cc=akpm@linux-foundation.org \
--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-fsdevel@vger.kernel.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=songliubraving@fb.com \
--cc=stable@vger.kernel.org \
--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 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.