Skip to content

Commit 16e4bce

Browse files
committed
Merge tag 'folio-5.19b' of git://git.infradead.org/users/willy/pagecache
Pull pagecache fixes from Matthew Wilcox: "Four folio-related fixes for 5.19: - Mark a folio accessed at the right time (Yu Kuai) - Fix a race for folios being replaced in the middle of a read (Brian Foster) - Clear folio->private in more places (Xiubo Li) - Take the invalidate_lock in page_cache_ra_order() (Alistair Popple)" * tag 'folio-5.19b' of git://git.infradead.org/users/willy/pagecache: filemap: Fix serialization adding transparent huge pages to page cache mm: Clear page->private when splitting or migrating a page filemap: Handle sibling entries in filemap_get_read_batch() filemap: Correct the conditions for marking a folio as accessed
2 parents 599d169 + 00fa15e commit 16e4bce

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

mm/filemap.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,6 +2385,8 @@ static void filemap_get_read_batch(struct address_space *mapping,
23852385
continue;
23862386
if (xas.xa_index > max || xa_is_value(folio))
23872387
break;
2388+
if (xa_is_sibling(folio))
2389+
break;
23882390
if (!folio_try_get_rcu(folio))
23892391
goto retry;
23902392

@@ -2629,6 +2631,13 @@ static int filemap_get_pages(struct kiocb *iocb, struct iov_iter *iter,
26292631
return err;
26302632
}
26312633

2634+
static inline bool pos_same_folio(loff_t pos1, loff_t pos2, struct folio *folio)
2635+
{
2636+
unsigned int shift = folio_shift(folio);
2637+
2638+
return (pos1 >> shift == pos2 >> shift);
2639+
}
2640+
26322641
/**
26332642
* filemap_read - Read data from the page cache.
26342643
* @iocb: The iocb to read.
@@ -2700,11 +2709,11 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter,
27002709
writably_mapped = mapping_writably_mapped(mapping);
27012710

27022711
/*
2703-
* When a sequential read accesses a page several times, only
2712+
* When a read accesses the same folio several times, only
27042713
* mark it as accessed the first time.
27052714
*/
2706-
if (iocb->ki_pos >> PAGE_SHIFT !=
2707-
ra->prev_pos >> PAGE_SHIFT)
2715+
if (!pos_same_folio(iocb->ki_pos, ra->prev_pos - 1,
2716+
fbatch.folios[0]))
27082717
folio_mark_accessed(fbatch.folios[0]);
27092718

27102719
for (i = 0; i < folio_batch_count(&fbatch); i++) {

mm/huge_memory.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2377,6 +2377,7 @@ static void __split_huge_page_tail(struct page *head, int tail,
23772377
page_tail);
23782378
page_tail->mapping = head->mapping;
23792379
page_tail->index = head->index + tail;
2380+
page_tail->private = 0;
23802381

23812382
/* Page flags must be visible before we make the page non-compound. */
23822383
smp_wmb();

mm/migrate.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,7 @@ static int unmap_and_move(new_page_t get_new_page,
11061106
if (!newpage)
11071107
return -ENOMEM;
11081108

1109+
newpage->private = 0;
11091110
rc = __unmap_and_move(page, newpage, force, mode);
11101111
if (rc == MIGRATEPAGE_SUCCESS)
11111112
set_page_owner_migrate_reason(newpage, reason);

mm/readahead.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ void page_cache_ra_order(struct readahead_control *ractl,
510510
new_order--;
511511
}
512512

513+
filemap_invalidate_lock_shared(mapping);
513514
while (index <= limit) {
514515
unsigned int order = new_order;
515516

@@ -536,6 +537,7 @@ void page_cache_ra_order(struct readahead_control *ractl,
536537
}
537538

538539
read_pages(ractl);
540+
filemap_invalidate_unlock_shared(mapping);
539541

540542
/*
541543
* If there were already pages in the page cache, then we may have

0 commit comments

Comments
 (0)