Skip to content

Commit 1e3d006

Browse files
authored
Merge pull request #55 from struct/11_21_28_optimizations
small optimization for iso_find_zone_range to not check zones twice
2 parents bb350fd + 119a695 commit 1e3d006

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

src/iso_alloc.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,10 @@ INTERNAL_HIDDEN iso_alloc_big_zone *iso_find_big_zone(void *p) {
13461346
INTERNAL_HIDDEN iso_alloc_zone *iso_find_zone_bitmap_range(void *p) {
13471347
iso_alloc_zone *zone = NULL;
13481348

1349+
/* Locally store the thread zone index's to ensure
1350+
* we don't check them twice if the cache misses */
1351+
uint16_t zones_checked[THREAD_ZONE_CACHE_SZ];
1352+
13491353
#if THREAD_SUPPORT && THREAD_CACHE
13501354
/* Hot Path: Check the thread cache for a zone this
13511355
* thread recently used for an alloc/free operation */
@@ -1356,12 +1360,18 @@ INTERNAL_HIDDEN iso_alloc_zone *iso_find_zone_bitmap_range(void *p) {
13561360
MASK_ZONE_PTRS(zone);
13571361
return zone;
13581362
}
1363+
zones_checked[i] = zone->index;
13591364
MASK_ZONE_PTRS(zone);
13601365
}
13611366
#endif
13621367

13631368
for(int32_t i = 0; i < _root->zones_used; i++) {
13641369
zone = &_root->zones[i];
1370+
1371+
if(i < thread_zone_cache_count && zones_checked[i] == zone->index) {
1372+
continue;
1373+
}
1374+
13651375
UNMASK_ZONE_PTRS(zone);
13661376
if(zone->bitmap_start <= p && (zone->bitmap_start + zone->bitmap_size) > p) {
13671377
MASK_ZONE_PTRS(zone);
@@ -1376,22 +1386,32 @@ INTERNAL_HIDDEN iso_alloc_zone *iso_find_zone_bitmap_range(void *p) {
13761386
INTERNAL_HIDDEN iso_alloc_zone *iso_find_zone_range(void *p) {
13771387
iso_alloc_zone *zone = NULL;
13781388

1389+
/* Locally store the thread zone index's to ensure
1390+
* we don't check them twice if the cache misses */
1391+
uint16_t zones_checked[THREAD_ZONE_CACHE_SZ];
1392+
13791393
#if THREAD_SUPPORT && THREAD_CACHE
13801394
/* Hot Path: Check the thread cache for a zone this
13811395
* thread recently used for an alloc/free operation */
1382-
for(int64_t i = 0; i < thread_zone_cache_count; i++) {
1396+
for(int32_t i = 0; i < thread_zone_cache_count; i++) {
13831397
UNMASK_ZONE_PTRS(thread_zone_cache[i].zone);
13841398
zone = thread_zone_cache[i].zone;
13851399
if(zone->user_pages_start <= p && (zone->user_pages_start + ZONE_USER_SIZE) > p) {
13861400
MASK_ZONE_PTRS(zone);
13871401
return zone;
13881402
}
1403+
zones_checked[i] = zone->index;
13891404
MASK_ZONE_PTRS(zone);
13901405
}
13911406
#endif
13921407

13931408
for(int32_t i = 0; i < _root->zones_used; i++) {
13941409
zone = &_root->zones[i];
1410+
1411+
if(i < thread_zone_cache_count && zones_checked[i] == zone->index) {
1412+
continue;
1413+
}
1414+
13951415
UNMASK_ZONE_PTRS(zone);
13961416
if(zone->user_pages_start <= p && (zone->user_pages_start + ZONE_USER_SIZE) > p) {
13971417
MASK_ZONE_PTRS(zone);

0 commit comments

Comments
 (0)