Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 1 | #ifndef _LINUX_KHUGEPAGED_H |
| 2 | #define _LINUX_KHUGEPAGED_H |
| 3 | |
Ingo Molnar | f7ccbae | 2017-02-08 18:51:30 +0100 | [diff] [blame] | 4 | #include <linux/sched/coredump.h> /* MMF_VM_HUGEPAGE */ |
| 5 | |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 6 | |
| 7 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
Kirill A. Shutemov | b46e756 | 2016-07-26 15:26:24 -0700 | [diff] [blame] | 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); |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 13 | extern int __khugepaged_enter(struct mm_struct *mm); |
| 14 | extern void __khugepaged_exit(struct mm_struct *mm); |
David Rientjes | 6d50e60 | 2014-10-29 14:50:31 -0700 | [diff] [blame] | 15 | extern int khugepaged_enter_vma_merge(struct vm_area_struct *vma, |
| 16 | unsigned long vm_flags); |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 17 | |
| 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 | |
| 32 | static 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 | |
| 39 | static 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 Rientjes | 6d50e60 | 2014-10-29 14:50:31 -0700 | [diff] [blame] | 45 | static inline int khugepaged_enter(struct vm_area_struct *vma, |
| 46 | unsigned long vm_flags) |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 47 | { |
| 48 | if (!test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags)) |
Andrea Arcangeli | a664b2d | 2011-01-13 15:47:17 -0800 | [diff] [blame] | 49 | if ((khugepaged_always() || |
David Rientjes | 6d50e60 | 2014-10-29 14:50:31 -0700 | [diff] [blame] | 50 | (khugepaged_req_madv() && (vm_flags & VM_HUGEPAGE))) && |
| 51 | !(vm_flags & VM_NOHUGEPAGE)) |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 52 | if (__khugepaged_enter(vma->vm_mm)) |
| 53 | return -ENOMEM; |
| 54 | return 0; |
| 55 | } |
| 56 | #else /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 57 | static inline int khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm) |
| 58 | { |
| 59 | return 0; |
| 60 | } |
| 61 | static inline void khugepaged_exit(struct mm_struct *mm) |
| 62 | { |
| 63 | } |
David Rientjes | 6d50e60 | 2014-10-29 14:50:31 -0700 | [diff] [blame] | 64 | static inline int khugepaged_enter(struct vm_area_struct *vma, |
| 65 | unsigned long vm_flags) |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 66 | { |
| 67 | return 0; |
| 68 | } |
David Rientjes | 6d50e60 | 2014-10-29 14:50:31 -0700 | [diff] [blame] | 69 | static inline int khugepaged_enter_vma_merge(struct vm_area_struct *vma, |
| 70 | unsigned long vm_flags) |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 71 | { |
| 72 | return 0; |
| 73 | } |
| 74 | #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 75 | |
| 76 | #endif /* _LINUX_KHUGEPAGED_H */ |