This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Replace divide and multiply with mask in sYSTRIm


 
Hi Andreas,

> > -  extra = ((top_size - pad - MINSIZE + (pagesz-1)) / pagesz - 1) * pagesz;
> > +  extra = (top_size - pad - MINSIZE + (pagesz-1)) & ~(pagesz-1);
> 
> That's not the same.  Your version is off by pagesz.

How does this look? It will round down a page when on a page boundary, like
the old version.

Anton

--

2010-07-26  Anton Blanchard  <anton@samba.org>

	* malloc/malloc.c (sYSTRIm): Replace divide and multiply with mask.
	* malloc/arena.c (heap_trim): 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 - 1) & ~(pagesz-1);
 
   if (extra > 0) {

Index: glibc/malloc/arena.c
===================================================================
--- glibc.orig/malloc/arena.c	2010-07-26 17:05:22.311992028 +1000
+++ glibc/malloc/arena.c	2010-07-26 17:06:50.400741083 +1000
@@ -879,7 +879,7 @@ heap_trim(heap, pad) heap_info *heap; si
     /*check_chunk(ar_ptr, top_chunk);*/
   }
   top_size = chunksize(top_chunk);
-  extra = ((top_size - pad - MINSIZE + (pagesz-1))/pagesz - 1) * pagesz;
+  extra = (top_size - pad - MINSIZE - 1) & ~(pagesz-1);
   if(extra < (long)pagesz)
     return 0;
   /* Try to shrink. */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]