Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm: actually mark kernel page table pages

Now that the API is in place, mark kernel page table pages just after they
are allocated. Unmark them just before they are freed.

Note: Unconditionally clearing the 'kernel' marking (via
ptdesc_clear_kernel()) would be functionally identical to what is here.
But having the if() makes it logically clear that this function can be
used for kernel and non-kernel page tables.

Link: https://lkml.kernel.org/r/20251022082635.2462433-4-baolu.lu@linux.intel.com
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Acked-by: David Hildenbrand <david@redhat.com>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Betkov <bp@alien8.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jann Horn <jannh@google.com>
Cc: Jean-Philippe Brucker <jean-philippe@linaro.org>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Robin Murohy <robin.murphy@arm.com>
Cc: Thomas Gleinxer <tglx@linutronix.de>
Cc: "Uladzislau Rezki (Sony)" <urezki@gmail.com>
Cc: Vasant Hegde <vasant.hegde@amd.com>
Cc: Vinicius Costa Gomes <vinicius.gomes@intel.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Will Deacon <will@kernel.org>
Cc: Yi Lai <yi1.lai@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Dave Hansen and committed by
Andrew Morton
97787052 27bfafac

+21
+18
include/asm-generic/pgalloc.h
··· 28 28 return NULL; 29 29 } 30 30 31 + ptdesc_set_kernel(ptdesc); 32 + 31 33 return ptdesc_address(ptdesc); 32 34 } 33 35 #define __pte_alloc_one_kernel(...) alloc_hooks(__pte_alloc_one_kernel_noprof(__VA_ARGS__)) ··· 148 146 pagetable_free(ptdesc); 149 147 return NULL; 150 148 } 149 + 150 + if (mm == &init_mm) 151 + ptdesc_set_kernel(ptdesc); 152 + 151 153 return ptdesc_address(ptdesc); 152 154 } 153 155 #define pmd_alloc_one(...) alloc_hooks(pmd_alloc_one_noprof(__VA_ARGS__)) ··· 185 179 return NULL; 186 180 187 181 pagetable_pud_ctor(ptdesc); 182 + 183 + if (mm == &init_mm) 184 + ptdesc_set_kernel(ptdesc); 185 + 188 186 return ptdesc_address(ptdesc); 189 187 } 190 188 #define __pud_alloc_one(...) alloc_hooks(__pud_alloc_one_noprof(__VA_ARGS__)) ··· 243 233 return NULL; 244 234 245 235 pagetable_p4d_ctor(ptdesc); 236 + 237 + if (mm == &init_mm) 238 + ptdesc_set_kernel(ptdesc); 239 + 246 240 return ptdesc_address(ptdesc); 247 241 } 248 242 #define __p4d_alloc_one(...) alloc_hooks(__p4d_alloc_one_noprof(__VA_ARGS__)) ··· 291 277 return NULL; 292 278 293 279 pagetable_pgd_ctor(ptdesc); 280 + 281 + if (mm == &init_mm) 282 + ptdesc_set_kernel(ptdesc); 283 + 294 284 return ptdesc_address(ptdesc); 295 285 } 296 286 #define __pgd_alloc(...) alloc_hooks(__pgd_alloc_noprof(__VA_ARGS__))
+3
include/linux/mm.h
··· 3057 3057 { 3058 3058 struct page *page = ptdesc_page(pt); 3059 3059 3060 + if (ptdesc_test_kernel(pt)) 3061 + ptdesc_clear_kernel(pt); 3062 + 3060 3063 __free_pages(page, compound_order(page)); 3061 3064 } 3062 3065