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