SC: Add page customization functionality.
This commit is contained in:
parent
017dca198c
commit
a7f68aed3e
@ -204,6 +204,7 @@ TESTS_UNIT := \
|
||||
$(srcroot)test/unit/rtree.c \
|
||||
$(srcroot)test/unit/seq.c \
|
||||
$(srcroot)test/unit/SFMT.c \
|
||||
$(srcroot)test/unit/sc.c \
|
||||
$(srcroot)test/unit/size_classes.c \
|
||||
$(srcroot)test/unit/slab.c \
|
||||
$(srcroot)test/unit/smoothstep.c \
|
||||
|
@ -297,6 +297,12 @@ struct sc_data_s {
|
||||
|
||||
extern sc_data_t sc_data_global;
|
||||
void sc_data_init(sc_data_t *data);
|
||||
/*
|
||||
* Updates slab sizes in [begin, end] to be pgs pages in length, if possible.
|
||||
* Otherwise, does its best to accomodate the request.
|
||||
*/
|
||||
void sc_data_update_slab_size(sc_data_t *data, size_t begin, size_t end,
|
||||
int pgs);
|
||||
void sc_boot();
|
||||
|
||||
#endif /* JEMALLOC_INTERNAL_SC_H */
|
||||
|
42
src/sc.c
42
src/sc.c
@ -2,6 +2,8 @@
|
||||
|
||||
#include "jemalloc/internal/assert.h"
|
||||
#include "jemalloc/internal/bit_util.h"
|
||||
#include "jemalloc/internal/bitmap.h"
|
||||
#include "jemalloc/internal/pages.h"
|
||||
#include "jemalloc/internal/sc.h"
|
||||
|
||||
/*
|
||||
@ -240,6 +242,46 @@ sc_data_init(sc_data_t *sc_data) {
|
||||
sc_data->initialized = true;
|
||||
}
|
||||
|
||||
static void
|
||||
sc_data_update_sc_slab_size(sc_t *sc, size_t reg_size, size_t pgs_guess) {
|
||||
size_t min_pgs = reg_size / PAGE;
|
||||
if (reg_size % PAGE != 0) {
|
||||
min_pgs++;
|
||||
}
|
||||
/*
|
||||
* BITMAP_MAXBITS is actually determined by putting the smallest
|
||||
* possible size-class on one page, so this can never be 0.
|
||||
*/
|
||||
size_t max_pgs = BITMAP_MAXBITS * reg_size / PAGE;
|
||||
|
||||
assert(min_pgs <= max_pgs);
|
||||
assert(min_pgs > 0);
|
||||
assert(max_pgs >= 1);
|
||||
if (pgs_guess < min_pgs) {
|
||||
sc->pgs = (int)min_pgs;
|
||||
} else if (pgs_guess > max_pgs) {
|
||||
sc->pgs = (int)max_pgs;
|
||||
} else {
|
||||
sc->pgs = (int)pgs_guess;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
sc_data_update_slab_size(sc_data_t *data, size_t begin, size_t end, int pgs) {
|
||||
assert(data->initialized);
|
||||
for (int i = 0; i < data->nsizes; i++) {
|
||||
sc_t *sc = &data->sc[i];
|
||||
if (!sc->bin) {
|
||||
break;
|
||||
}
|
||||
size_t reg_size = reg_size_compute(sc->lg_base, sc->lg_delta,
|
||||
sc->ndelta);
|
||||
if (begin <= reg_size && reg_size <= end) {
|
||||
sc_data_update_sc_slab_size(sc, reg_size, pgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
sc_boot() {
|
||||
sc_data_init(&sc_data_global);
|
||||
|
33
test/unit/sc.c
Normal file
33
test/unit/sc.c
Normal file
@ -0,0 +1,33 @@
|
||||
#include "test/jemalloc_test.h"
|
||||
|
||||
TEST_BEGIN(test_update_slab_size) {
|
||||
sc_data_t data;
|
||||
memset(&data, 0, sizeof(data));
|
||||
sc_data_init(&data);
|
||||
sc_t *tiny = &data.sc[0];
|
||||
size_t tiny_size = (ZU(1) << tiny->lg_base)
|
||||
+ (ZU(tiny->ndelta) << tiny->lg_delta);
|
||||
size_t pgs_too_big = (tiny_size * BITMAP_MAXBITS + PAGE - 1) / PAGE + 1;
|
||||
sc_data_update_slab_size(&data, tiny_size, tiny_size, (int)pgs_too_big);
|
||||
assert_zu_lt((size_t)tiny->pgs, pgs_too_big, "Allowed excessive pages");
|
||||
|
||||
sc_data_update_slab_size(&data, 1, 10 * PAGE, 1);
|
||||
for (int i = 0; i < data.nbins; i++) {
|
||||
sc_t *sc = &data.sc[i];
|
||||
size_t reg_size = (ZU(1) << sc->lg_base)
|
||||
+ (ZU(sc->ndelta) << sc->lg_delta);
|
||||
if (reg_size <= PAGE) {
|
||||
assert_d_eq(sc->pgs, 1, "Ignored valid page size hint");
|
||||
} else {
|
||||
assert_d_gt(sc->pgs, 1,
|
||||
"Allowed invalid page size hint");
|
||||
}
|
||||
}
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_update_slab_size);
|
||||
}
|
Loading…
Reference in New Issue
Block a user