Skip to content

Commit 4ddb1a4

Browse files
author
Jaegeuk Kim
committed
f2fs: clean up some macros in terms of GET_SEGNO
This patch cleans several macros by introducing: - BLKS_PER_SEC - GET_SEC_FROM_SEG - GET_SEG_FROM_SEC - GET_ZONE_FROM_SEC - GET_ZONE_FROM_SEG Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent 302bd34 commit 4ddb1a4

6 files changed

Lines changed: 45 additions & 42 deletions

File tree

‎fs/f2fs/debug.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ static void update_general_status(struct f2fs_sb_info *sbi)
109109
for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_NODE; i++) {
110110
struct curseg_info *curseg = CURSEG_I(sbi, i);
111111
si->curseg[i] = curseg->segno;
112-
si->cursec[i] = curseg->segno / sbi->segs_per_sec;
113-
si->curzone[i] = si->cursec[i] / sbi->secs_per_zone;
112+
si->cursec[i] = GET_SEC_FROM_SEG(sbi, curseg->segno);
113+
si->curzone[i] = GET_ZONE_FROM_SEC(sbi, si->cursec[i]);
114114
}
115115

116116
for (i = 0; i < 2; i++) {
@@ -134,7 +134,7 @@ static void update_sit_info(struct f2fs_sb_info *sbi)
134134

135135
bimodal = 0;
136136
total_vblocks = 0;
137-
blks_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg;
137+
blks_per_sec = BLKS_PER_SEC(sbi);
138138
hblks_per_sec = blks_per_sec / 2;
139139
for (segno = 0; segno < MAIN_SEGS(sbi); segno += sbi->segs_per_sec) {
140140
vblocks = get_valid_blocks(sbi, segno, true);

‎fs/f2fs/f2fs.h‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,11 @@ enum {
135135

136136
#define DEF_BATCHED_TRIM_SECTIONS 2048
137137
#define BATCHED_TRIM_SEGMENTS(sbi) \
138-
(SM_I(sbi)->trim_sections * (sbi)->segs_per_sec)
138+
(GET_SEG_FROM_SEC(sbi, SM_I(sbi)->trim_sections))
139139
#define BATCHED_TRIM_BLOCKS(sbi) \
140140
(BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg)
141-
#define MAX_DISCARD_BLOCKS(sbi) \
142-
((1 << (sbi)->log_blocks_per_seg) * (sbi)->segs_per_sec)
143-
#define DISCARD_ISSUE_RATE 8
141+
#define MAX_DISCARD_BLOCKS(sbi) BLKS_PER_SEC(sbi)
142+
#define DISCARD_ISSUE_RATE 8
144143
#define DEF_CP_INTERVAL 60 /* 60 secs */
145144
#define DEF_IDLE_INTERVAL 5 /* 5 secs */
146145

‎fs/f2fs/file.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,7 +1892,6 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
18921892
pgoff_t pg_start, pg_end;
18931893
unsigned int blk_per_seg = sbi->blocks_per_seg;
18941894
unsigned int total = 0, sec_num;
1895-
unsigned int pages_per_sec = sbi->segs_per_sec * blk_per_seg;
18961895
block_t blk_end = 0;
18971896
bool fragmented = false;
18981897
int err;
@@ -1956,7 +1955,7 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
19561955
map.m_lblk = pg_start;
19571956
map.m_len = pg_end - pg_start;
19581957

1959-
sec_num = (map.m_len + pages_per_sec - 1) / pages_per_sec;
1958+
sec_num = (map.m_len + BLKS_PER_SEC(sbi) - 1) / BLKS_PER_SEC(sbi);
19601959

19611960
/*
19621961
* make sure there are enough free section for LFS allocation, this can

‎fs/f2fs/gc.c‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -211,16 +211,16 @@ static unsigned int check_bg_victims(struct f2fs_sb_info *sbi)
211211
continue;
212212

213213
clear_bit(secno, dirty_i->victim_secmap);
214-
return secno * sbi->segs_per_sec;
214+
return GET_SEG_FROM_SEC(sbi, secno);
215215
}
216216
return NULL_SEGNO;
217217
}
218218

219219
static unsigned int get_cb_cost(struct f2fs_sb_info *sbi, unsigned int segno)
220220
{
221221
struct sit_info *sit_i = SIT_I(sbi);
222-
unsigned int secno = GET_SECNO(sbi, segno);
223-
unsigned int start = secno * sbi->segs_per_sec;
222+
unsigned int secno = GET_SEC_FROM_SEG(sbi, segno);
223+
unsigned int start = GET_SEG_FROM_SEC(sbi, secno);
224224
unsigned long long mtime = 0;
225225
unsigned int vblocks;
226226
unsigned char age = 0;
@@ -343,7 +343,7 @@ static int get_victim_by_default(struct f2fs_sb_info *sbi,
343343
nsearched++;
344344
}
345345

346-
secno = GET_SECNO(sbi, segno);
346+
secno = GET_SEC_FROM_SEG(sbi, segno);
347347

348348
if (sec_usage_check(sbi, secno))
349349
goto next;
@@ -372,7 +372,7 @@ static int get_victim_by_default(struct f2fs_sb_info *sbi,
372372
if (p.min_segno != NULL_SEGNO) {
373373
got_it:
374374
if (p.alloc_mode == LFS) {
375-
secno = GET_SECNO(sbi, p.min_segno);
375+
secno = GET_SEC_FROM_SEG(sbi, p.min_segno);
376376
if (gc_type == FG_GC)
377377
sbi->cur_victim_sec = secno;
378378
else
@@ -1006,16 +1006,15 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background)
10061006

10071007
void build_gc_manager(struct f2fs_sb_info *sbi)
10081008
{
1009-
u64 main_count, resv_count, ovp_count, blocks_per_sec;
1009+
u64 main_count, resv_count, ovp_count;
10101010

10111011
DIRTY_I(sbi)->v_ops = &default_v_ops;
10121012

10131013
/* threshold of # of valid blocks in a section for victims of FG_GC */
10141014
main_count = SM_I(sbi)->main_segments << sbi->log_blocks_per_seg;
10151015
resv_count = SM_I(sbi)->reserved_segments << sbi->log_blocks_per_seg;
10161016
ovp_count = SM_I(sbi)->ovp_segments << sbi->log_blocks_per_seg;
1017-
blocks_per_sec = sbi->blocks_per_seg * sbi->segs_per_sec;
10181017

1019-
sbi->fggc_threshold = div64_u64((main_count - ovp_count) * blocks_per_sec,
1020-
(main_count - resv_count));
1018+
sbi->fggc_threshold = div64_u64((main_count - ovp_count) *
1019+
BLKS_PER_SEC(sbi), (main_count - resv_count));
10211020
}

‎fs/f2fs/segment.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ static void __remove_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno,
637637
dirty_i->nr_dirty[t]--;
638638

639639
if (get_valid_blocks(sbi, segno, true) == 0)
640-
clear_bit(GET_SECNO(sbi, segno),
640+
clear_bit(GET_SEC_FROM_SEG(sbi, segno),
641641
dirty_i->victim_secmap);
642642
}
643643
}
@@ -1106,8 +1106,8 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)
11061106
continue;
11071107
}
11081108
next:
1109-
secno = GET_SECNO(sbi, start);
1110-
start_segno = secno * sbi->segs_per_sec;
1109+
secno = GET_SEC_FROM_SEG(sbi, start);
1110+
start_segno = GET_SEG_FROM_SEC(sbi, secno);
11111111
if (!IS_CURSEC(sbi, secno) &&
11121112
!get_valid_blocks(sbi, start, true))
11131113
f2fs_issue_discard(sbi, START_BLOCK(sbi, start_segno),
@@ -1462,8 +1462,8 @@ static void get_new_segment(struct f2fs_sb_info *sbi,
14621462
struct free_segmap_info *free_i = FREE_I(sbi);
14631463
unsigned int segno, secno, zoneno;
14641464
unsigned int total_zones = MAIN_SECS(sbi) / sbi->secs_per_zone;
1465-
unsigned int hint = *newseg / sbi->segs_per_sec;
1466-
unsigned int old_zoneno = GET_ZONENO_FROM_SEGNO(sbi, *newseg);
1465+
unsigned int hint = GET_SEC_FROM_SEG(sbi, *newseg);
1466+
unsigned int old_zoneno = GET_ZONE_FROM_SEG(sbi, *newseg);
14671467
unsigned int left_start = hint;
14681468
bool init = true;
14691469
int go_left = 0;
@@ -1473,8 +1473,8 @@ static void get_new_segment(struct f2fs_sb_info *sbi,
14731473

14741474
if (!new_sec && ((*newseg + 1) % sbi->segs_per_sec)) {
14751475
segno = find_next_zero_bit(free_i->free_segmap,
1476-
(hint + 1) * sbi->segs_per_sec, *newseg + 1);
1477-
if (segno < (hint + 1) * sbi->segs_per_sec)
1476+
GET_SEG_FROM_SEC(sbi, hint + 1), *newseg + 1);
1477+
if (segno < GET_SEG_FROM_SEC(sbi, hint + 1))
14781478
goto got_it;
14791479
}
14801480
find_other_zone:
@@ -1505,8 +1505,8 @@ static void get_new_segment(struct f2fs_sb_info *sbi,
15051505
secno = left_start;
15061506
skip_left:
15071507
hint = secno;
1508-
segno = secno * sbi->segs_per_sec;
1509-
zoneno = secno / sbi->secs_per_zone;
1508+
segno = GET_SEG_FROM_SEC(sbi, secno);
1509+
zoneno = GET_ZONE_FROM_SEC(sbi, secno);
15101510

15111511
/* give up on finding another zone */
15121512
if (!init)
@@ -1550,7 +1550,7 @@ static void reset_curseg(struct f2fs_sb_info *sbi, int type, int modified)
15501550
struct summary_footer *sum_footer;
15511551

15521552
curseg->segno = curseg->next_segno;
1553-
curseg->zone = GET_ZONENO_FROM_SEGNO(sbi, curseg->segno);
1553+
curseg->zone = GET_ZONE_FROM_SEG(sbi, curseg->segno);
15541554
curseg->next_blkoff = 0;
15551555
curseg->next_segno = NULL_SEGNO;
15561556

‎fs/f2fs/segment.h‎

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,16 @@
7878
((((blk_addr) == NULL_ADDR) || ((blk_addr) == NEW_ADDR)) ? \
7979
NULL_SEGNO : GET_L2R_SEGNO(FREE_I(sbi), \
8080
GET_SEGNO_FROM_SEG0(sbi, blk_addr)))
81-
#define GET_SECNO(sbi, segno) \
81+
#define BLKS_PER_SEC(sbi) \
82+
((sbi)->segs_per_sec * (sbi)->blocks_per_seg)
83+
#define GET_SEC_FROM_SEG(sbi, segno) \
8284
((segno) / (sbi)->segs_per_sec)
83-
#define GET_SEGNO_FROM_SECNO(sbi, secno) \
85+
#define GET_SEG_FROM_SEC(sbi, secno) \
8486
((secno) * (sbi)->segs_per_sec)
85-
#define GET_ZONENO_FROM_SEGNO(sbi, segno) \
86-
(((segno) / (sbi)->segs_per_sec) / (sbi)->secs_per_zone)
87+
#define GET_ZONE_FROM_SEC(sbi, secno) \
88+
((secno) / (sbi)->secs_per_zone)
89+
#define GET_ZONE_FROM_SEG(sbi, segno) \
90+
GET_ZONE_FROM_SEC(sbi, GET_SEC_FROM_SEG(sbi, segno))
8791

8892
#define GET_SUM_BLOCK(sbi, segno) \
8993
((sbi)->sm_info->ssa_blkaddr + (segno))
@@ -305,7 +309,7 @@ static inline struct sec_entry *get_sec_entry(struct f2fs_sb_info *sbi,
305309
unsigned int segno)
306310
{
307311
struct sit_info *sit_i = SIT_I(sbi);
308-
return &sit_i->sec_entries[GET_SECNO(sbi, segno)];
312+
return &sit_i->sec_entries[GET_SEC_FROM_SEG(sbi, segno)];
309313
}
310314

311315
static inline unsigned int get_valid_blocks(struct f2fs_sb_info *sbi,
@@ -360,8 +364,8 @@ static inline unsigned int find_next_inuse(struct free_segmap_info *free_i,
360364
static inline void __set_free(struct f2fs_sb_info *sbi, unsigned int segno)
361365
{
362366
struct free_segmap_info *free_i = FREE_I(sbi);
363-
unsigned int secno = segno / sbi->segs_per_sec;
364-
unsigned int start_segno = secno * sbi->segs_per_sec;
367+
unsigned int secno = GET_SEC_FROM_SEG(sbi, segno);
368+
unsigned int start_segno = GET_SEG_FROM_SEC(sbi, secno);
365369
unsigned int next;
366370

367371
spin_lock(&free_i->segmap_lock);
@@ -381,7 +385,8 @@ static inline void __set_inuse(struct f2fs_sb_info *sbi,
381385
unsigned int segno)
382386
{
383387
struct free_segmap_info *free_i = FREE_I(sbi);
384-
unsigned int secno = segno / sbi->segs_per_sec;
388+
unsigned int secno = GET_SEC_FROM_SEG(sbi, segno);
389+
385390
set_bit(segno, free_i->free_segmap);
386391
free_i->free_segments--;
387392
if (!test_and_set_bit(secno, free_i->free_secmap))
@@ -392,8 +397,8 @@ static inline void __set_test_and_free(struct f2fs_sb_info *sbi,
392397
unsigned int segno)
393398
{
394399
struct free_segmap_info *free_i = FREE_I(sbi);
395-
unsigned int secno = segno / sbi->segs_per_sec;
396-
unsigned int start_segno = secno * sbi->segs_per_sec;
400+
unsigned int secno = GET_SEC_FROM_SEG(sbi, segno);
401+
unsigned int start_segno = GET_SEG_FROM_SEC(sbi, secno);
397402
unsigned int next;
398403

399404
spin_lock(&free_i->segmap_lock);
@@ -414,7 +419,8 @@ static inline void __set_test_and_inuse(struct f2fs_sb_info *sbi,
414419
unsigned int segno)
415420
{
416421
struct free_segmap_info *free_i = FREE_I(sbi);
417-
unsigned int secno = segno / sbi->segs_per_sec;
422+
unsigned int secno = GET_SEC_FROM_SEG(sbi, segno);
423+
418424
spin_lock(&free_i->segmap_lock);
419425
if (!test_and_set_bit(segno, free_i->free_segmap)) {
420426
free_i->free_segments--;
@@ -479,12 +485,12 @@ static inline int overprovision_segments(struct f2fs_sb_info *sbi)
479485

480486
static inline int overprovision_sections(struct f2fs_sb_info *sbi)
481487
{
482-
return ((unsigned int) overprovision_segments(sbi)) / sbi->segs_per_sec;
488+
return GET_SEC_FROM_SEG(sbi, (unsigned int)overprovision_segments(sbi));
483489
}
484490

485491
static inline int reserved_sections(struct f2fs_sb_info *sbi)
486492
{
487-
return ((unsigned int) reserved_segments(sbi)) / sbi->segs_per_sec;
493+
return GET_SEC_FROM_SEG(sbi, (unsigned int)reserved_segments(sbi));
488494
}
489495

490496
static inline bool need_SSR(struct f2fs_sb_info *sbi)
@@ -722,7 +728,7 @@ static inline block_t sum_blk_addr(struct f2fs_sb_info *sbi, int base, int type)
722728
static inline bool no_fggc_candidate(struct f2fs_sb_info *sbi,
723729
unsigned int secno)
724730
{
725-
if (get_valid_blocks(sbi, GET_SEGNO_FROM_SECNO(sbi, secno), true) >=
731+
if (get_valid_blocks(sbi, GET_SEG_FROM_SEC(sbi, secno), true) >=
726732
sbi->fggc_threshold)
727733
return true;
728734
return false;

0 commit comments

Comments
 (0)