Commit | Line | Data |
---|---|---|
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> | |
12 | #include <linux/sched.h> | |
9a840895 | 13 | #include <linux/vmstat.h> |
f8af4da3 | 14 | |
08beca44 HD |
15 | struct stable_node; |
16 | ||
f8af4da3 HD |
17 | #ifdef CONFIG_KSM |
18 | int ksm_madvise(struct vm_area_struct *vma, unsigned long start, | |
19 | unsigned long end, int advice, unsigned long *vm_flags); | |
20 | int __ksm_enter(struct mm_struct *mm); | |
1c2fb7a4 | 21 | void __ksm_exit(struct mm_struct *mm); |
f8af4da3 HD |
22 | |
23 | static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm) | |
24 | { | |
25 | if (test_bit(MMF_VM_MERGEABLE, &oldmm->flags)) | |
26 | return __ksm_enter(mm); | |
27 | return 0; | |
28 | } | |
29 | ||
1c2fb7a4 | 30 | static inline void ksm_exit(struct mm_struct *mm) |
f8af4da3 HD |
31 | { |
32 | if (test_bit(MMF_VM_MERGEABLE, &mm->flags)) | |
1c2fb7a4 | 33 | __ksm_exit(mm); |
f8af4da3 | 34 | } |
9a840895 HD |
35 | |
36 | /* | |
37 | * A KSM page is one of those write-protected "shared pages" or "merged pages" | |
38 | * which KSM maps into multiple mms, wherever identical anonymous page content | |
08beca44 HD |
39 | * is found in VM_MERGEABLE vmas. It's a PageAnon page, pointing not to any |
40 | * anon_vma, but to that page's node of the stable tree. | |
9a840895 HD |
41 | */ |
42 | static inline int PageKsm(struct page *page) | |
43 | { | |
3ca7b3c5 HD |
44 | return ((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) == |
45 | (PAGE_MAPPING_ANON | PAGE_MAPPING_KSM); | |
9a840895 HD |
46 | } |
47 | ||
08beca44 HD |
48 | static inline struct stable_node *page_stable_node(struct page *page) |
49 | { | |
50 | return PageKsm(page) ? page_rmapping(page) : NULL; | |
51 | } | |
52 | ||
53 | static inline void set_page_stable_node(struct page *page, | |
54 | struct stable_node *stable_node) | |
55 | { | |
56 | page->mapping = (void *)stable_node + | |
57 | (PAGE_MAPPING_ANON | PAGE_MAPPING_KSM); | |
58 | } | |
59 | ||
9a840895 HD |
60 | static inline void page_add_ksm_rmap(struct page *page) |
61 | { | |
08beca44 | 62 | if (atomic_inc_and_test(&page->_mapcount)) |
9a840895 | 63 | __inc_zone_page_state(page, NR_ANON_PAGES); |
9a840895 | 64 | } |
f8af4da3 HD |
65 | #else /* !CONFIG_KSM */ |
66 | ||
67 | static inline int ksm_madvise(struct vm_area_struct *vma, unsigned long start, | |
68 | unsigned long end, int advice, unsigned long *vm_flags) | |
69 | { | |
70 | return 0; | |
71 | } | |
72 | ||
73 | static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm) | |
74 | { | |
75 | return 0; | |
76 | } | |
77 | ||
1c2fb7a4 | 78 | static inline void ksm_exit(struct mm_struct *mm) |
f8af4da3 HD |
79 | { |
80 | } | |
9a840895 HD |
81 | |
82 | static inline int PageKsm(struct page *page) | |
83 | { | |
84 | return 0; | |
85 | } | |
86 | ||
87 | /* No stub required for page_add_ksm_rmap(page) */ | |
f8af4da3 HD |
88 | #endif /* !CONFIG_KSM */ |
89 | ||
90 | #endif |