aboutsummaryrefslogtreecommitdiff
path: root/test/unit/background_thread_enable.c
diff options
context:
space:
mode:
authorWarner Losh <imp@FreeBSD.org>2025-02-05 23:20:13 +0000
committerWarner Losh <imp@FreeBSD.org>2025-02-05 23:20:13 +0000
commit48ec896efb0b78141df004eaa21288b84590c9da (patch)
tree33799792fd95c266d472ab1ae51d50ab4f942eb3 /test/unit/background_thread_enable.c
parentd28d7fbede216494aa3942af042cc084fcd6098a (diff)
jemalloc: Import 5.3.0 54eaed1d8b56b1aa528be3bdd1877e59c56fa90cvendor/jemalloc/5.3.0vendor/jemalloc
Import jemalloc 5.3.0. This import changes how manage the jemalloc vendor branch (which was just started anyway). Starting with 5.3.0, we import a clean tree from the upstream github, removing all the old files that are no longer upstream, or that we've kept around for some reason. We do this because we merge from this raw version of jemalloc into the FreeBSD contrib/jemalloc, then we run autogen stuff, generate all the generated .h files with gmake, then finally remove much of the generated files in contrib/jemalloc using an update script. Sponsored by: Netflix
Diffstat (limited to 'test/unit/background_thread_enable.c')
-rw-r--r--test/unit/background_thread_enable.c55
1 files changed, 33 insertions, 22 deletions
diff --git a/test/unit/background_thread_enable.c b/test/unit/background_thread_enable.c
index d894e937161d..44034ac67f19 100644
--- a/test/unit/background_thread_enable.c
+++ b/test/unit/background_thread_enable.c
@@ -2,12 +2,8 @@
const char *malloc_conf = "background_thread:false,narenas:1,max_background_threads:20";
-TEST_BEGIN(test_deferred) {
- test_skip_if(!have_background_thread);
-
- unsigned id;
- size_t sz_u = sizeof(unsigned);
-
+static unsigned
+max_test_narenas(void) {
/*
* 10 here is somewhat arbitrary, except insofar as we want to ensure
* that the number of background threads is smaller than the number of
@@ -15,17 +11,32 @@ TEST_BEGIN(test_deferred) {
* cpu to handle background purging, so this is a conservative
* approximation.
*/
- for (unsigned i = 0; i < 10 * ncpus; i++) {
- assert_d_eq(mallctl("arenas.create", &id, &sz_u, NULL, 0), 0,
+ unsigned ret = 10 * ncpus;
+ /* Limit the max to avoid VM exhaustion on 32-bit . */
+ if (ret > 512) {
+ ret = 512;
+ }
+
+ return ret;
+}
+
+TEST_BEGIN(test_deferred) {
+ test_skip_if(!have_background_thread);
+
+ unsigned id;
+ size_t sz_u = sizeof(unsigned);
+
+ for (unsigned i = 0; i < max_test_narenas(); i++) {
+ expect_d_eq(mallctl("arenas.create", &id, &sz_u, NULL, 0), 0,
"Failed to create arena");
}
bool enable = true;
size_t sz_b = sizeof(bool);
- assert_d_eq(mallctl("background_thread", NULL, NULL, &enable, sz_b), 0,
+ expect_d_eq(mallctl("background_thread", NULL, NULL, &enable, sz_b), 0,
"Failed to enable background threads");
enable = false;
- assert_d_eq(mallctl("background_thread", NULL, NULL, &enable, sz_b), 0,
+ expect_d_eq(mallctl("background_thread", NULL, NULL, &enable, sz_b), 0,
"Failed to disable background threads");
}
TEST_END
@@ -36,43 +47,43 @@ TEST_BEGIN(test_max_background_threads) {
size_t max_n_thds;
size_t opt_max_n_thds;
size_t sz_m = sizeof(max_n_thds);
- assert_d_eq(mallctl("opt.max_background_threads",
+ expect_d_eq(mallctl("opt.max_background_threads",
&opt_max_n_thds, &sz_m, NULL, 0), 0,
"Failed to get opt.max_background_threads");
- assert_d_eq(mallctl("max_background_threads", &max_n_thds, &sz_m, NULL,
+ expect_d_eq(mallctl("max_background_threads", &max_n_thds, &sz_m, NULL,
0), 0, "Failed to get max background threads");
- assert_zu_eq(opt_max_n_thds, max_n_thds,
+ expect_zu_eq(opt_max_n_thds, max_n_thds,
"max_background_threads and "
"opt.max_background_threads should match");
- assert_d_eq(mallctl("max_background_threads", NULL, NULL, &max_n_thds,
+ expect_d_eq(mallctl("max_background_threads", NULL, NULL, &max_n_thds,
sz_m), 0, "Failed to set max background threads");
unsigned id;
size_t sz_u = sizeof(unsigned);
- for (unsigned i = 0; i < 10 * ncpus; i++) {
- assert_d_eq(mallctl("arenas.create", &id, &sz_u, NULL, 0), 0,
+ for (unsigned i = 0; i < max_test_narenas(); i++) {
+ expect_d_eq(mallctl("arenas.create", &id, &sz_u, NULL, 0), 0,
"Failed to create arena");
}
bool enable = true;
size_t sz_b = sizeof(bool);
- assert_d_eq(mallctl("background_thread", NULL, NULL, &enable, sz_b), 0,
+ expect_d_eq(mallctl("background_thread", NULL, NULL, &enable, sz_b), 0,
"Failed to enable background threads");
- assert_zu_eq(n_background_threads, max_n_thds,
+ expect_zu_eq(n_background_threads, max_n_thds,
"Number of background threads should not change.\n");
size_t new_max_thds = max_n_thds - 1;
if (new_max_thds > 0) {
- assert_d_eq(mallctl("max_background_threads", NULL, NULL,
+ expect_d_eq(mallctl("max_background_threads", NULL, NULL,
&new_max_thds, sz_m), 0,
"Failed to set max background threads");
- assert_zu_eq(n_background_threads, new_max_thds,
+ expect_zu_eq(n_background_threads, new_max_thds,
"Number of background threads should decrease by 1.\n");
}
new_max_thds = 1;
- assert_d_eq(mallctl("max_background_threads", NULL, NULL, &new_max_thds,
+ expect_d_eq(mallctl("max_background_threads", NULL, NULL, &new_max_thds,
sz_m), 0, "Failed to set max background threads");
- assert_zu_eq(n_background_threads, new_max_thds,
+ expect_zu_eq(n_background_threads, new_max_thds,
"Number of background threads should be 1.\n");
}
TEST_END