mm: A few memory tracker fixes
Subsystems (5)
cover mm: A few memory tracker fixes
Hi! Here is a few fixes for memory softdirty tracker inspired by LKML thread https://lkml.org/lkml/2014/3/18/709 . It turned out that indeed I've missed to setup softdirty bit on file mappings in a few places. But it seems the only intensive user of this feature is the criu tool where we dump/restore shared memory areas completely regardless the softdirty bit status and shared file mapped areas are not dumped at all so I'm not sure if the patches are stable material. Please take a look, thanks.
Cyrill
--
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>
PATCH 1/4 mm: Make freshly remapped file pages being softdirty unconditionally
Hugh reported:
| I noticed your soft_dirty work in install_file_pte(): which looked | good at first, until I realized that it's propagating the soft_dirty | of a pte it's about to zap completely, to the unrelated entry it's | about to insert in its place. Which seems very odd to me.
Indeed this code ends up being nop in result -- pte_file_mksoft_dirty() operates with pte_t argument and returns new pte_t which were never used after. After looking more I think what we need is to soft-dirtify all newely remapped file pages because it should look like a new mapping for memory tracker.
--- mm/fremap.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
mm/fremap.c +2 -5
@@ -66,13 +66,10 @@ static int install_file_pte(struct mm_st ptfile =pgoff_to_pte (pgoff); -if (!pte_none (*pte)) { -if (pte_present (*pte) &&pte_soft_dirty (*pte)) -pte_file_mksoft_dirty (ptfile); +if (!pte_none (*pte))zap_pte (mm, vma, addr, pte); - } -set_pte_at (mm, addr, pte, ptfile); +set_pte_at (mm, addr, pte,pte_file_mksoft_dirty (ptfile));/* * We don't need to run update_mmu_cache() here because the "file pte" * being installed by install_file_pte() is not a real pte - it's a
--
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>
PATCH 2/4 mm: Dont forget to set softdirty on file mapped fault
In reply to Cyrill GorcunovOtherwise we may not notice that pte was softdirty.
--- mm/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory.c +1 -1
@@ -3422,7 +3422,7 @@ static int __do_fault(struct mm_struct *if (flags &FAULT_FLAG_WRITE ) entry =maybe_mkwrite (pte_mkdirty (entry), vma);else if (pte_file (orig_pte) &&pte_file_soft_dirty (orig_pte)) -pte_mksoft_dirty (entry); + entry =pte_mksoft_dirty (entry);if (anon) {inc_mm_counter_fast (mm,MM_ANONPAGES );page_add_new_anon_rmap (page, vma, address);
--
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>
Andrew Morton
maintainerRe: [patch 2/4] mm: Dont forget to set softdirty on file mapped fault
mm/memory.c static int __do_fault(struct mm_struct * · line 3428
Quoted 13 lines · On Mon, 24 Mar 2014 16:28:40 +0400 Cyrill Gorcunov <[email protected]> wrote:
Otherwise we may not notice that pte was softdirty.
mm/memory.c +1
-1@@ -3422,7 +3422,7 @@ static int __do_fault(struct mm_struct *if (flags &FAULT_FLAG_WRITE ) entry =maybe_mkwrite (pte_mkdirty (entry), vma);else if (pte_file (orig_pte) &&pte_file_soft_dirty (orig_pte)) -pte_mksoft_dirty (entry); + entry =pte_mksoft_dirty (entry);if (anon) {inc_mm_counter_fast (mm,MM_ANONPAGES );page_add_new_anon_rmap (page, vma, address);
This will need to be redone for current kernels, please. New patch, new title, new changelog, retest.
--
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>
Re: [patch 2/4] mm: Dont forget to set softdirty on file mapped fault
Quoted 3 lines · Andrew Morton
This will need to be redone for current kernels, please. New patch, new title, new changelog, retest.
Sure, will resend once done.
--
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>
Re: [patch 2/4] mm: Dont forget to set softdirty on file mapped fault
Quoted 6 lines · Cyrill Gorcunov
Quoted 3 lines · Andrew Morton
This will need to be redone for current kernels, please. New patch, new title, new changelog, retest.
Sure, will resend once done.
Andrew, sorry, I'm a bit confused, jost got notifications you've picked them up into -mm tree, right? So what I should do now -- by "current kernels" you mean latest Linus's git repo?
--
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>
Andrew Morton
maintainerRe: [patch 2/4] mm: Dont forget to set softdirty on file mapped fault
Quoted 10 lines · On Tue, 15 Apr 2014 02:38:21 +0400 Cyrill Gorcunov <[email protected]> wrote:
Quoted 6 lines · Cyrill Gorcunov
Quoted 3 lines · Andrew Morton
This will need to be redone for current kernels, please. New patch, new title, new changelog, retest.
Sure, will resend once done.
Andrew, sorry, I'm a bit confused, jost got notifications you've picked them up into -mm tree, right?
1, 3 and 4.
Quoted 2 lines
So what I should do now -- by "current kernels" you mean latest Linus's git repo?
yup.
--
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>
PATCH 3/4 mm: Dont forget to save file map softdiry bit on unmap
In reply to Cyrill Gorcunovpte_file_mksoft_dirty operates with argument passed by a value and returns modified result thus need to assign @ptfile here, otherwise it's nop operation which may lead to lose of softdirty bit.
--- mm/rmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/rmap.c +1 -1
@@ -1339,7 +1339,7 @@ static int try_to_unmap_cluster(unsignedif (page->index !=linear_page_index (vma, address)) {pte_t ptfile =pgoff_to_pte (page->index);if (pte_soft_dirty (pteval)) -pte_file_mksoft_dirty (ptfile); + ptfile =pte_file_mksoft_dirty (ptfile);set_pte_at (mm, address, pte, ptfile); }
--
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>
PATCH 4/4 mm: Clear VM_SOFTDIRTY flag inside clear_refs_write instead of clear_soft_dirty
In reply to Cyrill GorcunovThe clear_refs_write is called earlier than clear_soft_dirty and it is more natural to clear VM_SOFTDIRTY (which belongs to VMA entry but not PTEs) that early instead of clearing it a way deeper inside call chain.
--- fs/proc/task_mmu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/proc/task_mmu.c +4 -3
@@ -736,9 +736,6 @@ static inline void clear_soft_dirty(stru ptent = pte_file_clear_soft_dirty(ptent); } -if (vma->vm_flags &VM_SOFTDIRTY ) - vma->vm_flags &= ~VM_SOFTDIRTY ; -set_pte_at (vma->vm_mm, addr, pte, ptent);#endif }
@@ -843,6 +840,10 @@ static ssize_t clear_refs_write(struct fcontinue ;if (type ==CLEAR_REFS_MAPPED && !vma->vm_file)continue ; +if (type ==CLEAR_REFS_SOFT_DIRTY ) { +if (vma->vm_flags &VM_SOFTDIRTY ) + vma->vm_flags &= ~VM_SOFTDIRTY ; + }walk_page_range (vma->vm_start, vma->vm_end, &clear_refs_walk); }
--
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>
Andrew Morton
maintainerRe: [patch 4/4] mm: Clear VM_SOFTDIRTY flag inside clear_refs_write instead of clear_soft_dirty
Quoted 3 lines · On Mon, 24 Mar 2014 16:28:42 +0400 Cyrill Gorcunov <[email protected]> wrote:
The
clear_refs_writeis called earlier thanclear_soft_dirtyand it is more natural to clearVM_SOFTDIRTY(which belongs to VMA entry but not PTEs) that early instead of clearing it a way deeper inside call chain.
This patch had some significant conflicts with the pagewalk patches:
mm-hugetlbfs-fix-rmapping-for-anonymous-hugepages-with-page_pgoff.patch mm-hugetlbfs-fix-rmapping-for-anonymous-hugepages-with-page_pgoff-v2.patch mm-hugetlbfs-fix-rmapping-for-anonymous-hugepages-with-page_pgoff-v3.patch mm-hugetlbfs-fix-rmapping-for-anonymous-hugepages-with-page_pgoff-v3-fix.patch pagewalk-update-page-table-walker-core.patch pagewalk-update-page-table-walker-core-fix-end-address-calculation-in-walk_page_range.patch pagewalk-update-page-table-walker-core-fix-end-address-calculation-in-walk_page_range-fix.patch pagewalk-add-walk_page_vma.patch smaps-redefine-callback-functions-for-page-table-walker.patch clear_refs-redefine-callback-functions-for-page-table-walker.patch pagemap-redefine-callback-functions-for-page-table-walker.patch pagemap-redefine-callback-functions-for-page-table-walker-fix.patch numa_maps-redefine-callback-functions-for-page-table-walker.patch memcg-redefine-callback-functions-for-page-table-walker.patch arch-powerpc-mm-subpage-protc-use-walk_page_vma-instead-of-walk_page_range.patch pagewalk-remove-argument-hmask-from-hugetlb_entry.patch pagewalk-remove-argument-hmask-from-hugetlb_entry-fix.patch pagewalk-remove-argument-hmask-from-hugetlb_entry-fix-fix.patch mempolicy-apply-page-table-walker-on-queue_pages_range.patch mm-add-pte_present-check-on-existing-hugetlb_entry-callbacks.patch mm-pagewalkc-move-pte-null-check.patch
I resolved this by merging mm-softdirty-clear-vm_softdirty-flag-inside-clear_refs_write-instead-of-clear_soft_dirty.patch on top of the pagewalk patches as below - please carefully review.
I'm hoping we'll be able to get the pagewalk patches merged in 3.16-rc1
- we'll see what happens when the testing gets underway again.
From: Cyrill Gorcunov <[email protected]>
Subject: mm: softdirty: clear VM_SOFTDIRTY flag inside clear_refs_write() instead of clear_soft_dirty()
clear_refs_write() is called earlier than clear_soft_dirty() and it is more natural to clear VM_SOFTDIRTY (which belongs to VMA entry but not PTEs) that early instead of clearing it a way deeper inside call chain.
---
fs/proc/task_mmu.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
fs/proc/task_mmu.c renamed from fs/proc/task_mmu.c~mm-softdirty-clear-vm_softdirty-flag-inside-clear_refs_write-instead-of-clear_soft_dirty +8 -5
@@ -723,9 +723,6 @@ static inline void clear_soft_dirty(stru ptent = pte_file_clear_soft_dirty(ptent); } -if (vma->vm_flags &VM_SOFTDIRTY ) - vma->vm_flags &= ~VM_SOFTDIRTY ; -set_pte_at (vma->vm_mm, addr, pte, ptent);#endif }
@@ -762,11 +759,16 @@ static int clear_refs_test_walk(unsigned* Writing 1 to /proc/pid/clear_refs affects all pages. * Writing 2 to /proc/pid/clear_refs only affects anonymous pages. * Writing 3 to /proc/pid/clear_refs only affects file mapped pages. +* Writing 4 to /proc/pid/clear_refs affects all pages. */ if (cp->type ==CLEAR_REFS_ANON && vma->vm_file) walk->skip =1 ;if (cp->type ==CLEAR_REFS_MAPPED && !vma->vm_file) walk->skip =1 ; +if (cp->type ==CLEAR_REFS_SOFT_DIRTY ) { +if (vma->vm_flags &VM_SOFTDIRTY ) + vma->vm_flags &= ~VM_SOFTDIRTY ; + }return 0 ; }
@@ -795,8 +797,9 @@ static ssize_t clear_refs_write(struct fif (type ==CLEAR_REFS_SOFT_DIRTY ) { soft_dirty_cleared = true; -pr_warn_once ("The pagemap bits 55-60 has changed their meaning! " -"See the linux/Documentation/vm/pagemap.txt for details.\n" ); +pr_warn_once ("The pagemap bits 55-60 has changed their meaning!" +" See the linux/Documentation/vm/pagemap.txt for " +"details.\n" ); } task =get_proc_task (file_inode (file));
_
--
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>
Re: [patch 4/4] mm: Clear VM_SOFTDIRTY flag inside clear_refs_write instead of clear_soft_dirty
Quoted 4 lines · Andrew Morton
I resolved this by merging mm-softdirty-clear-vm_softdirty-flag-inside-clear_refs_write-instead-of-clear_soft_dirty.patch on top of the pagewalk patches as below - please carefully review.
Thanks a lot, Andrew! I've updated the patches and were planning to send them to you tonightm but because you applied it on top of pagewal patches, I think i rather need to fetch -next repo and review this patch and update the rest of the series on top (hope i'll do that in 3-4 hours).
Quoted 3 lines
I'm hoping we'll be able to get the pagewalk patches merged in 3.16-rc1
- we'll see what happens when the testing gets underway again.
--
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>
Andrew Morton
maintainerRe: [patch 4/4] mm: Clear VM_SOFTDIRTY flag inside clear_refs_write instead of clear_soft_dirty
Quoted 10 lines · On Tue, 15 Apr 2014 22:29:35 +0400 Cyrill Gorcunov <[email protected]> wrote:
Quoted 4 lines · Andrew Morton
I resolved this by merging mm-softdirty-clear-vm_softdirty-flag-inside-clear_refs_write-instead-of-clear_soft_dirty.patch on top of the pagewalk patches as below - please carefully review.
Thanks a lot, Andrew! I've updated the patches and were planning to send them to you tonightm but because you applied it on top of pagewal patches, I think i rather need to fetch -next repo and review this patch and update the rest of the series on top (hope i'll do that in 3-4 hours).
-mm isn't in -next at present. I'll get a release done later today for tomorrow's -next.
--
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>
Re: [patch 4/4] mm: Clear VM_SOFTDIRTY flag inside clear_refs_write instead of clear_soft_dirty
Quoted 8 lines · Andrew Morton
Quoted 6 lines · On Tue, 15 Apr 2014 22:29:35 +0400 Cyrill Gorcunov <[email protected]> wrote:
Quoted 4 lines · Andrew Morton
I resolved this by merging mm-softdirty-clear-vm_softdirty-flag-inside-clear_refs_write-instead-of-clear_soft_dirty.patch on top of the pagewalk patches as below - please carefully review.
Quoted 7 lines
Quoted 4 lines
Thanks a lot, Andrew! I've updated the patches and were planning to send them to you tonightm but because you applied it on top of pagewal patches, I think i rather need to fetch -next repo and review this patch and update the rest of the series on top (hope i'll do that in 3-4 hours).
-mm isn't in -next at present. I'll get a release done later today for tomorrow's -next.
OK. Could you please remind me the place I could fetch the patchwalk series from? (or better to wait until -mm get merged into -next?)
--
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>
Andrew Morton
maintainerRe: [patch 4/4] mm: Clear VM_SOFTDIRTY flag inside clear_refs_write instead of clear_soft_dirty
Quoted 14 lines · On Tue, 15 Apr 2014 22:48:51 +0400 Cyrill Gorcunov <[email protected]> wrote:
Quoted 13 lines · Andrew Morton
Quoted 10 lines · On Tue, 15 Apr 2014 22:29:35 +0400 Cyrill Gorcunov <[email protected]> wrote:
Quoted 4 lines · Andrew Morton
I resolved this by merging mm-softdirty-clear-vm_softdirty-flag-inside-clear_refs_write-instead-of-clear_soft_dirty.patch on top of the pagewalk patches as below - please carefully review.
Thanks a lot, Andrew! I've updated the patches and were planning to send them to you tonightm but because you applied it on top of pagewal patches, I think i rather need to fetch -next repo and review this patch and update the rest of the series on top (hope i'll do that in 3-4 hours).
Quoted 4 lines
Quoted 2 lines
-mm isn't in -next at present. I'll get a release done later today for tomorrow's -next.
OK. Could you please remind me the place I could fetch the patchwalk series from?
http://ozlabs.org/~akpm/mmots/
Quoted 1 line
(or better to wait until -mm get merged into -next?)
That's probably simpler.
--
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>
Re: [patch 4/4] mm: Clear VM_SOFTDIRTY flag inside clear_refs_write instead of clear_soft_dirty
Quoted 11 lines · Andrew Morton
Quoted 5 lines
Quoted 3 lines
-mm isn't in -next at present. I'll get a release done later today for tomorrow's -next.
OK. Could you please remind me the place I could fetch the patchwalk series from?
http://ozlabs.org/~akpm/mmots/
Quoted 1 line
(or better to wait until -mm get merged into -next?)
That's probably simpler.
I've fetched -next tree and updated patch looks good, thanks Andrew!
--
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>