Merge tag 'for-linus' of git://linux-c6x.org/git/projects/linux-c6x-upstreaming
[platform/adaptation/renesas_rcar/renesas_kernel.git] / include / linux / khugepaged.h
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);
9 extern int khugepaged_enter_vma_merge(struct vm_area_struct *vma);
10
11 #define khugepaged_enabled()                                           \
12         (transparent_hugepage_flags &                                  \
13          ((1<<TRANSPARENT_HUGEPAGE_FLAG) |                     \
14           (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG)))
15 #define khugepaged_always()                             \
16         (transparent_hugepage_flags &                   \
17          (1<<TRANSPARENT_HUGEPAGE_FLAG))
18 #define khugepaged_req_madv()                                   \
19         (transparent_hugepage_flags &                           \
20          (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG))
21 #define khugepaged_defrag()                                     \
22         (transparent_hugepage_flags &                           \
23          (1<<TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG))
24
25 static inline int khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm)
26 {
27         if (test_bit(MMF_VM_HUGEPAGE, &oldmm->flags))
28                 return __khugepaged_enter(mm);
29         return 0;
30 }
31
32 static inline void khugepaged_exit(struct mm_struct *mm)
33 {
34         if (test_bit(MMF_VM_HUGEPAGE, &mm->flags))
35                 __khugepaged_exit(mm);
36 }
37
38 static inline int khugepaged_enter(struct vm_area_struct *vma)
39 {
40         if (!test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags))
41                 if ((khugepaged_always() ||
42                      (khugepaged_req_madv() &&
43                       vma->vm_flags & VM_HUGEPAGE)) &&
44                     !(vma->vm_flags & VM_NOHUGEPAGE))
45                         if (__khugepaged_enter(vma->vm_mm))
46                                 return -ENOMEM;
47         return 0;
48 }
49 #else /* CONFIG_TRANSPARENT_HUGEPAGE */
50 static inline int khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm)
51 {
52         return 0;
53 }
54 static inline void khugepaged_exit(struct mm_struct *mm)
55 {
56 }
57 static inline int khugepaged_enter(struct vm_area_struct *vma)
58 {
59         return 0;
60 }
61 static inline int khugepaged_enter_vma_merge(struct vm_area_struct *vma)
62 {
63         return 0;
64 }
65 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
66
67 #endif /* _LINUX_KHUGEPAGED_H */