svcrdma: Select NFSv4.1 backchannel transport based on forward channel
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / linux / ksm.h
CommitLineData
f8af4da3
HD
1#ifndef __LINUX_KSM_H
2#define __LINUX_KSM_H
3/*
4 * Memory merging support.
5 *
6 * This code enables dynamic sharing of identical pages found in different
7 * memory areas, even if they are not shared by fork().
8 */
9
10#include <linux/bitops.h>
11#include <linux/mm.h>
5ad64688
HD
12#include <linux/pagemap.h>
13#include <linux/rmap.h>
f8af4da3
HD
14#include <linux/sched.h>
15
08beca44 16struct stable_node;
5ad64688 17struct mem_cgroup;
08beca44 18
f8af4da3
HD
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);
1c2fb7a4 23void __ksm_exit(struct mm_struct *mm);
f8af4da3
HD
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
1c2fb7a4 32static inline void ksm_exit(struct mm_struct *mm)
f8af4da3
HD
33{
34 if (test_bit(MMF_VM_MERGEABLE, &mm->flags))
1c2fb7a4 35 __ksm_exit(mm);
f8af4da3 36}
9a840895
HD
37
38/*
39 * A KSM page is one of those write-protected "shared pages" or "merged pages"
40 * which KSM maps into multiple mms, wherever identical anonymous page content
08beca44
HD
41 * is found in VM_MERGEABLE vmas. It's a PageAnon page, pointing not to any
42 * anon_vma, but to that page's node of the stable tree.
9a840895
HD
43 */
44static inline int PageKsm(struct page *page)
45{
3ca7b3c5
HD
46 return ((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) ==
47 (PAGE_MAPPING_ANON | PAGE_MAPPING_KSM);
9a840895
HD
48}
49
08beca44
HD
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
5ad64688
HD
62/*
63 * When do_swap_page() first faults in from swap what used to be a KSM page,
64 * no problem, it will be assigned to this vma's anon_vma; but thereafter,
65 * it might be faulted into a different anon_vma (or perhaps to a different
66 * offset in the same anon_vma). do_swap_page() cannot do all the locking
67 * needed to reconstitute a cross-anon_vma KSM page: for now it has to make
68 * a copy, and leave remerging the pages to a later pass of ksmd.
69 *
70 * We'd like to make this conditional on vma->vm_flags & VM_MERGEABLE,
71 * but what if the vma was unmerged while the page was swapped out?
72 */
cbf86cfe
HD
73struct page *ksm_might_need_to_copy(struct page *page,
74 struct vm_area_struct *vma, unsigned long address);
5ad64688
HD
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);
e9995ef9
HD
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);
5ad64688 82
f8af4da3
HD
83#else /* !CONFIG_KSM */
84
f8af4da3
HD
85static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm)
86{
87 return 0;
88}
89
1c2fb7a4 90static inline void ksm_exit(struct mm_struct *mm)
f8af4da3
HD
91{
92}
9a840895
HD
93
94static inline int PageKsm(struct page *page)
95{
96 return 0;
97}
98
f42647ac
HD
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
cbf86cfe 106static inline struct page *ksm_might_need_to_copy(struct page *page,
5ad64688
HD
107 struct vm_area_struct *vma, unsigned long address)
108{
cbf86cfe 109 return page;
5ad64688
HD
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}
e9995ef9
HD
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}
f42647ac 132#endif /* CONFIG_MMU */
f8af4da3
HD
133#endif /* !CONFIG_KSM */
134
5ad64688 135#endif /* __LINUX_KSM_H */