Commit 53cf9522 authored by Jaegeuk Kim's avatar Jaegeuk Kim

f2fs: introduce TOTAL_SECS macro

Let's use a macro to get the total number of sections.
Reviewed-by: default avatarNamjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk.kim@samsung.com>
parent 5c773ba3
...@@ -106,7 +106,7 @@ static void update_sit_info(struct f2fs_sb_info *sbi) ...@@ -106,7 +106,7 @@ static void update_sit_info(struct f2fs_sb_info *sbi)
} }
} }
mutex_unlock(&sit_i->sentry_lock); mutex_unlock(&sit_i->sentry_lock);
dist = sbi->total_sections * hblks_per_sec * hblks_per_sec / 100; dist = TOTAL_SECS(sbi) * hblks_per_sec * hblks_per_sec / 100;
si->bimodal = bimodal / dist; si->bimodal = bimodal / dist;
if (si->dirty_count) if (si->dirty_count)
si->avg_vblocks = total_vblocks / ndirty; si->avg_vblocks = total_vblocks / ndirty;
...@@ -138,14 +138,13 @@ static void update_mem_info(struct f2fs_sb_info *sbi) ...@@ -138,14 +138,13 @@ static void update_mem_info(struct f2fs_sb_info *sbi)
si->base_mem += f2fs_bitmap_size(TOTAL_SEGS(sbi)); si->base_mem += f2fs_bitmap_size(TOTAL_SEGS(sbi));
si->base_mem += 2 * SIT_VBLOCK_MAP_SIZE * TOTAL_SEGS(sbi); si->base_mem += 2 * SIT_VBLOCK_MAP_SIZE * TOTAL_SEGS(sbi);
if (sbi->segs_per_sec > 1) if (sbi->segs_per_sec > 1)
si->base_mem += sbi->total_sections * si->base_mem += TOTAL_SECS(sbi) * sizeof(struct sec_entry);
sizeof(struct sec_entry);
si->base_mem += __bitmap_size(sbi, SIT_BITMAP); si->base_mem += __bitmap_size(sbi, SIT_BITMAP);
/* build free segmap */ /* build free segmap */
si->base_mem += sizeof(struct free_segmap_info); si->base_mem += sizeof(struct free_segmap_info);
si->base_mem += f2fs_bitmap_size(TOTAL_SEGS(sbi)); si->base_mem += f2fs_bitmap_size(TOTAL_SEGS(sbi));
si->base_mem += f2fs_bitmap_size(sbi->total_sections); si->base_mem += f2fs_bitmap_size(TOTAL_SECS(sbi));
/* build curseg */ /* build curseg */
si->base_mem += sizeof(struct curseg_info) * NR_CURSEG_TYPE; si->base_mem += sizeof(struct curseg_info) * NR_CURSEG_TYPE;
......
...@@ -348,9 +348,8 @@ static void get_new_segment(struct f2fs_sb_info *sbi, ...@@ -348,9 +348,8 @@ static void get_new_segment(struct f2fs_sb_info *sbi,
unsigned int *newseg, bool new_sec, int dir) unsigned int *newseg, bool new_sec, int dir)
{ {
struct free_segmap_info *free_i = FREE_I(sbi); struct free_segmap_info *free_i = FREE_I(sbi);
unsigned int total_secs = sbi->total_sections;
unsigned int segno, secno, zoneno; unsigned int segno, secno, zoneno;
unsigned int total_zones = sbi->total_sections / sbi->secs_per_zone; unsigned int total_zones = TOTAL_SECS(sbi) / sbi->secs_per_zone;
unsigned int hint = *newseg / sbi->segs_per_sec; unsigned int hint = *newseg / sbi->segs_per_sec;
unsigned int old_zoneno = GET_ZONENO_FROM_SEGNO(sbi, *newseg); unsigned int old_zoneno = GET_ZONENO_FROM_SEGNO(sbi, *newseg);
unsigned int left_start = hint; unsigned int left_start = hint;
...@@ -367,12 +366,12 @@ static void get_new_segment(struct f2fs_sb_info *sbi, ...@@ -367,12 +366,12 @@ static void get_new_segment(struct f2fs_sb_info *sbi,
goto got_it; goto got_it;
} }
find_other_zone: find_other_zone:
secno = find_next_zero_bit(free_i->free_secmap, total_secs, hint); secno = find_next_zero_bit(free_i->free_secmap, TOTAL_SECS(sbi), hint);
if (secno >= total_secs) { if (secno >= TOTAL_SECS(sbi)) {
if (dir == ALLOC_RIGHT) { if (dir == ALLOC_RIGHT) {
secno = find_next_zero_bit(free_i->free_secmap, secno = find_next_zero_bit(free_i->free_secmap,
total_secs, 0); TOTAL_SECS(sbi), 0);
BUG_ON(secno >= total_secs); BUG_ON(secno >= TOTAL_SECS(sbi));
} else { } else {
go_left = 1; go_left = 1;
left_start = hint - 1; left_start = hint - 1;
...@@ -387,8 +386,8 @@ static void get_new_segment(struct f2fs_sb_info *sbi, ...@@ -387,8 +386,8 @@ static void get_new_segment(struct f2fs_sb_info *sbi,
continue; continue;
} }
left_start = find_next_zero_bit(free_i->free_secmap, left_start = find_next_zero_bit(free_i->free_secmap,
total_secs, 0); TOTAL_SECS(sbi), 0);
BUG_ON(left_start >= total_secs); BUG_ON(left_start >= TOTAL_SECS(sbi));
break; break;
} }
secno = left_start; secno = left_start;
...@@ -1390,7 +1389,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi) ...@@ -1390,7 +1389,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
} }
if (sbi->segs_per_sec > 1) { if (sbi->segs_per_sec > 1) {
sit_i->sec_entries = vzalloc(sbi->total_sections * sit_i->sec_entries = vzalloc(TOTAL_SECS(sbi) *
sizeof(struct sec_entry)); sizeof(struct sec_entry));
if (!sit_i->sec_entries) if (!sit_i->sec_entries)
return -ENOMEM; return -ENOMEM;
...@@ -1441,7 +1440,7 @@ static int build_free_segmap(struct f2fs_sb_info *sbi) ...@@ -1441,7 +1440,7 @@ static int build_free_segmap(struct f2fs_sb_info *sbi)
if (!free_i->free_segmap) if (!free_i->free_segmap)
return -ENOMEM; return -ENOMEM;
sec_bitmap_size = f2fs_bitmap_size(sbi->total_sections); sec_bitmap_size = f2fs_bitmap_size(TOTAL_SECS(sbi));
free_i->free_secmap = kmalloc(sec_bitmap_size, GFP_KERNEL); free_i->free_secmap = kmalloc(sec_bitmap_size, GFP_KERNEL);
if (!free_i->free_secmap) if (!free_i->free_secmap)
return -ENOMEM; return -ENOMEM;
......
...@@ -81,6 +81,7 @@ ...@@ -81,6 +81,7 @@
#define f2fs_bitmap_size(nr) \ #define f2fs_bitmap_size(nr) \
(BITS_TO_LONGS(nr) * sizeof(unsigned long)) (BITS_TO_LONGS(nr) * sizeof(unsigned long))
#define TOTAL_SEGS(sbi) (SM_I(sbi)->main_segments) #define TOTAL_SEGS(sbi) (SM_I(sbi)->main_segments)
#define TOTAL_SECS(sbi) (sbi->total_sections)
#define SECTOR_FROM_BLOCK(sbi, blk_addr) \ #define SECTOR_FROM_BLOCK(sbi, blk_addr) \
(blk_addr << ((sbi)->log_blocksize - F2FS_LOG_SECTOR_SIZE)) (blk_addr << ((sbi)->log_blocksize - F2FS_LOG_SECTOR_SIZE))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment