f2fs: use bool for booleans
[GitHub/exynos8895/android_kernel_samsung_universal8895.git] / fs / f2fs / segment.h
CommitLineData
0a8165d7 1/*
39a53e0c
JK
2 * fs/f2fs/segment.h
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
ac5d156c
JK
11#include <linux/blkdev.h>
12
39a53e0c
JK
13/* constant macro */
14#define NULL_SEGNO ((unsigned int)(~0))
5ec4e49f 15#define NULL_SECNO ((unsigned int)(~0))
39a53e0c 16
6224da87 17/* L: Logical segment # in volume, R: Relative segment # in main area */
39a53e0c
JK
18#define GET_L2R_SEGNO(free_i, segno) (segno - free_i->start_segno)
19#define GET_R2L_SEGNO(free_i, segno) (segno + free_i->start_segno)
20
21#define IS_DATASEG(t) \
22 ((t == CURSEG_HOT_DATA) || (t == CURSEG_COLD_DATA) || \
23 (t == CURSEG_WARM_DATA))
24
25#define IS_NODESEG(t) \
26 ((t == CURSEG_HOT_NODE) || (t == CURSEG_COLD_NODE) || \
27 (t == CURSEG_WARM_NODE))
28
5c773ba3
JK
29#define IS_CURSEG(sbi, seg) \
30 ((seg == CURSEG_I(sbi, CURSEG_HOT_DATA)->segno) || \
31 (seg == CURSEG_I(sbi, CURSEG_WARM_DATA)->segno) || \
32 (seg == CURSEG_I(sbi, CURSEG_COLD_DATA)->segno) || \
33 (seg == CURSEG_I(sbi, CURSEG_HOT_NODE)->segno) || \
34 (seg == CURSEG_I(sbi, CURSEG_WARM_NODE)->segno) || \
35 (seg == CURSEG_I(sbi, CURSEG_COLD_NODE)->segno))
39a53e0c
JK
36
37#define IS_CURSEC(sbi, secno) \
38 ((secno == CURSEG_I(sbi, CURSEG_HOT_DATA)->segno / \
39 sbi->segs_per_sec) || \
40 (secno == CURSEG_I(sbi, CURSEG_WARM_DATA)->segno / \
41 sbi->segs_per_sec) || \
42 (secno == CURSEG_I(sbi, CURSEG_COLD_DATA)->segno / \
43 sbi->segs_per_sec) || \
44 (secno == CURSEG_I(sbi, CURSEG_HOT_NODE)->segno / \
45 sbi->segs_per_sec) || \
46 (secno == CURSEG_I(sbi, CURSEG_WARM_NODE)->segno / \
47 sbi->segs_per_sec) || \
48 (secno == CURSEG_I(sbi, CURSEG_COLD_NODE)->segno / \
49 sbi->segs_per_sec)) \
50
51#define START_BLOCK(sbi, segno) \
52 (SM_I(sbi)->seg0_blkaddr + \
53 (GET_R2L_SEGNO(FREE_I(sbi), segno) << sbi->log_blocks_per_seg))
54#define NEXT_FREE_BLKADDR(sbi, curseg) \
55 (START_BLOCK(sbi, curseg->segno) + curseg->next_blkoff)
56
57#define MAIN_BASE_BLOCK(sbi) (SM_I(sbi)->main_blkaddr)
58
59#define GET_SEGOFF_FROM_SEG0(sbi, blk_addr) \
60 ((blk_addr) - SM_I(sbi)->seg0_blkaddr)
61#define GET_SEGNO_FROM_SEG0(sbi, blk_addr) \
62 (GET_SEGOFF_FROM_SEG0(sbi, blk_addr) >> sbi->log_blocks_per_seg)
63#define GET_SEGNO(sbi, blk_addr) \
64 (((blk_addr == NULL_ADDR) || (blk_addr == NEW_ADDR)) ? \
65 NULL_SEGNO : GET_L2R_SEGNO(FREE_I(sbi), \
66 GET_SEGNO_FROM_SEG0(sbi, blk_addr)))
67#define GET_SECNO(sbi, segno) \
68 ((segno) / sbi->segs_per_sec)
69#define GET_ZONENO_FROM_SEGNO(sbi, segno) \
70 ((segno / sbi->segs_per_sec) / sbi->secs_per_zone)
71
72#define GET_SUM_BLOCK(sbi, segno) \
73 ((sbi->sm_info->ssa_blkaddr) + segno)
74
75#define GET_SUM_TYPE(footer) ((footer)->entry_type)
76#define SET_SUM_TYPE(footer, type) ((footer)->entry_type = type)
77
78#define SIT_ENTRY_OFFSET(sit_i, segno) \
79 (segno % sit_i->sents_per_block)
80#define SIT_BLOCK_OFFSET(sit_i, segno) \
81 (segno / SIT_ENTRY_PER_BLOCK)
82#define START_SEGNO(sit_i, segno) \
83 (SIT_BLOCK_OFFSET(sit_i, segno) * SIT_ENTRY_PER_BLOCK)
84#define f2fs_bitmap_size(nr) \
85 (BITS_TO_LONGS(nr) * sizeof(unsigned long))
86#define TOTAL_SEGS(sbi) (SM_I(sbi)->main_segments)
53cf9522 87#define TOTAL_SECS(sbi) (sbi->total_sections)
39a53e0c 88
3cd8a239
JK
89#define SECTOR_FROM_BLOCK(sbi, blk_addr) \
90 (blk_addr << ((sbi)->log_blocksize - F2FS_LOG_SECTOR_SIZE))
ac5d156c
JK
91#define SECTOR_TO_BLOCK(sbi, sectors) \
92 (sectors >> ((sbi)->log_blocksize - F2FS_LOG_SECTOR_SIZE))
cc7b1bb1
CY
93#define MAX_BIO_BLOCKS(max_hw_blocks) \
94 (min((int)max_hw_blocks, BIO_MAX_PAGES))
3cd8a239 95
39a53e0c
JK
96/* during checkpoint, bio_private is used to synchronize the last bio */
97struct bio_private {
98 struct f2fs_sb_info *sbi;
99 bool is_sync;
100 void *wait;
101};
102
103/*
104 * indicate a block allocation direction: RIGHT and LEFT.
105 * RIGHT means allocating new sections towards the end of volume.
106 * LEFT means the opposite direction.
107 */
108enum {
109 ALLOC_RIGHT = 0,
110 ALLOC_LEFT
111};
112
113/*
114 * In the victim_sel_policy->alloc_mode, there are two block allocation modes.
115 * LFS writes data sequentially with cleaning operations.
116 * SSR (Slack Space Recycle) reuses obsolete space without cleaning operations.
117 */
118enum {
119 LFS = 0,
120 SSR
121};
122
123/*
124 * In the victim_sel_policy->gc_mode, there are two gc, aka cleaning, modes.
125 * GC_CB is based on cost-benefit algorithm.
126 * GC_GREEDY is based on greedy algorithm.
127 */
128enum {
129 GC_CB = 0,
130 GC_GREEDY
131};
132
133/*
134 * BG_GC means the background cleaning job.
135 * FG_GC means the on-demand cleaning job.
136 */
137enum {
138 BG_GC = 0,
139 FG_GC
140};
141
142/* for a function parameter to select a victim segment */
143struct victim_sel_policy {
144 int alloc_mode; /* LFS or SSR */
145 int gc_mode; /* GC_CB or GC_GREEDY */
146 unsigned long *dirty_segmap; /* dirty segment bitmap */
a26b7c8a 147 unsigned int max_search; /* maximum # of segments to search */
39a53e0c
JK
148 unsigned int offset; /* last scanned bitmap offset */
149 unsigned int ofs_unit; /* bitmap search unit */
150 unsigned int min_cost; /* minimum cost */
151 unsigned int min_segno; /* segment # having min. cost */
152};
153
154struct seg_entry {
155 unsigned short valid_blocks; /* # of valid blocks */
156 unsigned char *cur_valid_map; /* validity bitmap of blocks */
157 /*
158 * # of valid blocks and the validity bitmap stored in the the last
159 * checkpoint pack. This information is used by the SSR mode.
160 */
161 unsigned short ckpt_valid_blocks;
162 unsigned char *ckpt_valid_map;
163 unsigned char type; /* segment type like CURSEG_XXX_TYPE */
164 unsigned long long mtime; /* modification time of the segment */
165};
166
167struct sec_entry {
168 unsigned int valid_blocks; /* # of valid blocks in a section */
169};
170
171struct segment_allocation {
172 void (*allocate_segment)(struct f2fs_sb_info *, int, bool);
173};
174
175struct sit_info {
176 const struct segment_allocation *s_ops;
177
178 block_t sit_base_addr; /* start block address of SIT area */
179 block_t sit_blocks; /* # of blocks used by SIT area */
180 block_t written_valid_blocks; /* # of valid blocks in main area */
181 char *sit_bitmap; /* SIT bitmap pointer */
182 unsigned int bitmap_size; /* SIT bitmap size */
183
184 unsigned long *dirty_sentries_bitmap; /* bitmap for dirty sentries */
185 unsigned int dirty_sentries; /* # of dirty sentries */
186 unsigned int sents_per_block; /* # of SIT entries per block */
187 struct mutex sentry_lock; /* to protect SIT cache */
188 struct seg_entry *sentries; /* SIT segment-level cache */
189 struct sec_entry *sec_entries; /* SIT section-level cache */
190
191 /* for cost-benefit algorithm in cleaning procedure */
192 unsigned long long elapsed_time; /* elapsed time after mount */
193 unsigned long long mounted_time; /* mount time */
194 unsigned long long min_mtime; /* min. modification time */
195 unsigned long long max_mtime; /* max. modification time */
196};
197
198struct free_segmap_info {
199 unsigned int start_segno; /* start segment number logically */
200 unsigned int free_segments; /* # of free segments */
201 unsigned int free_sections; /* # of free sections */
202 rwlock_t segmap_lock; /* free segmap lock */
203 unsigned long *free_segmap; /* free segment bitmap */
204 unsigned long *free_secmap; /* free section bitmap */
205};
206
207/* Notice: The order of dirty type is same with CURSEG_XXX in f2fs.h */
208enum dirty_type {
209 DIRTY_HOT_DATA, /* dirty segments assigned as hot data logs */
210 DIRTY_WARM_DATA, /* dirty segments assigned as warm data logs */
211 DIRTY_COLD_DATA, /* dirty segments assigned as cold data logs */
212 DIRTY_HOT_NODE, /* dirty segments assigned as hot node logs */
213 DIRTY_WARM_NODE, /* dirty segments assigned as warm node logs */
214 DIRTY_COLD_NODE, /* dirty segments assigned as cold node logs */
215 DIRTY, /* to count # of dirty segments */
216 PRE, /* to count # of entirely obsolete segments */
217 NR_DIRTY_TYPE
218};
219
220struct dirty_seglist_info {
221 const struct victim_selection *v_ops; /* victim selction operation */
222 unsigned long *dirty_segmap[NR_DIRTY_TYPE];
223 struct mutex seglist_lock; /* lock for segment bitmaps */
224 int nr_dirty[NR_DIRTY_TYPE]; /* # of dirty segments */
5ec4e49f 225 unsigned long *victim_secmap; /* background GC victims */
39a53e0c
JK
226};
227
228/* victim selection function for cleaning and SSR */
229struct victim_selection {
230 int (*get_victim)(struct f2fs_sb_info *, unsigned int *,
231 int, int, char);
232};
233
234/* for active log information */
235struct curseg_info {
236 struct mutex curseg_mutex; /* lock for consistency */
237 struct f2fs_summary_block *sum_blk; /* cached summary block */
238 unsigned char alloc_type; /* current allocation type */
239 unsigned int segno; /* current segment number */
240 unsigned short next_blkoff; /* next block offset to write */
241 unsigned int zone; /* current zone number */
242 unsigned int next_segno; /* preallocated segment */
243};
244
245/*
246 * inline functions
247 */
248static inline struct curseg_info *CURSEG_I(struct f2fs_sb_info *sbi, int type)
249{
250 return (struct curseg_info *)(SM_I(sbi)->curseg_array + type);
251}
252
253static inline struct seg_entry *get_seg_entry(struct f2fs_sb_info *sbi,
254 unsigned int segno)
255{
256 struct sit_info *sit_i = SIT_I(sbi);
257 return &sit_i->sentries[segno];
258}
259
260static inline struct sec_entry *get_sec_entry(struct f2fs_sb_info *sbi,
261 unsigned int segno)
262{
263 struct sit_info *sit_i = SIT_I(sbi);
264 return &sit_i->sec_entries[GET_SECNO(sbi, segno)];
265}
266
267static inline unsigned int get_valid_blocks(struct f2fs_sb_info *sbi,
268 unsigned int segno, int section)
269{
270 /*
271 * In order to get # of valid blocks in a section instantly from many
272 * segments, f2fs manages two counting structures separately.
273 */
274 if (section > 1)
275 return get_sec_entry(sbi, segno)->valid_blocks;
276 else
277 return get_seg_entry(sbi, segno)->valid_blocks;
278}
279
280static inline void seg_info_from_raw_sit(struct seg_entry *se,
281 struct f2fs_sit_entry *rs)
282{
283 se->valid_blocks = GET_SIT_VBLOCKS(rs);
284 se->ckpt_valid_blocks = GET_SIT_VBLOCKS(rs);
285 memcpy(se->cur_valid_map, rs->valid_map, SIT_VBLOCK_MAP_SIZE);
286 memcpy(se->ckpt_valid_map, rs->valid_map, SIT_VBLOCK_MAP_SIZE);
287 se->type = GET_SIT_TYPE(rs);
288 se->mtime = le64_to_cpu(rs->mtime);
289}
290
291static inline void seg_info_to_raw_sit(struct seg_entry *se,
292 struct f2fs_sit_entry *rs)
293{
294 unsigned short raw_vblocks = (se->type << SIT_VBLOCKS_SHIFT) |
295 se->valid_blocks;
296 rs->vblocks = cpu_to_le16(raw_vblocks);
297 memcpy(rs->valid_map, se->cur_valid_map, SIT_VBLOCK_MAP_SIZE);
298 memcpy(se->ckpt_valid_map, rs->valid_map, SIT_VBLOCK_MAP_SIZE);
299 se->ckpt_valid_blocks = se->valid_blocks;
300 rs->mtime = cpu_to_le64(se->mtime);
301}
302
303static inline unsigned int find_next_inuse(struct free_segmap_info *free_i,
304 unsigned int max, unsigned int segno)
305{
306 unsigned int ret;
307 read_lock(&free_i->segmap_lock);
308 ret = find_next_bit(free_i->free_segmap, max, segno);
309 read_unlock(&free_i->segmap_lock);
310 return ret;
311}
312
313static inline void __set_free(struct f2fs_sb_info *sbi, unsigned int segno)
314{
315 struct free_segmap_info *free_i = FREE_I(sbi);
316 unsigned int secno = segno / sbi->segs_per_sec;
317 unsigned int start_segno = secno * sbi->segs_per_sec;
318 unsigned int next;
319
320 write_lock(&free_i->segmap_lock);
321 clear_bit(segno, free_i->free_segmap);
322 free_i->free_segments++;
323
324 next = find_next_bit(free_i->free_segmap, TOTAL_SEGS(sbi), start_segno);
325 if (next >= start_segno + sbi->segs_per_sec) {
326 clear_bit(secno, free_i->free_secmap);
327 free_i->free_sections++;
328 }
329 write_unlock(&free_i->segmap_lock);
330}
331
332static inline void __set_inuse(struct f2fs_sb_info *sbi,
333 unsigned int segno)
334{
335 struct free_segmap_info *free_i = FREE_I(sbi);
336 unsigned int secno = segno / sbi->segs_per_sec;
337 set_bit(segno, free_i->free_segmap);
338 free_i->free_segments--;
339 if (!test_and_set_bit(secno, free_i->free_secmap))
340 free_i->free_sections--;
341}
342
343static inline void __set_test_and_free(struct f2fs_sb_info *sbi,
344 unsigned int segno)
345{
346 struct free_segmap_info *free_i = FREE_I(sbi);
347 unsigned int secno = segno / sbi->segs_per_sec;
348 unsigned int start_segno = secno * sbi->segs_per_sec;
349 unsigned int next;
350
351 write_lock(&free_i->segmap_lock);
352 if (test_and_clear_bit(segno, free_i->free_segmap)) {
353 free_i->free_segments++;
354
355 next = find_next_bit(free_i->free_segmap, TOTAL_SEGS(sbi),
356 start_segno);
357 if (next >= start_segno + sbi->segs_per_sec) {
358 if (test_and_clear_bit(secno, free_i->free_secmap))
359 free_i->free_sections++;
360 }
361 }
362 write_unlock(&free_i->segmap_lock);
363}
364
365static inline void __set_test_and_inuse(struct f2fs_sb_info *sbi,
366 unsigned int segno)
367{
368 struct free_segmap_info *free_i = FREE_I(sbi);
369 unsigned int secno = segno / sbi->segs_per_sec;
370 write_lock(&free_i->segmap_lock);
371 if (!test_and_set_bit(segno, free_i->free_segmap)) {
372 free_i->free_segments--;
373 if (!test_and_set_bit(secno, free_i->free_secmap))
374 free_i->free_sections--;
375 }
376 write_unlock(&free_i->segmap_lock);
377}
378
379static inline void get_sit_bitmap(struct f2fs_sb_info *sbi,
380 void *dst_addr)
381{
382 struct sit_info *sit_i = SIT_I(sbi);
383 memcpy(dst_addr, sit_i->sit_bitmap, sit_i->bitmap_size);
384}
385
386static inline block_t written_block_count(struct f2fs_sb_info *sbi)
387{
388 struct sit_info *sit_i = SIT_I(sbi);
389 block_t vblocks;
390
391 mutex_lock(&sit_i->sentry_lock);
392 vblocks = sit_i->written_valid_blocks;
393 mutex_unlock(&sit_i->sentry_lock);
394
395 return vblocks;
396}
397
398static inline unsigned int free_segments(struct f2fs_sb_info *sbi)
399{
400 struct free_segmap_info *free_i = FREE_I(sbi);
401 unsigned int free_segs;
402
403 read_lock(&free_i->segmap_lock);
404 free_segs = free_i->free_segments;
405 read_unlock(&free_i->segmap_lock);
406
407 return free_segs;
408}
409
410static inline int reserved_segments(struct f2fs_sb_info *sbi)
411{
412 return SM_I(sbi)->reserved_segments;
413}
414
415static inline unsigned int free_sections(struct f2fs_sb_info *sbi)
416{
417 struct free_segmap_info *free_i = FREE_I(sbi);
418 unsigned int free_secs;
419
420 read_lock(&free_i->segmap_lock);
421 free_secs = free_i->free_sections;
422 read_unlock(&free_i->segmap_lock);
423
424 return free_secs;
425}
426
427static inline unsigned int prefree_segments(struct f2fs_sb_info *sbi)
428{
429 return DIRTY_I(sbi)->nr_dirty[PRE];
430}
431
432static inline unsigned int dirty_segments(struct f2fs_sb_info *sbi)
433{
434 return DIRTY_I(sbi)->nr_dirty[DIRTY_HOT_DATA] +
435 DIRTY_I(sbi)->nr_dirty[DIRTY_WARM_DATA] +
436 DIRTY_I(sbi)->nr_dirty[DIRTY_COLD_DATA] +
437 DIRTY_I(sbi)->nr_dirty[DIRTY_HOT_NODE] +
438 DIRTY_I(sbi)->nr_dirty[DIRTY_WARM_NODE] +
439 DIRTY_I(sbi)->nr_dirty[DIRTY_COLD_NODE];
440}
441
442static inline int overprovision_segments(struct f2fs_sb_info *sbi)
443{
444 return SM_I(sbi)->ovp_segments;
445}
446
447static inline int overprovision_sections(struct f2fs_sb_info *sbi)
448{
449 return ((unsigned int) overprovision_segments(sbi)) / sbi->segs_per_sec;
450}
451
452static inline int reserved_sections(struct f2fs_sb_info *sbi)
453{
454 return ((unsigned int) reserved_segments(sbi)) / sbi->segs_per_sec;
455}
456
457static inline bool need_SSR(struct f2fs_sb_info *sbi)
458{
c34e333f
JK
459 return ((prefree_segments(sbi) / sbi->segs_per_sec)
460 + free_sections(sbi) < overprovision_sections(sbi));
39a53e0c
JK
461}
462
43727527 463static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi, int freed)
39a53e0c 464{
5ac206cf
NJ
465 int node_secs = get_blocktype_secs(sbi, F2FS_DIRTY_NODES);
466 int dent_secs = get_blocktype_secs(sbi, F2FS_DIRTY_DENTS);
43727527 467
029cd28c
JK
468 if (sbi->por_doing)
469 return false;
470
43727527 471 return ((free_sections(sbi) + freed) <= (node_secs + 2 * dent_secs +
b1f1daf8 472 reserved_sections(sbi)));
39a53e0c
JK
473}
474
475static inline int utilization(struct f2fs_sb_info *sbi)
476{
222cbdc4 477 return div_u64((u64)valid_user_blocks(sbi) * 100, sbi->user_block_count);
39a53e0c
JK
478}
479
480/*
481 * Sometimes f2fs may be better to drop out-of-place update policy.
482 * So, if fs utilization is over MIN_IPU_UTIL, then f2fs tries to write
483 * data in the original place likewise other traditional file systems.
484 * But, currently set 100 in percentage, which means it is disabled.
485 * See below need_inplace_update().
486 */
487#define MIN_IPU_UTIL 100
488static inline bool need_inplace_update(struct inode *inode)
489{
490 struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
491 if (S_ISDIR(inode->i_mode))
492 return false;
493 if (need_SSR(sbi) && utilization(sbi) > MIN_IPU_UTIL)
494 return true;
495 return false;
496}
497
498static inline unsigned int curseg_segno(struct f2fs_sb_info *sbi,
499 int type)
500{
501 struct curseg_info *curseg = CURSEG_I(sbi, type);
502 return curseg->segno;
503}
504
505static inline unsigned char curseg_alloc_type(struct f2fs_sb_info *sbi,
506 int type)
507{
508 struct curseg_info *curseg = CURSEG_I(sbi, type);
509 return curseg->alloc_type;
510}
511
512static inline unsigned short curseg_blkoff(struct f2fs_sb_info *sbi, int type)
513{
514 struct curseg_info *curseg = CURSEG_I(sbi, type);
515 return curseg->next_blkoff;
516}
517
518static inline void check_seg_range(struct f2fs_sb_info *sbi, unsigned int segno)
519{
520 unsigned int end_segno = SM_I(sbi)->segment_count - 1;
521 BUG_ON(segno > end_segno);
522}
523
524/*
525 * This function is used for only debugging.
526 * NOTE: In future, we have to remove this function.
527 */
528static inline void verify_block_addr(struct f2fs_sb_info *sbi, block_t blk_addr)
529{
530 struct f2fs_sm_info *sm_info = SM_I(sbi);
531 block_t total_blks = sm_info->segment_count << sbi->log_blocks_per_seg;
532 block_t start_addr = sm_info->seg0_blkaddr;
533 block_t end_addr = start_addr + total_blks - 1;
534 BUG_ON(blk_addr < start_addr);
535 BUG_ON(blk_addr > end_addr);
536}
537
538/*
539 * Summary block is always treated as invalid block
540 */
541static inline void check_block_count(struct f2fs_sb_info *sbi,
542 int segno, struct f2fs_sit_entry *raw_sit)
543{
544 struct f2fs_sm_info *sm_info = SM_I(sbi);
545 unsigned int end_segno = sm_info->segment_count - 1;
546 int valid_blocks = 0;
547 int i;
548
549 /* check segment usage */
550 BUG_ON(GET_SIT_VBLOCKS(raw_sit) > sbi->blocks_per_seg);
551
552 /* check boundary of a given segment number */
553 BUG_ON(segno > end_segno);
554
555 /* check bitmap with valid block count */
556 for (i = 0; i < sbi->blocks_per_seg; i++)
557 if (f2fs_test_bit(i, raw_sit->valid_map))
558 valid_blocks++;
559 BUG_ON(GET_SIT_VBLOCKS(raw_sit) != valid_blocks);
560}
561
562static inline pgoff_t current_sit_addr(struct f2fs_sb_info *sbi,
563 unsigned int start)
564{
565 struct sit_info *sit_i = SIT_I(sbi);
566 unsigned int offset = SIT_BLOCK_OFFSET(sit_i, start);
567 block_t blk_addr = sit_i->sit_base_addr + offset;
568
569 check_seg_range(sbi, start);
570
571 /* calculate sit block address */
572 if (f2fs_test_bit(offset, sit_i->sit_bitmap))
573 blk_addr += sit_i->sit_blocks;
574
575 return blk_addr;
576}
577
578static inline pgoff_t next_sit_addr(struct f2fs_sb_info *sbi,
579 pgoff_t block_addr)
580{
581 struct sit_info *sit_i = SIT_I(sbi);
582 block_addr -= sit_i->sit_base_addr;
583 if (block_addr < sit_i->sit_blocks)
584 block_addr += sit_i->sit_blocks;
585 else
586 block_addr -= sit_i->sit_blocks;
587
588 return block_addr + sit_i->sit_base_addr;
589}
590
591static inline void set_to_next_sit(struct sit_info *sit_i, unsigned int start)
592{
593 unsigned int block_off = SIT_BLOCK_OFFSET(sit_i, start);
594
595 if (f2fs_test_bit(block_off, sit_i->sit_bitmap))
596 f2fs_clear_bit(block_off, sit_i->sit_bitmap);
597 else
598 f2fs_set_bit(block_off, sit_i->sit_bitmap);
599}
600
601static inline unsigned long long get_mtime(struct f2fs_sb_info *sbi)
602{
603 struct sit_info *sit_i = SIT_I(sbi);
604 return sit_i->elapsed_time + CURRENT_TIME_SEC.tv_sec -
605 sit_i->mounted_time;
606}
607
608static inline void set_summary(struct f2fs_summary *sum, nid_t nid,
609 unsigned int ofs_in_node, unsigned char version)
610{
611 sum->nid = cpu_to_le32(nid);
612 sum->ofs_in_node = cpu_to_le16(ofs_in_node);
613 sum->version = version;
614}
615
616static inline block_t start_sum_block(struct f2fs_sb_info *sbi)
617{
618 return __start_cp_addr(sbi) +
619 le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
620}
621
622static inline block_t sum_blk_addr(struct f2fs_sb_info *sbi, int base, int type)
623{
624 return __start_cp_addr(sbi) +
625 le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_total_block_count)
626 - (base + 1) + type;
627}
5ec4e49f
JK
628
629static inline bool sec_usage_check(struct f2fs_sb_info *sbi, unsigned int secno)
630{
631 if (IS_CURSEC(sbi, secno) || (sbi->cur_victim_sec == secno))
632 return true;
633 return false;
634}
ac5d156c
JK
635
636static inline unsigned int max_hw_blocks(struct f2fs_sb_info *sbi)
637{
638 struct block_device *bdev = sbi->sb->s_bdev;
639 struct request_queue *q = bdev_get_queue(bdev);
640 return SECTOR_TO_BLOCK(sbi, queue_max_sectors(q));
641}