1 1.1 christos #include "test/jemalloc_test.h" 2 1.1 christos 3 1.1 christos TEST_BEGIN(test_sz_psz2ind) { 4 1.1 christos /* 5 1.1 christos * Testing page size classes which reside prior to the regular group 6 1.1 christos * with all size classes divisible by page size. 7 1.1 christos * For x86_64 Linux, it's 4096, 8192, 12288, 16384, with corresponding 8 1.1 christos * pszind 0, 1, 2 and 3. 9 1.1 christos */ 10 1.1 christos for (size_t i = 0; i < SC_NGROUP; i++) { 11 1.1 christos for (size_t psz = i * PAGE + 1; psz <= (i + 1) * PAGE; psz++) { 12 1.1 christos pszind_t ind = sz_psz2ind(psz); 13 1.1.1.2 christos expect_zu_eq( 14 1.1.1.2 christos ind, i, "Got %u as sz_psz2ind of %zu", ind, psz); 15 1.1 christos } 16 1.1 christos } 17 1.1 christos 18 1.1 christos sc_data_t data; 19 1.1 christos memset(&data, 0, sizeof(data)); 20 1.1 christos sc_data_init(&data); 21 1.1 christos /* 22 1.1 christos * 'base' is the base of the first regular group with all size classes 23 1.1 christos * divisible by page size. 24 1.1 christos * For x86_64 Linux, it's 16384, and base_ind is 36. 25 1.1 christos */ 26 1.1 christos size_t base_psz = 1 << (SC_LG_NGROUP + LG_PAGE); 27 1.1 christos size_t base_ind = 0; 28 1.1.1.2 christos while (base_ind < SC_NSIZES 29 1.1.1.2 christos && reg_size_compute(data.sc[base_ind].lg_base, 30 1.1.1.2 christos data.sc[base_ind].lg_delta, data.sc[base_ind].ndelta) 31 1.1.1.2 christos < base_psz) { 32 1.1 christos base_ind++; 33 1.1 christos } 34 1.1.1.2 christos expect_zu_eq(reg_size_compute(data.sc[base_ind].lg_base, 35 1.1.1.2 christos data.sc[base_ind].lg_delta, data.sc[base_ind].ndelta), 36 1.1 christos base_psz, "Size class equal to %zu not found", base_psz); 37 1.1 christos /* 38 1.1 christos * Test different sizes falling into groups after the 'base'. The 39 1.1 christos * increment is PAGE / 3 for the execution speed purpose. 40 1.1 christos */ 41 1.1 christos base_ind -= SC_NGROUP; 42 1.1 christos for (size_t psz = base_psz; psz <= 64 * 1024 * 1024; psz += PAGE / 3) { 43 1.1 christos pszind_t ind = sz_psz2ind(psz); 44 1.1.1.2 christos sc_t gt_sc = data.sc[ind + base_ind]; 45 1.1 christos expect_zu_gt(psz, 46 1.1.1.2 christos reg_size_compute( 47 1.1.1.2 christos gt_sc.lg_base, gt_sc.lg_delta, gt_sc.ndelta), 48 1.1 christos "Got %u as sz_psz2ind of %zu", ind, psz); 49 1.1 christos sc_t le_sc = data.sc[ind + base_ind + 1]; 50 1.1 christos expect_zu_le(psz, 51 1.1.1.2 christos reg_size_compute( 52 1.1.1.2 christos le_sc.lg_base, le_sc.lg_delta, le_sc.ndelta), 53 1.1 christos "Got %u as sz_psz2ind of %zu", ind, psz); 54 1.1 christos } 55 1.1 christos 56 1.1 christos pszind_t max_ind = sz_psz2ind(SC_LARGE_MAXCLASS + 1); 57 1.1.1.2 christos expect_lu_eq(max_ind, SC_NPSIZES, "Got %u as sz_psz2ind of %llu", 58 1.1.1.2 christos max_ind, SC_LARGE_MAXCLASS); 59 1.1 christos } 60 1.1 christos TEST_END 61 1.1 christos 62 1.1 christos int 63 1.1 christos main(void) { 64 1.1 christos return test(test_sz_psz2ind); 65 1.1 christos } 66