Blame view
fs/f2fs/gc.h
4.78 KB
d29fbcdb0 f2fs: Use the cor... |
1 |
/* SPDX-License-Identifier: GPL-2.0 */ |
0a8165d7c f2fs: adjust kern... |
2 |
/* |
7bc090034 f2fs: add garbage... |
3 4 5 6 |
* fs/f2fs/gc.h * * Copyright (c) 2012 Samsung Electronics Co., Ltd. * http://www.samsung.com/ |
7bc090034 f2fs: add garbage... |
7 |
*/ |
7bc090034 f2fs: add garbage... |
8 9 10 11 12 |
#define GC_THREAD_MIN_WB_PAGES 1 /* * a threshold to determine * whether IO subsystem is idle * or not */ |
d9872a698 f2fs: introduce g... |
13 |
#define DEF_GC_THREAD_URGENT_SLEEP_TIME 500 /* 500 ms */ |
b59d0bae6 f2fs: add sysfs s... |
14 15 16 |
#define DEF_GC_THREAD_MIN_SLEEP_TIME 30000 /* milliseconds */ #define DEF_GC_THREAD_MAX_SLEEP_TIME 60000 #define DEF_GC_THREAD_NOGC_SLEEP_TIME 300000 /* wait 5 min */ |
093749e29 f2fs: support age... |
17 18 19 20 21 22 23 |
/* choose candidates from sections which has age of more than 7 days */ #define DEF_GC_THREAD_AGE_THRESHOLD (60 * 60 * 24 * 7) #define DEF_GC_THREAD_CANDIDATE_RATIO 20 /* select 20% oldest sections as candidates */ #define DEF_GC_THREAD_MAX_CANDIDATE_COUNT 10 /* select at most 10 sections as candidates */ #define DEF_GC_THREAD_AGE_WEIGHT 60 /* age weight */ #define DEFAULT_ACCURACY_CLASS 10000 /* accuracy class */ |
7bc090034 f2fs: add garbage... |
24 25 |
#define LIMIT_INVALID_BLOCK 40 /* percentage over total user space */ #define LIMIT_FREE_BLOCK 40 /* percentage over invalid + free space */ |
1ad71a271 f2fs: add an ioct... |
26 |
#define DEF_GC_FAILED_PINNED_FILES 2048 |
7bc090034 f2fs: add garbage... |
27 |
/* Search max. number of dirty segments to select a victim segment */ |
b1c57c1ca f2fs: add a sysfs... |
28 |
#define DEF_MAX_VICTIM_SEARCH 4096 /* covers 8GB */ |
7bc090034 f2fs: add garbage... |
29 |
|
7bc090034 f2fs: add garbage... |
30 31 32 |
struct f2fs_gc_kthread { struct task_struct *f2fs_gc_task; wait_queue_head_t gc_wait_queue_head; |
b59d0bae6 f2fs: add sysfs s... |
33 34 |
/* for gc sleep time */ |
d9872a698 f2fs: introduce g... |
35 |
unsigned int urgent_sleep_time; |
b59d0bae6 f2fs: add sysfs s... |
36 37 38 |
unsigned int min_sleep_time; unsigned int max_sleep_time; unsigned int no_gc_sleep_time; |
d2dc095f4 f2fs: add sysfs e... |
39 40 |
/* for changing gc mode */ |
d9872a698 f2fs: introduce g... |
41 |
unsigned int gc_wake; |
7bc090034 f2fs: add garbage... |
42 |
}; |
7dda2af83 f2fs: more fast l... |
43 44 45 46 |
struct gc_inode_list { struct list_head ilist; struct radix_tree_root iroot; }; |
093749e29 f2fs: support age... |
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
struct victim_info { unsigned long long mtime; /* mtime of section */ unsigned int segno; /* section No. */ }; struct victim_entry { struct rb_node rb_node; /* rb node located in rb-tree */ union { struct { unsigned long long mtime; /* mtime of section */ unsigned int segno; /* segment No. */ }; struct victim_info vi; /* victim info */ }; struct list_head list; }; |
0a8165d7c f2fs: adjust kern... |
63 |
/* |
7bc090034 f2fs: add garbage... |
64 65 |
* inline functions */ |
de881df97 f2fs: support zon... |
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
/* * On a Zoned device zone-capacity can be less than zone-size and if * zone-capacity is not aligned to f2fs segment size(2MB), then the segment * starting just before zone-capacity has some blocks spanning across the * zone-capacity, these blocks are not usable. * Such spanning segments can be in free list so calculate the sum of usable * blocks in currently free segments including normal and spanning segments. */ static inline block_t free_segs_blk_count_zoned(struct f2fs_sb_info *sbi) { block_t free_seg_blks = 0; struct free_segmap_info *free_i = FREE_I(sbi); int j; spin_lock(&free_i->segmap_lock); for (j = 0; j < MAIN_SEGS(sbi); j++) if (!test_bit(j, free_i->free_segmap)) free_seg_blks += f2fs_usable_blks_in_seg(sbi, j); spin_unlock(&free_i->segmap_lock); return free_seg_blks; } static inline block_t free_segs_blk_count(struct f2fs_sb_info *sbi) { if (f2fs_sb_has_blkzoned(sbi)) return free_segs_blk_count_zoned(sbi); return free_segments(sbi) << sbi->log_blocks_per_seg; } |
7bc090034 f2fs: add garbage... |
97 98 |
static inline block_t free_user_blocks(struct f2fs_sb_info *sbi) { |
de881df97 f2fs: support zon... |
99 100 101 102 103 104 |
block_t free_blks, ovp_blks; free_blks = free_segs_blk_count(sbi); ovp_blks = overprovision_segments(sbi) << sbi->log_blocks_per_seg; if (free_blks < ovp_blks) |
7bc090034 f2fs: add garbage... |
105 |
return 0; |
de881df97 f2fs: support zon... |
106 107 |
return free_blks - ovp_blks; |
7bc090034 f2fs: add garbage... |
108 109 110 111 112 113 114 115 116 117 118 119 120 |
} static inline block_t limit_invalid_user_blocks(struct f2fs_sb_info *sbi) { return (long)(sbi->user_block_count * LIMIT_INVALID_BLOCK) / 100; } static inline block_t limit_free_user_blocks(struct f2fs_sb_info *sbi) { block_t reclaimable_user_blocks = sbi->user_block_count - written_block_count(sbi); return (long)(reclaimable_user_blocks * LIMIT_FREE_BLOCK) / 100; } |
88dd89341 f2fs: clean up {i... |
121 |
static inline void increase_sleep_time(struct f2fs_gc_kthread *gc_th, |
b8c502b81 f2fs: fix potenti... |
122 |
unsigned int *wait) |
7bc090034 f2fs: add garbage... |
123 |
{ |
b8c502b81 f2fs: fix potenti... |
124 125 |
unsigned int min_time = gc_th->min_sleep_time; unsigned int max_time = gc_th->max_sleep_time; |
88dd89341 f2fs: clean up {i... |
126 127 |
if (*wait == gc_th->no_gc_sleep_time) return; |
6cb968d9b f2fs: avoid frequ... |
128 |
|
b8c502b81 f2fs: fix potenti... |
129 130 131 132 |
if ((long long)*wait + (long long)min_time > (long long)max_time) *wait = max_time; else *wait += min_time; |
7bc090034 f2fs: add garbage... |
133 |
} |
88dd89341 f2fs: clean up {i... |
134 |
static inline void decrease_sleep_time(struct f2fs_gc_kthread *gc_th, |
b8c502b81 f2fs: fix potenti... |
135 |
unsigned int *wait) |
7bc090034 f2fs: add garbage... |
136 |
{ |
b8c502b81 f2fs: fix potenti... |
137 |
unsigned int min_time = gc_th->min_sleep_time; |
88dd89341 f2fs: clean up {i... |
138 139 |
if (*wait == gc_th->no_gc_sleep_time) *wait = gc_th->max_sleep_time; |
6cb968d9b f2fs: avoid frequ... |
140 |
|
b8c502b81 f2fs: fix potenti... |
141 142 143 144 |
if ((long long)*wait - (long long)min_time < (long long)min_time) *wait = min_time; else *wait -= min_time; |
7bc090034 f2fs: add garbage... |
145 146 147 148 149 150 151 |
} static inline bool has_enough_invalid_blocks(struct f2fs_sb_info *sbi) { block_t invalid_user_blocks = sbi->user_block_count - written_block_count(sbi); /* |
e1c420452 f2fs: fix typo |
152 |
* Background GC is triggered with the following conditions. |
7bc090034 f2fs: add garbage... |
153 154 155 156 157 158 159 160 |
* 1. There are a number of invalid blocks. * 2. There is not enough free space. */ if (invalid_user_blocks > limit_invalid_user_blocks(sbi) && free_user_blocks(sbi) < limit_free_user_blocks(sbi)) return true; return false; } |