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: mprotect: avoid unnecessary struct page accessing if pte_protnone()

If the pte_protnone() is true, we could avoid unnecessary struct page
accessing and reduce cache footprint when scanning page tables for prot
numa, there was a similar change before, see more commit a818f5363a0e
("autonuma: reduce cache footprint when scanning page tables").

Link: https://lkml.kernel.org/r/20251023113737.3572790-3-wangkefeng.wang@huawei.com
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Acked-by: Zi Yan <ziy@nvidia.com>
Acked-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Dev Jain <dev.jain@arm.com>
Reviewed-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kefeng Wang and committed by
Andrew Morton
6e97624d 03aa8e4f

+13 -16
+13 -16
mm/mprotect.c
··· 118 118 return folio_pte_batch_flags(folio, NULL, ptep, &pte, max_nr_ptes, flags); 119 119 } 120 120 121 - static bool prot_numa_skip(struct vm_area_struct *vma, unsigned long addr, 122 - pte_t oldpte, pte_t *pte, int target_node, 123 - struct folio *folio) 121 + static bool prot_numa_skip(struct vm_area_struct *vma, int target_node, 122 + struct folio *folio) 124 123 { 125 124 bool ret = true; 126 125 bool toptier; 127 126 int nid; 128 - 129 - /* Avoid TLB flush if possible */ 130 - if (pte_protnone(oldpte)) 131 - goto skip; 132 127 133 128 if (!folio) 134 129 goto skip; ··· 302 307 struct page *page; 303 308 pte_t ptent; 304 309 310 + /* Already in the desired state. */ 311 + if (prot_numa && pte_protnone(oldpte)) 312 + continue; 313 + 305 314 page = vm_normal_page(vma, addr, oldpte); 306 315 if (page) 307 316 folio = page_folio(page); 317 + 308 318 /* 309 319 * Avoid trapping faults against the zero or KSM 310 320 * pages. See similar comment in change_huge_pmd. 311 321 */ 312 - if (prot_numa) { 313 - int ret = prot_numa_skip(vma, addr, oldpte, pte, 314 - target_node, folio); 315 - if (ret) { 322 + if (prot_numa && 323 + prot_numa_skip(vma, target_node, folio)) { 316 324 317 - /* determine batch to skip */ 318 - nr_ptes = mprotect_folio_pte_batch(folio, 319 - pte, oldpte, max_nr_ptes, /* flags = */ 0); 320 - continue; 321 - } 325 + /* determine batch to skip */ 326 + nr_ptes = mprotect_folio_pte_batch(folio, 327 + pte, oldpte, max_nr_ptes, /* flags = */ 0); 328 + continue; 322 329 } 323 330 324 331 nr_ptes = mprotect_folio_pte_batch(folio, pte, oldpte, max_nr_ptes, flags);