Skip to content

Commit ed49f6f

Browse files
fyin1xen0n
authored andcommitted
filemap: Batch PTE mappings
Call set_pte_range() once per contiguous range of the folio instead of once per page. This batches the updates to mm counters and the rmap. With a will-it-scale.page_fault3 like app (change file write fault testing to read fault testing. Trying to upstream it to will-it-scale at [1]) got 15% performance gain on a 48C/96T Cascade Lake test box with 96 processes running against xfs. Perf data collected before/after the change: 18.73%--page_add_file_rmap | --11.60%--__mod_lruvec_page_state | |--7.40%--__mod_memcg_lruvec_state | | | --5.58%--cgroup_rstat_updated | --2.53%--__mod_lruvec_state | --1.48%--__mod_node_page_state 9.93%--page_add_file_rmap_range | --2.67%--__mod_lruvec_page_state | |--1.95%--__mod_memcg_lruvec_state | | | --1.57%--cgroup_rstat_updated | --0.61%--__mod_lruvec_state | --0.54%--__mod_node_page_state The running time of __mode_lruvec_page_state() is reduced about 9%. [1]: antonblanchard/will-it-scale#37 Signed-off-by: Yin Fengwei <[email protected]> Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>
1 parent 98a70b1 commit ed49f6f

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

mm/filemap.c

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3486,11 +3486,12 @@ static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf,
34863486
struct file *file = vma->vm_file;
34873487
struct page *page = folio_page(folio, start);
34883488
unsigned int mmap_miss = READ_ONCE(file->f_ra.mmap_miss);
3489-
unsigned int ref_count = 0, count = 0;
3489+
unsigned int count = 0;
3490+
pte_t *old_ptep = vmf->pte;
34903491

34913492
do {
3492-
if (PageHWPoison(page))
3493-
continue;
3493+
if (PageHWPoison(page + count))
3494+
goto skip;
34943495

34953496
if (mmap_miss > 0)
34963497
mmap_miss--;
@@ -3500,20 +3501,33 @@ static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf,
35003501
* handled in the specific fault path, and it'll prohibit the
35013502
* fault-around logic.
35023503
*/
3503-
if (!pte_none(*vmf->pte))
3504-
continue;
3504+
if (!pte_none(vmf->pte[count]))
3505+
goto skip;
35053506

35063507
if (vmf->address == addr)
35073508
ret = VM_FAULT_NOPAGE;
35083509

3509-
ref_count++;
3510-
set_pte_range(vmf, folio, page, 1, addr);
3511-
} while (vmf->pte++, page++, addr += PAGE_SIZE, ++count < nr_pages);
3510+
count++;
3511+
continue;
3512+
skip:
3513+
if (count) {
3514+
set_pte_range(vmf, folio, page, count, addr);
3515+
folio_ref_add(folio, count);
3516+
}
35123517

3513-
/* Restore the vmf->pte */
3514-
vmf->pte -= nr_pages;
3518+
count++;
3519+
page += count;
3520+
vmf->pte += count;
3521+
addr += count * PAGE_SIZE;
3522+
count = 0;
3523+
} while (--nr_pages > 0);
3524+
3525+
if (count) {
3526+
set_pte_range(vmf, folio, page, count, addr);
3527+
folio_ref_add(folio, count);
3528+
}
35153529

3516-
folio_ref_add(folio, ref_count);
3530+
vmf->pte = old_ptep;
35173531
WRITE_ONCE(file->f_ra.mmap_miss, mmap_miss);
35183532

35193533
return ret;

0 commit comments

Comments
 (0)