[PATCH] include/linux/khugepaged.h: Improve the code only

From: chengang
Date: Sun May 15 2016 - 18:26:31 EST


From: Chen Gang <chengang@xxxxxxxxxxxxxxxx>

khugepaged_enabled() can be treated as khugepaged_always() or
khugepaged_req_madv(). The compiler will always treat it as "and 3".

khugepaged_enter() can return __khugepaged_enter() result directly,
since __khugepaged_enter() will return 0 or -ENOMEM.

Signed-off-by: Chen Gang <gang.chen.5i5j@xxxxxxxxx>
---
include/linux/khugepaged.h | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/include/linux/khugepaged.h b/include/linux/khugepaged.h
index eeb3079..0df1c1d 100644
--- a/include/linux/khugepaged.h
+++ b/include/linux/khugepaged.h
@@ -9,19 +9,16 @@ extern void __khugepaged_exit(struct mm_struct *mm);
extern int khugepaged_enter_vma_merge(struct vm_area_struct *vma,
unsigned long vm_flags);

-#define khugepaged_enabled() \
- (transparent_hugepage_flags & \
- ((1<<TRANSPARENT_HUGEPAGE_FLAG) | \
- (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG)))
#define khugepaged_always() \
(transparent_hugepage_flags & \
- (1<<TRANSPARENT_HUGEPAGE_FLAG))
-#define khugepaged_req_madv() \
- (transparent_hugepage_flags & \
- (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG))
-#define khugepaged_defrag() \
- (transparent_hugepage_flags & \
- (1<<TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG))
+ (1 << TRANSPARENT_HUGEPAGE_FLAG))
+#define khugepaged_req_madv() \
+ (transparent_hugepage_flags & \
+ (1 << TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG))
+#define khugepaged_enabled() (khugepaged_always() | khugepaged_req_madv())
+#define khugepaged_defrag() \
+ (transparent_hugepage_flags & \
+ (1 << TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG))

static inline int khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm)
{
@@ -43,8 +40,7 @@ static inline int khugepaged_enter(struct vm_area_struct *vma,
if ((khugepaged_always() ||
(khugepaged_req_madv() && (vm_flags & VM_HUGEPAGE))) &&
!(vm_flags & VM_NOHUGEPAGE))
- if (__khugepaged_enter(vma->vm_mm))
- return -ENOMEM;
+ return __khugepaged_enter(vma->vm_mm);
return 0;
}
#else /* CONFIG_TRANSPARENT_HUGEPAGE */
--
1.9.3