Skip to content

Commit d72dc8a

Browse files
jankaratorvalds
authored andcommitted
mm: make pagevec_lookup() update index
Make pagevec_lookup() (and underlying find_get_pages()) update index to the next page where iteration should continue. Most callers want this and also pagevec_lookup_tag() already does this. Link: http://lkml.kernel.org/r/20170726114704.7626-3-jack@suse.cz Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 26b433d commit d72dc8a

11 files changed

Lines changed: 32 additions & 37 deletions

File tree

‎fs/buffer.c‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,13 +1633,12 @@ void clean_bdev_aliases(struct block_device *bdev, sector_t block, sector_t len)
16331633

16341634
end = (block + len - 1) >> (PAGE_SHIFT - bd_inode->i_blkbits);
16351635
pagevec_init(&pvec, 0);
1636-
while (index <= end && pagevec_lookup(&pvec, bd_mapping, index,
1636+
while (index <= end && pagevec_lookup(&pvec, bd_mapping, &index,
16371637
min(end - index, (pgoff_t)PAGEVEC_SIZE - 1) + 1)) {
16381638
for (i = 0; i < pagevec_count(&pvec); i++) {
16391639
struct page *page = pvec.pages[i];
16401640

1641-
index = page->index;
1642-
if (index > end)
1641+
if (page->index > end)
16431642
break;
16441643
if (!page_has_buffers(page))
16451644
continue;
@@ -1670,7 +1669,6 @@ void clean_bdev_aliases(struct block_device *bdev, sector_t block, sector_t len)
16701669
}
16711670
pagevec_release(&pvec);
16721671
cond_resched();
1673-
index++;
16741672
}
16751673
}
16761674
EXPORT_SYMBOL(clean_bdev_aliases);
@@ -3552,7 +3550,8 @@ page_cache_seek_hole_data(struct inode *inode, loff_t offset, loff_t length,
35523550
unsigned want, nr_pages, i;
35533551

35543552
want = min_t(unsigned, end - index, PAGEVEC_SIZE);
3555-
nr_pages = pagevec_lookup(&pvec, inode->i_mapping, index, want);
3553+
nr_pages = pagevec_lookup(&pvec, inode->i_mapping, &index,
3554+
want);
35563555
if (nr_pages == 0)
35573556
break;
35583557

@@ -3594,7 +3593,6 @@ page_cache_seek_hole_data(struct inode *inode, loff_t offset, loff_t length,
35943593
if (nr_pages < want)
35953594
break;
35963595

3597-
index = pvec.pages[i - 1]->index + 1;
35983596
pagevec_release(&pvec);
35993597
} while (index < end);
36003598

‎fs/ext4/file.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ static int ext4_find_unwritten_pgoff(struct inode *inode,
468468
unsigned long nr_pages;
469469

470470
num = min_t(pgoff_t, end - index, PAGEVEC_SIZE - 1) + 1;
471-
nr_pages = pagevec_lookup(&pvec, inode->i_mapping, index,
471+
nr_pages = pagevec_lookup(&pvec, inode->i_mapping, &index,
472472
(pgoff_t)num);
473473
if (nr_pages == 0)
474474
break;
@@ -536,8 +536,6 @@ static int ext4_find_unwritten_pgoff(struct inode *inode,
536536
/* The no. of pages is less than our desired, we are done. */
537537
if (nr_pages < num)
538538
break;
539-
540-
index = pvec.pages[i - 1]->index + 1;
541539
pagevec_release(&pvec);
542540
} while (index <= end);
543541

‎fs/ext4/inode.c‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,7 +1720,7 @@ static void mpage_release_unused_pages(struct mpage_da_data *mpd,
17201720

17211721
pagevec_init(&pvec, 0);
17221722
while (index <= end) {
1723-
nr_pages = pagevec_lookup(&pvec, mapping, index, PAGEVEC_SIZE);
1723+
nr_pages = pagevec_lookup(&pvec, mapping, &index, PAGEVEC_SIZE);
17241724
if (nr_pages == 0)
17251725
break;
17261726
for (i = 0; i < nr_pages; i++) {
@@ -1737,7 +1737,6 @@ static void mpage_release_unused_pages(struct mpage_da_data *mpd,
17371737
}
17381738
unlock_page(page);
17391739
}
1740-
index = pvec.pages[nr_pages - 1]->index + 1;
17411740
pagevec_release(&pvec);
17421741
}
17431742
}
@@ -2348,7 +2347,7 @@ static int mpage_map_and_submit_buffers(struct mpage_da_data *mpd)
23482347

23492348
pagevec_init(&pvec, 0);
23502349
while (start <= end) {
2351-
nr_pages = pagevec_lookup(&pvec, inode->i_mapping, start,
2350+
nr_pages = pagevec_lookup(&pvec, inode->i_mapping, &start,
23522351
PAGEVEC_SIZE);
23532352
if (nr_pages == 0)
23542353
break;
@@ -2357,8 +2356,6 @@ static int mpage_map_and_submit_buffers(struct mpage_da_data *mpd)
23572356

23582357
if (page->index > end)
23592358
break;
2360-
/* Up to 'end' pages must be contiguous */
2361-
BUG_ON(page->index != start);
23622359
bh = head = page_buffers(page);
23632360
do {
23642361
if (lblk < mpd->map.m_lblk)
@@ -2403,7 +2400,6 @@ static int mpage_map_and_submit_buffers(struct mpage_da_data *mpd)
24032400
pagevec_release(&pvec);
24042401
return err;
24052402
}
2406-
start++;
24072403
}
24082404
pagevec_release(&pvec);
24092405
}

‎fs/fscache/page.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,19 +1178,18 @@ void __fscache_uncache_all_inode_pages(struct fscache_cookie *cookie,
11781178
pagevec_init(&pvec, 0);
11791179
next = 0;
11801180
do {
1181-
if (!pagevec_lookup(&pvec, mapping, next, PAGEVEC_SIZE))
1181+
if (!pagevec_lookup(&pvec, mapping, &next, PAGEVEC_SIZE))
11821182
break;
11831183
for (i = 0; i < pagevec_count(&pvec); i++) {
11841184
struct page *page = pvec.pages[i];
1185-
next = page->index;
11861185
if (PageFsCache(page)) {
11871186
__fscache_wait_on_page_write(cookie, page);
11881187
__fscache_uncache_page(cookie, page);
11891188
}
11901189
}
11911190
pagevec_release(&pvec);
11921191
cond_resched();
1193-
} while (++next);
1192+
} while (next);
11941193

11951194
_leave("");
11961195
}

‎fs/hugetlbfs/inode.c‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,
401401
const pgoff_t end = lend >> huge_page_shift(h);
402402
struct vm_area_struct pseudo_vma;
403403
struct pagevec pvec;
404-
pgoff_t next;
404+
pgoff_t next, index;
405405
int i, freed = 0;
406406
long lookup_nr = PAGEVEC_SIZE;
407407
bool truncate_op = (lend == LLONG_MAX);
@@ -420,7 +420,7 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,
420420
/*
421421
* When no more pages are found, we are done.
422422
*/
423-
if (!pagevec_lookup(&pvec, mapping, next, lookup_nr))
423+
if (!pagevec_lookup(&pvec, mapping, &next, lookup_nr))
424424
break;
425425

426426
for (i = 0; i < pagevec_count(&pvec); ++i) {
@@ -432,13 +432,13 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,
432432
* only possible in the punch hole case as end is
433433
* max page offset in the truncate case.
434434
*/
435-
next = page->index;
436-
if (next >= end)
435+
index = page->index;
436+
if (index >= end)
437437
break;
438438

439439
hash = hugetlb_fault_mutex_hash(h, current->mm,
440440
&pseudo_vma,
441-
mapping, next, 0);
441+
mapping, index, 0);
442442
mutex_lock(&hugetlb_fault_mutex_table[hash]);
443443

444444
/*
@@ -455,8 +455,8 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,
455455

456456
i_mmap_lock_write(mapping);
457457
hugetlb_vmdelete_list(&mapping->i_mmap,
458-
next * pages_per_huge_page(h),
459-
(next + 1) * pages_per_huge_page(h));
458+
index * pages_per_huge_page(h),
459+
(index + 1) * pages_per_huge_page(h));
460460
i_mmap_unlock_write(mapping);
461461
}
462462

@@ -475,14 +475,13 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,
475475
freed++;
476476
if (!truncate_op) {
477477
if (unlikely(hugetlb_unreserve_pages(inode,
478-
next, next + 1, 1)))
478+
index, index + 1, 1)))
479479
hugetlb_fix_reserve_counts(inode);
480480
}
481481

482482
unlock_page(page);
483483
mutex_unlock(&hugetlb_fault_mutex_table[hash]);
484484
}
485-
++next;
486485
huge_pagevec_release(&pvec);
487486
cond_resched();
488487
}

‎fs/nilfs2/page.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,9 @@ void nilfs_copy_back_pages(struct address_space *dmap,
312312

313313
pagevec_init(&pvec, 0);
314314
repeat:
315-
n = pagevec_lookup(&pvec, smap, index, PAGEVEC_SIZE);
315+
n = pagevec_lookup(&pvec, smap, &index, PAGEVEC_SIZE);
316316
if (!n)
317317
return;
318-
index = pvec.pages[n - 1]->index + 1;
319318

320319
for (i = 0; i < pagevec_count(&pvec); i++) {
321320
struct page *page = pvec.pages[i], *dpage;

‎fs/ramfs/file-nommu.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ static unsigned long ramfs_nommu_get_unmapped_area(struct file *file,
228228
if (!pages)
229229
goto out_free;
230230

231-
nr = find_get_pages(inode->i_mapping, pgoff, lpages, pages);
231+
nr = find_get_pages(inode->i_mapping, &pgoff, lpages, pages);
232232
if (nr != lpages)
233233
goto out_free_pages; /* leave if some pages were missing */
234234

‎include/linux/pagemap.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ struct page *find_lock_entry(struct address_space *mapping, pgoff_t offset);
353353
unsigned find_get_entries(struct address_space *mapping, pgoff_t start,
354354
unsigned int nr_entries, struct page **entries,
355355
pgoff_t *indices);
356-
unsigned find_get_pages(struct address_space *mapping, pgoff_t start,
356+
unsigned find_get_pages(struct address_space *mapping, pgoff_t *start,
357357
unsigned int nr_pages, struct page **pages);
358358
unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t start,
359359
unsigned int nr_pages, struct page **pages);

‎include/linux/pagevec.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ unsigned pagevec_lookup_entries(struct pagevec *pvec,
2828
pgoff_t *indices);
2929
void pagevec_remove_exceptionals(struct pagevec *pvec);
3030
unsigned pagevec_lookup(struct pagevec *pvec, struct address_space *mapping,
31-
pgoff_t start, unsigned nr_pages);
31+
pgoff_t *start, unsigned nr_pages);
3232
unsigned pagevec_lookup_tag(struct pagevec *pvec,
3333
struct address_space *mapping, pgoff_t *index, int tag,
3434
unsigned nr_pages);

‎mm/filemap.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ bool filemap_range_has_page(struct address_space *mapping,
403403
return false;
404404

405405
pagevec_init(&pvec, 0);
406-
if (!pagevec_lookup(&pvec, mapping, index, 1))
406+
if (!pagevec_lookup(&pvec, mapping, &index, 1))
407407
return false;
408408
ret = (pvec.pages[0]->index <= end);
409409
pagevec_release(&pvec);
@@ -1569,10 +1569,11 @@ unsigned find_get_entries(struct address_space *mapping,
15691569
*
15701570
* The search returns a group of mapping-contiguous pages with ascending
15711571
* indexes. There may be holes in the indices due to not-present pages.
1572+
* We also update @start to index the next page for the traversal.
15721573
*
15731574
* find_get_pages() returns the number of pages which were found.
15741575
*/
1575-
unsigned find_get_pages(struct address_space *mapping, pgoff_t start,
1576+
unsigned find_get_pages(struct address_space *mapping, pgoff_t *start,
15761577
unsigned int nr_pages, struct page **pages)
15771578
{
15781579
struct radix_tree_iter iter;
@@ -1583,7 +1584,7 @@ unsigned find_get_pages(struct address_space *mapping, pgoff_t start,
15831584
return 0;
15841585

15851586
rcu_read_lock();
1586-
radix_tree_for_each_slot(slot, &mapping->page_tree, &iter, start) {
1587+
radix_tree_for_each_slot(slot, &mapping->page_tree, &iter, *start) {
15871588
struct page *head, *page;
15881589
repeat:
15891590
page = radix_tree_deref_slot(slot);
@@ -1625,6 +1626,10 @@ unsigned find_get_pages(struct address_space *mapping, pgoff_t start,
16251626
}
16261627

16271628
rcu_read_unlock();
1629+
1630+
if (ret)
1631+
*start = pages[ret - 1]->index + 1;
1632+
16281633
return ret;
16291634
}
16301635

0 commit comments

Comments
 (0)