aboutsummaryrefslogtreecommitdiff
path: root/morecore.c
diff options
context:
space:
mode:
authorDavid Gibson <dgibson@sneetch.ozlabs.ibm.com>2005-11-22 14:47:35 +1100
committerDavid Gibson <dgibson@sneetch.ozlabs.ibm.com>2005-11-22 14:47:35 +1100
commit95894b7cd7a36ecb3675650093351bc90918ed86 (patch)
tree4992693fade3b859dbd4f32df5816e23a3c15596 /morecore.c
parent6f6e975457e67f8df50bbce763b9081576b12e47 (diff)
downloadlibhugetlbfs-95894b7cd7a36ecb3675650093351bc90918ed86.tar.gz
Vaguely working morecore.
Diffstat (limited to 'morecore.c')
-rw-r--r--morecore.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/morecore.c b/morecore.c
index 6141763..023a0ea 100644
--- a/morecore.c
+++ b/morecore.c
@@ -1,9 +1,12 @@
+#define _GNU_SOURCE
+
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <unistd.h>
#include <sys/mman.h>
#include <errno.h>
+#include <dlfcn.h>
#include "hugetlbfs.h"
@@ -16,6 +19,7 @@ static void *heapbase;
static void *heaptop;
static long mapsize;
+
/*
* Our plan is to ask for pages 'roughly' at the BASE. We expect nee require
* the kernel to offer us sequential pages from wherever it first gave us a
@@ -27,8 +31,6 @@ static long mapsize;
* to get them. Hurrah.
*/
-static void *(*orig_morecore)(ptrdiff_t);
-
static void *hugetlbfs_morecore(ptrdiff_t increment)
{
void *p;
@@ -47,7 +49,7 @@ static void *hugetlbfs_morecore(ptrdiff_t increment)
DEBUG("Attempting to map %ld bytes\n", newsize);
p = mmap(heapbase + mapsize, newsize, PROT_READ|PROT_WRITE,
- MAP_PRIVATE, heap_fd, mapsize);
+ MAP_PRIVATE | MAP_FIXED, heap_fd, mapsize);
if (p == MAP_FAILED) {
ERROR("Mapping failed in hugetlbfs_morecore()\n");
return NULL;
@@ -73,12 +75,12 @@ static void *hugetlbfs_morecore(ptrdiff_t increment)
return p;
}
-static void __attribute__ ((constructor)) setup_morecore(void)
+static void __attribute__((constructor)) setup_morecore(void)
{
char *env, *ep;
- unsigned long heapaddr;
+ unsigned long heapaddr = 0;
- orig_morecore = __morecore;
+ DEBUG("setup_morecore()\n");
env = getenv("HUGETLB_MORECORE");
if (! env)
@@ -90,8 +92,17 @@ static void __attribute__ ((constructor)) setup_morecore(void)
return;
}
- heapaddr = strtol(env, &ep, 16);
- if (*ep != '\0') {
+ env = getenv("HUGETLB_MORECORE_HEAPBASE");
+ if (env) {
+ heapaddr = strtol(env, &ep, 16);
+ if (*ep != '\0') {
+ ERROR("Can't parse HUGETLB_MORECORE_HEAPBASE: %s\n",
+ env);
+ return;
+ }
+ }
+
+ if (! heapaddr) {
heapaddr = (unsigned long)sbrk(0);
heapaddr = ALIGN(heapaddr, hugetlbfs_vaddr_granularity());
}
@@ -99,8 +110,8 @@ static void __attribute__ ((constructor)) setup_morecore(void)
DEBUG("Placing hugepage morecore heap at 0x%lx\n", heapaddr);
heaptop = heapbase = (void *)heapaddr;
-
__morecore = &hugetlbfs_morecore;
- /* we always want to use our morecore, not mmap() */
+
+ /* we always want to use our morecore, not ordinary mmap() */
mallopt(M_MMAP_MAX, 0);
}