|
2 | 2 |
|
3 | 3 | const char *malloc_conf = "background_thread:false,narenas:1,max_background_threads:20"; |
4 | 4 |
|
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) { |
11 | 7 | /* |
12 | 8 | * 10 here is somewhat arbitrary, except insofar as we want to ensure |
13 | 9 | * that the number of background threads is smaller than the number of |
14 | 10 | * arenas. I'll ragequit long before we have to spin up 10 threads per |
15 | 11 | * cpu to handle background purging, so this is a conservative |
16 | 12 | * approximation. |
17 | 13 | */ |
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++) { |
19 | 30 | expect_d_eq(mallctl("arenas.create", &id, &sz_u, NULL, 0), 0, |
20 | 31 | "Failed to create arena"); |
21 | 32 | } |
@@ -50,7 +61,7 @@ TEST_BEGIN(test_max_background_threads) { |
50 | 61 | unsigned id; |
51 | 62 | size_t sz_u = sizeof(unsigned); |
52 | 63 |
|
53 | | - for (unsigned i = 0; i < 10 * ncpus; i++) { |
| 64 | + for (unsigned i = 0; i < max_test_narenas(); i++) { |
54 | 65 | expect_d_eq(mallctl("arenas.create", &id, &sz_u, NULL, 0), 0, |
55 | 66 | "Failed to create arena"); |
56 | 67 | } |
|
0 commit comments