Skip to contentSkip to conversation

mm/ksm: One function call less in __ksm_enter()

PATCH In review Markus Elfring 2 participants 2 messages Jul 5, 2019 – Jul 8, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/ksm: One function call less in __ksm_enter()

From: Markus Elfring <[email protected]>
Date: Fri, 5 Jul 2019 16:02:26 +0200

Avoid an extra function call by using a ternary operator instead of a conditional statement.

This issue was detected by using the Coccinelle software.

---
 mm/ksm.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
mm/ksm.c +4 -4
index 3dc4346411e4..7934bab8ceae 100644
@@ -2521,10 +2521,10 @@ int __ksm_enter(struct mm_struct *mm)
 	 * scanning cursor, otherwise KSM pages in newly forked mms will be
 	 * missed: then we might as well insert at the end of the list.
 	 */
-	if (ksm_run & KSM_RUN_UNMERGE)
-		list_add_tail(&mm_slot->mm_list, &ksm_mm_head.mm_list);
-	else
-		list_add_tail(&mm_slot->mm_list, &ksm_scan.mm_slot->mm_list);
+	list_add_tail(&mm_slot->mm_list,
+		      ksm_run & KSM_RUN_UNMERGE
+		      ? &ksm_mm_head.mm_list
+		      : &ksm_scan.mm_slot->mm_list);
 	spin_unlock(&ksm_mmlist_lock);
 
 	set_bit(MMF_VM_MERGEABLE, &mm->flags);

--
2.22.0

#1 lore raw
Quoted 19 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 5 Jul 2019 16:02:26 +0200

Avoid an extra function call by using a ternary operator instead of a conditional statement.

This issue was detected by using the Coccinelle software.

---
 mm/ksm.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
mm/ksm.c +0 -0
index 3dc4346411e4..7934bab8ceae 100644
@@ -2521,10 +2521,10 @@ int __ksm_enter(struct mm_struct *mm)
 	 * scanning cursor, otherwise KSM pages in newly forked mms will be

mm/ksm.c int __ksm_enter(struct mm_struct *mm) · line 2527

Quoted 10 lines
mm/ksm.c +4 -4
 	 * missed: then we might as well insert at the end of the list.
 	 */
-	if (ksm_run & KSM_RUN_UNMERGE)
-		list_add_tail(&mm_slot->mm_list, &ksm_mm_head.mm_list);
-	else
-		list_add_tail(&mm_slot->mm_list, &ksm_scan.mm_slot->mm_list);
+	list_add_tail(&mm_slot->mm_list,
+		      ksm_run & KSM_RUN_UNMERGE
+		      ? &ksm_mm_head.mm_list
+		      : &ksm_scan.mm_slot->mm_list);

Despite coccinelle warnings, I'm not sure this patch does not make the readability worse...

Quoted 3 lines
mm/ksm.c +0 -0
 	spin_unlock(&ksm_mmlist_lock);
 
 	set_bit(MMF_VM_MERGEABLE, &mm->flags);