aboutsummaryrefslogtreecommitdiff
path: root/morecore.c
diff options
context:
space:
mode:
authoraglitke <aglitke@aglitke.localdomain>2006-09-07 09:26:48 -0500
committeraglitke <aglitke@aglitke.localdomain>2006-09-07 09:26:48 -0500
commitd109349663491a6be7e6741837e8d520e59d2bb4 (patch)
tree3139ca17bb2f47607dc892655062ba8ba6e8f794 /morecore.c
parentd48239bbcc878a024bda22a5b0c80eeee5340c85 (diff)
downloadlibhugetlbfs-d109349663491a6be7e6741837e8d520e59d2bb4.tar.gz
morecore: add commentsdev-20060911-1
I found the dearth of comments in morecore.c to be quite troublesome while debugging a related kernel bug. I hope these are accurate. Signed-off-by: Nishanth Aravamudan <nacc@us.ibm.com>
Diffstat (limited to 'morecore.c')
-rw-r--r--morecore.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/morecore.c b/morecore.c
index 9f13316..0574a7c 100644
--- a/morecore.c
+++ b/morecore.c
@@ -56,16 +56,26 @@ static void *hugetlbfs_morecore(ptrdiff_t increment)
DEBUG("hugetlbfs_morecore(%ld) = ...\n", (long)increment);
+ /*
+ * how much to grow the heap by =
+ * (size of heap) + malloc request - mmap'd space
+ */
newsize = (heaptop-heapbase) + increment - mapsize;
DEBUG("heapbase = %p, heaptop = %p, mapsize = %lx, newsize=%ld\n",
heapbase, heaptop, mapsize, newsize);
+ /* growing the heap */
if (newsize > 0) {
+ /*
+ * convert our request to a multiple of hugepages
+ * we will have more space allocated then used, basically
+ */
newsize = ALIGN(newsize, blocksize);
DEBUG("Attempting to map %ld bytes\n", newsize);
+ /* map in (extend) more of the file at the end of our last map */
p = mmap(heapbase + mapsize, newsize, PROT_READ|PROT_WRITE,
MAP_PRIVATE, heap_fd, mapsize);
if (p == MAP_FAILED) {
@@ -73,10 +83,12 @@ static void *hugetlbfs_morecore(ptrdiff_t increment)
return NULL;
}
+ /* if this is the first map */
if (! mapsize) {
if (heapbase && (heapbase != p))
WARNING("Heap originates at %p instead of %p\n",
p, heapbase);
+ /* then setup the heap variables */
heapbase = heaptop = p;
} else if (p != (heapbase + mapsize)) {
/* Couldn't get the mapping where we wanted */
@@ -101,10 +113,13 @@ static void *hugetlbfs_morecore(ptrdiff_t increment)
munlock(p, newsize);
#endif
+ /* we now have mmap'd further */
mapsize += newsize;
}
+ /* heap is continuous */
p = heaptop;
+ /* and we now have added this much more space to the heap */
heaptop = heaptop + increment;
DEBUG("... = %p\n", p);