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 rmap_walk_ksm(struct page *page, struct rmap_walk_control *rwc);
77void ksm_migrate_page(struct page *newpage, struct page *oldpage);
78
79#else
80
81static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm)
82{
83 return 0;
84}
85
86static inline void ksm_exit(struct mm_struct *mm)
87{
88}
89
90static inline int PageKsm(struct page *page)
91{
92 return 0;
93}
94
95#ifdef CONFIG_MMU
96static inline int ksm_madvise(struct vm_area_struct *vma, unsigned long start,
97 unsigned long end, int advice, unsigned long *vm_flags)
98{
99 return 0;
100}
101
102static inline struct page *ksm_might_need_to_copy(struct page *page,
103 struct vm_area_struct *vma, unsigned long address)
104{
105 return page;
106}
107
108static inline int page_referenced_ksm(struct page *page,
109 struct mem_cgroup *memcg, unsigned long *vm_flags)
110{
111 return 0;
112}
113
114static inline int rmap_walk_ksm(struct page *page,
115 struct rmap_walk_control *rwc)
116{
117 return 0;
118}
119
120static inline void ksm_migrate_page(struct page *newpage, struct page *oldpage)
121{
122}
123#endif
124#endif
125
126#endif
127