Skip to contentSkip to conversation

mm/slab.c: micro-optimization spare one branch in main flow

PATCH New [email protected] 1 participant 1 message Sep 16, 2020 Memory management

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/slab.c: micro-optimization spare one branch in main flow

From: Mateusz Nosek <[email protected]>

By small refactoring two 'unlikely' branches are changed so that if not one of them is true then only one branch occurs in 'likely' path of the function in question. Change verified in assembly generated by gcc 8.3.0.

---
 mm/slab.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
mm/slab.c +3 -2
index 2cb494d98fe9..e04ea756bcbc 100644
@@ -4186,9 +4186,10 @@ size_t __ksize(const void *objp)
 	struct kmem_cache *c;
 	size_t size;
 
-	BUG_ON(!objp);
-	if (unlikely(objp == ZERO_SIZE_PTR))
+	if (unlikely(ZERO_OR_NULL_PTR(objp))) {
+		BUG_ON(!objp);
 		return 0;
+	}
 
 	c = virt_to_cache(objp);
 	size = c ? c->object_size : 0;
Signature · 1 line
2.20.1