]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/linux/ksm.h
UBUNTU: SAUCE: LSM stacking: procfs: add smack subdir to attrs
[mirror_ubuntu-artful-kernel.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 14#include <linux/sched.h>
f7ccbae4 15#include <linux/sched/coredump.h>
f8af4da3 16
08beca44 17struct stable_node;
5ad64688 18struct mem_cgroup;
08beca44 19
f8af4da3
HD
20#ifdef CONFIG_KSM
21int ksm_madvise(struct vm_area_struct *vma, unsigned long start,
22 unsigned long end, int advice, unsigned long *vm_flags);
23int __ksm_enter(struct mm_struct *mm);
1c2fb7a4 24void __ksm_exit(struct mm_struct *mm);
f8af4da3
HD
25
26static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm)
27{
28 if (test_bit(MMF_VM_MERGEABLE, &oldmm->flags))
29 return __ksm_enter(mm);
30 return 0;
31}
32
1c2fb7a4 33static inline void ksm_exit(struct mm_struct *mm)
f8af4da3
HD
34{
35 if (test_bit(MMF_VM_MERGEABLE, &mm->flags))
1c2fb7a4 36 __ksm_exit(mm);
f8af4da3 37}
9a840895 38
08beca44
HD
39static inline struct stable_node *page_stable_node(struct page *page)
40{
41 return PageKsm(page) ? page_rmapping(page) : NULL;
42}
43
44static inline void set_page_stable_node(struct page *page,
45 struct stable_node *stable_node)
46{
bda807d4 47 page->mapping = (void *)((unsigned long)stable_node | PAGE_MAPPING_KSM);
08beca44
HD
48}
49
5ad64688
HD
50/*
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.
57 *
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?
60 */
cbf86cfe
HD
61struct page *ksm_might_need_to_copy(struct page *page,
62 struct vm_area_struct *vma, unsigned long address);
5ad64688 63
1df631ae 64void rmap_walk_ksm(struct page *page, struct rmap_walk_control *rwc);
e9995ef9 65void ksm_migrate_page(struct page *newpage, struct page *oldpage);
5ad64688 66
f8af4da3
HD
67#else /* !CONFIG_KSM */
68
f8af4da3
HD
69static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm)
70{
71 return 0;
72}
73
1c2fb7a4 74static inline void ksm_exit(struct mm_struct *mm)
f8af4da3
HD
75{
76}
9a840895 77
f42647ac
HD
78#ifdef CONFIG_MMU
79static inline int ksm_madvise(struct vm_area_struct *vma, unsigned long start,
80 unsigned long end, int advice, unsigned long *vm_flags)
81{
82 return 0;
83}
84
cbf86cfe 85static inline struct page *ksm_might_need_to_copy(struct page *page,
5ad64688
HD
86 struct vm_area_struct *vma, unsigned long address)
87{
cbf86cfe 88 return page;
5ad64688
HD
89}
90
91static inline int page_referenced_ksm(struct page *page,
92 struct mem_cgroup *memcg, unsigned long *vm_flags)
93{
94 return 0;
95}
96
1df631ae 97static inline void rmap_walk_ksm(struct page *page,
051ac83a 98 struct rmap_walk_control *rwc)
e9995ef9 99{
e9995ef9
HD
100}
101
102static inline void ksm_migrate_page(struct page *newpage, struct page *oldpage)
103{
104}
f42647ac 105#endif /* CONFIG_MMU */
f8af4da3
HD
106#endif /* !CONFIG_KSM */
107
5ad64688 108#endif /* __LINUX_KSM_H */