On 06.09.2006 [14:34:53 -0700], Nishanth Aravamudan wrote:
> On 06.09.2006 [12:07:15 -0700], Nishanth Aravamudan wrote:
> > 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]>
> 
> Hrm, further testing is revealing some issues with this.

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]>

---

Small problem found with original patch, fixed below.

diff -urpN a/morecore.c b/morecore.c
--- a/morecore.c        2006-09-06 14:48:20.000000000 -0700
+++ b/morecore.c        2006-09-06 14:44:43.000000000 -0700
@@ -101,6 +101,34 @@ 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) && (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;
+               goto done;
+       }
+       /*
+        * if newsize < 0 && increment > 0 then the request fits into
+        * the currently mapped space, and we'll fall through to the
+        * return
+        */
+
        /* growing the heap */
        if (newsize > 0) {
                /*
@@ -151,6 +179,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