Skip to content

Commit 1fdb412

Browse files
kiryltorvalds
authored andcommitted
mm: document do_fault_around() feature
Some clarification on how faultaround works. [akpm@linux-foundation.org: tweak comment text] Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent a9b0f86 commit 1fdb412

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

‎mm/memory.c‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2760,6 +2760,10 @@ void do_set_pte(struct vm_area_struct *vma, unsigned long address,
27602760

27612761
static unsigned long fault_around_bytes = 65536;
27622762

2763+
/*
2764+
* fault_around_pages() and fault_around_mask() round down fault_around_bytes
2765+
* to nearest page order. It's what do_fault_around() expects to see.
2766+
*/
27632767
static inline unsigned long fault_around_pages(void)
27642768
{
27652769
return rounddown_pow_of_two(fault_around_bytes) / PAGE_SIZE;
@@ -2801,6 +2805,29 @@ static int __init fault_around_debugfs(void)
28012805
late_initcall(fault_around_debugfs);
28022806
#endif
28032807

2808+
/*
2809+
* do_fault_around() tries to map few pages around the fault address. The hope
2810+
* is that the pages will be needed soon and this will lower the number of
2811+
* faults to handle.
2812+
*
2813+
* It uses vm_ops->map_pages() to map the pages, which skips the page if it's
2814+
* not ready to be mapped: not up-to-date, locked, etc.
2815+
*
2816+
* This function is called with the page table lock taken. In the split ptlock
2817+
* case the page table lock only protects only those entries which belong to
2818+
* the page table corresponding to the fault address.
2819+
*
2820+
* This function doesn't cross the VMA boundaries, in order to call map_pages()
2821+
* only once.
2822+
*
2823+
* fault_around_pages() defines how many pages we'll try to map.
2824+
* do_fault_around() expects it to return a power of two less than or equal to
2825+
* PTRS_PER_PTE.
2826+
*
2827+
* The virtual address of the area that we map is naturally aligned to the
2828+
* fault_around_pages() value (and therefore to page order). This way it's
2829+
* easier to guarantee that we don't cross page table boundaries.
2830+
*/
28042831
static void do_fault_around(struct vm_area_struct *vma, unsigned long address,
28052832
pte_t *pte, pgoff_t pgoff, unsigned int flags)
28062833
{

0 commit comments

Comments
 (0)