2017-05-31 01:45:37 +08:00
|
|
|
#include "jemalloc/internal/jemalloc_preamble.h"
|
|
|
|
#include "jemalloc/internal/sz.h"
|
|
|
|
|
|
|
|
JEMALLOC_ALIGNED(CACHELINE)
|
2018-07-20 08:08:10 +08:00
|
|
|
size_t sz_pind2sz_tab[SC_NPSIZES+1];
|
2017-12-15 04:46:39 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
sz_boot_pind2sz_tab(const sc_data_t *sc_data) {
|
|
|
|
int pind = 0;
|
|
|
|
for (unsigned i = 0; i < SC_NSIZES; i++) {
|
|
|
|
const sc_t *sc = &sc_data->sc[i];
|
|
|
|
if (sc->psz) {
|
|
|
|
sz_pind2sz_tab[pind] = (ZU(1) << sc->lg_base)
|
|
|
|
+ (ZU(sc->ndelta) << sc->lg_delta);
|
|
|
|
pind++;
|
|
|
|
}
|
|
|
|
}
|
2018-07-20 08:08:10 +08:00
|
|
|
for (int i = pind; i <= (int)SC_NPSIZES; i++) {
|
|
|
|
sz_pind2sz_tab[pind] = sc_data->large_maxclass + PAGE;
|
|
|
|
}
|
2017-12-15 04:46:39 +08:00
|
|
|
}
|
2017-05-31 01:45:37 +08:00
|
|
|
|
|
|
|
JEMALLOC_ALIGNED(CACHELINE)
|
2017-12-15 04:46:39 +08:00
|
|
|
size_t sz_index2size_tab[SC_NSIZES];
|
|
|
|
|
|
|
|
static void
|
|
|
|
sz_boot_index2size_tab(const sc_data_t *sc_data) {
|
|
|
|
for (unsigned i = 0; i < SC_NSIZES; i++) {
|
|
|
|
const sc_t *sc = &sc_data->sc[i];
|
|
|
|
sz_index2size_tab[i] = (ZU(1) << sc->lg_base)
|
|
|
|
+ (ZU(sc->ndelta) << (sc->lg_delta));
|
|
|
|
}
|
|
|
|
}
|
2017-05-31 01:45:37 +08:00
|
|
|
|
2017-12-15 04:46:39 +08:00
|
|
|
/*
|
|
|
|
* To keep this table small, we divide sizes by the tiny min size, which gives
|
|
|
|
* the smallest interval for which the result can change.
|
|
|
|
*/
|
2017-05-31 01:45:37 +08:00
|
|
|
JEMALLOC_ALIGNED(CACHELINE)
|
2018-10-09 01:11:04 +08:00
|
|
|
uint8_t sz_size2index_tab[(SC_LOOKUP_MAXCLASS >> SC_LG_TINY_MIN) + 1];
|
2017-12-15 04:46:39 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
sz_boot_size2index_tab(const sc_data_t *sc_data) {
|
2018-10-09 01:11:04 +08:00
|
|
|
size_t dst_max = (SC_LOOKUP_MAXCLASS >> SC_LG_TINY_MIN) + 1;
|
2017-12-15 04:46:39 +08:00
|
|
|
size_t dst_ind = 0;
|
|
|
|
for (unsigned sc_ind = 0; sc_ind < SC_NSIZES && dst_ind < dst_max;
|
|
|
|
sc_ind++) {
|
|
|
|
const sc_t *sc = &sc_data->sc[sc_ind];
|
|
|
|
size_t sz = (ZU(1) << sc->lg_base)
|
|
|
|
+ (ZU(sc->ndelta) << sc->lg_delta);
|
2018-10-09 01:11:04 +08:00
|
|
|
size_t max_ind = ((sz + (ZU(1) << SC_LG_TINY_MIN) - 1)
|
|
|
|
>> SC_LG_TINY_MIN);
|
2017-12-15 04:46:39 +08:00
|
|
|
for (; dst_ind <= max_ind && dst_ind < dst_max; dst_ind++) {
|
|
|
|
sz_size2index_tab[dst_ind] = sc_ind;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sz_boot(const sc_data_t *sc_data) {
|
|
|
|
sz_boot_pind2sz_tab(sc_data);
|
|
|
|
sz_boot_index2size_tab(sc_data);
|
|
|
|
sz_boot_size2index_tab(sc_data);
|
|
|
|
}
|