Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 1 | #ifndef _LINUX_KHUGEPAGED_H |
| 2 | #define _LINUX_KHUGEPAGED_H |
| 3 | |
| 4 | #include <linux/sched.h> /* MMF_VM_HUGEPAGE */ |
| 5 | |
| 6 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
Kirill A. Shutemov | b46e756 | 2016-07-26 15:26:24 -0700 | [diff] [blame^] | 7 | extern struct attribute_group khugepaged_attr_group; |
| 8 | |
| 9 | extern int khugepaged_init(void); |
| 10 | extern void khugepaged_destroy(void); |
| 11 | extern int start_stop_khugepaged(void); |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 12 | extern int __khugepaged_enter(struct mm_struct *mm); |
| 13 | extern void __khugepaged_exit(struct mm_struct *mm); |
David Rientjes | 6d50e60 | 2014-10-29 14:50:31 -0700 | [diff] [blame] | 14 | extern int khugepaged_enter_vma_merge(struct vm_area_struct *vma, |
| 15 | unsigned long vm_flags); |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 16 | |
| 17 | #define khugepaged_enabled() \ |
| 18 | (transparent_hugepage_flags & \ |
| 19 | ((1<<TRANSPARENT_HUGEPAGE_FLAG) | \ |
| 20 | (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG))) |
| 21 | #define khugepaged_always() \ |
| 22 | (transparent_hugepage_flags & \ |
| 23 | (1<<TRANSPARENT_HUGEPAGE_FLAG)) |
| 24 | #define khugepaged_req_madv() \ |
| 25 | (transparent_hugepage_flags & \ |
| 26 | (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG)) |
| 27 | #define khugepaged_defrag() \ |
| 28 | (transparent_hugepage_flags & \ |
| 29 | (1<<TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG)) |
| 30 | |
| 31 | static inline int khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm) |
| 32 | { |
| 33 | if (test_bit(MMF_VM_HUGEPAGE, &oldmm->flags)) |
| 34 | return __khugepaged_enter(mm); |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | static inline void khugepaged_exit(struct mm_struct *mm) |
| 39 | { |
| 40 | if (test_bit(MMF_VM_HUGEPAGE, &mm->flags)) |
| 41 | __khugepaged_exit(mm); |
| 42 | } |
| 43 | |
David Rientjes | 6d50e60 | 2014-10-29 14:50:31 -0700 | [diff] [blame] | 44 | static inline int khugepaged_enter(struct vm_area_struct *vma, |
| 45 | unsigned long vm_flags) |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 46 | { |
| 47 | if (!test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags)) |
Andrea Arcangeli | a664b2d | 2011-01-13 15:47:17 -0800 | [diff] [blame] | 48 | if ((khugepaged_always() || |
David Rientjes | 6d50e60 | 2014-10-29 14:50:31 -0700 | [diff] [blame] | 49 | (khugepaged_req_madv() && (vm_flags & VM_HUGEPAGE))) && |
| 50 | !(vm_flags & VM_NOHUGEPAGE)) |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 51 | if (__khugepaged_enter(vma->vm_mm)) |
| 52 | return -ENOMEM; |
| 53 | return 0; |
| 54 | } |
| 55 | #else /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 56 | static inline int khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm) |
| 57 | { |
| 58 | return 0; |
| 59 | } |
| 60 | static inline void khugepaged_exit(struct mm_struct *mm) |
| 61 | { |
| 62 | } |
David Rientjes | 6d50e60 | 2014-10-29 14:50:31 -0700 | [diff] [blame] | 63 | static inline int khugepaged_enter(struct vm_area_struct *vma, |
| 64 | unsigned long vm_flags) |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 65 | { |
| 66 | return 0; |
| 67 | } |
David Rientjes | 6d50e60 | 2014-10-29 14:50:31 -0700 | [diff] [blame] | 68 | static inline int khugepaged_enter_vma_merge(struct vm_area_struct *vma, |
| 69 | unsigned long vm_flags) |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 70 | { |
| 71 | return 0; |
| 72 | } |
| 73 | #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 74 | |
| 75 | #endif /* _LINUX_KHUGEPAGED_H */ |