All of lore.kernel.org
 help / color / mirror / Atom feed
diff for duplicates of <545D6AA1.9010907@gmail.com>

diff --git a/a/2.txt b/N1/2.txt
index 8b13789..66c24d3 100644
--- a/a/2.txt
+++ b/N1/2.txt
@@ -1 +1,150 @@
+>From db8ad0877146a69e1e5d5ab98825cefcf44a95bb Mon Sep 17 00:00:00 2001
+From: Timofey Titovets <nefelim4ag@gmail.com>
+Date: Sat, 8 Nov 2014 03:02:52 +0300
+Subject: [PATCH] KSM: Add auto flag new VMA as VM_MERGEABLE
 
+Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
+---
+ include/linux/ksm.h | 31 +++++++++++++++++++++++++++++++
+ mm/mmap.c           | 17 +++++++++++++++++
+ 2 files changed, 48 insertions(+)
+
+diff --git a/include/linux/ksm.h b/include/linux/ksm.h
+index 3be6bb1..c3fff64 100644
+--- a/include/linux/ksm.h
++++ b/include/linux/ksm.h
+@@ -76,6 +76,29 @@ struct page *ksm_might_need_to_copy(struct page *page,
+ int rmap_walk_ksm(struct page *page, struct rmap_walk_control *rwc);
+ void ksm_migrate_page(struct page *newpage, struct page *oldpage);
+ 
++/*
++ * Allow to mark new vma as VM_MERGEABLE
++ */
++#ifndef VM_SAO
++#define VM_SAO 0
++#endif
++static inline void ksm_vm_flags_mod(unsigned long *vm_flags)
++{
++	if (*vm_flags & (VM_MERGEABLE | VM_SHARED  | VM_MAYSHARE   |
++			 VM_PFNMAP    | VM_IO      | VM_DONTEXPAND |
++			 VM_HUGETLB | VM_NONLINEAR | VM_MIXEDMAP   | VM_SAO) )
++		return;
++	*vm_flags |= VM_MERGEABLE;
++}
++
++static inline void ksm_vma_add_new(struct vm_area_struct *vma)
++{
++	struct mm_struct *mm = vma->vm_mm;
++	if (!test_bit(MMF_VM_MERGEABLE, &mm->flags)) {
++		__ksm_enter(mm);
++	}
++}
++
+ #else  /* !CONFIG_KSM */
+ 
+ static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm)
+@@ -92,6 +115,14 @@ static inline int PageKsm(struct page *page)
+ 	return 0;
+ }
+ 
++static inline void ksm_vm_flags_mod(unsigned long *vm_flags_p)
++{
++}
++
++void ksm_vma_add_new(struct vm_area_struct *vma)
++{
++}
++
+ #ifdef CONFIG_MMU
+ static inline int ksm_madvise(struct vm_area_struct *vma, unsigned long start,
+ 		unsigned long end, int advice, unsigned long *vm_flags)
+diff --git a/mm/mmap.c b/mm/mmap.c
+index 7f85520..ce0073e 100644
+--- a/mm/mmap.c
++++ b/mm/mmap.c
+@@ -41,6 +41,7 @@
+ #include <linux/notifier.h>
+ #include <linux/memory.h>
+ #include <linux/printk.h>
++#include <linux/ksm.h>
+ 
+ #include <asm/uaccess.h>
+ #include <asm/cacheflush.h>
+@@ -911,10 +912,14 @@ again:			remove_next = 1 + (end > next->vm_end);
+ 			vma_gap_update(next);
+ 		else
+ 			mm->highest_vm_end = end;
++	} else {
++		if (next && !insert)
++			ksm_vma_add_new(next);
+ 	}
+ 	if (insert && file)
+ 		uprobe_mmap(insert);
+ 
++	ksm_vma_add_new(vma);
+ 	validate_mm(mm);
+ 
+ 	return 0;
+@@ -1307,6 +1312,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
+ 	vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
+ 			mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
+ 
++	/* If ksm is enabled, we add VM_MERGABLE to new VMAs. */
++	ksm_vm_flags_mod(&vm_flags);
++
+ 	if (flags & MAP_LOCKED)
+ 		if (!can_do_mlock())
+ 			return -EPERM;
+@@ -1648,6 +1656,7 @@ munmap_back:
+ 			allow_write_access(file);
+ 	}
+ 	file = vma->vm_file;
++	ksm_vma_add_new(vma);
+ out:
+ 	perf_event_mmap(vma);
+ 
+@@ -2484,6 +2493,8 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
+ 	else
+ 		err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
+ 
++	ksm_vma_add_new(vma);
++
+ 	/* Success. */
+ 	if (!err)
+ 		return 0;
+@@ -2659,6 +2670,9 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
+ 	if (error)
+ 		return error;
+ 
++	/* If ksm is enabled, we add VM_MERGABLE to new VMAs. */
++	ksm_vm_flags_mod(&flags);
++
+ 	/*
+ 	 * mm->mmap_sem is required to protect against another thread
+ 	 * changing the mappings in case we sleep.
+@@ -2708,6 +2722,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
+ 	vma->vm_flags = flags;
+ 	vma->vm_page_prot = vm_get_page_prot(flags);
+ 	vma_link(mm, vma, prev, rb_link, rb_parent);
++	ksm_vma_add_new(vma);
+ out:
+ 	perf_event_mmap(vma);
+ 	mm->total_vm += len >> PAGE_SHIFT;
+@@ -2887,6 +2902,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
+ 				new_vma->vm_ops->open(new_vma);
+ 			vma_link(mm, new_vma, prev, rb_link, rb_parent);
+ 			*need_rmap_locks = false;
++			ksm_vma_add_new(new_vma);
+ 		}
+ 	}
+ 	return new_vma;
+@@ -3004,6 +3020,7 @@ static struct vm_area_struct *__install_special_mapping(
+ 	mm->total_vm += len >> PAGE_SHIFT;
+ 
+ 	perf_event_mmap(vma);
++	ksm_vma_add_new(vma);
+ 
+ 	return vma;
+ 
+-- 
+2.1.3
diff --git a/a/content_digest b/N1/content_digest
index fc63d63..9b6ed58 100644
--- a/a/content_digest
+++ b/N1/content_digest
@@ -202,5 +202,155 @@
  "\01:2\0"
  "fn\00001-KSM-Add-auto-flag-new-VMA-as-VM_MERGEABLE.patch\0"
  "b\0"
+ ">From db8ad0877146a69e1e5d5ab98825cefcf44a95bb Mon Sep 17 00:00:00 2001\n"
+ "From: Timofey Titovets <nefelim4ag@gmail.com>\n"
+ "Date: Sat, 8 Nov 2014 03:02:52 +0300\n"
+ "Subject: [PATCH] KSM: Add auto flag new VMA as VM_MERGEABLE\n"
+ "\n"
+ "Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>\n"
+ "---\n"
+ " include/linux/ksm.h | 31 +++++++++++++++++++++++++++++++\n"
+ " mm/mmap.c           | 17 +++++++++++++++++\n"
+ " 2 files changed, 48 insertions(+)\n"
+ "\n"
+ "diff --git a/include/linux/ksm.h b/include/linux/ksm.h\n"
+ "index 3be6bb1..c3fff64 100644\n"
+ "--- a/include/linux/ksm.h\n"
+ "+++ b/include/linux/ksm.h\n"
+ "@@ -76,6 +76,29 @@ struct page *ksm_might_need_to_copy(struct page *page,\n"
+ " int rmap_walk_ksm(struct page *page, struct rmap_walk_control *rwc);\n"
+ " void ksm_migrate_page(struct page *newpage, struct page *oldpage);\n"
+ " \n"
+ "+/*\n"
+ "+ * Allow to mark new vma as VM_MERGEABLE\n"
+ "+ */\n"
+ "+#ifndef VM_SAO\n"
+ "+#define VM_SAO 0\n"
+ "+#endif\n"
+ "+static inline void ksm_vm_flags_mod(unsigned long *vm_flags)\n"
+ "+{\n"
+ "+\tif (*vm_flags & (VM_MERGEABLE | VM_SHARED  | VM_MAYSHARE   |\n"
+ "+\t\t\t VM_PFNMAP    | VM_IO      | VM_DONTEXPAND |\n"
+ "+\t\t\t VM_HUGETLB | VM_NONLINEAR | VM_MIXEDMAP   | VM_SAO) )\n"
+ "+\t\treturn;\n"
+ "+\t*vm_flags |= VM_MERGEABLE;\n"
+ "+}\n"
+ "+\n"
+ "+static inline void ksm_vma_add_new(struct vm_area_struct *vma)\n"
+ "+{\n"
+ "+\tstruct mm_struct *mm = vma->vm_mm;\n"
+ "+\tif (!test_bit(MMF_VM_MERGEABLE, &mm->flags)) {\n"
+ "+\t\t__ksm_enter(mm);\n"
+ "+\t}\n"
+ "+}\n"
+ "+\n"
+ " #else  /* !CONFIG_KSM */\n"
+ " \n"
+ " static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm)\n"
+ "@@ -92,6 +115,14 @@ static inline int PageKsm(struct page *page)\n"
+ " \treturn 0;\n"
+ " }\n"
+ " \n"
+ "+static inline void ksm_vm_flags_mod(unsigned long *vm_flags_p)\n"
+ "+{\n"
+ "+}\n"
+ "+\n"
+ "+void ksm_vma_add_new(struct vm_area_struct *vma)\n"
+ "+{\n"
+ "+}\n"
+ "+\n"
+ " #ifdef CONFIG_MMU\n"
+ " static inline int ksm_madvise(struct vm_area_struct *vma, unsigned long start,\n"
+ " \t\tunsigned long end, int advice, unsigned long *vm_flags)\n"
+ "diff --git a/mm/mmap.c b/mm/mmap.c\n"
+ "index 7f85520..ce0073e 100644\n"
+ "--- a/mm/mmap.c\n"
+ "+++ b/mm/mmap.c\n"
+ "@@ -41,6 +41,7 @@\n"
+ " #include <linux/notifier.h>\n"
+ " #include <linux/memory.h>\n"
+ " #include <linux/printk.h>\n"
+ "+#include <linux/ksm.h>\n"
+ " \n"
+ " #include <asm/uaccess.h>\n"
+ " #include <asm/cacheflush.h>\n"
+ "@@ -911,10 +912,14 @@ again:\t\t\tremove_next = 1 + (end > next->vm_end);\n"
+ " \t\t\tvma_gap_update(next);\n"
+ " \t\telse\n"
+ " \t\t\tmm->highest_vm_end = end;\n"
+ "+\t} else {\n"
+ "+\t\tif (next && !insert)\n"
+ "+\t\t\tksm_vma_add_new(next);\n"
+ " \t}\n"
+ " \tif (insert && file)\n"
+ " \t\tuprobe_mmap(insert);\n"
+ " \n"
+ "+\tksm_vma_add_new(vma);\n"
+ " \tvalidate_mm(mm);\n"
+ " \n"
+ " \treturn 0;\n"
+ "@@ -1307,6 +1312,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,\n"
+ " \tvm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |\n"
+ " \t\t\tmm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;\n"
+ " \n"
+ "+\t/* If ksm is enabled, we add VM_MERGABLE to new VMAs. */\n"
+ "+\tksm_vm_flags_mod(&vm_flags);\n"
+ "+\n"
+ " \tif (flags & MAP_LOCKED)\n"
+ " \t\tif (!can_do_mlock())\n"
+ " \t\t\treturn -EPERM;\n"
+ "@@ -1648,6 +1656,7 @@ munmap_back:\n"
+ " \t\t\tallow_write_access(file);\n"
+ " \t}\n"
+ " \tfile = vma->vm_file;\n"
+ "+\tksm_vma_add_new(vma);\n"
+ " out:\n"
+ " \tperf_event_mmap(vma);\n"
+ " \n"
+ "@@ -2484,6 +2493,8 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,\n"
+ " \telse\n"
+ " \t\terr = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);\n"
+ " \n"
+ "+\tksm_vma_add_new(vma);\n"
+ "+\n"
+ " \t/* Success. */\n"
+ " \tif (!err)\n"
+ " \t\treturn 0;\n"
+ "@@ -2659,6 +2670,9 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)\n"
+ " \tif (error)\n"
+ " \t\treturn error;\n"
+ " \n"
+ "+\t/* If ksm is enabled, we add VM_MERGABLE to new VMAs. */\n"
+ "+\tksm_vm_flags_mod(&flags);\n"
+ "+\n"
+ " \t/*\n"
+ " \t * mm->mmap_sem is required to protect against another thread\n"
+ " \t * changing the mappings in case we sleep.\n"
+ "@@ -2708,6 +2722,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)\n"
+ " \tvma->vm_flags = flags;\n"
+ " \tvma->vm_page_prot = vm_get_page_prot(flags);\n"
+ " \tvma_link(mm, vma, prev, rb_link, rb_parent);\n"
+ "+\tksm_vma_add_new(vma);\n"
+ " out:\n"
+ " \tperf_event_mmap(vma);\n"
+ " \tmm->total_vm += len >> PAGE_SHIFT;\n"
+ "@@ -2887,6 +2902,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,\n"
+ " \t\t\t\tnew_vma->vm_ops->open(new_vma);\n"
+ " \t\t\tvma_link(mm, new_vma, prev, rb_link, rb_parent);\n"
+ " \t\t\t*need_rmap_locks = false;\n"
+ "+\t\t\tksm_vma_add_new(new_vma);\n"
+ " \t\t}\n"
+ " \t}\n"
+ " \treturn new_vma;\n"
+ "@@ -3004,6 +3020,7 @@ static struct vm_area_struct *__install_special_mapping(\n"
+ " \tmm->total_vm += len >> PAGE_SHIFT;\n"
+ " \n"
+ " \tperf_event_mmap(vma);\n"
+ "+\tksm_vma_add_new(vma);\n"
+ " \n"
+ " \treturn vma;\n"
+ " \n"
+ "-- \n"
+ 2.1.3
 
-6b1df1e708eb7487b7dd77aa80016e87c16e3168292f778ae86bb5810b55fcc0
+2d3d0382079ce509bcb1d88904864c8e2098137ceaa622506acc2bf539d6a2a9

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.