Skip to content

Commit 9c1f966

Browse files
vmm: remove the object if exactly the requested size
Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent 889c6fb commit 9c1f966

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/aero_kernel/src/mem/alloc.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ impl Allocator {
152152
if let Some(slab) = slab {
153153
slab.alloc()
154154
} else {
155+
// the vmalloc allocator may require reverse dependency
156+
core::mem::drop(inner);
157+
155158
let size = align_up(layout.size() as _, Size4KiB::SIZE) / Size4KiB::SIZE;
156159

157160
vmalloc::get_vmalloc()
@@ -162,7 +165,6 @@ impl Allocator {
162165
}
163166

164167
fn dealloc(&self, ptr: *mut u8, layout: Layout) {
165-
let _inner = self.inner.lock_irq();
166168
let address = VirtAddr::new(ptr as u64);
167169

168170
if address >= vmalloc::VMALLOC_START && address < vmalloc::VMALLOC_END {

src/aero_kernel/src/mem/vmalloc.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,22 @@ impl Vmalloc {
108108
.iter()
109109
.find(|area| area.protected.lock().size >= size_bytes)?;
110110

111-
let mut area = area.protected.lock();
112-
let address = area.addr.clone();
111+
let mut area_p = area.protected.lock();
112+
let address = area_p.addr.clone();
113113

114-
if area.size > size_bytes {
115-
area.addr = area.addr + size_bytes;
116-
area.size -= size_bytes;
114+
if area_p.size > size_bytes {
115+
area_p.addr = area_p.addr + size_bytes;
116+
area_p.size -= size_bytes;
117117
} else {
118-
// the size of the area is exactly the size we need, so remove it from
119-
// the free list.
120-
log::warn!("todo: implement this")
118+
// NOTE: the area is has exactly the requested size, so we can remove it
119+
// from the free list.
120+
core::mem::drop(area_p); // unlock
121+
122+
let area_ptr = area as *const VmallocArea;
123+
124+
// SAFETY: The constructed pointer is a valid object that is in the tree,
125+
let mut area_cursor = unsafe { self.free_list.cursor_mut_from_ptr(area_ptr) };
126+
area_cursor.remove();
121127
}
122128

123129
let mut address_space = AddressSpace::this();

0 commit comments

Comments
 (0)