]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
f8af4da3 HD |
2 | #ifndef __LINUX_KSM_H |
3 | #define __LINUX_KSM_H | |
4 | /* | |
5 | * Memory merging support. | |
6 | * | |
7 | * This code enables dynamic sharing of identical pages found in different | |
8 | * memory areas, even if they are not shared by fork(). | |
9 | */ | |
10 | ||
11 | #include <linux/bitops.h> | |
12 | #include <linux/mm.h> | |
5ad64688 HD |
13 | #include <linux/pagemap.h> |
14 | #include <linux/rmap.h> | |
f8af4da3 | 15 | #include <linux/sched.h> |
f7ccbae4 | 16 | #include <linux/sched/coredump.h> |
f8af4da3 | 17 | |
08beca44 | 18 | struct stable_node; |
5ad64688 | 19 | struct mem_cgroup; |
08beca44 | 20 | |
f8af4da3 HD |
21 | #ifdef CONFIG_KSM |
22 | int ksm_madvise(struct vm_area_struct *vma, unsigned long start, | |
23 | unsigned long end, int advice, unsigned long *vm_flags); | |
24 | int __ksm_enter(struct mm_struct *mm); | |
1c2fb7a4 | 25 | void __ksm_exit(struct mm_struct *mm); |
f8af4da3 HD |
26 | |
27 | static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm) | |
28 | { | |
29 | if (test_bit(MMF_VM_MERGEABLE, &oldmm->flags)) | |
30 | return __ksm_enter(mm); | |
31 | return 0; | |
32 | } | |
33 | ||
1c2fb7a4 | 34 | static inline void ksm_exit(struct mm_struct *mm) |
f8af4da3 HD |
35 | { |
36 | if (test_bit(MMF_VM_MERGEABLE, &mm->flags)) | |
1c2fb7a4 | 37 | __ksm_exit(mm); |
f8af4da3 | 38 | } |
9a840895 | 39 | |
08beca44 HD |
40 | static inline struct stable_node *page_stable_node(struct page *page) |
41 | { | |
42 | return PageKsm(page) ? page_rmapping(page) : NULL; | |
43 | } | |
44 | ||
45 | static inline void set_page_stable_node(struct page *page, | |
46 | struct stable_node *stable_node) | |
47 | { | |
bda807d4 | 48 | page->mapping = (void *)((unsigned long)stable_node | PAGE_MAPPING_KSM); |
08beca44 HD |
49 | } |
50 | ||
5ad64688 HD |
51 | /* |
52 | * When do_swap_page() first faults in from swap what used to be a KSM page, | |
53 | * no problem, it will be assigned to this vma's anon_vma; but thereafter, | |
54 | * it might be faulted into a different anon_vma (or perhaps to a different | |
55 | * offset in the same anon_vma). do_swap_page() cannot do all the locking | |
56 | * needed to reconstitute a cross-anon_vma KSM page: for now it has to make | |
57 | * a copy, and leave remerging the pages to a later pass of ksmd. | |
58 | * | |
59 | * We'd like to make this conditional on vma->vm_flags & VM_MERGEABLE, | |
60 | * but what if the vma was unmerged while the page was swapped out? | |
61 | */ | |
cbf86cfe HD |
62 | struct page *ksm_might_need_to_copy(struct page *page, |
63 | struct vm_area_struct *vma, unsigned long address); | |
5ad64688 | 64 | |
1df631ae | 65 | void rmap_walk_ksm(struct page *page, struct rmap_walk_control *rwc); |
e9995ef9 | 66 | void ksm_migrate_page(struct page *newpage, struct page *oldpage); |
5ad64688 | 67 | |
f8af4da3 HD |
68 | #else /* !CONFIG_KSM */ |
69 | ||
f8af4da3 HD |
70 | static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm) |
71 | { | |
72 | return 0; | |
73 | } | |
74 | ||
1c2fb7a4 | 75 | static inline void ksm_exit(struct mm_struct *mm) |
f8af4da3 HD |
76 | { |
77 | } | |
9a840895 | 78 | |
f42647ac HD |
79 | #ifdef CONFIG_MMU |
80 | static inline int ksm_madvise(struct vm_area_struct *vma, unsigned long start, | |
81 | unsigned long end, int advice, unsigned long *vm_flags) | |
82 | { | |
83 | return 0; | |
84 | } | |
85 | ||
cbf86cfe | 86 | static inline struct page *ksm_might_need_to_copy(struct page *page, |
5ad64688 HD |
87 | struct vm_area_struct *vma, unsigned long address) |
88 | { | |
cbf86cfe | 89 | return page; |
5ad64688 HD |
90 | } |
91 | ||
92 | static inline int page_referenced_ksm(struct page *page, | |
93 | struct mem_cgroup *memcg, unsigned long *vm_flags) | |
94 | { | |
95 | return 0; | |
96 | } | |
97 | ||
1df631ae | 98 | static inline void rmap_walk_ksm(struct page *page, |
051ac83a | 99 | struct rmap_walk_control *rwc) |
e9995ef9 | 100 | { |
e9995ef9 HD |
101 | } |
102 | ||
103 | static inline void ksm_migrate_page(struct page *newpage, struct page *oldpage) | |
104 | { | |
105 | } | |
f42647ac | 106 | #endif /* CONFIG_MMU */ |
f8af4da3 HD |
107 | #endif /* !CONFIG_KSM */ |
108 | ||
5ad64688 | 109 | #endif /* __LINUX_KSM_H */ |