mm: make faultaround produce old ptes
Subsystems (3)
PATCH 1/1 mm: make faultaround produce old ptes
Currently, faultaround code produces young pte. This can screw up vmscan behaviour[1], as it makes vmscan think that these pages are hot and not push them out on first round.
Let modify faultaround to produce old pte, so they can easily be reclaimed under memory pressure.
This can to some extend defeat purpose of faultaround on machines without hardware accessed bit as it will not help up with reducing number of minor page faults.
We may want to disable faultaround on such machines altogether, but that's subject for separate patchset.
[1] https://lkml.kernel.org/r/[email protected]
--- include/linux/mm.h | 2 +- mm/filemap.c | 2 +- mm/memory.c | 23 ++++++++++++++++++----- 3 files changed, 20 insertions(+), 7 deletions(-)
include/linux/mm.h +1 -1
@@ -591,7 +591,7 @@ static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma) }void do_set_pte (struct vm_area_struct *vma,unsigned long address, -struct page *page,pte_t *pte,bool write,bool anon); +struct page *page,pte_t *pte,bool write,bool anon,bool old);#endif /*
mm/filemap.c +1 -1
@@ -2196,7 +2196,7 @@ repeat:if (file->f_ra.mmap_miss >0 ) file->f_ra.mmap_miss--; addr = address + (page->index - vmf->pgoff) *PAGE_SIZE ; -do_set_pte (vma, addr, page, pte, false, false); +do_set_pte (vma, addr, page, pte, false, false, true);unlock_page (page); goto next; unlock:
mm/memory.c +18 -5
@@ -2855,7 +2855,7 @@ static int __do_fault(struct vm_area_struct *vma, unsigned long address,* vm_ops->map_pages. */ void do_set_pte (struct vm_area_struct *vma,unsigned long address, -struct page *page,pte_t *pte,bool write,bool anon) +struct page *page,pte_t *pte,bool write,bool anon,bool old) {pte_t entry;
@@ -2863,6 +2863,8 @@ void do_set_pte(struct vm_area_struct *vma, unsigned long address, entry =mk_pte (page, vma->vm_page_prot);if (write) entry =maybe_mkwrite (pte_mkdirty (entry), vma); +if (old) + entry =pte_mkold (entry);if (anon) {inc_mm_counter_fast (vma->vm_mm,MM_ANONPAGES );page_add_new_anon_rmap (page, vma, address, false);
@@ -3000,9 +3002,20 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,*/ if (vma->vm_ops->map_pages && fault_around_bytes >>PAGE_SHIFT >1 ) { pte =pte_offset_map_lock (mm, pmd, address, &ptl); -do_fault_around (vma, address, pte, pgoff, flags);if (!pte_same (*pte, orig_pte)) goto unlock_out; +do_fault_around (vma, address, pte, pgoff, flags); +/* Check if the fault is handled by faultaround */ +if (!pte_same (*pte, orig_pte)) { +/* +* Faultaround produce old pte, but the pte we've +* handler fault for should be young. +*/ +pte_t entry =pte_mkyoung (*pte); +if (ptep_set_access_flags (vma, address, pte, entry,0 )) +update_mmu_cache (vma, address, pte); + goto unlock_out; + }pte_unmap_unlock (pte, ptl); }
@@ -3017,7 +3030,7 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,put_page (fault_page);return ret; } -do_set_pte (vma, address, fault_page, pte, false, false); +do_set_pte (vma, address, fault_page, pte, false, false, false);unlock_page (fault_page); unlock_out:pte_unmap_unlock (pte, ptl);
@@ -3069,7 +3082,7 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma, } goto uncharge_out; } -do_set_pte (vma, address, new_page, pte, true, true); +do_set_pte (vma, address, new_page, pte, true, true, false);mem_cgroup_commit_charge (new_page, memcg, false, false);lru_cache_add_active_or_unevictable (new_page, vma);pte_unmap_unlock (pte, ptl);
@@ -3126,7 +3139,7 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,put_page (fault_page);return ret; } -do_set_pte (vma, address, fault_page, pte, true, false); +do_set_pte (vma, address, fault_page, pte, true, false, false);pte_unmap_unlock (pte, ptl);if (set_page_dirty (fault_page))
Signature · 7 lines
2.8.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 14 lines · Kirill A. Shutemov
Currently, faultaround code produces young pte. This can screw up vmscan behaviour[1], as it makes vmscan think that these pages are hot and not push them out on first round.
Let modify faultaround to produce old pte, so they can easily be reclaimed under memory pressure.
This can to some extend defeat purpose of faultaround on machines without hardware accessed bit as it will not help up with reducing number of minor page faults.
We may want to disable faultaround on such machines altogether, but that's subject for separate patchset.
Quoted 8 lines
[1] https://lkml.kernel.org/r/[email protected]
Signed-off-by Kirill A. Shutemov <[email protected]>Cc Mel Gorman <[email protected]>Cc Rik van Riel <[email protected]>Cc Michal Hocko <[email protected]>Cc Vinayak Menon <[email protected]>Cc Minchan Kim <[email protected]>
I tested 512M mmap sequential word read test on non-HW access bit system (i.e., ARM) and confirmed it doesn't increase minor fault any more.
= old =
minor fault: 131291
elapsed time: 6747645 usec
= new =
minor fault: 131291
elapsed time: 6709263 usec
0.56% benefit
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 31 lines · Minchan Kim
Quoted 14 lines · Kirill A. Shutemov
Currently, faultaround code produces young pte. This can screw up vmscan behaviour[1], as it makes vmscan think that these pages are hot and not push them out on first round.
Let modify faultaround to produce old pte, so they can easily be reclaimed under memory pressure.
This can to some extend defeat purpose of faultaround on machines without hardware accessed bit as it will not help up with reducing number of minor page faults.
We may want to disable faultaround on such machines altogether, but that's subject for separate patchset.
Quoted 8 lines
[1] https://lkml.kernel.org/r/[email protected]
Signed-off-by Kirill A. Shutemov <[email protected]>Cc Mel Gorman <[email protected]>Cc Rik van Riel <[email protected]>Cc Michal Hocko <[email protected]>Cc Vinayak Menon <[email protected]>Cc Minchan Kim <[email protected]>I tested 512M mmap sequential word read test on non-HW access bit system (i.e., ARM) and confirmed it doesn't increase minor fault any more.
= old =
minor fault: 131291
elapsed time: 6747645 usec
Quoted 7 lines
= new =
minor fault: 131291
elapsed time: 6709263 usec0.56% benefit
Acked-by Minchan Kim <[email protected]>
Oops, label was wrong.
I meant
old : 4096 fault_around
new : 65536 fault_around
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 6 lines · Kirill A. Shutemov
Currently, faultaround code produces young pte. This can screw up vmscan behaviour[1], as it makes vmscan think that these pages are hot and not push them out on first round.
Let modify faultaround to produce old pte, so they can easily be reclaimed under memory pressure.
Could you be more specific about what was the original issue that led to this patch? I can understand that marking all those pages new might be too optimistic but when does it matter actually? Sparsely access file mmap?
Quoted 120 lines
This can to some extend defeat purpose of faultaround on machines without hardware accessed bit as it will not help up with reducing number of minor page faults.
We may want to disable faultaround on such machines altogether, but that's subject for separate patchset.
[1] https://lkml.kernel.org/r/[email protected]
Signed-off-by Kirill A. Shutemov <[email protected]>Cc Mel Gorman <[email protected]>Cc Rik van Riel <[email protected]>Cc Michal Hocko <[email protected]>Cc Vinayak Menon <[email protected]>Cc Minchan Kim <[email protected]>--- include/linux/mm.h | 2 +- mm/filemap.c | 2 +- mm/memory.c | 23 ++++++++++++++++++----- 3 files changed, 20 insertions(+), 7 deletions(-)include/linux/mm.h +1
-1@@ -591,7 +591,7 @@ static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma) }void do_set_pte (struct vm_area_struct *vma,unsigned long address, -struct page *page,pte_t *pte,bool write,bool anon); +struct page *page,pte_t *pte,bool write,bool anon,bool old);#endif /* mm/filemap.c +1
-1@@ -2196,7 +2196,7 @@ repeat:if (file->f_ra.mmap_miss >0 ) file->f_ra.mmap_miss--; addr = address + (page->index - vmf->pgoff) *PAGE_SIZE ; -do_set_pte (vma, addr, page, pte, false, false); +do_set_pte (vma, addr, page, pte, false, false, true);unlock_page (page); goto next; unlock:mm/memory.c +18
-5@@ -2855,7 +2855,7 @@ static int __do_fault(struct vm_area_struct *vma, unsigned long address,* vm_ops->map_pages. */ void do_set_pte (struct vm_area_struct *vma,unsigned long address, -struct page *page,pte_t *pte,bool write,bool anon) +struct page *page,pte_t *pte,bool write,bool anon,bool old) {pte_t entry;@@ -2863,6 +2863,8 @@ void do_set_pte(struct vm_area_struct *vma, unsigned long address, entry =mk_pte (page, vma->vm_page_prot);if (write) entry =maybe_mkwrite (pte_mkdirty (entry), vma); +if (old) + entry =pte_mkold (entry);if (anon) {inc_mm_counter_fast (vma->vm_mm,MM_ANONPAGES );page_add_new_anon_rmap (page, vma, address, false);@@ -3000,9 +3002,20 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,*/ if (vma->vm_ops->map_pages && fault_around_bytes >>PAGE_SHIFT >1 ) { pte =pte_offset_map_lock (mm, pmd, address, &ptl); -do_fault_around (vma, address, pte, pgoff, flags);if (!pte_same (*pte, orig_pte)) goto unlock_out; +do_fault_around (vma, address, pte, pgoff, flags); +/* Check if the fault is handled by faultaround */ +if (!pte_same (*pte, orig_pte)) { +/* +* Faultaround produce old pte, but the pte we've +* handler fault for should be young. +*/ +pte_t entry =pte_mkyoung (*pte); +if (ptep_set_access_flags (vma, address, pte, entry,0 )) +update_mmu_cache (vma, address, pte); + goto unlock_out; + }pte_unmap_unlock (pte, ptl); }@@ -3017,7 +3030,7 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,put_page (fault_page);return ret; } -do_set_pte (vma, address, fault_page, pte, false, false); +do_set_pte (vma, address, fault_page, pte, false, false, false);unlock_page (fault_page); unlock_out:pte_unmap_unlock (pte, ptl);@@ -3069,7 +3082,7 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma, } goto uncharge_out; } -do_set_pte (vma, address, new_page, pte, true, true); +do_set_pte (vma, address, new_page, pte, true, true, false);mem_cgroup_commit_charge (new_page, memcg, false, false);lru_cache_add_active_or_unevictable (new_page, vma);pte_unmap_unlock (pte, ptl);@@ -3126,7 +3139,7 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,put_page (fault_page);return ret; } -do_set_pte (vma, address, fault_page, pte, true, false); +do_set_pte (vma, address, fault_page, pte, true, false, false);pte_unmap_unlock (pte, ptl);if (set_page_dirty (fault_page))Signature · 1 line
2.8.1
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 5 lines · Michal Hocko
Quoted 4 lines · Kirill A. Shutemov
Currently, faultaround code produces young pte. This can screw up vmscan behaviour[1], as it makes vmscan think that these pages are hot and not push them out on first round.
Quoted 7 lines
Quoted 2 lines
Let modify faultaround to produce old pte, so they can easily be reclaimed under memory pressure.
Could you be more specific about what was the original issue that led to this patch? I can understand that marking all those pages new might be too optimistic but when does it matter actually? Sparsely access file mmap?
Yes, sparse file access. Faultaround gets more pages mapped and all of them are young. Under memory pressure, this makes vmscan to swap out anon pages instead or drop other page cache pages which otherwise stay resident.
Signature · 7 lines
Kirill A. Shutemov -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 14 lines · Kirill A. Shutemov
Quoted 5 lines · Michal Hocko
Quoted 4 lines · Kirill A. Shutemov
Currently, faultaround code produces young pte. This can screw up vmscan behaviour[1], as it makes vmscan think that these pages are hot and not push them out on first round.
Quoted 7 lines
Quoted 2 lines
Let modify faultaround to produce old pte, so they can easily be reclaimed under memory pressure.
Could you be more specific about what was the original issue that led to this patch? I can understand that marking all those pages new might be too optimistic but when does it matter actually? Sparsely access file mmap?
Quoted 4 lines
Yes, sparse file access. Faultaround gets more pages mapped and all of them are young. Under memory pressure, this makes vmscan to swap out anon pages instead or drop other page cache pages which otherwise stay resident.
I am wondering whether it would make more sense to do the fault around only when chances are that the memory will be used. E.g. ~VM_RAND_READ resp VM_SEQ_READ rather than unconditionally.
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 15 lines · Michal Hocko
Quoted 14 lines · Kirill A. Shutemov
Quoted 12 lines · Michal Hocko
Quoted 6 lines · Kirill A. Shutemov
Currently, faultaround code produces young pte. This can screw up vmscan behaviour[1], as it makes vmscan think that these pages are hot and not push them out on first round.
Let modify faultaround to produce old pte, so they can easily be reclaimed under memory pressure.
Could you be more specific about what was the original issue that led to this patch? I can understand that marking all those pages new might be too optimistic but when does it matter actually? Sparsely access file mmap?
Quoted 8 lines
Quoted 4 lines
Yes, sparse file access. Faultaround gets more pages mapped and all of them are young. Under memory pressure, this makes vmscan to swap out anon pages instead or drop other page cache pages which otherwise stay resident.
I am wondering whether it would make more sense to do the fault around only when chances are that the memory will be used. E.g. ~VM_RAND_READ resp
VM_SEQ_READrather than unconditionally.
I'm not sure about this.
The idea of faularound is that we already have almost everything in our hands to map additional pages for very little cost: all required locks has been taken and radix-tree look up will be done anyway.
So I don't see a benefit from limiting us here. Do you?
Signature · 7 lines
Kirill A. Shutemov -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Michal Hocko
Acked-byQuoted 25 lines · Kirill A. Shutemov
Quoted 15 lines · Michal Hocko
Quoted 14 lines · Kirill A. Shutemov
Quoted 12 lines · Michal Hocko
Quoted 6 lines · Kirill A. Shutemov
Currently, faultaround code produces young pte. This can screw up vmscan behaviour[1], as it makes vmscan think that these pages are hot and not push them out on first round.
Let modify faultaround to produce old pte, so they can easily be reclaimed under memory pressure.
Could you be more specific about what was the original issue that led to this patch? I can understand that marking all those pages new might be too optimistic but when does it matter actually? Sparsely access file mmap?
Quoted 8 lines
Quoted 4 lines
Yes, sparse file access. Faultaround gets more pages mapped and all of them are young. Under memory pressure, this makes vmscan to swap out anon pages instead or drop other page cache pages which otherwise stay resident.
I am wondering whether it would make more sense to do the fault around only when chances are that the memory will be used. E.g. ~VM_RAND_READ resp
VM_SEQ_READrather than unconditionally.
Quoted 5 lines
I'm not sure about this.
The idea of faularound is that we already have almost everything in our hands to map additional pages for very little cost: all required locks has been taken and radix-tree look up will be done anyway.
Fair enough. Meddling pte young bits sounds like a better approach then.
Feel free to add
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 19 lines · Kirill A. Shutemov
Currently, faultaround code produces young pte. This can screw up vmscan
behaviour[1], as it makes vmscan think that these pages are hot and not
push them out on first round.Let modify faultaround to produce old pte, so they can easily be reclaimed under memory pressure.
This can to some extend defeat purpose of faultaround on machines without hardware accessed bit as it will not help up with reducing number of minor page faults.
We may want to disable faultaround on such machines altogether, but that's subject for separate patchset.
[1] https://lkml.kernel.org/r/1460992636-711-1-git-send-email-vinmeno
[email protected]
Quoted 7 lines
Signed-off-by Kirill A. Shutemov <[email protected]>Cc Mel Gorman <[email protected]>Cc Rik van Riel <[email protected]>Cc Michal Hocko <[email protected]>Cc Vinayak Menon <[email protected]>Cc Minchan Kim <[email protected]>
Signature · 1 line
All Rights Reversed.