0001
0002 #ifndef __LINUX_KSM_H
0003 #define __LINUX_KSM_H
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/bitops.h>
0012 #include <linux/mm.h>
0013 #include <linux/pagemap.h>
0014 #include <linux/rmap.h>
0015 #include <linux/sched.h>
0016 #include <linux/sched/coredump.h>
0017
0018 struct stable_node;
0019 struct mem_cgroup;
0020
0021 #ifdef CONFIG_KSM
0022 int ksm_madvise(struct vm_area_struct *vma, unsigned long start,
0023 unsigned long end, int advice, unsigned long *vm_flags);
0024 int __ksm_enter(struct mm_struct *mm);
0025 void __ksm_exit(struct mm_struct *mm);
0026
0027 static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm)
0028 {
0029 if (test_bit(MMF_VM_MERGEABLE, &oldmm->flags))
0030 return __ksm_enter(mm);
0031 return 0;
0032 }
0033
0034 static inline void ksm_exit(struct mm_struct *mm)
0035 {
0036 if (test_bit(MMF_VM_MERGEABLE, &mm->flags))
0037 __ksm_exit(mm);
0038 }
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051 struct page *ksm_might_need_to_copy(struct page *page,
0052 struct vm_area_struct *vma, unsigned long address);
0053
0054 void rmap_walk_ksm(struct folio *folio, struct rmap_walk_control *rwc);
0055 void folio_migrate_ksm(struct folio *newfolio, struct folio *folio);
0056
0057 #else
0058
0059 static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm)
0060 {
0061 return 0;
0062 }
0063
0064 static inline void ksm_exit(struct mm_struct *mm)
0065 {
0066 }
0067
0068 #ifdef CONFIG_MMU
0069 static inline int ksm_madvise(struct vm_area_struct *vma, unsigned long start,
0070 unsigned long end, int advice, unsigned long *vm_flags)
0071 {
0072 return 0;
0073 }
0074
0075 static inline struct page *ksm_might_need_to_copy(struct page *page,
0076 struct vm_area_struct *vma, unsigned long address)
0077 {
0078 return page;
0079 }
0080
0081 static inline void rmap_walk_ksm(struct folio *folio,
0082 struct rmap_walk_control *rwc)
0083 {
0084 }
0085
0086 static inline void folio_migrate_ksm(struct folio *newfolio, struct folio *old)
0087 {
0088 }
0089 #endif
0090 #endif
0091
0092 #endif