~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/f2fs/gc.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 /*
  3  * fs/f2fs/gc.h
  4  *
  5  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
  6  *             http://www.samsung.com/
  7  */
  8 #define GC_THREAD_MIN_WB_PAGES          1       /*
  9                                                  * a threshold to determine
 10                                                  * whether IO subsystem is idle
 11                                                  * or not
 12                                                  */
 13 #define DEF_GC_THREAD_URGENT_SLEEP_TIME 500     /* 500 ms */
 14 #define DEF_GC_THREAD_MIN_SLEEP_TIME    30000   /* milliseconds */
 15 #define DEF_GC_THREAD_MAX_SLEEP_TIME    60000
 16 #define DEF_GC_THREAD_NOGC_SLEEP_TIME   300000  /* wait 5 min */
 17 
 18 /* GC sleep parameters for zoned deivces */
 19 #define DEF_GC_THREAD_MIN_SLEEP_TIME_ZONED      10
 20 #define DEF_GC_THREAD_MAX_SLEEP_TIME_ZONED      20
 21 #define DEF_GC_THREAD_NOGC_SLEEP_TIME_ZONED     60000
 22 
 23 /* choose candidates from sections which has age of more than 7 days */
 24 #define DEF_GC_THREAD_AGE_THRESHOLD             (60 * 60 * 24 * 7)
 25 #define DEF_GC_THREAD_CANDIDATE_RATIO           20      /* select 20% oldest sections as candidates */
 26 #define DEF_GC_THREAD_MAX_CANDIDATE_COUNT       10      /* select at most 10 sections as candidates */
 27 #define DEF_GC_THREAD_AGE_WEIGHT                60      /* age weight */
 28 #define DEFAULT_ACCURACY_CLASS                  10000   /* accuracy class */
 29 
 30 #define LIMIT_INVALID_BLOCK     40 /* percentage over total user space */
 31 #define LIMIT_FREE_BLOCK        40 /* percentage over invalid + free space */
 32 
 33 #define LIMIT_NO_ZONED_GC       60 /* percentage over total user space of no gc for zoned devices */
 34 #define LIMIT_BOOST_ZONED_GC    25 /* percentage over total user space of boosted gc for zoned devices */
 35 #define DEF_MIGRATION_WINDOW_GRANULARITY_ZONED  3
 36 #define BOOST_GC_MULTIPLE       5
 37 
 38 #define DEF_GC_FAILED_PINNED_FILES      2048
 39 #define MAX_GC_FAILED_PINNED_FILES      USHRT_MAX
 40 
 41 /* Search max. number of dirty segments to select a victim segment */
 42 #define DEF_MAX_VICTIM_SEARCH 4096 /* covers 8GB */
 43 
 44 #define NR_GC_CHECKPOINT_SECS (3)       /* data/node/dentry sections */
 45 
 46 struct f2fs_gc_kthread {
 47         struct task_struct *f2fs_gc_task;
 48         wait_queue_head_t gc_wait_queue_head;
 49 
 50         /* for gc sleep time */
 51         unsigned int urgent_sleep_time;
 52         unsigned int min_sleep_time;
 53         unsigned int max_sleep_time;
 54         unsigned int no_gc_sleep_time;
 55 
 56         /* for changing gc mode */
 57         bool gc_wake;
 58 
 59         /* for GC_MERGE mount option */
 60         wait_queue_head_t fggc_wq;              /*
 61                                                  * caller of f2fs_balance_fs()
 62                                                  * will wait on this wait queue.
 63                                                  */
 64 };
 65 
 66 struct gc_inode_list {
 67         struct list_head ilist;
 68         struct radix_tree_root iroot;
 69 };
 70 
 71 struct victim_entry {
 72         struct rb_node rb_node;         /* rb node located in rb-tree */
 73         unsigned long long mtime;       /* mtime of section */
 74         unsigned int segno;             /* segment No. */
 75         struct list_head list;
 76 };
 77 
 78 /*
 79  * inline functions
 80  */
 81 
 82 /*
 83  * On a Zoned device zone-capacity can be less than zone-size and if
 84  * zone-capacity is not aligned to f2fs segment size(2MB), then the segment
 85  * starting just before zone-capacity has some blocks spanning across the
 86  * zone-capacity, these blocks are not usable.
 87  * Such spanning segments can be in free list so calculate the sum of usable
 88  * blocks in currently free segments including normal and spanning segments.
 89  */
 90 static inline block_t free_segs_blk_count_zoned(struct f2fs_sb_info *sbi)
 91 {
 92         block_t free_seg_blks = 0;
 93         struct free_segmap_info *free_i = FREE_I(sbi);
 94         int j;
 95 
 96         spin_lock(&free_i->segmap_lock);
 97         for (j = 0; j < MAIN_SEGS(sbi); j++)
 98                 if (!test_bit(j, free_i->free_segmap))
 99                         free_seg_blks += f2fs_usable_blks_in_seg(sbi, j);
100         spin_unlock(&free_i->segmap_lock);
101 
102         return free_seg_blks;
103 }
104 
105 static inline block_t free_segs_blk_count(struct f2fs_sb_info *sbi)
106 {
107         if (f2fs_sb_has_blkzoned(sbi))
108                 return free_segs_blk_count_zoned(sbi);
109 
110         return SEGS_TO_BLKS(sbi, free_segments(sbi));
111 }
112 
113 static inline block_t free_user_blocks(struct f2fs_sb_info *sbi)
114 {
115         block_t free_blks, ovp_blks;
116 
117         free_blks = free_segs_blk_count(sbi);
118         ovp_blks = SEGS_TO_BLKS(sbi, overprovision_segments(sbi));
119 
120         if (free_blks < ovp_blks)
121                 return 0;
122 
123         return free_blks - ovp_blks;
124 }
125 
126 static inline block_t limit_invalid_user_blocks(block_t user_block_count)
127 {
128         return (long)(user_block_count * LIMIT_INVALID_BLOCK) / 100;
129 }
130 
131 static inline block_t limit_free_user_blocks(block_t reclaimable_user_blocks)
132 {
133         return (long)(reclaimable_user_blocks * LIMIT_FREE_BLOCK) / 100;
134 }
135 
136 static inline void increase_sleep_time(struct f2fs_gc_kthread *gc_th,
137                                                         unsigned int *wait)
138 {
139         unsigned int min_time = gc_th->min_sleep_time;
140         unsigned int max_time = gc_th->max_sleep_time;
141 
142         if (*wait == gc_th->no_gc_sleep_time)
143                 return;
144 
145         if ((long long)*wait + (long long)min_time > (long long)max_time)
146                 *wait = max_time;
147         else
148                 *wait += min_time;
149 }
150 
151 static inline void decrease_sleep_time(struct f2fs_gc_kthread *gc_th,
152                                                         unsigned int *wait)
153 {
154         unsigned int min_time = gc_th->min_sleep_time;
155 
156         if (*wait == gc_th->no_gc_sleep_time)
157                 *wait = gc_th->max_sleep_time;
158 
159         if ((long long)*wait - (long long)min_time < (long long)min_time)
160                 *wait = min_time;
161         else
162                 *wait -= min_time;
163 }
164 
165 static inline bool has_enough_free_blocks(struct f2fs_sb_info *sbi,
166                                                 unsigned int limit_perc)
167 {
168         return free_sections(sbi) > ((sbi->total_sections * limit_perc) / 100);
169 }
170 
171 static inline bool has_enough_invalid_blocks(struct f2fs_sb_info *sbi)
172 {
173         block_t user_block_count = sbi->user_block_count;
174         block_t invalid_user_blocks = user_block_count -
175                 written_block_count(sbi);
176         /*
177          * Background GC is triggered with the following conditions.
178          * 1. There are a number of invalid blocks.
179          * 2. There is not enough free space.
180          */
181         return (invalid_user_blocks >
182                         limit_invalid_user_blocks(user_block_count) &&
183                 free_user_blocks(sbi) <
184                         limit_free_user_blocks(invalid_user_blocks));
185 }
186 
187 static inline bool need_to_boost_gc(struct f2fs_sb_info *sbi)
188 {
189         if (f2fs_sb_has_blkzoned(sbi))
190                 return !has_enough_free_blocks(sbi, LIMIT_BOOST_ZONED_GC);
191         return has_enough_invalid_blocks(sbi);
192 }
193 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php