PA: have expand take sizes instead of new usize.

This avoids involving usize, which makes some of the stats modifications more
intuitively correct.
This commit is contained in:
David Goldblatt 2020-03-10 17:27:31 -07:00 committed by David Goldblatt
parent 5bcc2c2ab9
commit 74958567a4
3 changed files with 16 additions and 13 deletions

View File

@ -122,8 +122,7 @@ size_t pa_shard_extent_sn_next(pa_shard_t *shard);
edata_t *pa_alloc(tsdn_t *tsdn, pa_shard_t *shard, size_t size, edata_t *pa_alloc(tsdn_t *tsdn, pa_shard_t *shard, size_t size,
size_t alignment, bool slab, szind_t szind, bool *zero, size_t *mapped_add); size_t alignment, bool slab, szind_t szind, bool *zero, size_t *mapped_add);
/* Returns true on error, in which case nothing changed. */ /* Returns true on error, in which case nothing changed. */
bool bool pa_expand(tsdn_t *tsdn, pa_shard_t *shard, edata_t *edata, size_t old_size,
pa_expand(tsdn_t *tsdn, pa_shard_t *shard, edata_t *edata, size_t new_usize, size_t new_size, szind_t szind, bool slab, bool *zero, size_t *mapped_add);
szind_t szind, bool slab, bool *zero, size_t *mapped_add);
#endif /* JEMALLOC_INTERNAL_PA_H */ #endif /* JEMALLOC_INTERNAL_PA_H */

View File

@ -106,7 +106,9 @@ large_ralloc_no_move_expand(tsdn_t *tsdn, edata_t *edata, size_t usize,
zero = true; zero = true;
} }
size_t old_size = edata_size_get(edata);
size_t old_usize = edata_usize_get(edata); size_t old_usize = edata_usize_get(edata);
size_t new_size = usize + sz_large_pad;
/* /*
* Copy zero into is_zeroed_trail and pass the copy when allocating the * Copy zero into is_zeroed_trail and pass the copy when allocating the
@ -116,7 +118,7 @@ large_ralloc_no_move_expand(tsdn_t *tsdn, edata_t *edata, size_t usize,
bool is_zeroed_trail = zero; bool is_zeroed_trail = zero;
size_t mapped_add; size_t mapped_add;
szind_t szind = sz_size2index(usize); szind_t szind = sz_size2index(usize);
bool err = pa_expand(tsdn, &arena->pa_shard, edata, usize, bool err = pa_expand(tsdn, &arena->pa_shard, edata, old_size, new_size,
szind, /* slab */ false, &is_zeroed_trail, &mapped_add); szind, /* slab */ false, &is_zeroed_trail, &mapped_add);
if (err) { if (err) {
return true; return true;

View File

@ -96,29 +96,31 @@ pa_alloc(tsdn_t *tsdn, pa_shard_t *shard, size_t size, size_t alignment,
} }
bool bool
pa_expand(tsdn_t *tsdn, pa_shard_t *shard, edata_t *edata, size_t new_usize, pa_expand(tsdn_t *tsdn, pa_shard_t *shard, edata_t *edata, size_t old_size,
szind_t szind, bool slab, bool *zero, size_t *mapped_add) { size_t new_size, szind_t szind, bool slab, bool *zero, size_t *mapped_add) {
assert(new_size > old_size);
ehooks_t *ehooks = pa_shard_ehooks_get(shard); ehooks_t *ehooks = pa_shard_ehooks_get(shard);
size_t old_usize = edata_usize_get(edata);
size_t trail_size = new_usize - old_usize;
void *trail_begin = edata_past_get(edata); void *trail_begin = edata_past_get(edata);
size_t expand_amount = new_size - old_size;
*mapped_add = 0; *mapped_add = 0;
if (ehooks_merge_will_fail(ehooks)) { if (ehooks_merge_will_fail(ehooks)) {
return true; return true;
} }
edata_t *trail = ecache_alloc(tsdn, shard, ehooks, &shard->ecache_dirty, edata_t *trail = ecache_alloc(tsdn, shard, ehooks, &shard->ecache_dirty,
trail_begin, trail_size, PAGE, /* slab */ false, SC_NSIZES, zero); trail_begin, expand_amount, PAGE, /* slab */ false, SC_NSIZES,
zero);
if (trail == NULL) { if (trail == NULL) {
trail = ecache_alloc(tsdn, shard, ehooks, &shard->ecache_muzzy, trail = ecache_alloc(tsdn, shard, ehooks, &shard->ecache_muzzy,
trail_begin, trail_size, PAGE, /* slab */ false, SC_NSIZES, trail_begin, expand_amount, PAGE, /* slab */ false,
zero); SC_NSIZES, zero);
} }
if (trail == NULL) { if (trail == NULL) {
trail = ecache_alloc_grow(tsdn, shard, ehooks, trail = ecache_alloc_grow(tsdn, shard, ehooks,
&shard->ecache_retained, trail_begin, trail_size, PAGE, &shard->ecache_retained, trail_begin, expand_amount, PAGE,
/* slab */ false, SC_NSIZES, zero); /* slab */ false, SC_NSIZES, zero);
*mapped_add = trail_size; *mapped_add = expand_amount;
} }
if (trail == NULL) { if (trail == NULL) {
*mapped_add = 0; *mapped_add = 0;