2017-10-02 08:22:06 +08:00
|
|
|
#include "jemalloc/internal/jemalloc_preamble.h"
|
|
|
|
#include "jemalloc/internal/jemalloc_internal_includes.h"
|
|
|
|
|
2017-12-15 04:46:39 +08:00
|
|
|
#include "jemalloc/internal/assert.h"
|
2017-10-02 08:22:06 +08:00
|
|
|
#include "jemalloc/internal/bin.h"
|
2017-12-15 04:46:39 +08:00
|
|
|
#include "jemalloc/internal/sc.h"
|
2017-10-02 09:02:39 +08:00
|
|
|
#include "jemalloc/internal/witness.h"
|
2017-10-02 08:22:06 +08:00
|
|
|
|
2018-11-21 05:51:32 +08:00
|
|
|
bool
|
|
|
|
bin_update_shard_size(unsigned bin_shard_sizes[SC_NBINS], size_t start_size,
|
|
|
|
size_t end_size, size_t nshards) {
|
|
|
|
if (nshards > BIN_SHARDS_MAX || nshards == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (start_size > SC_SMALL_MAXCLASS) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (end_size > SC_SMALL_MAXCLASS) {
|
|
|
|
end_size = SC_SMALL_MAXCLASS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compute the index since this may happen before sz init. */
|
|
|
|
szind_t ind1 = sz_size2index_compute(start_size);
|
|
|
|
szind_t ind2 = sz_size2index_compute(end_size);
|
|
|
|
for (unsigned i = ind1; i <= ind2; i++) {
|
|
|
|
bin_shard_sizes[i] = (unsigned)nshards;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bin_shard_sizes_boot(unsigned bin_shard_sizes[SC_NBINS]) {
|
|
|
|
/* Load the default number of shards. */
|
|
|
|
for (unsigned i = 0; i < SC_NBINS; i++) {
|
|
|
|
bin_shard_sizes[i] = N_BIN_SHARDS_DEFAULT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-02 09:02:39 +08:00
|
|
|
bool
|
|
|
|
bin_init(bin_t *bin) {
|
2017-10-02 09:10:36 +08:00
|
|
|
if (malloc_mutex_init(&bin->lock, "bin", WITNESS_RANK_BIN,
|
2017-10-02 09:02:39 +08:00
|
|
|
malloc_mutex_rank_exclusive)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bin->slabcur = NULL;
|
2019-12-10 06:36:45 +08:00
|
|
|
edata_heap_new(&bin->slabs_nonfull);
|
|
|
|
edata_list_init(&bin->slabs_full);
|
2017-10-02 09:02:39 +08:00
|
|
|
if (config_stats) {
|
2017-11-05 03:50:19 +08:00
|
|
|
memset(&bin->stats, 0, sizeof(bin_stats_t));
|
2017-10-02 09:02:39 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2017-10-02 09:10:36 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
bin_prefork(tsdn_t *tsdn, bin_t *bin) {
|
|
|
|
malloc_mutex_prefork(tsdn, &bin->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bin_postfork_parent(tsdn_t *tsdn, bin_t *bin) {
|
|
|
|
malloc_mutex_postfork_parent(tsdn, &bin->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bin_postfork_child(tsdn_t *tsdn, bin_t *bin) {
|
|
|
|
malloc_mutex_postfork_child(tsdn, &bin->lock);
|
|
|
|
}
|