[PATCH] malloc: Improve csize2tidx

Wilco Dijkstra Wilco.Dijkstra@arm.com
Tue Mar 18 12:59:59 GMT 2025


Remove the alignment rounding up from csize2tidx - this makes no sense
since the input should be a chunk size.  Removing it enables further
optimizations, for example chunksize_nomask can be safely used and
invalid sizes < MINSIZE are not mapped to a valid tidx.

Passes regress, OK for commit?

---

diff --git a/malloc/malloc.c b/malloc/malloc.c
index 931ca481127c6f5199787058d86a0621328de04b..55fb2ab0ecd5491591e0d04ae38a9bd1088af623 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -298,7 +298,7 @@
 # define tidx2usize(idx)	(((size_t) idx) * MALLOC_ALIGNMENT + MINSIZE - SIZE_SZ)
 
 /* When "x" is from chunksize().  */
-# define csize2tidx(x) (((x) - MINSIZE + MALLOC_ALIGNMENT - 1) / MALLOC_ALIGNMENT)
+# define csize2tidx(x) (((x) - MINSIZE) / MALLOC_ALIGNMENT)
 /* When "x" is a user-provided size.  */
 # define usize2tidx(x) csize2tidx (request2size (x))
 


More information about the Libc-alpha mailing list