tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

restoring old jemalloc patches



hi folks, while skimming jemalloc, noticed a comment about our old code
being better.
there's a while loop trying to get aligned allocations, so it probably
does matter (pages_map_slow).

Any good benchmarks to use?
Bring in code from old jemalloc customized for netbsd.

There's a loop calling os_pages_map trying to get aligned mappings.
XXX how to bench

Index: dist/src/pages.c
===================================================================
RCS file: /cvsroot/src/external/bsd/jemalloc/dist/src/pages.c,v
retrieving revision 1.5
diff -u -r1.5 pages.c
--- dist/src/pages.c	26 Apr 2019 23:57:59 -0000	1.5
+++ dist/src/pages.c	11 Jul 2019 22:24:42 -0000
@@ -53,6 +53,41 @@
 
 /******************************************************************************/
 
+#ifdef __NetBSD__
+static void *
+os_pages_map(void *addr, size_t size, size_t alignment, bool *commit) {
+	assert(ALIGNMENT_ADDR2BASE(addr, os_page) == addr);
+	assert(ALIGNMENT_CEILING(size, os_page) == size);
+	assert(size != 0);
+
+	/* We always over-commit. */
+	*commit = true;
+
+	void *ret;
+
+	/*
+	 * We don't use MAP_FIXED here, because it can cause the *replacement*
+	 * of existing mappings, and we only want to create new mappings.
+	 */
+	ret = mmap(addr, size, PROT_READ | PROT_WRITE,
+	    MAP_PRIVATE | MAP_ANON | MAP_ALIGNED(alignment), -1, 0);
+	assert(ret != NULL);
+
+	if (ret == MAP_FAILED)
+		ret = NULL;
+	else if (addr != NULL && ret != addr) {
+		/*
+		 * We succeeded in mapping memory, but not in the right place.
+		 */
+		os_pages_unmap(ret, size);
+		ret = NULL;
+	}
+
+	assert(ret == NULL || (addr == NULL && ret != addr)
+	    || (addr != NULL && ret == addr));
+	return (ret);
+}
+#else
 static void *
 os_pages_map(void *addr, size_t size, size_t alignment, bool *commit) {
 	assert(ALIGNMENT_ADDR2BASE(addr, os_page) == addr);
@@ -104,6 +139,7 @@
 	    ret == addr));
 	return ret;
 }
+#endif
 
 static void *
 os_pages_trim(void *addr, size_t alloc_size, size_t leadsize, size_t size,
@@ -592,6 +628,8 @@
 		mmap_flags |= MAP_NORESERVE;
 	}
 #  endif
+#elif defined(__NetBSD__)
+	os_overcommits = true;
 #else
 	os_overcommits = false;
 #endif


Home | Main Index | Thread Index | Old Index