mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-24 13:53:11 +00:00
Add opt.bin_shards to specify number of bin shards.
The option uses the same format as "slab_sizes" to specify number of shards for each bin size.
This commit is contained in:
48
src/bin.c
48
src/bin.c
@@ -6,13 +6,11 @@
|
||||
#include "jemalloc/internal/sc.h"
|
||||
#include "jemalloc/internal/witness.h"
|
||||
|
||||
unsigned opt_bin_shard_maxszind;
|
||||
unsigned opt_n_bin_shards;
|
||||
|
||||
bin_info_t bin_infos[SC_NBINS];
|
||||
|
||||
void
|
||||
bin_infos_init(sc_data_t *sc_data, bin_info_t bin_infos[SC_NBINS]) {
|
||||
static void
|
||||
bin_infos_init(sc_data_t *sc_data, unsigned bin_shard_sizes[SC_NBINS],
|
||||
bin_info_t bin_infos[SC_NBINS]) {
|
||||
for (unsigned i = 0; i < SC_NBINS; i++) {
|
||||
bin_info_t *bin_info = &bin_infos[i];
|
||||
sc_t *sc = &sc_data->sc[i];
|
||||
@@ -21,19 +19,49 @@ bin_infos_init(sc_data_t *sc_data, bin_info_t bin_infos[SC_NBINS]) {
|
||||
bin_info->slab_size = (sc->pgs << LG_PAGE);
|
||||
bin_info->nregs =
|
||||
(uint32_t)(bin_info->slab_size / bin_info->reg_size);
|
||||
bin_info->n_shards = (i < opt_bin_shard_maxszind) ? opt_n_bin_shards : 1;
|
||||
bin_info->n_shards = bin_shard_sizes[i];
|
||||
bitmap_info_t bitmap_info = BITMAP_INFO_INITIALIZER(
|
||||
bin_info->nregs);
|
||||
bin_info->bitmap_info = bitmap_info;
|
||||
}
|
||||
}
|
||||
|
||||
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_boot(sc_data_t *sc_data) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
bin_boot(sc_data_t *sc_data, unsigned bin_shard_sizes[SC_NBINS]) {
|
||||
assert(sc_data->initialized);
|
||||
opt_bin_shard_maxszind = OPT_BIN_SHARD_MAXSZIND;
|
||||
opt_n_bin_shards = OPT_N_BIN_SHARDS;
|
||||
bin_infos_init(sc_data, bin_infos);
|
||||
bin_infos_init(sc_data, bin_shard_sizes, bin_infos);
|
||||
}
|
||||
|
||||
bool
|
||||
|
||||
Reference in New Issue
Block a user