1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_KHUGEPAGED_H
3 #define _LINUX_KHUGEPAGED_H
5 #include <linux/sched/coredump.h> /* MMF_VM_HUGEPAGE */
8 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
9 extern struct attribute_group khugepaged_attr_group
;
11 extern int khugepaged_init(void);
12 extern void khugepaged_destroy(void);
13 extern int start_stop_khugepaged(void);
14 extern int __khugepaged_enter(struct mm_struct
*mm
);
15 extern void __khugepaged_exit(struct mm_struct
*mm
);
16 extern int khugepaged_enter_vma_merge(struct vm_area_struct
*vma
,
17 unsigned long vm_flags
);
19 #define khugepaged_enabled() \
20 (transparent_hugepage_flags & \
21 ((1<<TRANSPARENT_HUGEPAGE_FLAG) | \
22 (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG)))
23 #define khugepaged_always() \
24 (transparent_hugepage_flags & \
25 (1<<TRANSPARENT_HUGEPAGE_FLAG))
26 #define khugepaged_req_madv() \
27 (transparent_hugepage_flags & \
28 (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG))
29 #define khugepaged_defrag() \
30 (transparent_hugepage_flags & \
31 (1<<TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG))
33 static inline int khugepaged_fork(struct mm_struct
*mm
, struct mm_struct
*oldmm
)
35 if (test_bit(MMF_VM_HUGEPAGE
, &oldmm
->flags
))
36 return __khugepaged_enter(mm
);
40 static inline void khugepaged_exit(struct mm_struct
*mm
)
42 if (test_bit(MMF_VM_HUGEPAGE
, &mm
->flags
))
43 __khugepaged_exit(mm
);
46 static inline int khugepaged_enter(struct vm_area_struct
*vma
,
47 unsigned long vm_flags
)
49 if (!test_bit(MMF_VM_HUGEPAGE
, &vma
->vm_mm
->flags
))
50 if ((khugepaged_always() ||
51 (khugepaged_req_madv() && (vm_flags
& VM_HUGEPAGE
))) &&
52 !(vm_flags
& VM_NOHUGEPAGE
) &&
53 !test_bit(MMF_DISABLE_THP
, &vma
->vm_mm
->flags
))
54 if (__khugepaged_enter(vma
->vm_mm
))
58 #else /* CONFIG_TRANSPARENT_HUGEPAGE */
59 static inline int khugepaged_fork(struct mm_struct
*mm
, struct mm_struct
*oldmm
)
63 static inline void khugepaged_exit(struct mm_struct
*mm
)
66 static inline int khugepaged_enter(struct vm_area_struct
*vma
,
67 unsigned long vm_flags
)
71 static inline int khugepaged_enter_vma_merge(struct vm_area_struct
*vma
,
72 unsigned long vm_flags
)
76 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
78 #endif /* _LINUX_KHUGEPAGED_H */