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 christos expect_zu_eq(ind, i, "Got %u as sz_psz2ind of %zu", ind, 14 1.1 christos 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 christos while (base_ind < SC_NSIZES && 29 1.1 christos reg_size_compute(data.sc[base_ind].lg_base, 30 1.1 christos data.sc[base_ind].lg_delta, 31 1.1 christos data.sc[base_ind].ndelta) < base_psz) { 32 1.1 christos base_ind++; 33 1.1 christos } 34 1.1 christos expect_zu_eq( 35 1.1 christos reg_size_compute(data.sc[base_ind].lg_base, 36 1.1 christos data.sc[base_ind].lg_delta, data.sc[base_ind].ndelta), 37 1.1 christos base_psz, "Size class equal to %zu not found", base_psz); 38 1.1 christos /* 39 1.1 christos * Test different sizes falling into groups after the 'base'. The 40 1.1 christos * increment is PAGE / 3 for the execution speed purpose. 41 1.1 christos */ 42 1.1 christos base_ind -= SC_NGROUP; 43 1.1 christos for (size_t psz = base_psz; psz <= 64 * 1024 * 1024; psz += PAGE / 3) { 44 1.1 christos pszind_t ind = sz_psz2ind(psz); 45 1.1 christos sc_t gt_sc = data.sc[ind + base_ind]; 46 1.1 christos expect_zu_gt(psz, 47 1.1 christos reg_size_compute(gt_sc.lg_base, gt_sc.lg_delta, 48 1.1 christos gt_sc.ndelta), 49 1.1 christos "Got %u as sz_psz2ind of %zu", ind, psz); 50 1.1 christos sc_t le_sc = data.sc[ind + base_ind + 1]; 51 1.1 christos expect_zu_le(psz, 52 1.1 christos reg_size_compute(le_sc.lg_base, le_sc.lg_delta, 53 1.1 christos le_sc.ndelta), 54 1.1 christos "Got %u as sz_psz2ind of %zu", ind, psz); 55 1.1 christos } 56 1.1 christos 57 1.1 christos pszind_t max_ind = sz_psz2ind(SC_LARGE_MAXCLASS + 1); 58 1.1 christos expect_lu_eq(max_ind, SC_NPSIZES, 59 1.1 christos "Got %u as sz_psz2ind of %llu", max_ind, SC_LARGE_MAXCLASS); 60 1.1 christos } 61 1.1 christos TEST_END 62 1.1 christos 63 1.1 christos int 64 1.1 christos main(void) { 65 1.1 christos return test(test_sz_psz2ind); 66 1.1 christos } 67