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 |
| 7 | extern int __khugepaged_enter(struct mm_struct *mm); |
| 8 | extern void __khugepaged_exit(struct mm_struct *mm); |
David Rientjes | 6d50e60 | 2014-10-29 14:50:31 -0700 | [diff] [blame] | 9 | extern int khugepaged_enter_vma_merge(struct vm_area_struct *vma, |
| 10 | unsigned long vm_flags); |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 11 | |
| 12 | #define khugepaged_enabled() \ |
| 13 | (transparent_hugepage_flags & \ |
| 14 | ((1<<TRANSPARENT_HUGEPAGE_FLAG) | \ |
| 15 | (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG))) |
| 16 | #define khugepaged_always() \ |
| 17 | (transparent_hugepage_flags & \ |
| 18 | (1<<TRANSPARENT_HUGEPAGE_FLAG)) |
| 19 | #define khugepaged_req_madv() \ |
| 20 | (transparent_hugepage_flags & \ |
| 21 | (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG)) |
| 22 | #define khugepaged_defrag() \ |
| 23 | (transparent_hugepage_flags & \ |
| 24 | (1<<TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG)) |
| 25 | |
| 26 | static inline int khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm) |
| 27 | { |
| 28 | if (test_bit(MMF_VM_HUGEPAGE, &oldmm->flags)) |
| 29 | return __khugepaged_enter(mm); |
| 30 | return 0; |
| 31 | } |
| 32 | |
| 33 | static inline void khugepaged_exit(struct mm_struct *mm) |
| 34 | { |
| 35 | if (test_bit(MMF_VM_HUGEPAGE, &mm->flags)) |
| 36 | __khugepaged_exit(mm); |
| 37 | } |
| 38 | |
David Rientjes | 6d50e60 | 2014-10-29 14:50:31 -0700 | [diff] [blame] | 39 | static inline int khugepaged_enter(struct vm_area_struct *vma, |
| 40 | unsigned long vm_flags) |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 41 | { |
| 42 | if (!test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags)) |
Andrea Arcangeli | a664b2d | 2011-01-13 15:47:17 -0800 | [diff] [blame] | 43 | if ((khugepaged_always() || |
David Rientjes | 6d50e60 | 2014-10-29 14:50:31 -0700 | [diff] [blame] | 44 | (khugepaged_req_madv() && (vm_flags & VM_HUGEPAGE))) && |
| 45 | !(vm_flags & VM_NOHUGEPAGE)) |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 46 | if (__khugepaged_enter(vma->vm_mm)) |
| 47 | return -ENOMEM; |
| 48 | return 0; |
| 49 | } |
| 50 | #else /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 51 | static inline int khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm) |
| 52 | { |
| 53 | return 0; |
| 54 | } |
| 55 | static inline void khugepaged_exit(struct mm_struct *mm) |
| 56 | { |
| 57 | } |
David Rientjes | 6d50e60 | 2014-10-29 14:50:31 -0700 | [diff] [blame] | 58 | static inline int khugepaged_enter(struct vm_area_struct *vma, |
| 59 | unsigned long vm_flags) |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 60 | { |
| 61 | return 0; |
| 62 | } |
David Rientjes | 6d50e60 | 2014-10-29 14:50:31 -0700 | [diff] [blame] | 63 | static inline int khugepaged_enter_vma_merge(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 | } |
| 68 | #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 69 | |
| 70 | #endif /* _LINUX_KHUGEPAGED_H */ |