1 #include "jemalloc/internal/jemalloc_preamble.h"
2 #include "jemalloc/internal/jemalloc_internal_includes.h"
3
4 #include "jemalloc/internal/bin.h"
5 #include "jemalloc/internal/witness.h"
6
7 const 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
22 bool
bin_init(bin_t * bin)23 bin_init(bin_t *bin) {
24 if (malloc_mutex_init(&bin->lock, "bin", WITNESS_RANK_BIN,
25 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) {
32 memset(&bin->stats, 0, sizeof(bin_stats_t));
33 }
34 return false;
35 }
36
37 void
bin_prefork(tsdn_t * tsdn,bin_t * bin)38 bin_prefork(tsdn_t *tsdn, bin_t *bin) {
39 malloc_mutex_prefork(tsdn, &bin->lock);
40 }
41
42 void
bin_postfork_parent(tsdn_t * tsdn,bin_t * bin)43 bin_postfork_parent(tsdn_t *tsdn, bin_t *bin) {
44 malloc_mutex_postfork_parent(tsdn, &bin->lock);
45 }
46
47 void
bin_postfork_child(tsdn_t * tsdn,bin_t * bin)48 bin_postfork_child(tsdn_t *tsdn, bin_t *bin) {
49 malloc_mutex_postfork_child(tsdn, &bin->lock);
50 }
51