File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -62,7 +62,10 @@ impl<const ORDER: usize> FrameAllocator<ORDER> {
62
62
} else {
63
63
32
64
64
} ;
65
- let size = min ( lowbit, prev_power_of_two ( end - current_start) ) ;
65
+ let size = min (
66
+ min ( lowbit, prev_power_of_two ( end - current_start) ) ,
67
+ 1 << ( ORDER - 1 ) ,
68
+ ) ;
66
69
total += size;
67
70
68
71
self . free_list [ size. trailing_zeros ( ) as usize ] . insert ( current_start) ;
Original file line number Diff line number Diff line change @@ -122,18 +122,28 @@ fn test_frame_allocator_add() {
122
122
}
123
123
124
124
#[ test]
125
- #[ should_panic]
126
- fn test_frame_allocator_add_large_size_panics ( ) {
125
+ fn test_frame_allocator_allocate_large ( ) {
126
+ let mut frame = FrameAllocator :: < 32 > :: new ( ) ;
127
+ assert_eq ! ( frame. alloc( 10_000_000_000 ) , None ) ;
128
+ }
129
+
130
+ #[ test]
131
+ fn test_frame_allocator_add_large_size_split ( ) {
127
132
let mut frame = FrameAllocator :: < 32 > :: new ( ) ;
128
133
129
134
frame. insert ( 0 ..10_000_000_000 ) ;
135
+
136
+ assert_eq ! ( frame. alloc( 0x8000_0001 ) , None ) ;
137
+ assert_eq ! ( frame. alloc( 0x8000_0000 ) , Some ( 0x8000_0000 ) ) ;
138
+ assert_eq ! ( frame. alloc( 0x8000_0000 ) , Some ( 0x1_0000_0000 ) ) ;
130
139
}
131
140
132
141
#[ test]
133
142
fn test_frame_allocator_add_large_size ( ) {
134
143
let mut frame = FrameAllocator :: < 33 > :: new ( ) ;
135
144
136
145
frame. insert ( 0 ..10_000_000_000 ) ;
146
+ assert_eq ! ( frame. alloc( 0x8000_0001 ) , Some ( 0x1_0000_0000 ) ) ;
137
147
}
138
148
139
149
#[ test]
You can’t perform that action at this time.
0 commit comments