Skip to content

Commit 30f62b9

Browse files
VMoolaakpm00
authored andcommitted
mm/gup: remove unnecessary check in memfd_pin_folios()
Patch series "mm/gup: Cleanup memfd_pin_folios()". A couple straightforward cleanups to memfd_pin_folios() found through code inspection. Saves 124 bytes of kernel text overall and makes the code more readable. This patch (of 2): Commit 89c1905 ("mm/gup: introduce memfd_pin_folios() for pinning memfd folios") checks if filemap_get_folios_contig() returned duplicate folios to prevent multiple attempts at pinning the same folio. Commit 8ab1b16 ("mm: fix filemap_get_folios_contig returning batches of identical folios") ensures that filemap_get_folios_contig() returns a batch of distinct folios. We can remove the duplicate folio check to simplify the code and save 58 bytes of text. Link: https://lkml.kernel.org/r/20250430010059.892632-1-vishal.moola@gmail.com Link: https://lkml.kernel.org/r/20250430010059.892632-2-vishal.moola@gmail.com Signed-off-by: Vishal Moola (Oracle) <vishal.moola@gmail.com> Acked-by: David Hildenbrand <david@redhat.com> Cc: Vivek Kasireddy <vivek.kasireddy@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent dd309bf commit 30f62b9

File tree

1 file changed

+1
-14
lines changed

1 file changed

+1
-14
lines changed

mm/gup.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3590,7 +3590,7 @@ long memfd_pin_folios(struct file *memfd, loff_t start, loff_t end,
35903590
{
35913591
unsigned int flags, nr_folios, nr_found;
35923592
unsigned int i, pgshift = PAGE_SHIFT;
3593-
pgoff_t start_idx, end_idx, next_idx;
3593+
pgoff_t start_idx, end_idx;
35943594
struct folio *folio = NULL;
35953595
struct folio_batch fbatch;
35963596
struct hstate *h;
@@ -3640,19 +3640,7 @@ long memfd_pin_folios(struct file *memfd, loff_t start, loff_t end,
36403640
folio = NULL;
36413641
}
36423642

3643-
next_idx = 0;
36443643
for (i = 0; i < nr_found; i++) {
3645-
/*
3646-
* As there can be multiple entries for a
3647-
* given folio in the batch returned by
3648-
* filemap_get_folios_contig(), the below
3649-
* check is to ensure that we pin and return a
3650-
* unique set of folios between start and end.
3651-
*/
3652-
if (next_idx &&
3653-
next_idx != folio_index(fbatch.folios[i]))
3654-
continue;
3655-
36563644
folio = page_folio(&fbatch.folios[i]->page);
36573645

36583646
if (try_grab_folio(folio, 1, FOLL_PIN)) {
@@ -3665,7 +3653,6 @@ long memfd_pin_folios(struct file *memfd, loff_t start, loff_t end,
36653653
*offset = offset_in_folio(folio, start);
36663654

36673655
folios[nr_folios] = folio;
3668-
next_idx = folio_next_index(folio);
36693656
if (++nr_folios == max_folios)
36703657
break;
36713658
}

0 commit comments

Comments
 (0)