This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] Replace divide and multiply with mask in sYSTRIm
- From: Anton Blanchard <anton at samba dot org>
- To: libc-alpha at sourceware dot org
- Date: Mon, 26 Jul 2010 14:36:51 +1000
- Subject: [PATCH] Replace divide and multiply with mask in sYSTRIm
When profiling a simple malloc/free testcase, sYSTRIm was found to
have a divide in it. Looking closer we are using a divide and multiply
to round something to mp_.pagesize bytes. Since this is always a
power of two and we have assertions in a number of places to enforce
this, replace with a mask.
A simple testcase of malloc/free of 513 bytes on a POWER7 box
shows a decent improvement:
baseline: 6869000 ops/sec
patched: 8174000 ops/sec
Almost 19% faster
Anton
--
2010-07-26 Anton Blanchard <anton@samba.org>
* malloc/malloc.c (sYSTRIm): Replace divide and multiply with mask.
Index: glibc/malloc/malloc.c
===================================================================
--- glibc.orig/malloc/malloc.c 2010-07-26 13:42:35.470741337 +1000
+++ glibc/malloc/malloc.c 2010-07-26 13:58:29.870741493 +1000
@@ -3466,7 +3466,7 @@ static int sYSTRIm(pad, av) size_t pad;
top_size = chunksize(av->top);
/* Release in pagesize units, keeping at least one page */
- extra = ((top_size - pad - MINSIZE + (pagesz-1)) / pagesz - 1) * pagesz;
+ extra = (top_size - pad - MINSIZE + (pagesz-1)) & ~(pagesz-1);
if (extra > 0) {