1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_KHUGEPAGED_H
3 #define _LINUX_KHUGEPAGED_H
4 
5 #include <linux/sched/coredump.h> /* MMF_VM_HUGEPAGE */
6 
7 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
8 extern struct attribute_group khugepaged_attr_group;
9 
10 extern int khugepaged_init(void);
11 extern void khugepaged_destroy(void);
12 extern int start_stop_khugepaged(void);
13 extern void __khugepaged_enter(struct mm_struct *mm);
14 extern void __khugepaged_exit(struct mm_struct *mm);
15 extern void khugepaged_enter_vma(struct vm_area_struct *vma,
16 				 unsigned long vm_flags);
17 extern void khugepaged_min_free_kbytes_update(void);
18 extern bool current_is_khugepaged(void);
19 #ifdef CONFIG_SHMEM
20 extern int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr,
21 				   bool install_pmd);
22 #else
collapse_pte_mapped_thp(struct mm_struct * mm,unsigned long addr,bool install_pmd)23 static inline int collapse_pte_mapped_thp(struct mm_struct *mm,
24 					  unsigned long addr, bool install_pmd)
25 {
26 	return 0;
27 }
28 #endif
29 
khugepaged_fork(struct mm_struct * mm,struct mm_struct * oldmm)30 static inline void khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm)
31 {
32 	if (test_bit(MMF_VM_HUGEPAGE, &oldmm->flags))
33 		__khugepaged_enter(mm);
34 }
35 
khugepaged_exit(struct mm_struct * mm)36 static inline void khugepaged_exit(struct mm_struct *mm)
37 {
38 	if (test_bit(MMF_VM_HUGEPAGE, &mm->flags))
39 		__khugepaged_exit(mm);
40 }
41 #else /* CONFIG_TRANSPARENT_HUGEPAGE */
khugepaged_fork(struct mm_struct * mm,struct mm_struct * oldmm)42 static inline void khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm)
43 {
44 }
khugepaged_exit(struct mm_struct * mm)45 static inline void khugepaged_exit(struct mm_struct *mm)
46 {
47 }
khugepaged_enter_vma(struct vm_area_struct * vma,unsigned long vm_flags)48 static inline void khugepaged_enter_vma(struct vm_area_struct *vma,
49 					unsigned long vm_flags)
50 {
51 }
collapse_pte_mapped_thp(struct mm_struct * mm,unsigned long addr,bool install_pmd)52 static inline int collapse_pte_mapped_thp(struct mm_struct *mm,
53 					  unsigned long addr, bool install_pmd)
54 {
55 	return 0;
56 }
57 
khugepaged_min_free_kbytes_update(void)58 static inline void khugepaged_min_free_kbytes_update(void)
59 {
60 }
61 
current_is_khugepaged(void)62 static inline bool current_is_khugepaged(void)
63 {
64 	return false;
65 }
66 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
67 
68 #endif /* _LINUX_KHUGEPAGED_H */
69