1#include "jemalloc/internal/jemalloc_preamble.h"
2#include "jemalloc/internal/jemalloc_internal_includes.h"
3
4#include "jemalloc/internal/assert.h"
5#include "jemalloc/internal/bin.h"
6#include "jemalloc/internal/sc.h"
7#include "jemalloc/internal/witness.h"
8
9bin_info_t bin_infos[SC_NBINS];
10
11void
12bin_infos_init(sc_data_t *sc_data, bin_info_t bin_infos[SC_NBINS]) {
13 for (unsigned i = 0; i < SC_NBINS; i++) {
14 bin_info_t *bin_info = &bin_infos[i];
15 sc_t *sc = &sc_data->sc[i];
16 bin_info->reg_size = ((size_t)1U << sc->lg_base)
17 + ((size_t)sc->ndelta << sc->lg_delta);
18 bin_info->slab_size = (sc->pgs << LG_PAGE);
19 bin_info->nregs =
20 (uint32_t)(bin_info->slab_size / bin_info->reg_size);
21 bitmap_info_t bitmap_info = BITMAP_INFO_INITIALIZER(
22 bin_info->nregs);
23 bin_info->bitmap_info = bitmap_info;
24 }
25}
26
27void
28bin_boot(sc_data_t *sc_data) {
29 assert(sc_data->initialized);
30 bin_infos_init(sc_data, bin_infos);
31}
32
33bool
34bin_init(bin_t *bin) {
35 if (malloc_mutex_init(&bin->lock, "bin", WITNESS_RANK_BIN,
36 malloc_mutex_rank_exclusive)) {
37 return true;
38 }
39 bin->slabcur = NULL;
40 extent_heap_new(&bin->slabs_nonfull);
41 extent_list_init(&bin->slabs_full);
42 if (config_stats) {
43 memset(&bin->stats, 0, sizeof(bin_stats_t));
44 }
45 return false;
46}
47
48void
49bin_prefork(tsdn_t *tsdn, bin_t *bin) {
50 malloc_mutex_prefork(tsdn, &bin->lock);
51}
52
53void
54bin_postfork_parent(tsdn_t *tsdn, bin_t *bin) {
55 malloc_mutex_postfork_parent(tsdn, &bin->lock);
56}
57
58void
59bin_postfork_child(tsdn_t *tsdn, bin_t *bin) {
60 malloc_mutex_postfork_child(tsdn, &bin->lock);
61}
62