aboutsummaryrefslogtreecommitdiff
path: root/morecore.c
diff options
context:
space:
mode:
Diffstat (limited to 'morecore.c')
-rw-r--r--morecore.c40
1 files changed, 30 insertions, 10 deletions
diff --git a/morecore.c b/morecore.c
index e120d55..20c4860 100644
--- a/morecore.c
+++ b/morecore.c
@@ -73,6 +73,9 @@ static void *hugetlbfs_morecore(ptrdiff_t increment)
void *p;
long delta;
int mmap_reserve = __hugetlb_opts.no_reserve ? MAP_NORESERVE : 0;
+ int mmap_hugetlb = 0;
+ int using_default_pagesize =
+ (hpage_size == kernel_default_hugepage_size());
INFO("hugetlbfs_morecore(%ld) = ...\n", (long)increment);
@@ -88,14 +91,24 @@ static void *hugetlbfs_morecore(ptrdiff_t increment)
/* align to multiple of hugepagesize. */
delta = ALIGN(delta, hpage_size);
+#ifdef MAP_HUGETLB
+ mmap_hugetlb = MAP_HUGETLB;
+#endif
+
if (delta > 0) {
/* growing the heap */
INFO("Attempting to map %ld bytes\n", delta);
/* map in (extend) more of the file at the end of our last map */
- p = mmap(heapbase + mapsize, delta, PROT_READ|PROT_WRITE,
- MAP_PRIVATE|mmap_reserve, heap_fd, mapsize);
+ if (__hugetlb_opts.map_hugetlb && using_default_pagesize)
+ p = mmap(heapbase + mapsize, delta, PROT_READ|PROT_WRITE,
+ mmap_hugetlb|MAP_ANONYMOUS|MAP_PRIVATE|mmap_reserve,
+ heap_fd, mapsize);
+ else
+ p = mmap(heapbase + mapsize, delta, PROT_READ|PROT_WRITE,
+ MAP_PRIVATE|mmap_reserve, heap_fd, mapsize);
+
if (p == MAP_FAILED) {
WARNING("New heap segment map at %p failed: %s\n",
heapbase+mapsize, strerror(errno));
@@ -166,7 +179,7 @@ static void *hugetlbfs_morecore(ptrdiff_t increment)
if (ret) {
WARNING("Unmapping failed while shrinking heap: "
"%s\n", strerror(errno));
- } else {
+ } else if (!__hugetlb_opts.map_hugetlb && !using_default_pagesize){
/*
* Now shrink the hugetlbfs file.
@@ -223,15 +236,22 @@ void hugetlbfs_setup_morecore(void)
else
WARNING("Hugepage size (%s)\n", strerror(errno));
return;
- } else if (!hugetlbfs_find_path_for_size(hpage_size)) {
- WARNING("Hugepage size %li unavailable", hpage_size);
- return;
}
- heap_fd = hugetlbfs_unlinked_fd_for_size(hpage_size);
- if (heap_fd < 0) {
- WARNING("Couldn't open hugetlbfs file for morecore\n");
- return;
+ if(__hugetlb_opts.map_hugetlb &&
+ hpage_size == kernel_default_hugepage_size()) {
+ heap_fd = -1;
+ } else {
+ if (!hugetlbfs_find_path_for_size(hpage_size)) {
+ WARNING("Hugepage size %li unavailable", hpage_size);
+ return;
+ }
+
+ heap_fd = hugetlbfs_unlinked_fd_for_size(hpage_size);
+ if (heap_fd < 0) {
+ WARNING("Couldn't open hugetlbfs file for morecore\n");
+ return;
+ }
}
if (__hugetlb_opts.heapbase) {