xref: /netbsd-src/external/bsd/jemalloc.old/dist/src/bin.c (revision 8e33eff89e26cf71871ead62f0d5063e1313c33a)
1*8e33eff8Schristos #include "jemalloc/internal/jemalloc_preamble.h"
2*8e33eff8Schristos #include "jemalloc/internal/jemalloc_internal_includes.h"
3*8e33eff8Schristos 
4*8e33eff8Schristos #include "jemalloc/internal/bin.h"
5*8e33eff8Schristos #include "jemalloc/internal/witness.h"
6*8e33eff8Schristos 
7*8e33eff8Schristos const bin_info_t bin_infos[NBINS] = {
8*8e33eff8Schristos #define BIN_INFO_bin_yes(reg_size, slab_size, nregs)			\
9*8e33eff8Schristos 	{reg_size, slab_size, nregs, BITMAP_INFO_INITIALIZER(nregs)},
10*8e33eff8Schristos #define BIN_INFO_bin_no(reg_size, slab_size, nregs)
11*8e33eff8Schristos #define SC(index, lg_grp, lg_delta, ndelta, psz, bin, pgs,		\
12*8e33eff8Schristos     lg_delta_lookup)							\
13*8e33eff8Schristos 	BIN_INFO_bin_##bin((1U<<lg_grp) + (ndelta<<lg_delta),		\
14*8e33eff8Schristos 	    (pgs << LG_PAGE), (pgs << LG_PAGE) / ((1U<<lg_grp) +	\
15*8e33eff8Schristos 	    (ndelta<<lg_delta)))
16*8e33eff8Schristos 	SIZE_CLASSES
17*8e33eff8Schristos #undef BIN_INFO_bin_yes
18*8e33eff8Schristos #undef BIN_INFO_bin_no
19*8e33eff8Schristos #undef SC
20*8e33eff8Schristos };
21*8e33eff8Schristos 
22*8e33eff8Schristos bool
23*8e33eff8Schristos bin_init(bin_t *bin) {
24*8e33eff8Schristos 	if (malloc_mutex_init(&bin->lock, "bin", WITNESS_RANK_BIN,
25*8e33eff8Schristos 	    malloc_mutex_rank_exclusive)) {
26*8e33eff8Schristos 		return true;
27*8e33eff8Schristos 	}
28*8e33eff8Schristos 	bin->slabcur = NULL;
29*8e33eff8Schristos 	extent_heap_new(&bin->slabs_nonfull);
30*8e33eff8Schristos 	extent_list_init(&bin->slabs_full);
31*8e33eff8Schristos 	if (config_stats) {
32*8e33eff8Schristos 		memset(&bin->stats, 0, sizeof(bin_stats_t));
33*8e33eff8Schristos 	}
34*8e33eff8Schristos 	return false;
35*8e33eff8Schristos }
36*8e33eff8Schristos 
37*8e33eff8Schristos void
38*8e33eff8Schristos bin_prefork(tsdn_t *tsdn, bin_t *bin) {
39*8e33eff8Schristos 	malloc_mutex_prefork(tsdn, &bin->lock);
40*8e33eff8Schristos }
41*8e33eff8Schristos 
42*8e33eff8Schristos void
43*8e33eff8Schristos bin_postfork_parent(tsdn_t *tsdn, bin_t *bin) {
44*8e33eff8Schristos 	malloc_mutex_postfork_parent(tsdn, &bin->lock);
45*8e33eff8Schristos }
46*8e33eff8Schristos 
47*8e33eff8Schristos void
48*8e33eff8Schristos bin_postfork_child(tsdn_t *tsdn, bin_t *bin) {
49*8e33eff8Schristos 	malloc_mutex_postfork_child(tsdn, &bin->lock);
50*8e33eff8Schristos }
51