We currently skip over negative increments, but in a potentially
incorrect manner, as we still move our heap around. If both newsize and
increment are negative, then we check to see if we can free up at least
a full hugepage. We then unmap appropriately and move the top of the
heap around.

Signed-off-by: Nishanth Aravamudan <[EMAIL PROTECTED]>

diff -urpN a/morecore.c b/morecore.c
--- a/morecore.c        2006-09-06 12:00:12.000000000 -0700
+++ b/morecore.c        2006-09-06 12:02:02.000000000 -0700
@@ -101,6 +101,36 @@ static void *hugetlbfs_morecore(ptrdiff_
        DEBUG("heapbase = %p, heaptop = %p, mapsize = %lx, newsize=%ld\n",
              heapbase, heaptop, mapsize, newsize);
 
+       /* maybe need to shrink the heap, as we're giving back memory */
+       if (newsize < 0) {
+               if (increment < 0) {
+                       newsize = labs(newsize);
+                       if (newsize > blocksize) {
+                               /* number of hugepages we can free from mapsize 
*/
+                               newsize = ALIGN(newsize - blocksize, blocksize);
+                               /*
+                                * free up hugepages at the appropriate
+                                * boundary
+                                */
+                               munmap(heapbase + mapsize - newsize, newsize);
+                               mapsize -= newsize;
+                       }
+
+                       /*
+                        * need to do this in the reverse order for
+                        * shrinking the heap
+                        */
+                       heaptop = heaptop + increment;
+                       p = heaptop;
+               }
+               /*
+                * if newsize < 0 && increment > 0 then the request fits into
+                * the currently mapped space, and we'll fall through to the
+                * return
+                */
+               goto done;
+       }
+
        /* growing the heap */
        if (newsize > 0) {
                /*
@@ -151,6 +181,7 @@ static void *hugetlbfs_morecore(ptrdiff_
        /* and we now have added this much more space to the heap */
        heaptop = heaptop + increment;
 
+done:
        DEBUG("... = %p\n", p);
        return p;
 }

-- 
Nishanth Aravamudan <[EMAIL PROTECTED]>
IBM Linux Technology Center

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Libhugetlbfs-devel mailing list
Libhugetlbfs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel

Reply via email to