Linux 4.6-rc6
[cris-mirror.git] / include / linux / ksm.h
blob7ae216a39c9e97455db75e0d7fb5ba04b53ccbe8
1 #ifndef __LINUX_KSM_H
2 #define __LINUX_KSM_H
3 /*
4 * Memory merging support.
6 * This code enables dynamic sharing of identical pages found in different
7 * memory areas, even if they are not shared by fork().
8 */
10 #include <linux/bitops.h>
11 #include <linux/mm.h>
12 #include <linux/pagemap.h>
13 #include <linux/rmap.h>
14 #include <linux/sched.h>
16 struct stable_node;
17 struct mem_cgroup;
19 #ifdef CONFIG_KSM
20 int ksm_madvise(struct vm_area_struct *vma, unsigned long start,
21 unsigned long end, int advice, unsigned long *vm_flags);
22 int __ksm_enter(struct mm_struct *mm);
23 void __ksm_exit(struct mm_struct *mm);
25 static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm)
27 if (test_bit(MMF_VM_MERGEABLE, &oldmm->flags))
28 return __ksm_enter(mm);
29 return 0;
32 static inline void ksm_exit(struct mm_struct *mm)
34 if (test_bit(MMF_VM_MERGEABLE, &mm->flags))
35 __ksm_exit(mm);
38 static inline struct stable_node *page_stable_node(struct page *page)
40 return PageKsm(page) ? page_rmapping(page) : NULL;
43 static inline void set_page_stable_node(struct page *page,
44 struct stable_node *stable_node)
46 page->mapping = (void *)stable_node +
47 (PAGE_MAPPING_ANON | PAGE_MAPPING_KSM);
51 * When do_swap_page() first faults in from swap what used to be a KSM page,
52 * no problem, it will be assigned to this vma's anon_vma; but thereafter,
53 * it might be faulted into a different anon_vma (or perhaps to a different
54 * offset in the same anon_vma). do_swap_page() cannot do all the locking
55 * needed to reconstitute a cross-anon_vma KSM page: for now it has to make
56 * a copy, and leave remerging the pages to a later pass of ksmd.
58 * We'd like to make this conditional on vma->vm_flags & VM_MERGEABLE,
59 * but what if the vma was unmerged while the page was swapped out?
61 struct page *ksm_might_need_to_copy(struct page *page,
62 struct vm_area_struct *vma, unsigned long address);
64 int rmap_walk_ksm(struct page *page, struct rmap_walk_control *rwc);
65 void ksm_migrate_page(struct page *newpage, struct page *oldpage);
67 #else /* !CONFIG_KSM */
69 static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm)
71 return 0;
74 static inline void ksm_exit(struct mm_struct *mm)
78 #ifdef CONFIG_MMU
79 static inline int ksm_madvise(struct vm_area_struct *vma, unsigned long start,
80 unsigned long end, int advice, unsigned long *vm_flags)
82 return 0;
85 static inline struct page *ksm_might_need_to_copy(struct page *page,
86 struct vm_area_struct *vma, unsigned long address)
88 return page;
91 static inline int page_referenced_ksm(struct page *page,
92 struct mem_cgroup *memcg, unsigned long *vm_flags)
94 return 0;
97 static inline int rmap_walk_ksm(struct page *page,
98 struct rmap_walk_control *rwc)
100 return 0;
103 static inline void ksm_migrate_page(struct page *newpage, struct page *oldpage)
106 #endif /* CONFIG_MMU */
107 #endif /* !CONFIG_KSM */
109 #endif /* __LINUX_KSM_H */