mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-04-14 22:51:50 +03:00
Refactor prng to not use 64-bit atomics on 32-bit platforms.
This resolves #495.
This commit is contained in:
parent
a4e83e8593
commit
5d6cb6eb66
7 changed files with 365 additions and 33 deletions
|
|
@ -1199,7 +1199,7 @@ arena_decay_deadline_init(arena_t *arena)
|
|||
if (arena->decay.time > 0) {
|
||||
nstime_t jitter;
|
||||
|
||||
nstime_init(&jitter, prng_range(&arena->decay.jitter_state,
|
||||
nstime_init(&jitter, prng_range_u64(&arena->decay.jitter_state,
|
||||
nstime_ns(&arena->decay.interval)));
|
||||
nstime_add(&arena->decay.deadline, &jitter);
|
||||
}
|
||||
|
|
@ -2565,7 +2565,8 @@ arena_malloc_large(tsdn_t *tsdn, arena_t *arena, szind_t binind, bool zero)
|
|||
* that is a multiple of the cacheline size, e.g. [0 .. 63) * 64
|
||||
* for 4 KiB pages and 64-byte cachelines.
|
||||
*/
|
||||
r = prng_lg_range(&arena->offset_state, LG_PAGE - LG_CACHELINE);
|
||||
r = prng_lg_range_zu(&arena->offset_state, LG_PAGE -
|
||||
LG_CACHELINE, false);
|
||||
random_offset = ((uintptr_t)r) << LG_CACHELINE;
|
||||
} else
|
||||
random_offset = 0;
|
||||
|
|
@ -3503,7 +3504,7 @@ arena_new(tsdn_t *tsdn, unsigned ind)
|
|||
* deterministic seed.
|
||||
*/
|
||||
arena->offset_state = config_debug ? ind :
|
||||
(uint64_t)(uintptr_t)arena;
|
||||
(size_t)(uintptr_t)arena;
|
||||
}
|
||||
|
||||
arena->dss_prec = chunk_dss_prec_get();
|
||||
|
|
|
|||
|
|
@ -99,7 +99,8 @@ ckh_try_bucket_insert(ckh_t *ckh, size_t bucket, const void *key,
|
|||
* Cycle through the cells in the bucket, starting at a random position.
|
||||
* The randomness avoids worst-case search overhead as buckets fill up.
|
||||
*/
|
||||
offset = (unsigned)prng_lg_range(&ckh->prng_state, LG_CKH_BUCKET_CELLS);
|
||||
offset = (unsigned)prng_lg_range_u64(&ckh->prng_state,
|
||||
LG_CKH_BUCKET_CELLS);
|
||||
for (i = 0; i < (ZU(1) << LG_CKH_BUCKET_CELLS); i++) {
|
||||
cell = &ckh->tab[(bucket << LG_CKH_BUCKET_CELLS) +
|
||||
((i + offset) & ((ZU(1) << LG_CKH_BUCKET_CELLS) - 1))];
|
||||
|
|
@ -141,7 +142,7 @@ ckh_evict_reloc_insert(ckh_t *ckh, size_t argbucket, void const **argkey,
|
|||
* were an item for which both hashes indicated the same
|
||||
* bucket.
|
||||
*/
|
||||
i = (unsigned)prng_lg_range(&ckh->prng_state,
|
||||
i = (unsigned)prng_lg_range_u64(&ckh->prng_state,
|
||||
LG_CKH_BUCKET_CELLS);
|
||||
cell = &ckh->tab[(bucket << LG_CKH_BUCKET_CELLS) + i];
|
||||
assert(cell->key != NULL);
|
||||
|
|
|
|||
|
|
@ -874,7 +874,7 @@ prof_sample_threshold_update(prof_tdata_t *tdata)
|
|||
* pp 500
|
||||
* (http://luc.devroye.org/rnbookindex.html)
|
||||
*/
|
||||
r = prng_lg_range(&tdata->prng_state, 53);
|
||||
r = prng_lg_range_u64(&tdata->prng_state, 53);
|
||||
u = (double)r * (1.0/9007199254740992.0L);
|
||||
tdata->bytes_until_sample = (uint64_t)(log(u) /
|
||||
log(1.0 - (1.0 / (double)((uint64_t)1U << lg_prof_sample))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue