1#ifndef __LINUX_KSM_H
2#define __LINUX_KSM_H
3
4
5
6
7
8
9
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>
15
16struct stable_node;
17struct mem_cgroup;
18
19struct page *ksm_does_need_to_copy(struct page *page,
20 struct vm_area_struct *vma, unsigned long address);
21
22#ifdef CONFIG_KSM
23int ksm_madvise(struct vm_area_struct *vma, unsigned long start,
24 unsigned long end, int advice, unsigned long *vm_flags);
25int __ksm_enter(struct mm_struct *mm);
26void __ksm_exit(struct mm_struct *mm);
27
28static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm)
29{
30 if (test_bit(MMF_VM_MERGEABLE, &oldmm->flags))
31 return __ksm_enter(mm);
32 return 0;
33}
34
35static inline void ksm_exit(struct mm_struct *mm)
36{
37 if (test_bit(MMF_VM_MERGEABLE, &mm->flags))
38 __ksm_exit(mm);
39}
40
41
42
43
44
45
46
47static inline int PageKsm(struct page *page)
48{
49 return ((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) ==
50 (PAGE_MAPPING_ANON | PAGE_MAPPING_KSM);
51}
52
53static inline struct stable_node *page_stable_node(struct page *page)
54{
55 return PageKsm(page) ? page_rmapping(page) : NULL;
56}
57
58static inline void set_page_stable_node(struct page *page,
59 struct stable_node *stable_node)
60{
61 page->mapping = (void *)stable_node +
62 (PAGE_MAPPING_ANON | PAGE_MAPPING_KSM);
63}
64
65
66
67
68
69
70
71
72
73
74
75
76static inline int ksm_might_need_to_copy(struct page *page,
77 struct vm_area_struct *vma, unsigned long address)
78{
79 struct anon_vma *anon_vma = page_anon_vma(page);
80
81 return anon_vma &&
82 (anon_vma->root != vma->anon_vma->root ||
83 page->index != linear_page_index(vma, address));
84}
85
86int page_referenced_ksm(struct page *page,
87 struct mem_cgroup *memcg, unsigned long *vm_flags);
88int try_to_unmap_ksm(struct page *page, enum ttu_flags flags);
89int rmap_walk_ksm(struct page *page, int (*rmap_one)(struct page *,
90 struct vm_area_struct *, unsigned long, void *), void *arg);
91void ksm_migrate_page(struct page *newpage, struct page *oldpage);
92
93#else
94
95static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm)
96{
97 return 0;
98}
99
100static inline void ksm_exit(struct mm_struct *mm)
101{
102}
103
104static inline int PageKsm(struct page *page)
105{
106 return 0;
107}
108
109#ifdef CONFIG_MMU
110static inline int ksm_madvise(struct vm_area_struct *vma, unsigned long start,
111 unsigned long end, int advice, unsigned long *vm_flags)
112{
113 return 0;
114}
115
116static inline int ksm_might_need_to_copy(struct page *page,
117 struct vm_area_struct *vma, unsigned long address)
118{
119 return 0;
120}
121
122static inline int page_referenced_ksm(struct page *page,
123 struct mem_cgroup *memcg, unsigned long *vm_flags)
124{
125 return 0;
126}
127
128static inline int try_to_unmap_ksm(struct page *page, enum ttu_flags flags)
129{
130 return 0;
131}
132
133static inline int rmap_walk_ksm(struct page *page, int (*rmap_one)(struct page*,
134 struct vm_area_struct *, unsigned long, void *), void *arg)
135{
136 return 0;
137}
138
139static inline void ksm_migrate_page(struct page *newpage, struct page *oldpage)
140{
141}
142#endif
143#endif
144
145#endif
146