diff options
Diffstat (limited to 'fs/f2fs/segment.h')
-rw-r--r-- | fs/f2fs/segment.h | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h index 552dadbb2327..062424a0e4c3 100644 --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h | |||
@@ -8,10 +8,13 @@ | |||
8 | * it under the terms of the GNU General Public License version 2 as | 8 | * it under the terms of the GNU General Public License version 2 as |
9 | * published by the Free Software Foundation. | 9 | * published by the Free Software Foundation. |
10 | */ | 10 | */ |
11 | #include <linux/blkdev.h> | ||
12 | |||
11 | /* constant macro */ | 13 | /* constant macro */ |
12 | #define NULL_SEGNO ((unsigned int)(~0)) | 14 | #define NULL_SEGNO ((unsigned int)(~0)) |
15 | #define NULL_SECNO ((unsigned int)(~0)) | ||
13 | 16 | ||
14 | /* V: Logical segment # in volume, R: Relative segment # in main area */ | 17 | /* L: Logical segment # in volume, R: Relative segment # in main area */ |
15 | #define GET_L2R_SEGNO(free_i, segno) (segno - free_i->start_segno) | 18 | #define GET_L2R_SEGNO(free_i, segno) (segno - free_i->start_segno) |
16 | #define GET_R2L_SEGNO(free_i, segno) (segno + free_i->start_segno) | 19 | #define GET_R2L_SEGNO(free_i, segno) (segno + free_i->start_segno) |
17 | 20 | ||
@@ -23,13 +26,13 @@ | |||
23 | ((t == CURSEG_HOT_NODE) || (t == CURSEG_COLD_NODE) || \ | 26 | ((t == CURSEG_HOT_NODE) || (t == CURSEG_COLD_NODE) || \ |
24 | (t == CURSEG_WARM_NODE)) | 27 | (t == CURSEG_WARM_NODE)) |
25 | 28 | ||
26 | #define IS_CURSEG(sbi, segno) \ | 29 | #define IS_CURSEG(sbi, seg) \ |
27 | ((segno == CURSEG_I(sbi, CURSEG_HOT_DATA)->segno) || \ | 30 | ((seg == CURSEG_I(sbi, CURSEG_HOT_DATA)->segno) || \ |
28 | (segno == CURSEG_I(sbi, CURSEG_WARM_DATA)->segno) || \ | 31 | (seg == CURSEG_I(sbi, CURSEG_WARM_DATA)->segno) || \ |
29 | (segno == CURSEG_I(sbi, CURSEG_COLD_DATA)->segno) || \ | 32 | (seg == CURSEG_I(sbi, CURSEG_COLD_DATA)->segno) || \ |
30 | (segno == CURSEG_I(sbi, CURSEG_HOT_NODE)->segno) || \ | 33 | (seg == CURSEG_I(sbi, CURSEG_HOT_NODE)->segno) || \ |
31 | (segno == CURSEG_I(sbi, CURSEG_WARM_NODE)->segno) || \ | 34 | (seg == CURSEG_I(sbi, CURSEG_WARM_NODE)->segno) || \ |
32 | (segno == CURSEG_I(sbi, CURSEG_COLD_NODE)->segno)) | 35 | (seg == CURSEG_I(sbi, CURSEG_COLD_NODE)->segno)) |
33 | 36 | ||
34 | #define IS_CURSEC(sbi, secno) \ | 37 | #define IS_CURSEC(sbi, secno) \ |
35 | ((secno == CURSEG_I(sbi, CURSEG_HOT_DATA)->segno / \ | 38 | ((secno == CURSEG_I(sbi, CURSEG_HOT_DATA)->segno / \ |
@@ -81,9 +84,12 @@ | |||
81 | #define f2fs_bitmap_size(nr) \ | 84 | #define f2fs_bitmap_size(nr) \ |
82 | (BITS_TO_LONGS(nr) * sizeof(unsigned long)) | 85 | (BITS_TO_LONGS(nr) * sizeof(unsigned long)) |
83 | #define TOTAL_SEGS(sbi) (SM_I(sbi)->main_segments) | 86 | #define TOTAL_SEGS(sbi) (SM_I(sbi)->main_segments) |
87 | #define TOTAL_SECS(sbi) (sbi->total_sections) | ||
84 | 88 | ||
85 | #define SECTOR_FROM_BLOCK(sbi, blk_addr) \ | 89 | #define SECTOR_FROM_BLOCK(sbi, blk_addr) \ |
86 | (blk_addr << ((sbi)->log_blocksize - F2FS_LOG_SECTOR_SIZE)) | 90 | (blk_addr << ((sbi)->log_blocksize - F2FS_LOG_SECTOR_SIZE)) |
91 | #define SECTOR_TO_BLOCK(sbi, sectors) \ | ||
92 | (sectors >> ((sbi)->log_blocksize - F2FS_LOG_SECTOR_SIZE)) | ||
87 | 93 | ||
88 | /* during checkpoint, bio_private is used to synchronize the last bio */ | 94 | /* during checkpoint, bio_private is used to synchronize the last bio */ |
89 | struct bio_private { | 95 | struct bio_private { |
@@ -213,7 +219,7 @@ struct dirty_seglist_info { | |||
213 | unsigned long *dirty_segmap[NR_DIRTY_TYPE]; | 219 | unsigned long *dirty_segmap[NR_DIRTY_TYPE]; |
214 | struct mutex seglist_lock; /* lock for segment bitmaps */ | 220 | struct mutex seglist_lock; /* lock for segment bitmaps */ |
215 | int nr_dirty[NR_DIRTY_TYPE]; /* # of dirty segments */ | 221 | int nr_dirty[NR_DIRTY_TYPE]; /* # of dirty segments */ |
216 | unsigned long *victim_segmap[2]; /* BG_GC, FG_GC */ | 222 | unsigned long *victim_secmap; /* background GC victims */ |
217 | }; | 223 | }; |
218 | 224 | ||
219 | /* victim selection function for cleaning and SSR */ | 225 | /* victim selection function for cleaning and SSR */ |
@@ -464,8 +470,7 @@ static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi, int freed) | |||
464 | 470 | ||
465 | static inline int utilization(struct f2fs_sb_info *sbi) | 471 | static inline int utilization(struct f2fs_sb_info *sbi) |
466 | { | 472 | { |
467 | return (long int)valid_user_blocks(sbi) * 100 / | 473 | return div_u64(valid_user_blocks(sbi) * 100, sbi->user_block_count); |
468 | (long int)sbi->user_block_count; | ||
469 | } | 474 | } |
470 | 475 | ||
471 | /* | 476 | /* |
@@ -616,3 +621,17 @@ static inline block_t sum_blk_addr(struct f2fs_sb_info *sbi, int base, int type) | |||
616 | le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_total_block_count) | 621 | le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_total_block_count) |
617 | - (base + 1) + type; | 622 | - (base + 1) + type; |
618 | } | 623 | } |
624 | |||
625 | static inline bool sec_usage_check(struct f2fs_sb_info *sbi, unsigned int secno) | ||
626 | { | ||
627 | if (IS_CURSEC(sbi, secno) || (sbi->cur_victim_sec == secno)) | ||
628 | return true; | ||
629 | return false; | ||
630 | } | ||
631 | |||
632 | static inline unsigned int max_hw_blocks(struct f2fs_sb_info *sbi) | ||
633 | { | ||
634 | struct block_device *bdev = sbi->sb->s_bdev; | ||
635 | struct request_queue *q = bdev_get_queue(bdev); | ||
636 | return SECTOR_TO_BLOCK(sbi, queue_max_sectors(q)); | ||
637 | } | ||