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/khugepaged: use start_addr/addr for improved readability

When collapsing a pmd, there are two address in use:

* address points to the start of pmd
* address points to each individual page

Current naming makes it difficult to distinguish these two and is hence
error prone.

Considering the plan to collapse mTHP, name the first one `start_addr' and
the second `addr' for better readability and consistency.

Link: https://lkml.kernel.org/r/20250922140938.27343-1-richard.weiyang@gmail.com
Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
Suggested-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Nico Pache <npache@redhat.com>
Acked-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Dev Jain <dev.jain@arm.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: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Mariano Pache <npache@redhat.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Wei Yang and committed by
Andrew Morton
1acc3693 dd83609b

+22 -21
+22 -21
mm/khugepaged.c
··· 537 537 } 538 538 539 539 static int __collapse_huge_page_isolate(struct vm_area_struct *vma, 540 - unsigned long address, 540 + unsigned long start_addr, 541 541 pte_t *pte, 542 542 struct collapse_control *cc, 543 543 struct list_head *compound_pagelist) 544 544 { 545 545 struct page *page = NULL; 546 546 struct folio *folio = NULL; 547 + unsigned long addr = start_addr; 547 548 pte_t *_pte; 548 549 int none_or_zero = 0, shared = 0, result = SCAN_FAIL, referenced = 0; 549 550 550 551 for (_pte = pte; _pte < pte + HPAGE_PMD_NR; 551 - _pte++, address += PAGE_SIZE) { 552 + _pte++, addr += PAGE_SIZE) { 552 553 pte_t pteval = ptep_get(_pte); 553 554 if (pte_none(pteval) || (pte_present(pteval) && 554 555 is_zero_pfn(pte_pfn(pteval)))) { ··· 572 571 result = SCAN_PTE_UFFD_WP; 573 572 goto out; 574 573 } 575 - page = vm_normal_page(vma, address, pteval); 574 + page = vm_normal_page(vma, addr, pteval); 576 575 if (unlikely(!page) || unlikely(is_zone_device_page(page))) { 577 576 result = SCAN_PAGE_NULL; 578 577 goto out; ··· 657 656 */ 658 657 if (cc->is_khugepaged && 659 658 (pte_young(pteval) || folio_test_young(folio) || 660 - folio_test_referenced(folio) || mmu_notifier_test_young(vma->vm_mm, 661 - address))) 659 + folio_test_referenced(folio) || 660 + mmu_notifier_test_young(vma->vm_mm, addr))) 662 661 referenced++; 663 662 } 664 663 ··· 987 986 */ 988 987 static int __collapse_huge_page_swapin(struct mm_struct *mm, 989 988 struct vm_area_struct *vma, 990 - unsigned long haddr, pmd_t *pmd, 989 + unsigned long start_addr, pmd_t *pmd, 991 990 int referenced) 992 991 { 993 992 int swapped_in = 0; 994 993 vm_fault_t ret = 0; 995 - unsigned long address, end = haddr + (HPAGE_PMD_NR * PAGE_SIZE); 994 + unsigned long addr, end = start_addr + (HPAGE_PMD_NR * PAGE_SIZE); 996 995 int result; 997 996 pte_t *pte = NULL; 998 997 spinlock_t *ptl; 999 998 1000 - for (address = haddr; address < end; address += PAGE_SIZE) { 999 + for (addr = start_addr; addr < end; addr += PAGE_SIZE) { 1001 1000 struct vm_fault vmf = { 1002 1001 .vma = vma, 1003 - .address = address, 1004 - .pgoff = linear_page_index(vma, address), 1002 + .address = addr, 1003 + .pgoff = linear_page_index(vma, addr), 1005 1004 .flags = FAULT_FLAG_ALLOW_RETRY, 1006 1005 .pmd = pmd, 1007 1006 }; ··· 1011 1010 * Here the ptl is only used to check pte_same() in 1012 1011 * do_swap_page(), so readonly version is enough. 1013 1012 */ 1014 - pte = pte_offset_map_ro_nolock(mm, pmd, address, &ptl); 1013 + pte = pte_offset_map_ro_nolock(mm, pmd, addr, &ptl); 1015 1014 if (!pte) { 1016 1015 mmap_read_unlock(mm); 1017 1016 result = SCAN_PMD_NULL; ··· 1254 1253 1255 1254 static int hpage_collapse_scan_pmd(struct mm_struct *mm, 1256 1255 struct vm_area_struct *vma, 1257 - unsigned long address, bool *mmap_locked, 1256 + unsigned long start_addr, bool *mmap_locked, 1258 1257 struct collapse_control *cc) 1259 1258 { 1260 1259 pmd_t *pmd; ··· 1263 1262 int none_or_zero = 0, shared = 0; 1264 1263 struct page *page = NULL; 1265 1264 struct folio *folio = NULL; 1266 - unsigned long _address; 1265 + unsigned long addr; 1267 1266 spinlock_t *ptl; 1268 1267 int node = NUMA_NO_NODE, unmapped = 0; 1269 1268 1270 - VM_BUG_ON(address & ~HPAGE_PMD_MASK); 1269 + VM_BUG_ON(start_addr & ~HPAGE_PMD_MASK); 1271 1270 1272 - result = find_pmd_or_thp_or_none(mm, address, &pmd); 1271 + result = find_pmd_or_thp_or_none(mm, start_addr, &pmd); 1273 1272 if (result != SCAN_SUCCEED) 1274 1273 goto out; 1275 1274 1276 1275 memset(cc->node_load, 0, sizeof(cc->node_load)); 1277 1276 nodes_clear(cc->alloc_nmask); 1278 - pte = pte_offset_map_lock(mm, pmd, address, &ptl); 1277 + pte = pte_offset_map_lock(mm, pmd, start_addr, &ptl); 1279 1278 if (!pte) { 1280 1279 result = SCAN_PMD_NULL; 1281 1280 goto out; 1282 1281 } 1283 1282 1284 - for (_address = address, _pte = pte; _pte < pte + HPAGE_PMD_NR; 1285 - _pte++, _address += PAGE_SIZE) { 1283 + for (addr = start_addr, _pte = pte; _pte < pte + HPAGE_PMD_NR; 1284 + _pte++, addr += PAGE_SIZE) { 1286 1285 pte_t pteval = ptep_get(_pte); 1287 1286 if (is_swap_pte(pteval)) { 1288 1287 ++unmapped; ··· 1330 1329 goto out_unmap; 1331 1330 } 1332 1331 1333 - page = vm_normal_page(vma, _address, pteval); 1332 + page = vm_normal_page(vma, addr, pteval); 1334 1333 if (unlikely(!page) || unlikely(is_zone_device_page(page))) { 1335 1334 result = SCAN_PAGE_NULL; 1336 1335 goto out_unmap; ··· 1399 1398 if (cc->is_khugepaged && 1400 1399 (pte_young(pteval) || folio_test_young(folio) || 1401 1400 folio_test_referenced(folio) || 1402 - mmu_notifier_test_young(vma->vm_mm, _address))) 1401 + mmu_notifier_test_young(vma->vm_mm, addr))) 1403 1402 referenced++; 1404 1403 } 1405 1404 if (cc->is_khugepaged && ··· 1412 1411 out_unmap: 1413 1412 pte_unmap_unlock(pte, ptl); 1414 1413 if (result == SCAN_SUCCEED) { 1415 - result = collapse_huge_page(mm, address, referenced, 1414 + result = collapse_huge_page(mm, start_addr, referenced, 1416 1415 unmapped, cc); 1417 1416 /* collapse_huge_page will return with the mmap_lock released */ 1418 1417 *mmap_locked = false;