summaryrefslogtreecommitdiff
path: root/deps/jemalloc/test/integration/mallocx.c
diff options
context:
space:
mode:
authorOran Agra <oran@redislabs.com>2021-10-18 12:45:11 +0300
committerGitHub <noreply@github.com>2021-10-18 12:45:11 +0300
commitc4b4b6c06b0562740d214d0df467b2ba40396ffc (patch)
treeccd9a5e688f16311edefdacb63994976f8c6f687 /deps/jemalloc/test/integration/mallocx.c
parent276b460ea9554f79109eb9a234a847a2520cf4c2 (diff)
parent85737e674552bafefb6beb9a37531645e5d2178b (diff)
downloadredis-c4b4b6c06b0562740d214d0df467b2ba40396ffc.tar.gz
Merge pull request #9623 from yoav-steinberg/upgrade_jemalloc_5.2.1
Upgraded to jemalloc 5.2.1 from 5.1.0. Cherry picked all relevant fixes (by diffing our 5.1.0 to upstream 5.10 and finding relevant commits). Details of what was done: [cherry-picked] fd7d51c 2021-05-03 Resolve nonsense static analysis warnings (Oran Agra) [cherry-picked] 448c435 2020-09-29 Fix compilation warnings in Lua and jemalloc dependencies (#7785) (YoongHM) [skipped - already in upstream] 9216b96 2020-09-21 Fix compilation warning in jemalloc's malloc_vsnprintf (#7789) (YoongHM) [cherry-picked] 88d71f4 2020-05-20 fix a rare active defrag edge case bug leading to stagnation (Oran Agra) [skipped - already in upstream] 2fec7d9 2019-05-30 Jemalloc: Avoid blocking on background thread lock for stats. [cherry-picked] 920158e 2018-07-11 Active defrag fixes for 32bit builds (again) (Oran Agra) [cherry-picked] e8099ca 2018-06-26 add defrag hint support into jemalloc 5 (Oran Agra) [re-done] 4e729fc 2018-05-24 Generate configure for Jemalloc. (antirez) Additionally had to do this: 7727cc2 2021-10-10 Fix defrag to support sharded bins in arena (added in v5.2.1) (Yoav Steinberg) When reviewing please look at all except the first commit which is just replacing 5.1.0 with 5.2.1 sources. Also I think we should merge this without squashing to preserve the changes we did to to jemalloc.
Diffstat (limited to 'deps/jemalloc/test/integration/mallocx.c')
-rw-r--r--deps/jemalloc/test/integration/mallocx.c52
1 files changed, 49 insertions, 3 deletions
diff --git a/deps/jemalloc/test/integration/mallocx.c b/deps/jemalloc/test/integration/mallocx.c
index fd960f30c..645d4db48 100644
--- a/deps/jemalloc/test/integration/mallocx.c
+++ b/deps/jemalloc/test/integration/mallocx.c
@@ -51,6 +51,16 @@ purge(void) {
"Unexpected mallctl error");
}
+/*
+ * GCC "-Walloc-size-larger-than" warning detects when one of the memory
+ * allocation functions is called with a size larger than the maximum size that
+ * they support. Here we want to explicitly test that the allocation functions
+ * do indeed fail properly when this is the case, which triggers the warning.
+ * Therefore we disable the warning for these tests.
+ */
+JEMALLOC_DIAGNOSTIC_PUSH
+JEMALLOC_DIAGNOSTIC_IGNORE_ALLOC_SIZE_LARGER_THAN
+
TEST_BEGIN(test_overflow) {
size_t largemax;
@@ -71,6 +81,38 @@ TEST_BEGIN(test_overflow) {
}
TEST_END
+static void *
+remote_alloc(void *arg) {
+ unsigned arena;
+ size_t sz = sizeof(unsigned);
+ assert_d_eq(mallctl("arenas.create", (void *)&arena, &sz, NULL, 0), 0,
+ "Unexpected mallctl() failure");
+ size_t large_sz;
+ sz = sizeof(size_t);
+ assert_d_eq(mallctl("arenas.lextent.0.size", (void *)&large_sz, &sz,
+ NULL, 0), 0, "Unexpected mallctl failure");
+
+ void *ptr = mallocx(large_sz, MALLOCX_ARENA(arena)
+ | MALLOCX_TCACHE_NONE);
+ void **ret = (void **)arg;
+ *ret = ptr;
+
+ return NULL;
+}
+
+TEST_BEGIN(test_remote_free) {
+ thd_t thd;
+ void *ret;
+ thd_create(&thd, remote_alloc, (void *)&ret);
+ thd_join(thd, NULL);
+ assert_ptr_not_null(ret, "Unexpected mallocx failure");
+
+ /* Avoid TCACHE_NONE to explicitly test tcache_flush(). */
+ dallocx(ret, 0);
+ mallctl("thread.tcache.flush", NULL, NULL, NULL, 0);
+}
+TEST_END
+
TEST_BEGIN(test_oom) {
size_t largemax;
bool oom;
@@ -84,7 +126,7 @@ TEST_BEGIN(test_oom) {
largemax = get_large_size(get_nlarge()-1);
oom = false;
for (i = 0; i < sizeof(ptrs) / sizeof(void *); i++) {
- ptrs[i] = mallocx(largemax, 0);
+ ptrs[i] = mallocx(largemax, MALLOCX_ARENA(0));
if (ptrs[i] == NULL) {
oom = true;
}
@@ -113,6 +155,9 @@ TEST_BEGIN(test_oom) {
}
TEST_END
+/* Re-enable the "-Walloc-size-larger-than=" warning */
+JEMALLOC_DIAGNOSTIC_POP
+
TEST_BEGIN(test_basic) {
#define MAXSZ (((size_t)1) << 23)
size_t sz;
@@ -178,12 +223,12 @@ TEST_BEGIN(test_alignment_and_size) {
sz += (alignment >> (LG_SIZEOF_PTR-1)) - 1) {
for (i = 0; i < NITER; i++) {
nsz = nallocx(sz, MALLOCX_ALIGN(alignment) |
- MALLOCX_ZERO);
+ MALLOCX_ZERO | MALLOCX_ARENA(0));
assert_zu_ne(nsz, 0,
"nallocx() error for alignment=%zu, "
"size=%zu (%#zx)", alignment, sz, sz);
ps[i] = mallocx(sz, MALLOCX_ALIGN(alignment) |
- MALLOCX_ZERO);
+ MALLOCX_ZERO | MALLOCX_ARENA(0));
assert_ptr_not_null(ps[i],
"mallocx() error for alignment=%zu, "
"size=%zu (%#zx)", alignment, sz, sz);
@@ -223,6 +268,7 @@ main(void) {
return test(
test_overflow,
test_oom,
+ test_remote_free,
test_basic,
test_alignment_and_size);
}