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
9bool
10bin_update_shard_size(unsigned bin_shard_sizes[SC_NBINS], size_t start_size,
11 size_t end_size, size_t nshards) {
12 if (nshards > BIN_SHARDS_MAX || nshards == 0) {
13 return true;
14 }
15
16 if (start_size > SC_SMALL_MAXCLASS) {
17 return false;
18 }
19 if (end_size > SC_SMALL_MAXCLASS) {
20 end_size = SC_SMALL_MAXCLASS;
21 }
22
23 /* Compute the index since this may happen before sz init. */
24 szind_t ind1 = sz_size2index_compute(start_size);
25 szind_t ind2 = sz_size2index_compute(end_size);
26 for (unsigned i = ind1; i <= ind2; i++) {
27 bin_shard_sizes[i] = (unsigned)nshards;
28 }
29
30 return false;
31}
32
33void
34bin_shard_sizes_boot(unsigned bin_shard_sizes[SC_NBINS]) {
35 /* Load the default number of shards. */
36 for (unsigned i = 0; i < SC_NBINS; i++) {
37 bin_shard_sizes[i] = N_BIN_SHARDS_DEFAULT;
38 }
39}
40
41bool
42bin_init(bin_t *bin) {
43 if (malloc_mutex_init(&bin->lock, "bin", WITNESS_RANK_BIN,
44 malloc_mutex_rank_exclusive)) {
45 return true;
46 }
47 bin->slabcur = NULL;
48 edata_heap_new(&bin->slabs_nonfull);
49 edata_list_active_init(&bin->slabs_full);
50 if (config_stats) {
51 memset(&bin->stats, 0, sizeof(bin_stats_t));
52 }
53 return false;
54}
55
56void
57bin_prefork(tsdn_t *tsdn, bin_t *bin) {
58 malloc_mutex_prefork(tsdn, &bin->lock);
59}
60
61void
62bin_postfork_parent(tsdn_t *tsdn, bin_t *bin) {
63 malloc_mutex_postfork_parent(tsdn, &bin->lock);
64}
65
66void
67bin_postfork_child(tsdn_t *tsdn, bin_t *bin) {
68 malloc_mutex_postfork_child(tsdn, &bin->lock);
69}
70