@@ -11,16 +11,17 @@ use spin::Mutex;
11
11
12
12
/// A frame allocator that uses buddy system, requiring a global allocator.
13
13
///
14
- /// The max order of the allocator is specified via the const generic parameter `ORDER`. The frame
15
- /// allocator will only be able to allocate ranges of size up to 2<sup>ORDER </sup>, out of a total
16
- /// range of size at most 2<sup>ORDER + 1</sup> - 1.
14
+ /// The max order of the allocator is determined by the const generic parameter `ORDER` (`MAX_ORDER = ORDER - 1`).
15
+ /// The frame allocator will only be able to allocate ranges of size up to 2<sup>MAX_ORDER </sup>, out of a total
16
+ /// range of size at most 2<sup>MAX_ORDER + 1</sup> - 1.
17
17
///
18
18
/// # Usage
19
19
///
20
20
/// Create a frame allocator and add some frames to it:
21
21
/// ```
22
22
/// use buddy_system_allocator::*;
23
- /// let mut frame = FrameAllocator::<32>::new();
23
+ /// // Notice that the max order is `ORDER - 1`.
24
+ /// let mut frame = FrameAllocator::<33>::new();
24
25
/// assert!(frame.alloc(1).is_none());
25
26
///
26
27
/// frame.add_frame(0, 3);
@@ -29,8 +30,8 @@ use spin::Mutex;
29
30
/// let num = frame.alloc(2);
30
31
/// assert_eq!(num, Some(0));
31
32
/// ```
32
- pub struct FrameAllocator < const ORDER : usize = 32 > {
33
- // buddy system with max order of ORDER
33
+ pub struct FrameAllocator < const ORDER : usize = 33 > {
34
+ // buddy system with max order of ` ORDER - 1`
34
35
free_list : [ BTreeSet < usize > ; ORDER ] ,
35
36
36
37
// statistics
@@ -175,7 +176,8 @@ impl<const ORDER: usize> FrameAllocator<ORDER> {
175
176
/// Create a locked frame allocator and add frames to it:
176
177
/// ```
177
178
/// use buddy_system_allocator::*;
178
- /// let mut frame = LockedFrameAllocator::<32>::new();
179
+ /// // Notice that the max order is `ORDER - 1`.
180
+ /// let mut frame = LockedFrameAllocator::<33>::new();
179
181
/// assert!(frame.lock().alloc(1).is_none());
180
182
///
181
183
/// frame.lock().add_frame(0, 3);
@@ -185,7 +187,7 @@ impl<const ORDER: usize> FrameAllocator<ORDER> {
185
187
/// assert_eq!(num, Some(0));
186
188
/// ```
187
189
#[ cfg( feature = "use_spin" ) ]
188
- pub struct LockedFrameAllocator < const ORDER : usize = 32 > ( Mutex < FrameAllocator < ORDER > > ) ;
190
+ pub struct LockedFrameAllocator < const ORDER : usize = 33 > ( Mutex < FrameAllocator < ORDER > > ) ;
189
191
190
192
#[ cfg( feature = "use_spin" ) ]
191
193
impl < const ORDER : usize > LockedFrameAllocator < ORDER > {
0 commit comments