mm: Track vma changes with VM_SOFTDIRTY bit
Subsystems (6)
PATCH 1/1 mm: Track vma changes with VM_SOFTDIRTY bit
Pavel reported that in case if vma area get unmapped and then mapped (or expanded) in-place, the soft dirty tracker won't be able to recognize this situation since it works on pte level and ptes are get zapped on unmap, loosing soft dirty bit of course.
So to resolve this situation we need to track actions on vma level, there VM_SOFTDIRTY flag comes in. When new vma area created (or old expanded) we set this bit, and keep it here until application calls for clearing soft dirty bit.
Thus when user space application track memory changes now it can detect if vma area is renewed.
--- fs/exec.c | 2 +- fs/proc/task_mmu.c | 46 ++++++++++++++++++++++++++++++++++++---------- include/linux/mm.h | 6 ++++++ mm/mmap.c | 12 +++++++++++- 4 files changed, 54 insertions(+), 12 deletions(-)
fs/exec.c +1 -1
@@ -266,7 +266,7 @@ static int __bprm_mm_init(struct linux_bBUILD_BUG_ON (VM_STACK_FLAGS &VM_STACK_INCOMPLETE_SETUP ); vma->vm_end =STACK_TOP_MAX ; vma->vm_start = vma->vm_end -PAGE_SIZE ; - vma->vm_flags =VM_STACK_FLAGS |VM_STACK_INCOMPLETE_SETUP ; + vma->vm_flags =VM_SOFTDIRTY |VM_STACK_FLAGS |VM_STACK_INCOMPLETE_SETUP ; vma->vm_page_prot =vm_get_page_prot (vma->vm_flags);INIT_LIST_HEAD (&vma->anon_vma_chain);
fs/proc/task_mmu.c +36 -10
106 lines not on this page · raw message
include/linux/mm.h +6 -0
@@ -115,6 +115,12 @@ extern unsigned int kobjsize(const void#define VM_ARCH_1 0x01000000/* Architecture-specific flag */ #define VM_DONTDUMP 0x04000000/* Do not include in the core dump */ +#ifdef CONFIG_MEM_SOFT_DIRTY +# define VM_SOFTDIRTY 0x08000000/* Not soft dirty clean area */ +#else +# define VM_SOFTDIRTY 0 +#endif +#define VM_MIXEDMAP 0x10000000/* Can contain "struct page" and pure PFN pages */ #define VM_HUGEPAGE 0x20000000/* MADV_HUGEPAGE marked this vma */ #define VM_NOHUGEPAGE 0x40000000/* MADV_NOHUGEPAGE marked this vma */
mm/mmap.c +11 -1
@@ -1616,6 +1616,15 @@ out:if (file)uprobe_mmap (vma); +/* +* New (or expanded) vma always get soft dirty status. +* Otherwise user-space soft-dirty page tracker won't +* be able to distinguish situation when vma area unmapped, +* then new mapped in-place (which must be aimed as +* a completely new data area). +*/ + vma->vm_flags |=VM_SOFTDIRTY ; +return addr; unmap_and_free_vma:
@@ -2663,6 +2672,7 @@ out: mm->total_vm += len >>PAGE_SHIFT ;if (flags &VM_LOCKED ) mm->locked_vm += (len >>PAGE_SHIFT ); + vma->vm_flags |=VM_SOFTDIRTY ;return addr; }
@@ -2930,7 +2940,7 @@ int install_special_mapping(struct mm_st vma->vm_start = addr; vma->vm_end = addr + len; - vma->vm_flags = vm_flags | mm->def_flags |VM_DONTEXPAND ; + vma->vm_flags = vm_flags | mm->def_flags |VM_DONTEXPAND |VM_SOFTDIRTY ; vma->vm_page_prot =vm_get_page_prot (vma->vm_flags); vma->vm_ops = &special_mapping_vmops;
--
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
maintainerQuoted 6 lines · On Mon, 19 Aug 2013 23:58:36 +0400 Cyrill Gorcunov <[email protected]> wrote:
Pavel reported that in case if vma area get unmapped and then mapped (or expanded) in-place, the soft dirty tracker won't be able to recognize this situation since it works on pte level and ptes are get zapped on unmap, loosing soft dirty bit of course.
Quoted 8 lines
So to resolve this situation we need to track actions on vma level, there
VM_SOFTDIRTYflag comes in. When new vma area created (or old expanded) we set this bit, and keep it here until application calls for clearing soft dirty bit.Thus when user space application track memory changes now it can detect if vma area is renewed.
Can we please update Documentation/vm/soft-dirty.txt for this?
--
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 · Andrew Morton
Quoted 3 lines
Thus when user space application track memory changes now it can detect if vma area is renewed.
Can we please update
Documentation/vm/soft-dirty.txtfor this?
Oops. Sorry, forgot about soft-dirty.txt. Sure I'll update it later tonight or tomorrow, thanks!
--
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>