MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / slab_size

Function slab_size

deps/jemalloc/src/sc.c:24–53  ·  view source on GitHub ↗

Returns the number of pages in the slab. */

Source from the content-addressed store, hash-verified

22
23/* Returns the number of pages in the slab. */
24static int
25slab_size(int lg_page, int lg_base, int lg_delta, int ndelta) {
26 size_t page = (ZU(1) << lg_page);
27 size_t reg_size = reg_size_compute(lg_base, lg_delta, ndelta);
28
29 size_t try_slab_size = page;
30 size_t try_nregs = try_slab_size / reg_size;
31 size_t perfect_slab_size = 0;
32 bool perfect = false;
33 /*
34 * This loop continues until we find the least common multiple of the
35 * page size and size class size. Size classes are all of the form
36 * base + ndelta * delta == (ndelta + base/ndelta) * delta, which is
37 * (ndelta + ngroup) * delta. The way we choose slabbing strategies
38 * means that delta is at most the page size and ndelta < ngroup. So
39 * the loop executes for at most 2 * ngroup - 1 iterations, which is
40 * also the bound on the number of pages in a slab chosen by default.
41 * With the current default settings, this is at most 7.
42 */
43 while (!perfect) {
44 perfect_slab_size = try_slab_size;
45 size_t perfect_nregs = try_nregs;
46 try_slab_size += page;
47 try_nregs = try_slab_size / reg_size;
48 if (perfect_slab_size == perfect_nregs * reg_size) {
49 perfect = true;
50 }
51 }
52 return (int)(perfect_slab_size / page);
53}
54
55static void
56size_class(

Callers 1

size_classFunction · 0.85

Calls 1

reg_size_computeFunction · 0.85

Tested by

no test coverage detected