mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-05-16 09:56:22 +03:00
SEC: Allow arbitrarily many shards, cached sizes.
This commit is contained in:
parent
11beab38bc
commit
36c6bfb963
7 changed files with 59 additions and 41 deletions
|
|
@ -1565,7 +1565,7 @@ arena_new(tsdn_t *tsdn, unsigned ind, extent_hooks_t *extent_hooks) {
|
|||
* so arena_hpa_global is not yet initialized.
|
||||
*/
|
||||
if (opt_hpa && ehooks_are_default(base_ehooks_get(base)) && ind != 0) {
|
||||
if (pa_shard_enable_hpa(&arena->pa_shard, &opt_hpa_opts,
|
||||
if (pa_shard_enable_hpa(tsdn, &arena->pa_shard, &opt_hpa_opts,
|
||||
&opt_hpa_sec_opts)) {
|
||||
goto label_error;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1781,7 +1781,7 @@ malloc_init_hard_a0_locked() {
|
|||
opt_hpa = false;
|
||||
}
|
||||
} else if (opt_hpa) {
|
||||
if (pa_shard_enable_hpa(&a0->pa_shard, &opt_hpa_opts,
|
||||
if (pa_shard_enable_hpa(TSDN_NULL, &a0->pa_shard, &opt_hpa_opts,
|
||||
&opt_hpa_sec_opts)) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
7
src/pa.c
7
src/pa.c
|
|
@ -49,13 +49,14 @@ pa_shard_init(tsdn_t *tsdn, pa_shard_t *shard, emap_t *emap, base_t *base,
|
|||
}
|
||||
|
||||
bool
|
||||
pa_shard_enable_hpa(pa_shard_t *shard, const hpa_shard_opts_t *hpa_opts,
|
||||
const sec_opts_t *hpa_sec_opts) {
|
||||
pa_shard_enable_hpa(tsdn_t *tsdn, pa_shard_t *shard,
|
||||
const hpa_shard_opts_t *hpa_opts, const sec_opts_t *hpa_sec_opts) {
|
||||
if (hpa_shard_init(&shard->hpa_shard, shard->emap, shard->base,
|
||||
&shard->edata_cache, shard->ind, hpa_opts)) {
|
||||
return true;
|
||||
}
|
||||
if (sec_init(&shard->hpa_sec, &shard->hpa_shard.pai, hpa_sec_opts)) {
|
||||
if (sec_init(tsdn, &shard->hpa_sec, shard->base, &shard->hpa_shard.pai,
|
||||
hpa_sec_opts)) {
|
||||
return true;
|
||||
}
|
||||
shard->ever_used_hpa = true;
|
||||
|
|
|
|||
50
src/sec.c
50
src/sec.c
|
|
@ -19,35 +19,55 @@ sec_bin_init(sec_bin_t *bin) {
|
|||
}
|
||||
|
||||
bool
|
||||
sec_init(sec_t *sec, pai_t *fallback, const sec_opts_t *opts) {
|
||||
size_t nshards_clipped = opts->nshards;
|
||||
if (nshards_clipped > SEC_NSHARDS_MAX) {
|
||||
nshards_clipped = SEC_NSHARDS_MAX;
|
||||
sec_init(tsdn_t *tsdn, sec_t *sec, base_t *base, pai_t *fallback,
|
||||
const sec_opts_t *opts) {
|
||||
size_t max_alloc = opts->max_alloc & PAGE_MASK;
|
||||
pszind_t npsizes = sz_psz2ind(max_alloc);
|
||||
if (sz_pind2sz(npsizes) > opts->max_alloc) {
|
||||
npsizes--;
|
||||
}
|
||||
for (size_t i = 0; i < nshards_clipped; i++) {
|
||||
sec_shard_t *shard = &sec->shards[i];
|
||||
size_t sz_shards = opts->nshards * sizeof(sec_shard_t);
|
||||
size_t sz_bins = opts->nshards * (size_t)npsizes * sizeof(sec_bin_t);
|
||||
size_t sz_alloc = sz_shards + sz_bins;
|
||||
void *dynalloc = base_alloc(tsdn, base, sz_alloc, CACHELINE);
|
||||
if (dynalloc == NULL) {
|
||||
return true;
|
||||
}
|
||||
sec_shard_t *shard_cur = (sec_shard_t *)dynalloc;
|
||||
sec->shards = shard_cur;
|
||||
sec_bin_t *bin_cur = (sec_bin_t *)&shard_cur[opts->nshards];
|
||||
/* Just for asserts, below. */
|
||||
sec_bin_t *bin_start = bin_cur;
|
||||
|
||||
for (size_t i = 0; i < opts->nshards; i++) {
|
||||
sec_shard_t *shard = shard_cur;
|
||||
shard_cur++;
|
||||
bool err = malloc_mutex_init(&shard->mtx, "sec_shard",
|
||||
WITNESS_RANK_SEC_SHARD, malloc_mutex_rank_exclusive);
|
||||
if (err) {
|
||||
return true;
|
||||
}
|
||||
shard->enabled = true;
|
||||
for (pszind_t j = 0; j < SEC_NPSIZES; j++) {
|
||||
shard->bins = bin_cur;
|
||||
for (pszind_t j = 0; j < npsizes; j++) {
|
||||
sec_bin_init(&shard->bins[j]);
|
||||
bin_cur++;
|
||||
}
|
||||
shard->bytes_cur = 0;
|
||||
shard->to_flush_next = 0;
|
||||
}
|
||||
/*
|
||||
* Should have exactly matched the bin_start to the first unused byte
|
||||
* after the shards.
|
||||
*/
|
||||
assert((void *)shard_cur == (void *)bin_start);
|
||||
/* And the last bin to use up the last bytes of the allocation. */
|
||||
assert((char *)bin_cur == ((char *)dynalloc + sz_alloc));
|
||||
sec->fallback = fallback;
|
||||
|
||||
size_t max_alloc_clipped = opts->max_alloc;
|
||||
if (max_alloc_clipped > sz_pind2sz(SEC_NPSIZES - 1)) {
|
||||
max_alloc_clipped = sz_pind2sz(SEC_NPSIZES - 1);
|
||||
}
|
||||
|
||||
sec->opts = *opts;
|
||||
sec->opts.nshards = nshards_clipped;
|
||||
sec->opts.max_alloc = max_alloc_clipped;
|
||||
sec->npsizes = npsizes;
|
||||
|
||||
/*
|
||||
* Initialize these last so that an improper use of an SEC whose
|
||||
|
|
@ -106,7 +126,7 @@ sec_flush_some_and_unlock(tsdn_t *tsdn, sec_t *sec, sec_shard_t *shard) {
|
|||
|
||||
/* Update our victim-picking state. */
|
||||
shard->to_flush_next++;
|
||||
if (shard->to_flush_next == SEC_NPSIZES) {
|
||||
if (shard->to_flush_next == sec->npsizes) {
|
||||
shard->to_flush_next = 0;
|
||||
}
|
||||
|
||||
|
|
@ -249,7 +269,7 @@ sec_flush_all_locked(tsdn_t *tsdn, sec_t *sec, sec_shard_t *shard) {
|
|||
shard->bytes_cur = 0;
|
||||
edata_list_active_t to_flush;
|
||||
edata_list_active_init(&to_flush);
|
||||
for (pszind_t i = 0; i < SEC_NPSIZES; i++) {
|
||||
for (pszind_t i = 0; i < sec->npsizes; i++) {
|
||||
sec_bin_t *bin = &shard->bins[i];
|
||||
bin->bytes_cur = 0;
|
||||
edata_list_active_concat(&to_flush, &bin->freelist);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue