Skip to content

Commit 35c9e66

Browse files
committed
perf improvements
1 parent 9e97b16 commit 35c9e66

2 files changed

Lines changed: 21 additions & 16 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Additional information about the allocator and some of its design choices can be
1212

1313
## Design
1414

15-
You can think of Isolation Alloc as a [region based](https://en.wikipedia.org/wiki/Region-based_memory_management) memory allocator. If you are familiar with the implementation of arenas in other allocators then the concepts here will be familiar to you.
15+
At a high level IsoAlloc creates zones which are used to manage regions of memory that hold individual allocations of a specific size. If you are familiar with the implementation of arenas in other heap allocators then the concepts here will be familiar to you.
1616

1717
![Design of isoalloc schema](/misc/isoalloc_design.svg)
1818

src/iso_alloc.c

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,22 @@ INTERNAL_HIDDEN iso_alloc_zone_t *find_suitable_zone(size_t size) {
866866
size = ALIGN_SZ_UP(size);
867867
}
868868

869+
size_t orig_size = size;
870+
871+
/* If we are dealing with very small zones then
872+
* find the first zone in the lookup table that
873+
* could possibly allocate this chunk. We only
874+
* do this for sizes up to 256 because we don't
875+
* want 1) to waste memory and 2) weaken our
876+
* isolation primitives */
877+
while(size <= ZONE_256) {
878+
if(_root->zone_lookup_table[size] == 0) {
879+
size = next_pow2(size);
880+
} else {
881+
break;
882+
}
883+
}
884+
869885
/* Fast path via lookup table */
870886
if(_root->zone_lookup_table[size] != 0) {
871887
i = _root->zone_lookup_table[size];
@@ -905,9 +921,9 @@ INTERNAL_HIDDEN iso_alloc_zone_t *find_suitable_zone(size_t size) {
905921
* slower iterative approach is used. The longer a
906922
* program runs the more likely we will fail this
907923
* fast path as default zones may fill up */
908-
if(size >= ZONE_512 && size <= MAX_DEFAULT_ZONE_SZ) {
924+
if(orig_size >= ZONE_512 && orig_size <= MAX_DEFAULT_ZONE_SZ) {
909925
i = DEFAULT_ZONE_COUNT >> 1;
910-
} else if(size > MAX_DEFAULT_ZONE_SZ) {
926+
} else if(orig_size > MAX_DEFAULT_ZONE_SZ) {
911927
i = DEFAULT_ZONE_COUNT;
912928
}
913929
#else
@@ -917,16 +933,11 @@ INTERNAL_HIDDEN iso_alloc_zone_t *find_suitable_zone(size_t size) {
917933
for(; i < _root->zones_used; i++) {
918934
zone = &_root->zones[i];
919935

920-
if(zone->chunk_size < size || zone->internal == false) {
936+
if(zone->chunk_size < orig_size || zone->internal == false) {
921937
continue;
922938
}
923939

924-
/* Don't waste memory, enforce spatial separation by size */
925-
if(zone->chunk_size >= ZONE_1024 && size <= ZONE_128) {
926-
continue;
927-
}
928-
929-
if(is_zone_usable(zone, size) != NULL) {
940+
if(is_zone_usable(zone, orig_size) != NULL) {
930941
return zone;
931942
}
932943
}
@@ -1093,12 +1104,6 @@ INTERNAL_HIDDEN ASSUME_ALIGNED void *_iso_alloc(iso_alloc_zone_t *zone, size_t s
10931104
for(size_t i = 0; i < zone_cache_count; i++) {
10941105
if(zone_cache[i].chunk_size >= size) {
10951106
iso_alloc_zone_t *_zone = zone_cache[i].zone;
1096-
1097-
/* Don't waste memory, enforce spatial separation by size */
1098-
if(_zone->chunk_size >= ZONE_1024 && size <= ZONE_128) {
1099-
continue;
1100-
}
1101-
11021107
if(is_zone_usable(_zone, size) != NULL) {
11031108
zone = _zone;
11041109
break;

0 commit comments

Comments
 (0)