Skip to content

Commit 0d9abff

Browse files
committed
perf improvements in retirement check, clean up comments
1 parent 870c49f commit 0d9abff

4 files changed

Lines changed: 9 additions & 5 deletions

File tree

include/conf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
/* Zones can be retired after a certain number of
4747
* allocations. This is computed as the total count
48-
* of chunks the zone can handle multiplied by this
48+
* of chunks the zone can hold multiplied by this
4949
* value. The zone is replaced at that point if all
5050
* of its current chunks are free */
5151
#define ZONE_ALLOC_RETIRE 32

include/iso_alloc_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ typedef struct {
450450
uint16_t zones_used;
451451
void *guard_below;
452452
void *guard_above;
453+
uint32_t zone_retirement_shf;
453454
uintptr_t *chunk_quarantine;
454455
size_t chunk_quarantine_count;
455456
/* Zones are linked by their next_sz_index member which

src/iso_alloc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ INTERNAL_HIDDEN void iso_alloc_initialize_global_root(void) {
177177
* result in a soft page fault */
178178
MLOCK(&_root, sizeof(iso_alloc_root));
179179

180+
_root->zone_retirement_shf = _log2(ZONE_ALLOC_RETIRE);
180181
_root->zones_size = (MAX_ZONES * sizeof(iso_alloc_zone_t));
181182
_root->zones_size += (g_page_size * 2);
182183
_root->zones_size = ROUND_UP_PAGE(_root->zones_size);
@@ -779,8 +780,7 @@ INTERNAL_HIDDEN bit_slot_t iso_scan_zone_free_slot_slow(iso_alloc_zone_t *zone)
779780
bit_slot_t bts = bm[i];
780781

781782
for(int64_t j = 0; j < BITS_PER_QWORD; j += BITS_PER_CHUNK) {
782-
/* We can easily check if every bitslot represented by
783-
* this qword is allocated with or without canaries */
783+
/* Check each bit to see if its available */
784784
if((GET_BIT(bts, j)) == 0) {
785785
return ((i << BITS_PER_QWORD_SHIFT) + j);
786786
}
@@ -1619,7 +1619,7 @@ INTERNAL_HIDDEN bool _is_zone_retired(iso_alloc_zone_t *zone) {
16191619
* and has allocated and freed more than ZONE_ALLOC_RETIRE
16201620
* chunks in its lifetime then we destroy and replace it with
16211621
* a new zone */
1622-
if(UNLIKELY(zone->af_count == 0 && zone->alloc_count > (zone->chunk_count * ZONE_ALLOC_RETIRE))) {
1622+
if(UNLIKELY(zone->af_count == 0 && zone->alloc_count > (zone->chunk_count << _root->zone_retirement_shf))) {
16231623
if(zone->internal == true && zone->chunk_size < (MAX_DEFAULT_ZONE_SZ * 2)) {
16241624
return true;
16251625
}

src/iso_alloc_mem_tags.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ INTERNAL_HIDDEN void *_untag_ptr(void *p, iso_alloc_zone_t *zone) {
5151

5252
INTERNAL_HIDDEN bool _refresh_zone_mem_tags(iso_alloc_zone_t *zone) {
5353
#if MEMORY_TAGGING
54-
if(UNLIKELY(zone->af_count == 0 && zone->alloc_count > (zone->chunk_count * ZONE_ALLOC_RETIRE)) >> 2) {
54+
/* This implements a similar policy to zone retirement.
55+
* The only difference is that we refresh all tags at
56+
* %25 of the configured zone retirement age */
57+
if(UNLIKELY(zone->af_count == 0 && zone->alloc_count > (zone->chunk_count << _root->zone_retirement_shf)) >> 2) {
5558
size_t s = ROUND_UP_PAGE(zone->chunk_count * MEM_TAG_SIZE);
5659
uint64_t *_mtp = (zone->user_pages_start - g_page_size - s);
5760

0 commit comments

Comments
 (0)