0001
0002
0003
0004
0005
0006
0007
0008 #define GC_THREAD_MIN_WB_PAGES 1
0009
0010
0011
0012
0013 #define DEF_GC_THREAD_URGENT_SLEEP_TIME 500
0014 #define DEF_GC_THREAD_MIN_SLEEP_TIME 30000
0015 #define DEF_GC_THREAD_MAX_SLEEP_TIME 60000
0016 #define DEF_GC_THREAD_NOGC_SLEEP_TIME 300000
0017
0018
0019 #define DEF_GC_THREAD_AGE_THRESHOLD (60 * 60 * 24 * 7)
0020 #define DEF_GC_THREAD_CANDIDATE_RATIO 20
0021 #define DEF_GC_THREAD_MAX_CANDIDATE_COUNT 10
0022 #define DEF_GC_THREAD_AGE_WEIGHT 60
0023 #define DEFAULT_ACCURACY_CLASS 10000
0024
0025 #define LIMIT_INVALID_BLOCK 40
0026 #define LIMIT_FREE_BLOCK 40
0027
0028 #define DEF_GC_FAILED_PINNED_FILES 2048
0029
0030
0031 #define DEF_MAX_VICTIM_SEARCH 4096
0032
0033 struct f2fs_gc_kthread {
0034 struct task_struct *f2fs_gc_task;
0035 wait_queue_head_t gc_wait_queue_head;
0036
0037
0038 unsigned int urgent_sleep_time;
0039 unsigned int min_sleep_time;
0040 unsigned int max_sleep_time;
0041 unsigned int no_gc_sleep_time;
0042
0043
0044 unsigned int gc_wake;
0045
0046
0047 wait_queue_head_t fggc_wq;
0048
0049
0050
0051 };
0052
0053 struct gc_inode_list {
0054 struct list_head ilist;
0055 struct radix_tree_root iroot;
0056 };
0057
0058 struct victim_info {
0059 unsigned long long mtime;
0060 unsigned int segno;
0061 };
0062
0063 struct victim_entry {
0064 struct rb_node rb_node;
0065 union {
0066 struct {
0067 unsigned long long mtime;
0068 unsigned int segno;
0069 };
0070 struct victim_info vi;
0071 };
0072 struct list_head list;
0073 };
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087 static inline block_t free_segs_blk_count_zoned(struct f2fs_sb_info *sbi)
0088 {
0089 block_t free_seg_blks = 0;
0090 struct free_segmap_info *free_i = FREE_I(sbi);
0091 int j;
0092
0093 spin_lock(&free_i->segmap_lock);
0094 for (j = 0; j < MAIN_SEGS(sbi); j++)
0095 if (!test_bit(j, free_i->free_segmap))
0096 free_seg_blks += f2fs_usable_blks_in_seg(sbi, j);
0097 spin_unlock(&free_i->segmap_lock);
0098
0099 return free_seg_blks;
0100 }
0101
0102 static inline block_t free_segs_blk_count(struct f2fs_sb_info *sbi)
0103 {
0104 if (f2fs_sb_has_blkzoned(sbi))
0105 return free_segs_blk_count_zoned(sbi);
0106
0107 return free_segments(sbi) << sbi->log_blocks_per_seg;
0108 }
0109
0110 static inline block_t free_user_blocks(struct f2fs_sb_info *sbi)
0111 {
0112 block_t free_blks, ovp_blks;
0113
0114 free_blks = free_segs_blk_count(sbi);
0115 ovp_blks = overprovision_segments(sbi) << sbi->log_blocks_per_seg;
0116
0117 if (free_blks < ovp_blks)
0118 return 0;
0119
0120 return free_blks - ovp_blks;
0121 }
0122
0123 static inline block_t limit_invalid_user_blocks(block_t user_block_count)
0124 {
0125 return (long)(user_block_count * LIMIT_INVALID_BLOCK) / 100;
0126 }
0127
0128 static inline block_t limit_free_user_blocks(block_t reclaimable_user_blocks)
0129 {
0130 return (long)(reclaimable_user_blocks * LIMIT_FREE_BLOCK) / 100;
0131 }
0132
0133 static inline void increase_sleep_time(struct f2fs_gc_kthread *gc_th,
0134 unsigned int *wait)
0135 {
0136 unsigned int min_time = gc_th->min_sleep_time;
0137 unsigned int max_time = gc_th->max_sleep_time;
0138
0139 if (*wait == gc_th->no_gc_sleep_time)
0140 return;
0141
0142 if ((long long)*wait + (long long)min_time > (long long)max_time)
0143 *wait = max_time;
0144 else
0145 *wait += min_time;
0146 }
0147
0148 static inline void decrease_sleep_time(struct f2fs_gc_kthread *gc_th,
0149 unsigned int *wait)
0150 {
0151 unsigned int min_time = gc_th->min_sleep_time;
0152
0153 if (*wait == gc_th->no_gc_sleep_time)
0154 *wait = gc_th->max_sleep_time;
0155
0156 if ((long long)*wait - (long long)min_time < (long long)min_time)
0157 *wait = min_time;
0158 else
0159 *wait -= min_time;
0160 }
0161
0162 static inline bool has_enough_invalid_blocks(struct f2fs_sb_info *sbi)
0163 {
0164 block_t user_block_count = sbi->user_block_count;
0165 block_t invalid_user_blocks = user_block_count -
0166 written_block_count(sbi);
0167
0168
0169
0170
0171
0172 return (invalid_user_blocks >
0173 limit_invalid_user_blocks(user_block_count) &&
0174 free_user_blocks(sbi) <
0175 limit_free_user_blocks(invalid_user_blocks));
0176 }