@@ -11,16 +11,17 @@ use spin::Mutex;
1111
1212/// A frame allocator that uses buddy system, requiring a global allocator.
1313///
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.
1717///
1818/// # Usage
1919///
2020/// Create a frame allocator and add some frames to it:
2121/// ```
2222/// 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();
2425/// assert!(frame.alloc(1).is_none());
2526///
2627/// frame.add_frame(0, 3);
@@ -29,8 +30,8 @@ use spin::Mutex;
2930/// let num = frame.alloc(2);
3031/// assert_eq!(num, Some(0));
3132/// ```
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`
3435 free_list : [ BTreeSet < usize > ; ORDER ] ,
3536
3637 // statistics
@@ -175,7 +176,8 @@ impl<const ORDER: usize> FrameAllocator<ORDER> {
175176/// Create a locked frame allocator and add frames to it:
176177/// ```
177178/// 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();
179181/// assert!(frame.lock().alloc(1).is_none());
180182///
181183/// frame.lock().add_frame(0, 3);
@@ -185,7 +187,7 @@ impl<const ORDER: usize> FrameAllocator<ORDER> {
185187/// assert_eq!(num, Some(0));
186188/// ```
187189#[ 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 > > ) ;
189191
190192#[ cfg( feature = "use_spin" ) ]
191193impl < const ORDER : usize > LockedFrameAllocator < ORDER > {
0 commit comments