@@ -57,8 +57,8 @@ pub struct Block {
5757 line_map : [ LineHeader ; NUM_LINES_PER_BLOCK ] ,
5858 /// 第一个hole的起始行号
5959 cursor : usize ,
60- /// 第一个hole的长度(行数
61- limit : usize ,
60+ // // / 第一个hole的长度(行数
61+ // limit: usize,
6262 /// 是否被标记
6363 pub marked : bool ,
6464 /// 洞的数量
@@ -166,7 +166,6 @@ impl Block {
166166 ptr. write ( Self {
167167 line_map : [ 0 ; NUM_LINES_PER_BLOCK ] ,
168168 cursor : 3 , // 跳过前三行,都用来放metadata。浪费一点空间(metadata从0.8%->1.2%)
169- limit : ( NUM_LINES_PER_BLOCK - 3 ) ,
170169 marked : false ,
171170 hole_num : 1 ,
172171 available_line_num : NUM_LINES_PER_BLOCK - 3 ,
@@ -184,7 +183,6 @@ impl Block {
184183 pub fn show ( & self ) {
185184 println ! ( "size: {}" , self . get_size( ) ) ;
186185 println ! ( "first_hole_line_idx: {}" , self . cursor) ;
187- println ! ( "first_hole_line_len: {}" , self . limit) ;
188186 println ! ( "marked: {}" , self . marked) ;
189187 println ! ( "hole_num: {}" , self . hole_num) ;
190188 println ! ( "available_line_num: {}" , self . available_line_num) ;
@@ -213,7 +211,6 @@ impl Block {
213211 }
214212 pub fn reset_header ( & mut self ) {
215213 self . cursor = 3 ;
216- self . limit = NUM_LINES_PER_BLOCK - 3 ;
217214 self . line_map = [ 0 ; NUM_LINES_PER_BLOCK ] ;
218215 self . marked = false ;
219216 self . hole_num = 1 ;
@@ -270,17 +267,14 @@ impl Block {
270267 if len > 0 {
271268 if first_hole_line_len == 0 {
272269 first_hole_line_idx = idx - len;
273- first_hole_line_len = len;
274270 }
275271 holes += 1 ;
276272 }
277273
278274 self . cursor = first_hole_line_idx;
279- self . limit = first_hole_line_len;
280275 self . marked = false ;
281276 self . hole_num = holes;
282277 self . eva_target = false ;
283- // println!("holes: {}, first_idx: {} , first_len: {} {:?}", holes,first_hole_line_idx,first_hole_line_len,self.line_map.iter().map(|&x| x & 1).collect::<Vec<_>>());
284278 if let Some ( count) = ( * mark_histogram) . get_mut ( & self . hole_num ) {
285279 * count += marked_num;
286280 } else {
@@ -325,32 +319,16 @@ impl Block {
325319 }
326320 len = 0 ;
327321 }
328- // self.show();
329- // panic!("prev_hole: {:?}, idx: {}, len: {}, size_line: {}", prev_hole, idx, len, size_line);
322+
330323 idx += 1 ;
331324 }
332- // panic!("xxx");
333325
334326 if len >= size_line {
335327 return Some ( ( idx - len, len) ) ;
336328 }
337329 None
338330 }
339331
340- /// # find_first_hole
341- ///
342- /// Find the first hole in the block.
343- ///
344- /// Return the start line index and the length of the hole (u8, u8).
345- ///
346- /// If no hole found, return `None`.
347- pub fn find_first_hole ( & self ) -> Option < ( usize , usize ) > {
348- if self . limit == 0 {
349- return None ;
350- }
351- ( self . cursor , self . limit ) . into ( )
352- }
353-
354332 /// # get_nth_line
355333 ///
356334 /// get the line at nth index as * mut u8
@@ -477,21 +455,17 @@ impl Block {
477455 // 设置起始line header的obj_type
478456 let header = self . line_map . get_mut ( start) . unwrap ( ) ;
479457 * header |= ( obj_type as u8 ) << 2 | 0b10000000 ;
480- // header.set_obj_type(obj_type);
481- // header.set_is_head(true);
458+
482459 // 更新first_hole_line_idx和first_hole_line_len
483460 if start == self . cursor {
484461 self . cursor += line_size;
485- self . limit -= line_size;
462+ // self.limit -= line_size;
486463 }
487- if self . limit == 0 {
488- if let Some ( ( idx, len) ) = self . find_next_hole ( ( self . cursor , self . limit ) , 1 ) {
489- self . cursor = idx;
490- self . limit = len;
491- } else {
492- self . hole_num -= 1 ;
493- return Some ( ( start, false ) ) ;
494- }
464+ if let Some ( ( idx, _) ) = self . find_next_hole ( ( self . cursor , 0 ) , 1 ) {
465+ self . cursor = idx;
466+ } else {
467+ self . hole_num -= 1 ;
468+ return Some ( ( start, false ) ) ;
495469 }
496470 if self . cursor > start + len && len == line_size {
497471 // 正好匹配,那么减少一个hole
@@ -512,8 +486,8 @@ mod tests {
512486 unsafe {
513487 let mut ga = GlobalAllocator :: new ( 1024 * 1024 * 1024 ) ;
514488 let block = & mut * ga. get_block ( ) ;
515- // 第一个hole应该是从第三行开始,长度是253
516- assert_eq ! ( block. find_first_hole( ) , Some ( ( 3 , 253 ) ) ) ;
489+ // // 第一个hole应该是从第三行开始,长度是253
490+ // assert_eq!(block.find_first_hole(), Some((3, 253)));
517491 // 标记hole隔一行之后的第一行为已使用
518492 let header = block. get_nth_line_header ( 4 ) ;
519493 header. set_used ( true ) ;
@@ -535,7 +509,7 @@ mod tests {
535509 let block = & mut * ga. get_block ( ) ;
536510 // 设置第5行已被使用
537511 block. get_nth_line_header ( 5 ) . set_used ( true ) ;
538- block. limit = 2 ;
512+ // block.limit = 2;
539513 block. hole_num = 2 ;
540514 // 从第三行开始分配,长度为128
541515 // 分配前:
@@ -566,7 +540,7 @@ mod tests {
566540 assert_eq ! ( start, 3 ) ;
567541 // assert_eq!(newcursor, Some(block.get_nth_line(4)));
568542 assert_eq ! ( block. cursor, 4 ) ;
569- assert_eq ! ( block. limit, 1 ) ;
543+ // assert_eq!(block.limit, 1);
570544 let l = block. get_nth_line_header ( 3 ) . get_obj_type ( ) ;
571545 assert_eq ! ( l, crate :: block:: ObjectType :: Atomic ) ;
572546 // 从第4行开始分配,长度为129
@@ -585,15 +559,15 @@ mod tests {
585559 // ......
586560 assert_eq ! ( block. alloc( 129 , crate :: block:: ObjectType :: Atomic ) , None ) ;
587561 assert_eq ! ( block. cursor, 4 ) ;
588- assert_eq ! ( block. limit, 1 ) ;
562+ // assert_eq!(block.limit, 1);
589563
590564 block. cursor = 6 ;
591- block. limit = 250 ;
565+ // block.limit = 250;
592566 let ( start, newcursor) = block
593567 . alloc ( ( 256 - 6 ) * LINE_SIZE , crate :: block:: ObjectType :: Complex )
594568 . expect ( "cannot alloc new line" ) ;
595569 block. cursor = 4 ;
596- block. limit = 1 ;
570+ // block.limit = 1;
597571 // 从第6行开始分配,长度为256-6
598572 // 分配后:
599573 // --------
@@ -613,7 +587,7 @@ mod tests {
613587 assert_eq ! ( start, 6 ) ;
614588 assert_eq ! ( newcursor, false ) ;
615589 assert_eq ! ( block. cursor, 4 ) ;
616- assert_eq ! ( block. limit, 1 ) ;
590+ // assert_eq!(block.limit, 1);
617591 let ( start, newcursor) = block
618592 . alloc ( 128 , crate :: block:: ObjectType :: Atomic )
619593 . expect ( "cannot alloc new line" ) ;
@@ -634,7 +608,7 @@ mod tests {
634608 assert_eq ! ( start, 4 ) ;
635609 assert_eq ! ( newcursor, false ) ;
636610 // assert_eq!(block.first_hole_line_idx, 255); 这个时候没hole了,此值无意义,len为0
637- assert_eq ! ( block. limit, 0 ) ;
611+ // assert_eq!(block.limit, 0);
638612
639613 // test big alloc
640614 let obj = ga. get_big_obj ( BLOCK_SIZE ) ;
0 commit comments