blob: 1e032a1ddb3eaa75c0a0a894c93ee240406226b0 [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
Kirill A. Shutemovb46e7562016-07-26 15:26:24 -07007extern struct attribute_group khugepaged_attr_group;
8
9extern int khugepaged_init(void);
10extern void khugepaged_destroy(void);
11extern int start_stop_khugepaged(void);
Andrea Arcangeliba761492011-01-13 15:46:58 -080012extern int __khugepaged_enter(struct mm_struct *mm);
13extern void __khugepaged_exit(struct mm_struct *mm);
David Rientjes6d50e602014-10-29 14:50:31 -070014extern int khugepaged_enter_vma_merge(struct vm_area_struct *vma,
15 unsigned long vm_flags);
Andrea Arcangeliba761492011-01-13 15:46:58 -080016
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
31static 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
38static 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 Rientjes6d50e602014-10-29 14:50:31 -070044static inline int khugepaged_enter(struct vm_area_struct *vma,
45 unsigned long vm_flags)
Andrea Arcangeliba761492011-01-13 15:46:58 -080046{
47 if (!test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags))
Andrea Arcangelia664b2d2011-01-13 15:47:17 -080048 if ((khugepaged_always() ||
David Rientjes6d50e602014-10-29 14:50:31 -070049 (khugepaged_req_madv() && (vm_flags & VM_HUGEPAGE))) &&
50 !(vm_flags & VM_NOHUGEPAGE))
Andrea Arcangeliba761492011-01-13 15:46:58 -080051 if (__khugepaged_enter(vma->vm_mm))
52 return -ENOMEM;
53 return 0;
54}
55#else /* CONFIG_TRANSPARENT_HUGEPAGE */
56static inline int khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm)
57{
58 return 0;
59}
60static inline void khugepaged_exit(struct mm_struct *mm)
61{
62}
David Rientjes6d50e602014-10-29 14:50:31 -070063static inline int khugepaged_enter(struct vm_area_struct *vma,
64 unsigned long vm_flags)
Andrea Arcangeliba761492011-01-13 15:46:58 -080065{
66 return 0;
67}
David Rientjes6d50e602014-10-29 14:50:31 -070068static inline int khugepaged_enter_vma_merge(struct vm_area_struct *vma,
69 unsigned long vm_flags)
Andrea Arcangeliba761492011-01-13 15:46:58 -080070{
71 return 0;
72}
73#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
74
75#endif /* _LINUX_KHUGEPAGED_H */