Issue a warning upon directly accessing an arena's bins
An arena's bins should normally be accessed via the `arena_get_bin` function, which properly takes into account bin-shards. To ensure that we don't accidentally commit code which incorrectly accesses the bins directly, we mark the field with `__attribute__((deprecated))` with an appropriate warning message, and suppress the warning in the few places where directly accessing the bins is allowed.
This commit is contained in:
parent
120abd703a
commit
424dd61d57
@ -99,7 +99,9 @@ struct arena_s {
|
|||||||
* The arena is allocated alongside its bins; really this is a
|
* The arena is allocated alongside its bins; really this is a
|
||||||
* dynamically sized array determined by the binshard settings.
|
* dynamically sized array determined by the binshard settings.
|
||||||
*/
|
*/
|
||||||
bin_t bins[0];
|
JEMALLOC_WARN_ON_USAGE("Do not use this field directly. "
|
||||||
|
"Use `arena_get_bin` instead.")
|
||||||
|
bin_t all_bins[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* JEMALLOC_INTERNAL_ARENA_STRUCTS_H */
|
#endif /* JEMALLOC_INTERNAL_ARENA_STRUCTS_H */
|
||||||
|
20
src/arena.c
20
src/arena.c
@ -1700,7 +1700,9 @@ arena_new(tsdn_t *tsdn, unsigned ind, const arena_config_t *config) {
|
|||||||
/* Initialize bins. */
|
/* Initialize bins. */
|
||||||
atomic_store_u(&arena->binshard_next, 0, ATOMIC_RELEASE);
|
atomic_store_u(&arena->binshard_next, 0, ATOMIC_RELEASE);
|
||||||
for (i = 0; i < nbins_total; i++) {
|
for (i = 0; i < nbins_total; i++) {
|
||||||
bool err = bin_init(&arena->bins[i]);
|
JEMALLOC_SUPPRESS_WARN_ON_USAGE(
|
||||||
|
bool err = bin_init(&arena->all_bins[i]);
|
||||||
|
)
|
||||||
if (err) {
|
if (err) {
|
||||||
goto label_error;
|
goto label_error;
|
||||||
}
|
}
|
||||||
@ -1849,7 +1851,9 @@ arena_boot(sc_data_t *sc_data, base_t *base, bool hpa) {
|
|||||||
(1U << sc->lg_base) + (sc->ndelta << sc->lg_delta));
|
(1U << sc->lg_base) + (sc->ndelta << sc->lg_delta));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t cur_offset = (uint32_t)offsetof(arena_t, bins);
|
JEMALLOC_SUPPRESS_WARN_ON_USAGE(
|
||||||
|
uint32_t cur_offset = (uint32_t)offsetof(arena_t, all_bins);
|
||||||
|
)
|
||||||
for (szind_t i = 0; i < SC_NBINS; i++) {
|
for (szind_t i = 0; i < SC_NBINS; i++) {
|
||||||
arena_bin_offsets[i] = cur_offset;
|
arena_bin_offsets[i] = cur_offset;
|
||||||
nbins_total += bin_infos[i].n_shards;
|
nbins_total += bin_infos[i].n_shards;
|
||||||
@ -1904,14 +1908,18 @@ arena_prefork7(tsdn_t *tsdn, arena_t *arena) {
|
|||||||
void
|
void
|
||||||
arena_prefork8(tsdn_t *tsdn, arena_t *arena) {
|
arena_prefork8(tsdn_t *tsdn, arena_t *arena) {
|
||||||
for (unsigned i = 0; i < nbins_total; i++) {
|
for (unsigned i = 0; i < nbins_total; i++) {
|
||||||
bin_prefork(tsdn, &arena->bins[i]);
|
JEMALLOC_SUPPRESS_WARN_ON_USAGE(
|
||||||
|
bin_prefork(tsdn, &arena->all_bins[i]);
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
arena_postfork_parent(tsdn_t *tsdn, arena_t *arena) {
|
arena_postfork_parent(tsdn_t *tsdn, arena_t *arena) {
|
||||||
for (unsigned i = 0; i < nbins_total; i++) {
|
for (unsigned i = 0; i < nbins_total; i++) {
|
||||||
bin_postfork_parent(tsdn, &arena->bins[i]);
|
JEMALLOC_SUPPRESS_WARN_ON_USAGE(
|
||||||
|
bin_postfork_parent(tsdn, &arena->all_bins[i]);
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
malloc_mutex_postfork_parent(tsdn, &arena->large_mtx);
|
malloc_mutex_postfork_parent(tsdn, &arena->large_mtx);
|
||||||
@ -1949,7 +1957,9 @@ arena_postfork_child(tsdn_t *tsdn, arena_t *arena) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned i = 0; i < nbins_total; i++) {
|
for (unsigned i = 0; i < nbins_total; i++) {
|
||||||
bin_postfork_child(tsdn, &arena->bins[i]);
|
JEMALLOC_SUPPRESS_WARN_ON_USAGE(
|
||||||
|
bin_postfork_child(tsdn, &arena->all_bins[i]);
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
malloc_mutex_postfork_child(tsdn, &arena->large_mtx);
|
malloc_mutex_postfork_child(tsdn, &arena->large_mtx);
|
||||||
|
Loading…
Reference in New Issue
Block a user