@@ -54,7 +54,11 @@ impl LockedFrameAllocator {
5454}
5555
5656unsafe impl FrameAllocator < Size4KiB > for LockedFrameAllocator {
57+ #[ track_caller]
5758 fn allocate_frame ( & self ) -> Option < PhysFrame < Size4KiB > > {
59+ // let caller = core::panic::Location::caller();
60+ // log::debug!("allocation request of 4KiB by {:?}", caller);
61+
5862 self . 0
5963 . get ( )
6064 . map ( |m| {
@@ -69,7 +73,11 @@ unsafe impl FrameAllocator<Size4KiB> for LockedFrameAllocator {
6973 } )
7074 }
7175
76+ #[ track_caller]
7277 fn deallocate_frame ( & self , frame : PhysFrame < Size4KiB > ) {
78+ // let caller = core::panic::Location::caller();
79+ // log::debug!("deallocation request of 4KiB by {:?}", caller);
80+
7381 self . 0
7482 . get ( )
7583 . map ( |m| m. lock ( ) . deallocate_frame_inner ( frame. start_address ( ) , 0 ) )
@@ -78,7 +86,11 @@ unsafe impl FrameAllocator<Size4KiB> for LockedFrameAllocator {
7886}
7987
8088unsafe impl FrameAllocator < Size2MiB > for LockedFrameAllocator {
89+ #[ track_caller]
8190 fn allocate_frame ( & self ) -> Option < PhysFrame < Size2MiB > > {
91+ // let caller = core::panic::Location::caller();
92+ // log::debug!("allocation request of 2MiB by {:?}", caller);
93+
8294 self . 0
8395 . get ( )
8496 . map ( |m| {
@@ -93,7 +105,11 @@ unsafe impl FrameAllocator<Size2MiB> for LockedFrameAllocator {
93105 } )
94106 }
95107
108+ #[ track_caller]
96109 fn deallocate_frame ( & self , frame : PhysFrame < Size2MiB > ) {
110+ // let caller = core::panic::Location::caller();
111+ // log::debug!("deallocation request of 2MiB by {:?}", caller);
112+
97113 self . 0
98114 . get ( )
99115 . map ( |m| m. lock ( ) . deallocate_frame_inner ( frame. start_address ( ) , 1 ) )
@@ -230,6 +246,25 @@ const CONVENTIONAL_MEM_END: PhysAddr = unsafe { PhysAddr::new_unchecked(Size4KiB
230246
231247static VM_FRAMES : Once < Vec < VmFrame > > = Once :: new ( ) ;
232248
249+ /// Buddy allocator combines power-of-two allocator with free buffer
250+ /// coalescing.
251+ ///
252+ /// ## Overview
253+ ///
254+ /// Overview of the buddy allocation algorithm:
255+ ///
256+ /// * Memory is broken up into large blocks of pages where each block
257+ /// is a power of two number of pages.
258+ ///
259+ /// * If a block of the desired size is not available, a larger block is
260+ /// broken up in half and the two blocks are marked as buddies then one half
261+ /// is used for the allocation and the other half is marked free.
262+ ///
263+ /// * The blocks are continuously halved as necessary until a block of the
264+ /// desired size is available.
265+ ///
266+ /// * When a block is later freed, the buddy is examined and the two coalesced
267+ /// if it is free.
233268pub struct GlobalFrameAllocator {
234269 buddies : [ & ' static mut [ u64 ] ; 3 ] ,
235270 free : [ usize ; 3 ] ,
0 commit comments