From: Qi Zheng <qi.zheng@linux.dev>
To: "David Hildenbrand (Red Hat)" <david@kernel.org>,
linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Vlastimil Babka <vbabka@suse.cz>, Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>
Subject: Re: [PATCH v1 2/2] mm/memory: handle non-split locks correctly in zap_empty_pte_table()
Date: Tue, 20 Jan 2026 11:32:05 +0800 [thread overview]
Message-ID: <062eab31-14ac-4644-814a-daa6f2349d92@linux.dev> (raw)
In-Reply-To: <20260119220708.3438514-3-david@kernel.org>
On 1/20/26 6:07 AM, David Hildenbrand (Red Hat) wrote:
> While we handle pte_lockptr() == pmd_lockptr() correctly in
> zap_pte_table_if_empty(), we don't handle it in zap_empty_pte_table(),
> making the spin_trylock() always fail and forcing us onto the slow path.
>
> So let's handle the scenario where pte_lockptr() == pmd_lockptr()
> better, which can only happen if CONFIG_SPLIT_PTE_PTLOCKS is not set.
>
> This is only relevant once we unlock CONFIG_PT_RECLAIM on architectures
> that are not x86-64.
>
> Signed-off-by: David Hildenbrand (Red Hat) <david@kernel.org>
> ---
> mm/memory.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
Reviewed-by: Qi Zheng <zhengqi.arch@bytedance.com>
Thanks!
>
> diff --git a/mm/memory.c b/mm/memory.c
> index c3055b2577c27..3852075ea62d4 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -1833,16 +1833,18 @@ static bool pte_table_reclaim_possible(unsigned long start, unsigned long end,
> return details && details->reclaim_pt && (end - start >= PMD_SIZE);
> }
>
> -static bool zap_empty_pte_table(struct mm_struct *mm, pmd_t *pmd, pmd_t *pmdval)
> +static bool zap_empty_pte_table(struct mm_struct *mm, pmd_t *pmd,
> + spinlock_t *ptl, pmd_t *pmdval)
> {
> spinlock_t *pml = pmd_lockptr(mm, pmd);
>
> - if (!spin_trylock(pml))
> + if (ptl != pml && !spin_trylock(pml))
> return false;
>
> *pmdval = pmdp_get(pmd);
> pmd_clear(pmd);
> - spin_unlock(pml);
> + if (ptl != pml)
> + spin_unlock(pml);
> return true;
> }
>
> @@ -1934,7 +1936,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb,
> * from being repopulated by another thread.
> */
> if (can_reclaim_pt && direct_reclaim && addr == end)
> - direct_reclaim = zap_empty_pte_table(mm, pmd, &pmdval);
> + direct_reclaim = zap_empty_pte_table(mm, pmd, ptl, &pmdval);
>
> add_mm_rss_vec(mm, rss);
> lazy_mmu_mode_disable();
prev parent reply other threads:[~2026-01-20 3:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-19 22:07 [PATCH v1 0/2] mm: move pte table reclaim code to memory.c David Hildenbrand (Red Hat)
2026-01-19 22:07 ` [PATCH v1 1/2] " David Hildenbrand (Red Hat)
2026-01-20 3:30 ` Qi Zheng
2026-01-20 11:19 ` Kiryl Shutsemau
2026-01-21 12:08 ` David Hildenbrand (Red Hat)
2026-01-19 22:07 ` [PATCH v1 2/2] mm/memory: handle non-split locks correctly in zap_empty_pte_table() David Hildenbrand (Red Hat)
2026-01-20 3:32 ` Qi Zheng [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=062eab31-14ac-4644-814a-daa6f2349d92@linux.dev \
--to=qi.zheng@linux.dev \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mhocko@suse.com \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
/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