Skip to content

Instantly share code, notes, and snippets.

@pietern
Created August 25, 2011 16:11
Show Gist options
  • Save pietern/1171054 to your computer and use it in GitHub Desktop.
Save pietern/1171054 to your computer and use it in GitHub Desktop.
diff --git a/deps/jemalloc/src/chunk_mmap.c b/deps/jemalloc/src/chunk_mmap.c
index 164e86e..c2ce465 100644
--- a/deps/jemalloc/src/chunk_mmap.c
+++ b/deps/jemalloc/src/chunk_mmap.c
@@ -48,9 +48,25 @@ pages_map(void *addr, size_t size, bool noreserve)
if (noreserve)
flags |= MAP_NORESERVE;
#endif
+
+#ifdef MAP_HUGETLB
+ flags |= MAP_HUGETLB;
+#endif
ret = mmap(addr, size, PROT_READ | PROT_WRITE, flags, -1, 0);
assert(ret != NULL);
+#ifdef MAP_HUGETLB
+ /*
+ * Retry on ENOMEM when we tried to map using huge pages.
+ * This strategy is far from optimal, needs way more heuristics...
+ */
+ if (ret == MAP_FAILED && errno == ENOMEM) {
+ flags &= ~MAP_HUGETLB;
+ ret = mmap(addr, size, PROT_READ | PROT_WRITE, flags, -1, 0);
+ assert(ret != NULL);
+ }
+#endif
+
if (ret == MAP_FAILED)
ret = NULL;
else if (addr != NULL && ret != addr) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment