]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - include/linux/ksm.h
drm/panel: Add support for the Raspberry Pi 7" Touchscreen.
[mirror_ubuntu-zesty-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
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 37
08beca44
HD
38static inline struct stable_node *page_stable_node(struct page *page)
39{
40 return PageKsm(page) ? page_rmapping(page) : NULL;
41}
42
43static inline void set_page_stable_node(struct page *page,
44 struct stable_node *stable_node)
45{
bda807d4 46 page->mapping = (void *)((unsigned long)stable_node | PAGE_MAPPING_KSM);
08beca44
HD
47}
48
5ad64688
HD
49/*
50 * When do_swap_page() first faults in from swap what used to be a KSM page,
51 * no problem, it will be assigned to this vma's anon_vma; but thereafter,
52 * it might be faulted into a different anon_vma (or perhaps to a different
53 * offset in the same anon_vma). do_swap_page() cannot do all the locking
54 * needed to reconstitute a cross-anon_vma KSM page: for now it has to make
55 * a copy, and leave remerging the pages to a later pass of ksmd.
56 *
57 * We'd like to make this conditional on vma->vm_flags & VM_MERGEABLE,
58 * but what if the vma was unmerged while the page was swapped out?
59 */
cbf86cfe
HD
60struct page *ksm_might_need_to_copy(struct page *page,
61 struct vm_area_struct *vma, unsigned long address);
5ad64688 62
051ac83a 63int rmap_walk_ksm(struct page *page, struct rmap_walk_control *rwc);
e9995ef9 64void ksm_migrate_page(struct page *newpage, struct page *oldpage);
5ad64688 65
f8af4da3
HD
66#else /* !CONFIG_KSM */
67
f8af4da3
HD
68static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm)
69{
70 return 0;
71}
72
1c2fb7a4 73static inline void ksm_exit(struct mm_struct *mm)
f8af4da3
HD
74{
75}
9a840895 76
f42647ac
HD
77#ifdef CONFIG_MMU
78static inline int ksm_madvise(struct vm_area_struct *vma, unsigned long start,
79 unsigned long end, int advice, unsigned long *vm_flags)
80{
81 return 0;
82}
83
cbf86cfe 84static inline struct page *ksm_might_need_to_copy(struct page *page,
5ad64688
HD
85 struct vm_area_struct *vma, unsigned long address)
86{
cbf86cfe 87 return page;
5ad64688
HD
88}
89
90static inline int page_referenced_ksm(struct page *page,
91 struct mem_cgroup *memcg, unsigned long *vm_flags)
92{
93 return 0;
94}
95
051ac83a
JK
96static inline int rmap_walk_ksm(struct page *page,
97 struct rmap_walk_control *rwc)
e9995ef9
HD
98{
99 return 0;
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 */