blob: 0886bc4ea925d0ff361cc6d4300333a9efaac6af [file] [log] [blame]
David T. Goldblatt4bf4a1c2017-10-01 17:22:06 -07001#include "jemalloc/internal/jemalloc_preamble.h"
2#include "jemalloc/internal/jemalloc_internal_includes.h"
3
4#include "jemalloc/internal/bin.h"
David T. Goldblatta8dd8872017-10-01 18:02:39 -07005#include "jemalloc/internal/witness.h"
David T. Goldblatt4bf4a1c2017-10-01 17:22:06 -07006
7const bin_info_t bin_infos[NBINS] = {
8#define BIN_INFO_bin_yes(reg_size, slab_size, nregs) \
9 {reg_size, slab_size, nregs, BITMAP_INFO_INITIALIZER(nregs)},
10#define BIN_INFO_bin_no(reg_size, slab_size, nregs)
11#define SC(index, lg_grp, lg_delta, ndelta, psz, bin, pgs, \
12 lg_delta_lookup) \
13 BIN_INFO_bin_##bin((1U<<lg_grp) + (ndelta<<lg_delta), \
14 (pgs << LG_PAGE), (pgs << LG_PAGE) / ((1U<<lg_grp) + \
15 (ndelta<<lg_delta)))
16 SIZE_CLASSES
17#undef BIN_INFO_bin_yes
18#undef BIN_INFO_bin_no
19#undef SC
20};
21
David T. Goldblatta8dd8872017-10-01 18:02:39 -070022bool
23bin_init(bin_t *bin) {
David T. Goldblatt48bb4a02017-10-01 18:10:36 -070024 if (malloc_mutex_init(&bin->lock, "bin", WITNESS_RANK_BIN,
David T. Goldblatta8dd8872017-10-01 18:02:39 -070025 malloc_mutex_rank_exclusive)) {
26 return true;
27 }
28 bin->slabcur = NULL;
29 extent_heap_new(&bin->slabs_nonfull);
30 extent_list_init(&bin->slabs_full);
31 if (config_stats) {
David T. Goldblatt7f1b02e2017-11-04 12:50:19 -070032 memset(&bin->stats, 0, sizeof(bin_stats_t));
David T. Goldblatta8dd8872017-10-01 18:02:39 -070033 }
34 return false;
35}
David T. Goldblatt48bb4a02017-10-01 18:10:36 -070036
37void
38bin_prefork(tsdn_t *tsdn, bin_t *bin) {
39 malloc_mutex_prefork(tsdn, &bin->lock);
40}
41
42void
43bin_postfork_parent(tsdn_t *tsdn, bin_t *bin) {
44 malloc_mutex_postfork_parent(tsdn, &bin->lock);
45}
46
47void
48bin_postfork_child(tsdn_t *tsdn, bin_t *bin) {
49 malloc_mutex_postfork_child(tsdn, &bin->lock);
50}