]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm: move common part of pagetable_*_ctor to helper
authorKevin Brodsky <kevin.brodsky@arm.com>
Fri, 3 Jan 2025 18:44:10 +0000 (18:44 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 26 Jan 2025 04:22:24 +0000 (20:22 -0800)
Patch series "Account page tables at all levels".

This series should be considered in conjunction with Qi's series [1].
Together, they ensure that page table ctor/dtor are called at all levels
(PTE to PGD) and all architectures, where page tables are regular pages.
Besides the improvement in accounting and general cleanup, this also
create a single place where construction/destruction hooks can be called
for all page tables, namely the now-generic pagetable_dtor() introduced
by Qi, and __pagetable_ctor() introduced in this series.

[1] https://lore.kernel.org/linux-mm/cover.1735549103.git.zhengqi.arch@bytedance.com/

This patch (of 6):

pagetable_*_ctor all have the same basic implementation.  Move the common
part to a helper to reduce duplication.

Link: https://lkml.kernel.org/r/20250103184415.2744423-1-kevin.brodsky@arm.com
Link: https://lkml.kernel.org/r/20250103184415.2744423-2-kevin.brodsky@arm.com
Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com>
Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
Acked-by: Qi Zheng <zhengqi.arch@bytedance.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/mm.h

index c550912a5d6dc567a376ce8d0138f85fe64c2155..2949b58fd633ed8ccfaaee5cfe3d463d854f899a 100644 (file)
@@ -2992,6 +2992,14 @@ static inline bool ptlock_init(struct ptdesc *ptdesc) { return true; }
 static inline void ptlock_free(struct ptdesc *ptdesc) {}
 #endif /* defined(CONFIG_SPLIT_PTE_PTLOCKS) */
 
+static inline void __pagetable_ctor(struct ptdesc *ptdesc)
+{
+       struct folio *folio = ptdesc_folio(ptdesc);
+
+       __folio_set_pgtable(folio);
+       lruvec_stat_add_folio(folio, NR_PAGETABLE);
+}
+
 static inline void pagetable_dtor(struct ptdesc *ptdesc)
 {
        struct folio *folio = ptdesc_folio(ptdesc);
@@ -3009,12 +3017,9 @@ static inline void pagetable_dtor_free(struct ptdesc *ptdesc)
 
 static inline bool pagetable_pte_ctor(struct ptdesc *ptdesc)
 {
-       struct folio *folio = ptdesc_folio(ptdesc);
-
        if (!ptlock_init(ptdesc))
                return false;
-       __folio_set_pgtable(folio);
-       lruvec_stat_add_folio(folio, NR_PAGETABLE);
+       __pagetable_ctor(ptdesc);
        return true;
 }
 
@@ -3118,13 +3123,10 @@ static inline spinlock_t *pmd_lock(struct mm_struct *mm, pmd_t *pmd)
 
 static inline bool pagetable_pmd_ctor(struct ptdesc *ptdesc)
 {
-       struct folio *folio = ptdesc_folio(ptdesc);
-
        if (!pmd_ptlock_init(ptdesc))
                return false;
-       __folio_set_pgtable(folio);
        ptdesc_pmd_pts_init(ptdesc);
-       lruvec_stat_add_folio(folio, NR_PAGETABLE);
+       __pagetable_ctor(ptdesc);
        return true;
 }
 
@@ -3149,18 +3151,12 @@ static inline spinlock_t *pud_lock(struct mm_struct *mm, pud_t *pud)
 
 static inline void pagetable_pud_ctor(struct ptdesc *ptdesc)
 {
-       struct folio *folio = ptdesc_folio(ptdesc);
-
-       __folio_set_pgtable(folio);
-       lruvec_stat_add_folio(folio, NR_PAGETABLE);
+       __pagetable_ctor(ptdesc);
 }
 
 static inline void pagetable_p4d_ctor(struct ptdesc *ptdesc)
 {
-       struct folio *folio = ptdesc_folio(ptdesc);
-
-       __folio_set_pgtable(folio);
-       lruvec_stat_add_folio(folio, NR_PAGETABLE);
+       __pagetable_ctor(ptdesc);
 }
 
 extern void __init pagecache_init(void);