diff options
Diffstat (limited to 'fs/f2fs/segment.h')
-rw-r--r-- | fs/f2fs/segment.h | 81 |
1 files changed, 52 insertions, 29 deletions
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h index 269f690b4e24..5731682d7516 100644 --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h | |||
@@ -20,13 +20,8 @@ | |||
20 | #define GET_L2R_SEGNO(free_i, segno) (segno - free_i->start_segno) | 20 | #define GET_L2R_SEGNO(free_i, segno) (segno - free_i->start_segno) |
21 | #define GET_R2L_SEGNO(free_i, segno) (segno + free_i->start_segno) | 21 | #define GET_R2L_SEGNO(free_i, segno) (segno + free_i->start_segno) |
22 | 22 | ||
23 | #define IS_DATASEG(t) \ | 23 | #define IS_DATASEG(t) (t <= CURSEG_COLD_DATA) |
24 | ((t == CURSEG_HOT_DATA) || (t == CURSEG_COLD_DATA) || \ | 24 | #define IS_NODESEG(t) (t >= CURSEG_HOT_NODE) |
25 | (t == CURSEG_WARM_DATA)) | ||
26 | |||
27 | #define IS_NODESEG(t) \ | ||
28 | ((t == CURSEG_HOT_NODE) || (t == CURSEG_COLD_NODE) || \ | ||
29 | (t == CURSEG_WARM_NODE)) | ||
30 | 25 | ||
31 | #define IS_CURSEG(sbi, seg) \ | 26 | #define IS_CURSEG(sbi, seg) \ |
32 | ((seg == CURSEG_I(sbi, CURSEG_HOT_DATA)->segno) || \ | 27 | ((seg == CURSEG_I(sbi, CURSEG_HOT_DATA)->segno) || \ |
@@ -83,25 +78,20 @@ | |||
83 | (segno / SIT_ENTRY_PER_BLOCK) | 78 | (segno / SIT_ENTRY_PER_BLOCK) |
84 | #define START_SEGNO(sit_i, segno) \ | 79 | #define START_SEGNO(sit_i, segno) \ |
85 | (SIT_BLOCK_OFFSET(sit_i, segno) * SIT_ENTRY_PER_BLOCK) | 80 | (SIT_BLOCK_OFFSET(sit_i, segno) * SIT_ENTRY_PER_BLOCK) |
81 | #define SIT_BLK_CNT(sbi) \ | ||
82 | ((TOTAL_SEGS(sbi) + SIT_ENTRY_PER_BLOCK - 1) / SIT_ENTRY_PER_BLOCK) | ||
86 | #define f2fs_bitmap_size(nr) \ | 83 | #define f2fs_bitmap_size(nr) \ |
87 | (BITS_TO_LONGS(nr) * sizeof(unsigned long)) | 84 | (BITS_TO_LONGS(nr) * sizeof(unsigned long)) |
88 | #define TOTAL_SEGS(sbi) (SM_I(sbi)->main_segments) | 85 | #define TOTAL_SEGS(sbi) (SM_I(sbi)->main_segments) |
89 | #define TOTAL_SECS(sbi) (sbi->total_sections) | 86 | #define TOTAL_SECS(sbi) (sbi->total_sections) |
90 | 87 | ||
91 | #define SECTOR_FROM_BLOCK(sbi, blk_addr) \ | 88 | #define SECTOR_FROM_BLOCK(sbi, blk_addr) \ |
92 | (blk_addr << ((sbi)->log_blocksize - F2FS_LOG_SECTOR_SIZE)) | 89 | (((sector_t)blk_addr) << (sbi)->log_sectors_per_block) |
93 | #define SECTOR_TO_BLOCK(sbi, sectors) \ | 90 | #define SECTOR_TO_BLOCK(sbi, sectors) \ |
94 | (sectors >> ((sbi)->log_blocksize - F2FS_LOG_SECTOR_SIZE)) | 91 | (sectors >> (sbi)->log_sectors_per_block) |
95 | #define MAX_BIO_BLOCKS(max_hw_blocks) \ | 92 | #define MAX_BIO_BLOCKS(max_hw_blocks) \ |
96 | (min((int)max_hw_blocks, BIO_MAX_PAGES)) | 93 | (min((int)max_hw_blocks, BIO_MAX_PAGES)) |
97 | 94 | ||
98 | /* during checkpoint, bio_private is used to synchronize the last bio */ | ||
99 | struct bio_private { | ||
100 | struct f2fs_sb_info *sbi; | ||
101 | bool is_sync; | ||
102 | void *wait; | ||
103 | }; | ||
104 | |||
105 | /* | 95 | /* |
106 | * indicate a block allocation direction: RIGHT and LEFT. | 96 | * indicate a block allocation direction: RIGHT and LEFT. |
107 | * RIGHT means allocating new sections towards the end of volume. | 97 | * RIGHT means allocating new sections towards the end of volume. |
@@ -458,8 +448,8 @@ static inline int reserved_sections(struct f2fs_sb_info *sbi) | |||
458 | 448 | ||
459 | static inline bool need_SSR(struct f2fs_sb_info *sbi) | 449 | static inline bool need_SSR(struct f2fs_sb_info *sbi) |
460 | { | 450 | { |
461 | return ((prefree_segments(sbi) / sbi->segs_per_sec) | 451 | return (prefree_segments(sbi) / sbi->segs_per_sec) |
462 | + free_sections(sbi) < overprovision_sections(sbi)); | 452 | + free_sections(sbi) < overprovision_sections(sbi); |
463 | } | 453 | } |
464 | 454 | ||
465 | static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi, int freed) | 455 | static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi, int freed) |
@@ -467,38 +457,71 @@ static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi, int freed) | |||
467 | int node_secs = get_blocktype_secs(sbi, F2FS_DIRTY_NODES); | 457 | int node_secs = get_blocktype_secs(sbi, F2FS_DIRTY_NODES); |
468 | int dent_secs = get_blocktype_secs(sbi, F2FS_DIRTY_DENTS); | 458 | int dent_secs = get_blocktype_secs(sbi, F2FS_DIRTY_DENTS); |
469 | 459 | ||
470 | if (sbi->por_doing) | 460 | if (unlikely(sbi->por_doing)) |
471 | return false; | 461 | return false; |
472 | 462 | ||
473 | return ((free_sections(sbi) + freed) <= (node_secs + 2 * dent_secs + | 463 | return (free_sections(sbi) + freed) <= (node_secs + 2 * dent_secs + |
474 | reserved_sections(sbi))); | 464 | reserved_sections(sbi)); |
475 | } | 465 | } |
476 | 466 | ||
477 | static inline bool excess_prefree_segs(struct f2fs_sb_info *sbi) | 467 | static inline bool excess_prefree_segs(struct f2fs_sb_info *sbi) |
478 | { | 468 | { |
479 | return (prefree_segments(sbi) > SM_I(sbi)->rec_prefree_segments); | 469 | return prefree_segments(sbi) > SM_I(sbi)->rec_prefree_segments; |
480 | } | 470 | } |
481 | 471 | ||
482 | static inline int utilization(struct f2fs_sb_info *sbi) | 472 | static inline int utilization(struct f2fs_sb_info *sbi) |
483 | { | 473 | { |
484 | return div_u64((u64)valid_user_blocks(sbi) * 100, sbi->user_block_count); | 474 | return div_u64((u64)valid_user_blocks(sbi) * 100, |
475 | sbi->user_block_count); | ||
485 | } | 476 | } |
486 | 477 | ||
487 | /* | 478 | /* |
488 | * Sometimes f2fs may be better to drop out-of-place update policy. | 479 | * Sometimes f2fs may be better to drop out-of-place update policy. |
489 | * So, if fs utilization is over MIN_IPU_UTIL, then f2fs tries to write | 480 | * And, users can control the policy through sysfs entries. |
490 | * data in the original place likewise other traditional file systems. | 481 | * There are five policies with triggering conditions as follows. |
491 | * But, currently set 100 in percentage, which means it is disabled. | 482 | * F2FS_IPU_FORCE - all the time, |
492 | * See below need_inplace_update(). | 483 | * F2FS_IPU_SSR - if SSR mode is activated, |
484 | * F2FS_IPU_UTIL - if FS utilization is over threashold, | ||
485 | * F2FS_IPU_SSR_UTIL - if SSR mode is activated and FS utilization is over | ||
486 | * threashold, | ||
487 | * F2FS_IPUT_DISABLE - disable IPU. (=default option) | ||
493 | */ | 488 | */ |
494 | #define MIN_IPU_UTIL 100 | 489 | #define DEF_MIN_IPU_UTIL 70 |
490 | |||
491 | enum { | ||
492 | F2FS_IPU_FORCE, | ||
493 | F2FS_IPU_SSR, | ||
494 | F2FS_IPU_UTIL, | ||
495 | F2FS_IPU_SSR_UTIL, | ||
496 | F2FS_IPU_DISABLE, | ||
497 | }; | ||
498 | |||
495 | static inline bool need_inplace_update(struct inode *inode) | 499 | static inline bool need_inplace_update(struct inode *inode) |
496 | { | 500 | { |
497 | struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); | 501 | struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); |
502 | |||
503 | /* IPU can be done only for the user data */ | ||
498 | if (S_ISDIR(inode->i_mode)) | 504 | if (S_ISDIR(inode->i_mode)) |
499 | return false; | 505 | return false; |
500 | if (need_SSR(sbi) && utilization(sbi) > MIN_IPU_UTIL) | 506 | |
507 | switch (SM_I(sbi)->ipu_policy) { | ||
508 | case F2FS_IPU_FORCE: | ||
501 | return true; | 509 | return true; |
510 | case F2FS_IPU_SSR: | ||
511 | if (need_SSR(sbi)) | ||
512 | return true; | ||
513 | break; | ||
514 | case F2FS_IPU_UTIL: | ||
515 | if (utilization(sbi) > SM_I(sbi)->min_ipu_util) | ||
516 | return true; | ||
517 | break; | ||
518 | case F2FS_IPU_SSR_UTIL: | ||
519 | if (need_SSR(sbi) && utilization(sbi) > SM_I(sbi)->min_ipu_util) | ||
520 | return true; | ||
521 | break; | ||
522 | case F2FS_IPU_DISABLE: | ||
523 | break; | ||
524 | } | ||
502 | return false; | 525 | return false; |
503 | } | 526 | } |
504 | 527 | ||