blob: eeb3079857155355161047eda5d2d298d7fd2a3f [file] [log] [blame]
Andrea Arcangeliba761492011-01-13 15:46:58 -08001#ifndef _LINUX_KHUGEPAGED_H
2#define _LINUX_KHUGEPAGED_H
3
4#include <linux/sched.h> /* MMF_VM_HUGEPAGE */
5
6#ifdef CONFIG_TRANSPARENT_HUGEPAGE
7extern int __khugepaged_enter(struct mm_struct *mm);
8extern void __khugepaged_exit(struct mm_struct *mm);
David Rientjes6d50e602014-10-29 14:50:31 -07009extern int khugepaged_enter_vma_merge(struct vm_area_struct *vma,
10 unsigned long vm_flags);
Andrea Arcangeliba761492011-01-13 15:46:58 -080011
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
26static 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
33static 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 Rientjes6d50e602014-10-29 14:50:31 -070039static inline int khugepaged_enter(struct vm_area_struct *vma,
40 unsigned long vm_flags)
Andrea Arcangeliba761492011-01-13 15:46:58 -080041{
42 if (!test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags))
Andrea Arcangelia664b2d2011-01-13 15:47:17 -080043 if ((khugepaged_always() ||
David Rientjes6d50e602014-10-29 14:50:31 -070044 (khugepaged_req_madv() && (vm_flags & VM_HUGEPAGE))) &&
45 !(vm_flags & VM_NOHUGEPAGE))
Andrea Arcangeliba761492011-01-13 15:46:58 -080046 if (__khugepaged_enter(vma->vm_mm))
47 return -ENOMEM;
48 return 0;
49}
50#else /* CONFIG_TRANSPARENT_HUGEPAGE */
51static inline int khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm)
52{
53 return 0;
54}
55static inline void khugepaged_exit(struct mm_struct *mm)
56{
57}
David Rientjes6d50e602014-10-29 14:50:31 -070058static inline int khugepaged_enter(struct vm_area_struct *vma,
59 unsigned long vm_flags)
Andrea Arcangeliba761492011-01-13 15:46:58 -080060{
61 return 0;
62}
David Rientjes6d50e602014-10-29 14:50:31 -070063static inline int khugepaged_enter_vma_merge(struct vm_area_struct *vma,
64 unsigned long vm_flags)
Andrea Arcangeliba761492011-01-13 15:46:58 -080065{
66 return 0;
67}
68#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
69
70#endif /* _LINUX_KHUGEPAGED_H */