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: change to return bool for ptep_test_and_clear_young()

Patch series "change young flag check functions to return bool", v2.

This is a cleanup patchset to change all young flag check functions to
return bool, as discussed with David in the previous thread[1]. Since
callers only care about whether the young flag was set, returning bool
makes the intention clearer. No functional changes intended.


This patch (of 6):

Callers use ptep_test_and_clear_young() to clear the young flag and check
whether it was set. Change the return type to bool to make the intention
clearer.

Link: https://lkml.kernel.org/r/cover.1774075004.git.baolin.wang@linux.alibaba.com
Link: https://lkml.kernel.org/r/57e70efa9703d43959aa645246ea3cbdba14fa17.1774075004.git.baolin.wang@linux.alibaba.com
Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Baolin Wang and committed by
Andrew Morton
a62ca3f4 f2a48f8f

+46 -50
+7 -9
arch/arm64/include/asm/pgtable.h
··· 1282 1282 __set_pte(ptep, __pte(0)); 1283 1283 } 1284 1284 1285 - static inline int __ptep_test_and_clear_young(struct vm_area_struct *vma, 1286 - unsigned long address, 1287 - pte_t *ptep) 1285 + static inline bool __ptep_test_and_clear_young(struct vm_area_struct *vma, 1286 + unsigned long address, pte_t *ptep) 1288 1287 { 1289 1288 pte_t old_pte, pte; 1290 1289 ··· 1645 1646 extern pte_t contpte_get_and_clear_full_ptes(struct mm_struct *mm, 1646 1647 unsigned long addr, pte_t *ptep, 1647 1648 unsigned int nr, int full); 1648 - int contpte_test_and_clear_young_ptes(struct vm_area_struct *vma, 1649 + bool contpte_test_and_clear_young_ptes(struct vm_area_struct *vma, 1649 1650 unsigned long addr, pte_t *ptep, unsigned int nr); 1650 1651 int contpte_clear_flush_young_ptes(struct vm_area_struct *vma, 1651 1652 unsigned long addr, pte_t *ptep, unsigned int nr); ··· 1812 1813 } 1813 1814 1814 1815 #define test_and_clear_young_ptes test_and_clear_young_ptes 1815 - static inline int test_and_clear_young_ptes(struct vm_area_struct *vma, 1816 - unsigned long addr, pte_t *ptep, 1817 - unsigned int nr) 1816 + static inline bool test_and_clear_young_ptes(struct vm_area_struct *vma, 1817 + unsigned long addr, pte_t *ptep, unsigned int nr) 1818 1818 { 1819 1819 if (likely(nr == 1 && !pte_cont(__ptep_get(ptep)))) 1820 1820 return __ptep_test_and_clear_young(vma, addr, ptep); ··· 1822 1824 } 1823 1825 1824 1826 #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG 1825 - static inline int ptep_test_and_clear_young(struct vm_area_struct *vma, 1826 - unsigned long addr, pte_t *ptep) 1827 + static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma, 1828 + unsigned long addr, pte_t *ptep) 1827 1829 { 1828 1830 return test_and_clear_young_ptes(vma, addr, ptep, 1); 1829 1831 }
+3 -4
arch/arm64/mm/contpte.c
··· 508 508 } 509 509 EXPORT_SYMBOL_GPL(contpte_get_and_clear_full_ptes); 510 510 511 - int contpte_test_and_clear_young_ptes(struct vm_area_struct *vma, 512 - unsigned long addr, pte_t *ptep, 513 - unsigned int nr) 511 + bool contpte_test_and_clear_young_ptes(struct vm_area_struct *vma, 512 + unsigned long addr, pte_t *ptep, unsigned int nr) 514 513 { 515 514 /* 516 515 * ptep_clear_flush_young() technically requires us to clear the access ··· 524 525 */ 525 526 526 527 unsigned long end = addr + nr * PAGE_SIZE; 527 - int young = 0; 528 + bool young = false; 528 529 529 530 ptep = contpte_align_addr_ptep(&addr, &end, ptep, nr); 530 531 for (; addr != end; ptep++, addr += PAGE_SIZE)
+1 -1
arch/microblaze/include/asm/pgtable.h
··· 318 318 319 319 #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG 320 320 struct vm_area_struct; 321 - static inline int ptep_test_and_clear_young(struct vm_area_struct *vma, 321 + static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma, 322 322 unsigned long address, pte_t *ptep) 323 323 { 324 324 return (pte_update(ptep, _PAGE_ACCESSED, 0) & _PAGE_ACCESSED) != 0;
+4 -3
arch/parisc/include/asm/pgtable.h
··· 438 438 } 439 439 #define ptep_get ptep_get 440 440 441 - static inline int ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep) 441 + static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma, 442 + unsigned long addr, pte_t *ptep) 442 443 { 443 444 pte_t pte; 444 445 445 446 pte = ptep_get(ptep); 446 447 if (!pte_young(pte)) { 447 - return 0; 448 + return false; 448 449 } 449 450 set_pte_at(vma->vm_mm, addr, ptep, pte_mkold(pte)); 450 - return 1; 451 + return true; 451 452 } 452 453 453 454 int ptep_clear_flush_young(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep);
+2 -2
arch/powerpc/include/asm/book3s/32/pgtable.h
··· 295 295 * for our hash-based implementation, we fix that up here. 296 296 */ 297 297 #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG 298 - static inline int __ptep_test_and_clear_young(struct mm_struct *mm, 299 - unsigned long addr, pte_t *ptep) 298 + static inline bool __ptep_test_and_clear_young(struct mm_struct *mm, 299 + unsigned long addr, pte_t *ptep) 300 300 { 301 301 unsigned long old; 302 302 old = pte_update(mm, addr, ptep, _PAGE_ACCESSED, 0, 0);
+3 -3
arch/powerpc/include/asm/book3s/64/pgtable.h
··· 349 349 * For radix: H_PAGE_HASHPTE should be zero. Hence we can use the same 350 350 * function for both hash and radix. 351 351 */ 352 - static inline int __ptep_test_and_clear_young(struct mm_struct *mm, 353 - unsigned long addr, pte_t *ptep) 352 + static inline bool __ptep_test_and_clear_young(struct mm_struct *mm, 353 + unsigned long addr, pte_t *ptep) 354 354 { 355 355 unsigned long old; 356 356 357 357 if ((pte_raw(*ptep) & cpu_to_be64(_PAGE_ACCESSED | H_PAGE_HASHPTE)) == 0) 358 - return 0; 358 + return false; 359 359 old = pte_update(mm, addr, ptep, _PAGE_ACCESSED, 0, 0); 360 360 return (old & _PAGE_ACCESSED) != 0; 361 361 }
+2 -2
arch/powerpc/include/asm/nohash/pgtable.h
··· 101 101 } 102 102 #endif 103 103 104 - static inline int ptep_test_and_clear_young(struct vm_area_struct *vma, 105 - unsigned long addr, pte_t *ptep) 104 + static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma, 105 + unsigned long addr, pte_t *ptep) 106 106 { 107 107 unsigned long old; 108 108
+2 -2
arch/riscv/include/asm/pgtable.h
··· 659 659 extern int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address, 660 660 pte_t *ptep, pte_t entry, int dirty); 661 661 #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG /* defined in mm/pgtable.c */ 662 - extern int ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long address, 663 - pte_t *ptep); 662 + bool ptep_test_and_clear_young(struct vm_area_struct *vma, 663 + unsigned long address, pte_t *ptep); 664 664 665 665 #define __HAVE_ARCH_PTEP_GET_AND_CLEAR 666 666 static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
+3 -4
arch/riscv/mm/pgtable.c
··· 29 29 return true; 30 30 } 31 31 32 - int ptep_test_and_clear_young(struct vm_area_struct *vma, 33 - unsigned long address, 34 - pte_t *ptep) 32 + bool ptep_test_and_clear_young(struct vm_area_struct *vma, 33 + unsigned long address, pte_t *ptep) 35 34 { 36 35 if (!pte_young(ptep_get(ptep))) 37 - return 0; 36 + return false; 38 37 return test_and_clear_bit(_PAGE_ACCESSED_OFFSET, &pte_val(*ptep)); 39 38 } 40 39 EXPORT_SYMBOL_GPL(ptep_test_and_clear_young);
+2 -2
arch/s390/include/asm/pgtable.h
··· 1164 1164 pte_t ptep_xchg_lazy(struct mm_struct *, unsigned long, pte_t *, pte_t); 1165 1165 1166 1166 #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG 1167 - static inline int ptep_test_and_clear_young(struct vm_area_struct *vma, 1168 - unsigned long addr, pte_t *ptep) 1167 + static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma, 1168 + unsigned long addr, pte_t *ptep) 1169 1169 { 1170 1170 pte_t pte = *ptep; 1171 1171
+2 -2
arch/x86/include/asm/pgtable.h
··· 1232 1232 pte_t entry, int dirty); 1233 1233 1234 1234 #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG 1235 - extern int ptep_test_and_clear_young(struct vm_area_struct *vma, 1236 - unsigned long addr, pte_t *ptep); 1235 + bool ptep_test_and_clear_young(struct vm_area_struct *vma, 1236 + unsigned long addr, pte_t *ptep); 1237 1237 1238 1238 #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH 1239 1239 extern int ptep_clear_flush_young(struct vm_area_struct *vma,
+3 -3
arch/x86/mm/pgtable.c
··· 443 443 } 444 444 #endif 445 445 446 - int ptep_test_and_clear_young(struct vm_area_struct *vma, 447 - unsigned long addr, pte_t *ptep) 446 + bool ptep_test_and_clear_young(struct vm_area_struct *vma, 447 + unsigned long addr, pte_t *ptep) 448 448 { 449 - int ret = 0; 449 + bool ret = false; 450 450 451 451 if (pte_young(*ptep)) 452 452 ret = test_and_clear_bit(_PAGE_BIT_ACCESSED,
+4 -5
arch/xtensa/include/asm/pgtable.h
··· 304 304 305 305 struct vm_area_struct; 306 306 307 - static inline int 308 - ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long addr, 309 - pte_t *ptep) 307 + static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma, 308 + unsigned long addr, pte_t *ptep) 310 309 { 311 310 pte_t pte = *ptep; 312 311 if (!pte_young(pte)) 313 - return 0; 312 + return false; 314 313 update_pte(ptep, pte_mkold(pte)); 315 - return 1; 314 + return true; 316 315 } 317 316 318 317 static inline pte_t
+8 -8
include/linux/pgtable.h
··· 491 491 #endif 492 492 493 493 #ifndef __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG 494 - static inline int ptep_test_and_clear_young(struct vm_area_struct *vma, 495 - unsigned long address, 496 - pte_t *ptep) 494 + static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma, 495 + unsigned long address, pte_t *ptep) 497 496 { 498 497 pte_t pte = ptep_get(ptep); 499 - int r = 1; 498 + bool young = true; 499 + 500 500 if (!pte_young(pte)) 501 - r = 0; 501 + young = false; 502 502 else 503 503 set_pte_at(vma->vm_mm, address, ptep, pte_mkold(pte)); 504 - return r; 504 + return young; 505 505 } 506 506 #endif 507 507 ··· 1123 1123 * 1124 1124 * Returns: whether any PTE was young. 1125 1125 */ 1126 - static inline int test_and_clear_young_ptes(struct vm_area_struct *vma, 1126 + static inline bool test_and_clear_young_ptes(struct vm_area_struct *vma, 1127 1127 unsigned long addr, pte_t *ptep, unsigned int nr) 1128 1128 { 1129 - int young = 0; 1129 + bool young = false; 1130 1130 1131 1131 for (;;) { 1132 1132 young |= ptep_test_and_clear_young(vma, addr, ptep);