@@ -54,7 +54,11 @@ impl LockedFrameAllocator {
54
54
}
55
55
56
56
unsafe impl FrameAllocator < Size4KiB > for LockedFrameAllocator {
57
+ #[ track_caller]
57
58
fn allocate_frame ( & self ) -> Option < PhysFrame < Size4KiB > > {
59
+ // let caller = core::panic::Location::caller();
60
+ // log::debug!("allocation request of 4KiB by {:?}", caller);
61
+
58
62
self . 0
59
63
. get ( )
60
64
. map ( |m| {
@@ -69,7 +73,11 @@ unsafe impl FrameAllocator<Size4KiB> for LockedFrameAllocator {
69
73
} )
70
74
}
71
75
76
+ #[ track_caller]
72
77
fn deallocate_frame ( & self , frame : PhysFrame < Size4KiB > ) {
78
+ // let caller = core::panic::Location::caller();
79
+ // log::debug!("deallocation request of 4KiB by {:?}", caller);
80
+
73
81
self . 0
74
82
. get ( )
75
83
. map ( |m| m. lock ( ) . deallocate_frame_inner ( frame. start_address ( ) , 0 ) )
@@ -78,7 +86,11 @@ unsafe impl FrameAllocator<Size4KiB> for LockedFrameAllocator {
78
86
}
79
87
80
88
unsafe impl FrameAllocator < Size2MiB > for LockedFrameAllocator {
89
+ #[ track_caller]
81
90
fn allocate_frame ( & self ) -> Option < PhysFrame < Size2MiB > > {
91
+ // let caller = core::panic::Location::caller();
92
+ // log::debug!("allocation request of 2MiB by {:?}", caller);
93
+
82
94
self . 0
83
95
. get ( )
84
96
. map ( |m| {
@@ -93,7 +105,11 @@ unsafe impl FrameAllocator<Size2MiB> for LockedFrameAllocator {
93
105
} )
94
106
}
95
107
108
+ #[ track_caller]
96
109
fn deallocate_frame ( & self , frame : PhysFrame < Size2MiB > ) {
110
+ // let caller = core::panic::Location::caller();
111
+ // log::debug!("deallocation request of 2MiB by {:?}", caller);
112
+
97
113
self . 0
98
114
. get ( )
99
115
. 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
230
246
231
247
static VM_FRAMES : Once < Vec < VmFrame > > = Once :: new ( ) ;
232
248
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.
233
268
pub struct GlobalFrameAllocator {
234
269
buddies : [ & ' static mut [ u64 ] ; 3 ] ,
235
270
free : [ usize ; 3 ] ,
0 commit comments