Skip to content
This repository was archived by the owner on Dec 25, 2025. It is now read-only.

Commit 0fff99e

Browse files
committed
Optimize SlubAllocator::flush()
1 parent 6813261 commit 0fff99e

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

kernel/src/memory/heap.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,29 @@ void SlubAllocator::flush(int idx, CpuCache::ClassCache& cache) {
344344
SizeClass& sc = this->size_classes[idx];
345345
LockGuard guard(sc.lock);
346346

347+
Slab* last_slab = nullptr;
348+
uintptr_t last_page_base = 0;
349+
347350
// Process all pointers in the batch
348351
for (int i = 0; i < cache.free_count; ++i) {
349352
void* ptr = cache.free_buf[i];
350-
Slab* s = HeapMap::get(ptr);
353+
354+
if ((i + 1) < cache.free_count) {
355+
// 0 -> Read
356+
// 3 - > High temporal locality
357+
__builtin_prefetch(cache.free_buf[i + 1], 0, 3);
358+
}
359+
360+
Slab* s;
361+
uintptr_t curr_page_base = align_down(reinterpret_cast<uintptr_t>(ptr), PAGE_SIZE_4K);
362+
363+
if (curr_page_base == last_page_base) {
364+
s = last_slab;
365+
} else {
366+
s = HeapMap::get(ptr);
367+
last_slab = s;
368+
last_page_base = curr_page_base;
369+
}
351370

352371
// Return to freelist
353372
*reinterpret_cast<void**>(ptr) = s->freelist;

0 commit comments

Comments
 (0)