summaryrefslogtreecommitdiff
path: root/na/mm/slab.cc
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2026-05-02 23:33:11 +0800
committerRichard Qin <richard.qin.x@gmail.com>2026-05-02 23:33:11 +0800
commit11a6be89b6c75b31f29c86136d53aac5044da7a2 (patch)
tree0ca910710dea9169be608966b03ce5581926f797 /na/mm/slab.cc
parent6907a90418ba856ff9331e6b4ba5d26b76034c2d (diff)
downloadlume-11a6be89b6c75b31f29c86136d53aac5044da7a2.tar.gz
lume-11a6be89b6c75b31f29c86136d53aac5044da7a2.tar.xz
feat: refactor memory management and integrate memblock
- Updated physical memory management (PMM) to utilize memblock for memory layout and frame allocation. - Enhanced the virtual memory manager (VMM) to allocate the frame map from memblock, ensuring it starts at the correct virtual address without relocation. - Improved frame allocation and deallocation functions to handle physical addresses more consistently. - Adjusted the slab allocator to correctly convert between physical and virtual addresses. - Refined page fault handling to ensure proper frame allocation and address translation. - Streamlined the initialization process for PMM and VMM, ensuring a more robust setup of memory structures. Co-authored-by: Copilot <copilot@github.com>
Diffstat (limited to 'na/mm/slab.cc')
-rw-r--r--na/mm/slab.cc12
1 files changed, 6 insertions, 6 deletions
diff --git a/na/mm/slab.cc b/na/mm/slab.cc
index ef15b6a..98029aa 100644
--- a/na/mm/slab.cc
+++ b/na/mm/slab.cc
@@ -36,7 +36,7 @@
*/
static inline void* frame_to_page_va(Frame* f)
{
- return reinterpret_cast<void*>(pa_to_va(frame_to_pa(f)));
+ return reinterpret_cast<void*>(pa_to_va(frame_to_pa(f)).raw);
}
/* Round up x to the next multiple of align (align must be power of 2) */
@@ -193,9 +193,9 @@ void KmemCache::free(void* obj)
uint64 obj_addr = reinterpret_cast<uint64>(obj);
/* Convert VA to PA. Like pmm.cc, handle both PA and VA cases. */
- uint64 obj_pa = ensure_pa(obj_addr);
+ uint64 obj_pa = va_to_pa(virt_addr(obj_addr)).raw;
uint64 page_pa = obj_pa & ~(kPageSize - 1);
- Frame* f = pa_to_frame(page_pa);
+ Frame* f = pa_to_frame(phys_addr(page_pa));
if (f->state != FrameState::Slab || f->slab.cache != this)
kernel_panic("slab free: object does not belong to this cache");
@@ -255,7 +255,7 @@ void* kmalloc(uint32 size)
Frame* f = pmm_alloc_frames(order);
if (!f)
return nullptr;
- return reinterpret_cast<void*>(pa_to_va(frame_to_pa(f)));
+ return reinterpret_cast<void*>(pa_to_va(frame_to_pa(f)).raw);
}
KmemCache* cache = find_cache(size);
@@ -270,9 +270,9 @@ void kfree(void* ptr)
return;
uint64 addr = reinterpret_cast<uint64>(ptr);
- uint64 pa = ensure_pa(addr);
+ uint64 pa = va_to_pa(virt_addr(addr)).raw;
uint64 page_pa = pa & ~(kPageSize - 1);
- Frame* f = pa_to_frame(page_pa);
+ Frame* f = pa_to_frame(phys_addr(page_pa));
if (f->state == FrameState::Slab) {
KmemCache* cache = f->slab.cache;