Skip to content

Commit 2cbea1d

Browse files
Wu Fengguangtorvalds
authored andcommitted
readahead: trigger mmap sequential readahead on PG_readahead
Previously the mmap sequential readahead is triggered by updating ra->prev_pos on each page fault and compare it with current page offset. It costs dirtying the cache line on each _minor_ page fault. So remove the ra->prev_pos recording, and instead tag PG_readahead to trigger the possible sequential readahead. It's not only more simple, but also will work more reliably and reduce cache line bouncing on concurrent page faults on shared struct file. In the mosbench exim benchmark which does multi-threaded page faults on shared struct file, the ra->mmap_miss and ra->prev_pos updates are found to cause excessive cache line bouncing on tmpfs, which actually disabled readahead totally (shmem_backing_dev_info.ra_pages == 0). So remove the ra->prev_pos recording, and instead tag PG_readahead to trigger the possible sequential readahead. It's not only more simple, but also will work more reliably on concurrent reads on shared struct file. Signed-off-by: Wu Fengguang <fengguang.wu@intel.com> Tested-by: Tim Chen <tim.c.chen@intel.com> Reported-by: Andi Kleen <ak@linux.intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 207d04b commit 2cbea1d

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

‎mm/filemap.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,8 +1559,7 @@ static void do_sync_mmap_readahead(struct vm_area_struct *vma,
15591559
if (!ra->ra_pages)
15601560
return;
15611561

1562-
if (VM_SequentialReadHint(vma) ||
1563-
offset - 1 == (ra->prev_pos >> PAGE_CACHE_SHIFT)) {
1562+
if (VM_SequentialReadHint(vma)) {
15641563
page_cache_sync_readahead(mapping, ra, file, offset,
15651564
ra->ra_pages);
15661565
return;
@@ -1583,7 +1582,7 @@ static void do_sync_mmap_readahead(struct vm_area_struct *vma,
15831582
ra_pages = max_sane_readahead(ra->ra_pages);
15841583
ra->start = max_t(long, 0, offset - ra_pages / 2);
15851584
ra->size = ra_pages;
1586-
ra->async_size = 0;
1585+
ra->async_size = ra_pages / 4;
15871586
ra_submit(ra, mapping, file);
15881587
}
15891588

@@ -1689,7 +1688,6 @@ int filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
16891688
return VM_FAULT_SIGBUS;
16901689
}
16911690

1692-
ra->prev_pos = (loff_t)offset << PAGE_CACHE_SHIFT;
16931691
vmf->page = page;
16941692
return ret | VM_FAULT_LOCKED;
16951693

0 commit comments

Comments
 (0)