Skip to contentSkip to conversation

mm/slub: Refactor note_cmpxchg_failure for better readability

PATCH In review Ye Liu 3 participants 3 messages Sep 9, 2025 – Sep 10, 2025

Subsystems (2)
lore
Share & tools
lore

Ye Liu

author
#0 lore raw

PATCH v3 1/1 mm/slub: Refactor note_cmpxchg_failure for better readability

From: Ye Liu <[email protected]>

Use IS_ENABLED() and standard if-else to make the code clearer.

---
Changes in v3:
- Add "---" in front of the change log. Changes in v2:
- Insert newline after && as it's more than 80 columns.

---
 mm/slub.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
mm/slub.c +5 -6
index 30003763d224..5711d6d29a3f 100644
@@ -3064,18 +3064,17 @@ static inline void note_cmpxchg_failure(const char *n,
 
 	pr_info("%s %s: cmpxchg redo ", n, s->name);
 
-#ifdef CONFIG_PREEMPTION
-	if (tid_to_cpu(tid) != tid_to_cpu(actual_tid))
+	if (IS_ENABLED(CONFIG_PREEMPTION) &&
+	    tid_to_cpu(tid) != tid_to_cpu(actual_tid)) {
 		pr_warn("due to cpu change %d -> %d\n",
 			tid_to_cpu(tid), tid_to_cpu(actual_tid));
-	else
-#endif
-	if (tid_to_event(tid) != tid_to_event(actual_tid))
+	} else if (tid_to_event(tid) != tid_to_event(actual_tid)) {
 		pr_warn("due to cpu running other code. Event %ld->%ld\n",
 			tid_to_event(tid), tid_to_event(actual_tid));
-	else
+	} else {
 		pr_warn("for unknown reason: actual=%lx was=%lx target=%lx\n",
 			actual_tid, tid, next_tid(tid));
+	}
 #endif
 	stat(s, CMPXCHG_DOUBLE_CPU_FAIL);
 }
Signature · 1 line
2.43.0
Reviewed-by on v3 1/1
#1 lore raw
Quoted 35 lines · Ye Liu

From: Ye Liu <[email protected]>

Use IS_ENABLED() and standard if-else to make the code clearer.

---
Changes in v3:
- Add "---" in front of the change log. Changes in v2:
- Insert newline after && as it's more than 80 columns.

---
 mm/slub.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
mm/slub.c +3 -5
index 30003763d224..5711d6d29a3f 100644
@@ -3064,18 +3064,17 @@ static inline void note_cmpxchg_failure(const char *n,
 
 	pr_info("%s %s: cmpxchg redo ", n, s->name);
 
-#ifdef CONFIG_PREEMPTION
-	if (tid_to_cpu(tid) != tid_to_cpu(actual_tid))
+	if (IS_ENABLED(CONFIG_PREEMPTION) &&
+	    tid_to_cpu(tid) != tid_to_cpu(actual_tid)) {
 		pr_warn("due to cpu change %d -> %d\n",
 			tid_to_cpu(tid), tid_to_cpu(actual_tid));
-	else
-#endif
-	if (tid_to_event(tid) != tid_to_event(actual_tid))
+	} else if (tid_to_event(tid) != tid_to_event(actual_tid)) {

mm/slub.c static inline void note_cmpxchg_failure(const char *n, · line 3080

Quoted 10 lines
mm/slub.c +2 -1
 		pr_warn("due to cpu running other code. Event %ld->%ld\n",
 			tid_to_event(tid), tid_to_event(actual_tid));
-	else
+	} else {
 		pr_warn("for unknown reason: actual=%lx was=%lx target=%lx\n",
 			actual_tid, tid, next_tid(tid));
+	}
 #endif
 	stat(s, CMPXCHG_DOUBLE_CPU_FAIL);
 }
#2 lore raw
In reply to Ye Liu
Quoted 7 lines · Ye Liu

From: Ye Liu <[email protected]>

Use IS_ENABLED() and standard if-else to make the code clearer.

Thanks, added to slab/for-next

Quoted 38 lines

---
Changes in v3:
- Add "---" in front of the change log. Changes in v2:
- Insert newline after && as it's more than 80 columns.

---
 mm/slub.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
mm/slub.c +5 -6
index 30003763d224..5711d6d29a3f 100644
@@ -3064,18 +3064,17 @@ static inline void note_cmpxchg_failure(const char *n,
 
 	pr_info("%s %s: cmpxchg redo ", n, s->name);
 
-#ifdef CONFIG_PREEMPTION
-	if (tid_to_cpu(tid) != tid_to_cpu(actual_tid))
+	if (IS_ENABLED(CONFIG_PREEMPTION) &&
+	    tid_to_cpu(tid) != tid_to_cpu(actual_tid)) {
 		pr_warn("due to cpu change %d -> %d\n",
 			tid_to_cpu(tid), tid_to_cpu(actual_tid));
-	else
-#endif
-	if (tid_to_event(tid) != tid_to_event(actual_tid))
+	} else if (tid_to_event(tid) != tid_to_event(actual_tid)) {
 		pr_warn("due to cpu running other code. Event %ld->%ld\n",
 			tid_to_event(tid), tid_to_event(actual_tid));
-	else
+	} else {
 		pr_warn("for unknown reason: actual=%lx was=%lx target=%lx\n",
 			actual_tid, tid, next_tid(tid));
+	}
 #endif
 	stat(s, CMPXCHG_DOUBLE_CPU_FAIL);
 }