From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: "Jose A. Perez de Azpillaga" <azpijr@gmail.com>
Cc: David Hildenbrand <david@kernel.org>, Zi Yan <ziy@nvidia.com>,
Andrew Morton <akpm@linux-foundation.org>,
Zach O'Keefe <zokeefe@google.com>,
Hugh Dickins <hughd@google.com>,
Kiryl Shutsemau <kas@kernel.org>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Dev Jain <dev.jain@arm.com>,
"Liam R. Howlett" <liam@infradead.org>,
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>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>, Michal Hocko <mhocko@suse.com>,
linux-mm@kvack.org, Matthew Wilcox <willy@infradead.org>,
Jan Kara <jack@suse.cz>, Johannes Weiner <hannes@cmpxchg.org>,
Rik van Riel <riel@surriel.com>,
Song Liu <songliubraving@fb.com>,
linux-fsdevel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v2 3/3] mm/memory: don't allocate in finish_fault() with the folio locked
Date: Mon, 30 Nov 2026 18:52:50 +0000 [thread overview]
Message-ID: <aw3Cg8PSkVACPejT@gremlin> (raw)
In-Reply-To: <20261127091344.113688-4-azpijr@gmail.com>
On Fri, Nov 27, 2026 at 10:12:16AM +0100, Jose A. Perez de Azpillaga wrote:
> __do_fault() preallocates a page table only when the PMD is empty, so
> that finish_fault() does not have to allocate one with the folio locked.
This is written in a sort of way, so as to automatically confused,
whoever reads it, with its comma.
How about:
__do_fault() tries to avoid page table allocation in finish_fault()
by pre-allocating one if the PMD is empty.
However, it is no longer safe to assume that a page table found
here (thus avoiding pre-allocation) remains in place, since < stuff
about locks below >
?
> Since retract_page_tables() no longer takes the mmap and VMA locks, the
> page table can be removed while the fault waits in ->fault().
> finish_fault() then finds an empty PMD without a preallocated table, and
> calls pte_alloc() with the folio locked.
>
> Allocating with __GFP_FS while holding a folio lock can deadlock in
> reclaim, for example the memcg reclaim deadlock on cgroup v1 described
> in commit 63f3655f9501 ("mm, memcg: fix reclaim deadlock with
> writeback").
Do we have to have this example in every commit message? :)) I mean I guess
fine. I just find cgroup v1 very deprecate-y.
>
> If the folio can't be mapped with a PMD, return VM_FAULT_NOPAGE instead,
> as we already do when pte_offset_map_lock() fails. The retried fault
> preallocates the page table before locking the folio.
Is that safe from this race, or does it just mean you could go on a
VM_FAULT_NOPAGE loop again? Maybe worth mentioning?
It feels like the pre-faulting mechanism is now a sort of best-effort thing
since it can't now correctly detect if it's necessary or not. Maybe worth a
comment at the point of pre-allocation saying that?
>
> Fixes: 1d65b771bc08 ("mm/khugepaged: retract_page_tables() without mmap or vma lock")
> Cc: stable@vger.kernel.org
> Signed-off-by: Jose A. Perez de Azpillaga <azpijr@gmail.com>
> ---
> Changes in v2:
> - return VM_FAULT_NOPAGE after trying do_set_pmd() (David)
> - drop the ppc64 sentence, do_set_pmd() is handled on its own now
>
> v1: https://lore.kernel.org/20261125100058.15200-3-azpijr@gmail.com
>
> mm/memory.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/mm/memory.c b/mm/memory.c
> index 05d03b32ce52..dd0cb09ba7ef 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -6000,10 +6000,14 @@ vm_fault_t finish_fault(struct vm_fault *vmf)
> return ret;
> }
>
> - if (vmf->prealloc_pte)
> - pmd_install(vma->vm_mm, vmf->pmd, &vmf->prealloc_pte);
> - else if (unlikely(pte_alloc(vma->vm_mm, vmf->pmd)))
> - return VM_FAULT_OOM;
> + /*
> + * The page table was removed after __do_fault() found it, so
> + * nothing was preallocated. Allocating with the folio locked
> + * can deadlock in reclaim, so retry the fault instead.
> + */
"Dearest Diary, Today I deadlocked on an allocation and it was the most
wondrous deadlock evah!11"
Let's maybe deschlop here, e.g.:
/*
* Page table retraction can happen after we decided there was
* no need to prealloc and the folio is locked, so to avoid
* deadlock against concurrent reclaim, just retry the fault.
*/
OK not fewer words but I think clearer :)
> + if (!vmf->prealloc_pte)
> + return VM_FAULT_NOPAGE;
> + pmd_install(vma->vm_mm, vmf->pmd, &vmf->prealloc_pte);
> }
>
> nr_pages = folio_nr_pages(folio);
> --
> 2.56.1
>
--
Cheers, Lorenzo
next prev parent reply other threads:[~2026-11-30 18:53 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 9:12 [PATCH v2 0/3] mm: don't allocate page tables with the folio locked Jose A. Perez de Azpillaga
2026-11-27 9:12 ` [PATCH v2 1/3] mm/memory: allocate the deposit page table with NOFS in do_set_pmd() Jose A. Perez de Azpillaga
2026-11-30 7:15 ` Baolin Wang
2026-11-30 10:49 ` David Hildenbrand (Arm)
2026-11-30 18:33 ` Lorenzo Stoakes (ARM)
2026-11-30 22:21 ` Jose A. Perez de Azpillaga
2026-12-01 13:12 ` Lorenzo Stoakes (ARM)
2026-12-01 2:43 ` Zi Yan
2026-11-27 9:12 ` [PATCH v2 2/3] mm/khugepaged: allocate page tables with NOFS in set_huge_pmd() Jose A. Perez de Azpillaga
2026-11-30 7:17 ` Baolin Wang
2026-11-30 10:50 ` David Hildenbrand (Arm)
2026-11-30 18:37 ` Lorenzo Stoakes (ARM)
2026-12-01 2:44 ` Zi Yan
2026-11-27 9:12 ` [PATCH v2 3/3] mm/memory: don't allocate in finish_fault() with the folio locked Jose A. Perez de Azpillaga
2026-11-30 7:28 ` Baolin Wang
2026-11-30 10:51 ` David Hildenbrand (Arm)
2026-11-30 18:52 ` Lorenzo Stoakes (ARM) [this message]
2026-11-30 22:25 ` Jose A. Perez de Azpillaga
2026-11-30 10:49 ` [PATCH v2 0/3] mm: don't allocate page tables " David Hildenbrand (Arm)
2026-11-30 22:28 ` Jose A. Perez de Azpillaga
2026-11-30 10:51 ` David Hildenbrand (Arm)
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=aw3Cg8PSkVACPejT@gremlin \
--to=ljs@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-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.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.