2 * Initial dummy version just to illustrate KSM's interface to other files.
5 #include <linux/errno.h>
6 #include <linux/mman.h>
9 int ksm_madvise(struct vm_area_struct *vma, unsigned long start,
10 unsigned long end, int advice, unsigned long *vm_flags)
12 struct mm_struct *mm = vma->vm_mm;
17 * Be somewhat over-protective for now!
19 if (*vm_flags & (VM_MERGEABLE | VM_SHARED | VM_MAYSHARE |
20 VM_PFNMAP | VM_IO | VM_DONTEXPAND |
21 VM_RESERVED | VM_HUGETLB | VM_INSERTPAGE |
22 VM_MIXEDMAP | VM_SAO))
23 return 0; /* just ignore the advice */
25 if (!test_bit(MMF_VM_MERGEABLE, &mm->flags))
26 if (__ksm_enter(mm) < 0)
29 *vm_flags |= VM_MERGEABLE;
32 case MADV_UNMERGEABLE:
33 if (!(*vm_flags & VM_MERGEABLE))
34 return 0; /* just ignore the advice */
36 /* Unmerge any merged pages here */
38 *vm_flags &= ~VM_MERGEABLE;
45 int __ksm_enter(struct mm_struct *mm)
47 /* Allocate a structure to track mm and link it into KSM's list */
48 set_bit(MMF_VM_MERGEABLE, &mm->flags);
52 void __ksm_exit(struct mm_struct *mm)
54 /* Unlink and free all KSM's structures which track this mm */
55 clear_bit(MMF_VM_MERGEABLE, &mm->flags);