Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 2 | #ifndef _LINUX_KHUGEPAGED_H |
| 3 | #define _LINUX_KHUGEPAGED_H |
| 4 | |
Ingo Molnar | f7ccbae | 2017-02-08 18:51:30 +0100 | [diff] [blame] | 5 | #include <linux/sched/coredump.h> /* MMF_VM_HUGEPAGE */ |
| 6 | |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 7 | |
| 8 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
Kirill A. Shutemov | b46e756 | 2016-07-26 15:26:24 -0700 | [diff] [blame] | 9 | extern struct attribute_group khugepaged_attr_group; |
| 10 | |
| 11 | extern int khugepaged_init(void); |
| 12 | extern void khugepaged_destroy(void); |
| 13 | extern int start_stop_khugepaged(void); |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 14 | extern int __khugepaged_enter(struct mm_struct *mm); |
| 15 | extern void __khugepaged_exit(struct mm_struct *mm); |
David Rientjes | 6d50e60 | 2014-10-29 14:50:31 -0700 | [diff] [blame] | 16 | extern int khugepaged_enter_vma_merge(struct vm_area_struct *vma, |
| 17 | unsigned long vm_flags); |
Song Liu | 27e1f82 | 2019-09-23 15:38:30 -0700 | [diff] [blame] | 18 | #ifdef CONFIG_SHMEM |
| 19 | extern void collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr); |
| 20 | #else |
| 21 | static inline void collapse_pte_mapped_thp(struct mm_struct *mm, |
| 22 | unsigned long addr) |
| 23 | { |
| 24 | } |
| 25 | #endif |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 26 | |
| 27 | #define khugepaged_enabled() \ |
| 28 | (transparent_hugepage_flags & \ |
| 29 | ((1<<TRANSPARENT_HUGEPAGE_FLAG) | \ |
| 30 | (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG))) |
| 31 | #define khugepaged_always() \ |
| 32 | (transparent_hugepage_flags & \ |
| 33 | (1<<TRANSPARENT_HUGEPAGE_FLAG)) |
| 34 | #define khugepaged_req_madv() \ |
| 35 | (transparent_hugepage_flags & \ |
| 36 | (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG)) |
| 37 | #define khugepaged_defrag() \ |
| 38 | (transparent_hugepage_flags & \ |
| 39 | (1<<TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG)) |
| 40 | |
| 41 | static inline int khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm) |
| 42 | { |
| 43 | if (test_bit(MMF_VM_HUGEPAGE, &oldmm->flags)) |
| 44 | return __khugepaged_enter(mm); |
| 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | static inline void khugepaged_exit(struct mm_struct *mm) |
| 49 | { |
| 50 | if (test_bit(MMF_VM_HUGEPAGE, &mm->flags)) |
| 51 | __khugepaged_exit(mm); |
| 52 | } |
| 53 | |
David Rientjes | 6d50e60 | 2014-10-29 14:50:31 -0700 | [diff] [blame] | 54 | static inline int khugepaged_enter(struct vm_area_struct *vma, |
| 55 | unsigned long vm_flags) |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 56 | { |
| 57 | if (!test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags)) |
Andrea Arcangeli | a664b2d | 2011-01-13 15:47:17 -0800 | [diff] [blame] | 58 | if ((khugepaged_always() || |
David Rientjes | 6d50e60 | 2014-10-29 14:50:31 -0700 | [diff] [blame] | 59 | (khugepaged_req_madv() && (vm_flags & VM_HUGEPAGE))) && |
Michal Hocko | 1860033 | 2017-07-10 15:48:02 -0700 | [diff] [blame] | 60 | !(vm_flags & VM_NOHUGEPAGE) && |
| 61 | !test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)) |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 62 | if (__khugepaged_enter(vma->vm_mm)) |
| 63 | return -ENOMEM; |
| 64 | return 0; |
| 65 | } |
| 66 | #else /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 67 | static inline int khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm) |
| 68 | { |
| 69 | return 0; |
| 70 | } |
| 71 | static inline void khugepaged_exit(struct mm_struct *mm) |
| 72 | { |
| 73 | } |
David Rientjes | 6d50e60 | 2014-10-29 14:50:31 -0700 | [diff] [blame] | 74 | static inline int khugepaged_enter(struct vm_area_struct *vma, |
| 75 | unsigned long vm_flags) |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 76 | { |
| 77 | return 0; |
| 78 | } |
David Rientjes | 6d50e60 | 2014-10-29 14:50:31 -0700 | [diff] [blame] | 79 | static inline int khugepaged_enter_vma_merge(struct vm_area_struct *vma, |
| 80 | unsigned long vm_flags) |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 81 | { |
| 82 | return 0; |
| 83 | } |
Song Liu | 27e1f82 | 2019-09-23 15:38:30 -0700 | [diff] [blame] | 84 | static inline void collapse_pte_mapped_thp(struct mm_struct *mm, |
| 85 | unsigned long addr) |
| 86 | { |
| 87 | } |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 88 | #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 89 | |
| 90 | #endif /* _LINUX_KHUGEPAGED_H */ |