blob: 5d9a400af5091f297abec57050b5aa2b2ced11aa [file] [log] [blame]
Andrea Arcangeliba761492011-01-13 15:46:58 -08001#ifndef _LINUX_KHUGEPAGED_H
2#define _LINUX_KHUGEPAGED_H
3
Ingo Molnarf7ccbae2017-02-08 18:51:30 +01004#include <linux/sched/coredump.h> /* MMF_VM_HUGEPAGE */
5
Andrea Arcangeliba761492011-01-13 15:46:58 -08006
7#ifdef CONFIG_TRANSPARENT_HUGEPAGE
Kirill A. Shutemovb46e7562016-07-26 15:26:24 -07008extern struct attribute_group khugepaged_attr_group;
9
10extern int khugepaged_init(void);
11extern void khugepaged_destroy(void);
12extern int start_stop_khugepaged(void);
Andrea Arcangeliba761492011-01-13 15:46:58 -080013extern int __khugepaged_enter(struct mm_struct *mm);
14extern void __khugepaged_exit(struct mm_struct *mm);
David Rientjes6d50e602014-10-29 14:50:31 -070015extern int khugepaged_enter_vma_merge(struct vm_area_struct *vma,
16 unsigned long vm_flags);
Andrea Arcangeliba761492011-01-13 15:46:58 -080017
18#define khugepaged_enabled() \
19 (transparent_hugepage_flags & \
20 ((1<<TRANSPARENT_HUGEPAGE_FLAG) | \
21 (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG)))
22#define khugepaged_always() \
23 (transparent_hugepage_flags & \
24 (1<<TRANSPARENT_HUGEPAGE_FLAG))
25#define khugepaged_req_madv() \
26 (transparent_hugepage_flags & \
27 (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG))
28#define khugepaged_defrag() \
29 (transparent_hugepage_flags & \
30 (1<<TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG))
31
32static inline int khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm)
33{
34 if (test_bit(MMF_VM_HUGEPAGE, &oldmm->flags))
35 return __khugepaged_enter(mm);
36 return 0;
37}
38
39static inline void khugepaged_exit(struct mm_struct *mm)
40{
41 if (test_bit(MMF_VM_HUGEPAGE, &mm->flags))
42 __khugepaged_exit(mm);
43}
44
David Rientjes6d50e602014-10-29 14:50:31 -070045static inline int khugepaged_enter(struct vm_area_struct *vma,
46 unsigned long vm_flags)
Andrea Arcangeliba761492011-01-13 15:46:58 -080047{
48 if (!test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags))
Andrea Arcangelia664b2d2011-01-13 15:47:17 -080049 if ((khugepaged_always() ||
David Rientjes6d50e602014-10-29 14:50:31 -070050 (khugepaged_req_madv() && (vm_flags & VM_HUGEPAGE))) &&
51 !(vm_flags & VM_NOHUGEPAGE))
Andrea Arcangeliba761492011-01-13 15:46:58 -080052 if (__khugepaged_enter(vma->vm_mm))
53 return -ENOMEM;
54 return 0;
55}
56#else /* CONFIG_TRANSPARENT_HUGEPAGE */
57static inline int khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm)
58{
59 return 0;
60}
61static inline void khugepaged_exit(struct mm_struct *mm)
62{
63}
David Rientjes6d50e602014-10-29 14:50:31 -070064static inline int khugepaged_enter(struct vm_area_struct *vma,
65 unsigned long vm_flags)
Andrea Arcangeliba761492011-01-13 15:46:58 -080066{
67 return 0;
68}
David Rientjes6d50e602014-10-29 14:50:31 -070069static inline int khugepaged_enter_vma_merge(struct vm_area_struct *vma,
70 unsigned long vm_flags)
Andrea Arcangeliba761492011-01-13 15:46:58 -080071{
72 return 0;
73}
74#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
75
76#endif /* _LINUX_KHUGEPAGED_H */