Skip to content

Commit 58cc21c

Browse files
committed
SizedAllocator: push to the free list in reverse order
This means objects will be allocated in increasing address order, which is objectively better for cache locality and prefetching
1 parent c44940e commit 58cc21c

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

runtime/include/alaska/SizedAllocator.hpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,18 @@ namespace alaska {
122122

123123

124124
inline long SizedAllocator::extend(long count) {
125-
long e = 0;
126-
for (; e < count && bump_next != objects_end; e++) {
127-
free_list.free_local(bump_next);
128-
bump_next = (void *)((uintptr_t)bump_next + object_size);
125+
long extended_count = 0;
126+
off_t start = (off_t)bump_next;
127+
off_t end = start + object_size * count;
128+
if (end > (off_t)objects_end) end = (off_t)objects_end;
129+
bump_next = (void *)end;
130+
131+
for (off_t o = end - object_size; o >= start; o -= object_size) {
132+
free_list.free_local((void *)o);
133+
extended_count++;
129134
}
130-
return e;
135+
136+
return extended_count;
131137
}
132138

133139

0 commit comments

Comments
 (0)