Skip to content

Commit 66c8895

Browse files
committed
Make test/unit/background_thread_enable more conservative.
To avoid resource exhaustion on 32-bit platforms.
1 parent a7d73dd commit 66c8895

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

test/unit/background_thread_enable.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,31 @@
22

33
const char *malloc_conf = "background_thread:false,narenas:1,max_background_threads:20";
44

5-
TEST_BEGIN(test_deferred) {
6-
test_skip_if(!have_background_thread);
7-
8-
unsigned id;
9-
size_t sz_u = sizeof(unsigned);
10-
5+
static unsigned
6+
max_test_narenas(void) {
117
/*
128
* 10 here is somewhat arbitrary, except insofar as we want to ensure
139
* that the number of background threads is smaller than the number of
1410
* arenas. I'll ragequit long before we have to spin up 10 threads per
1511
* cpu to handle background purging, so this is a conservative
1612
* approximation.
1713
*/
18-
for (unsigned i = 0; i < 10 * ncpus; i++) {
14+
unsigned ret = 10 * ncpus;
15+
/* Limit the max to avoid VM exhaustion on 32-bit . */
16+
if (ret > 512) {
17+
ret = 512;
18+
}
19+
20+
return ret;
21+
}
22+
23+
TEST_BEGIN(test_deferred) {
24+
test_skip_if(!have_background_thread);
25+
26+
unsigned id;
27+
size_t sz_u = sizeof(unsigned);
28+
29+
for (unsigned i = 0; i < max_test_narenas(); i++) {
1930
expect_d_eq(mallctl("arenas.create", &id, &sz_u, NULL, 0), 0,
2031
"Failed to create arena");
2132
}
@@ -50,7 +61,7 @@ TEST_BEGIN(test_max_background_threads) {
5061
unsigned id;
5162
size_t sz_u = sizeof(unsigned);
5263

53-
for (unsigned i = 0; i < 10 * ncpus; i++) {
64+
for (unsigned i = 0; i < max_test_narenas(); i++) {
5465
expect_d_eq(mallctl("arenas.create", &id, &sz_u, NULL, 0), 0,
5566
"Failed to create arena");
5667
}

0 commit comments

Comments
 (0)