From: Oscar Salvador <osalvador@suse.de>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: David Hildenbrand <david@kernel.org>,
Michal Hocko <mhocko@suse.com>,
Muchun Song <muchun.song@linux.dev>,
Vlastimil Babka <vbabka@kernel.org>,
Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Oscar Salvador <osalvador@suse.de>
Subject: [RFC PATCH v3 2/8] mm: Add {pmd,pud}_huge_lock helper
Date: Mon, 25 May 2026 18:55:22 +0200 [thread overview]
Message-ID: <20260525165528.184397-3-osalvador@suse.de> (raw)
In-Reply-To: <20260525165528.184397-1-osalvador@suse.de>
HugeTLB and THP use the same lock for pud and pmd,
so create two helpers that can be directly used by both of them,
as they will be used in the generic pagewalkers.
Signed-off-by: Oscar Salvador <osalvador@suse.de>
---
include/linux/mm_inline.h | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h
index a171070e15f0..93637890cbeb 100644
--- a/include/linux/mm_inline.h
+++ b/include/linux/mm_inline.h
@@ -667,4 +667,36 @@ static inline size_t num_pages_contiguous(struct page **pages, size_t nr_pages)
return i;
}
+static inline spinlock_t *pmd_huge_lock(pmd_t *pmd, struct vm_area_struct *vma)
+{
+ spinlock_t *ptl;
+
+ if (pmd_present(*pmd) || !pmd_none(*pmd)) {
+ ptl = pmd_lock(vma->vm_mm, pmd);
+ if (pmd_present(*pmd) && pmd_leaf(*pmd))
+ return ptl;
+ else if (!pmd_present(*pmd) && !pmd_none(*pmd))
+ return ptl;
+ spin_unlock(ptl);
+ }
+
+ return NULL;
+}
+
+static inline spinlock_t *pud_huge_lock(pud_t *pud, struct vm_area_struct *vma)
+{
+ spinlock_t *ptl;
+
+ if (pud_present(*pud) || !pud_none(*pud)) {
+ ptl = pud_lock(vma->vm_mm, pud);
+ if (pud_present(*pud) && pud_leaf(*pud))
+ return ptl;
+ else if (!pud_present(*pud) && !pud_none(*pud))
+ return ptl;
+ spin_unlock(ptl);
+ }
+
+ return NULL;
+}
+
#endif
--
2.53.0
next prev parent reply other threads:[~2026-05-25 16:55 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-25 16:55 [RFC PATCH v3 0/8] Implement a new generic pagewalk API Oscar Salvador
2026-05-25 16:55 ` [RFC PATCH v3 1/8] mm: Add softleaf_from_pud Oscar Salvador
2026-05-25 16:55 ` Oscar Salvador [this message]
2026-05-25 16:55 ` [RFC PATCH v3 3/8] mm: Implement folio_pmd_batch Oscar Salvador
2026-05-25 16:55 ` [RFC PATCH v3 4/8] mm: Implement pt_range_walk Oscar Salvador
2026-05-25 16:55 ` [RFC PATCH v3 5/8] mm: Make /proc/pid/smaps use the new generic pagewalk API Oscar Salvador
2026-05-25 16:55 ` [RFC PATCH v3 6/8] mm: Make /proc/pid/numa_maps " Oscar Salvador
2026-05-25 16:55 ` [RFC PATCH v3 7/8] mm: Make /proc/pid/pagemap " Oscar Salvador
2026-05-25 16:55 ` [RFC PATCH v3 8/8] mm: Make /proc/pid/clear_refs " Oscar Salvador
2026-05-26 5:49 ` [syzbot ci] Re: Implement a " syzbot ci
2026-06-11 12:01 ` Oscar Salvador (SUSE)
2026-06-11 13:22 ` syzbot ci
2026-06-11 13:52 ` Oscar Salvador (SUSE)
2026-06-11 15:08 ` syzbot ci
2026-06-11 12:07 ` [RFC PATCH v3 0/8] " Lorenzo Stoakes
2026-06-11 12:29 ` Oscar Salvador (SUSE)
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=20260525165528.184397-3-osalvador@suse.de \
--to=osalvador@suse.de \
--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=muchun.song@linux.dev \
--cc=vbabka@kernel.org \
/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
all inboxes | Powered by JetHome®