@@ -2690,6 +2690,27 @@ int __ksm_enter(struct mm_struct *mm, int flag)
return 0;
}
+static void unmerge_vmas(struct mm_struct *mm)
+{
+ struct vm_area_struct *vma;
+ struct vma_iterator vmi;
+
+ vma_iter_init(&vmi, mm, 0);
+
+ mmap_read_lock(mm);
+ for_each_vma(vmi, vma) {
+ if (vma->vm_flags & VM_MERGEABLE) {
+ unsigned long flags = vma->vm_flags;
+
+ if (ksm_madvise(vma, vma->vm_start, vma->vm_end, MADV_UNMERGEABLE, &flags))
+ continue;
+
+ vm_flags_clear(vma, VM_MERGEABLE);
+ }
+ }
+ mmap_read_unlock(mm);
+}
+
void __ksm_exit(struct mm_struct *mm, int flag)
{
struct ksm_mm_slot *mm_slot;
@@ -2697,8 +2718,10 @@ void __ksm_exit(struct mm_struct *mm, int flag)
int easy_to_free = 0;
if (!(current->flags & PF_EXITING) && flag == MMF_VM_MERGE_ANY &&
- test_bit(MMF_VM_MERGE_ANY, &mm->flags))
+ test_bit(MMF_VM_MERGE_ANY, &mm->flags)) {
clear_bit(MMF_VM_MERGE_ANY, &mm->flags);
+ unmerge_vmas(mm);
+ }
/*
* This process is exiting: if it's straightforward (as is the
This adds the ability to disable ksm for a process if ksm has been enabled for the process. Signed-off-by: Stefan Roesch <shr@devkernel.io> --- mm/ksm.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)