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/gup: remove record_subpages()

We can just cleanup the code by calculating the #refs earlier, so we can
just inline what remains of record_subpages().

Calculate the number of references/pages ahead of times, and record them
only once all our tests passed.

[david@redhat.com: fix `pages' adjustment]
Link: https://lkml.kernel.org/r/cc7f03f8-da8b-407e-a03a-e8e5a9ec5462@redhat.com
Link: https://lkml.kernel.org/r/20250901150359.867252-20-david@redhat.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Eric Biggers <ebiggers@kernel.org>
Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

David Hildenbrand and committed by
Andrew Morton
e3c05b6e 541541db

+10 -17
+10 -17
mm/gup.c
··· 484 484 #ifdef CONFIG_MMU 485 485 486 486 #ifdef CONFIG_HAVE_GUP_FAST 487 - static int record_subpages(struct page *page, unsigned long sz, 488 - unsigned long addr, unsigned long end, 489 - struct page **pages) 490 - { 491 - int nr; 492 - 493 - page += (addr & (sz - 1)) >> PAGE_SHIFT; 494 - for (nr = 0; addr != end; nr++, addr += PAGE_SIZE) 495 - pages[nr] = page++; 496 - 497 - return nr; 498 - } 499 - 500 487 /** 501 488 * try_grab_folio_fast() - Attempt to get or pin a folio in fast path. 502 489 * @page: pointer to page to be grabbed ··· 2958 2971 if (pmd_special(orig)) 2959 2972 return 0; 2960 2973 2961 - page = pmd_page(orig); 2962 - refs = record_subpages(page, PMD_SIZE, addr, end, pages + *nr); 2974 + refs = (end - addr) >> PAGE_SHIFT; 2975 + page = pmd_page(orig) + ((addr & ~PMD_MASK) >> PAGE_SHIFT); 2963 2976 2964 2977 folio = try_grab_folio_fast(page, refs, flags); 2965 2978 if (!folio) ··· 2979 2992 return 0; 2980 2993 } 2981 2994 2995 + pages += *nr; 2982 2996 *nr += refs; 2997 + for (; refs; refs--) 2998 + *(pages++) = page++; 2983 2999 folio_set_referenced(folio); 2984 3000 return 1; 2985 3001 } ··· 3001 3011 if (pud_special(orig)) 3002 3012 return 0; 3003 3013 3004 - page = pud_page(orig); 3005 - refs = record_subpages(page, PUD_SIZE, addr, end, pages + *nr); 3014 + refs = (end - addr) >> PAGE_SHIFT; 3015 + page = pud_page(orig) + ((addr & ~PUD_MASK) >> PAGE_SHIFT); 3006 3016 3007 3017 folio = try_grab_folio_fast(page, refs, flags); 3008 3018 if (!folio) ··· 3023 3033 return 0; 3024 3034 } 3025 3035 3036 + pages += *nr; 3026 3037 *nr += refs; 3038 + for (; refs; refs--) 3039 + *(pages++) = page++; 3027 3040 folio_set_referenced(folio); 3028 3041 return 1; 3029 3042 }