sz.c 2.0 KB

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