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