Blame view

fs/f2fs/gc.h 2.94 KB
7c1a000d4   Chao Yu   f2fs: add SPDX li...
1
  // SPDX-License-Identifier: GPL-2.0
0a8165d7c   Jaegeuk Kim   f2fs: adjust kern...
2
  /*
7bc090034   Jaegeuk Kim   f2fs: add garbage...
3
4
5
6
   * fs/f2fs/gc.h
   *
   * Copyright (c) 2012 Samsung Electronics Co., Ltd.
   *             http://www.samsung.com/
7bc090034   Jaegeuk Kim   f2fs: add garbage...
7
   */
7bc090034   Jaegeuk Kim   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   Jaegeuk Kim   f2fs: introduce g...
13
  #define DEF_GC_THREAD_URGENT_SLEEP_TIME	500	/* 500 ms */
b59d0bae6   Namjae Jeon   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 */
7bc090034   Jaegeuk Kim   f2fs: add garbage...
17
18
  #define LIMIT_INVALID_BLOCK	40 /* percentage over total user space */
  #define LIMIT_FREE_BLOCK	40 /* percentage over invalid + free space */
1ad71a271   Jaegeuk Kim   f2fs: add an ioct...
19
  #define DEF_GC_FAILED_PINNED_FILES	2048
7bc090034   Jaegeuk Kim   f2fs: add garbage...
20
  /* Search max. number of dirty segments to select a victim segment */
b1c57c1ca   Jaegeuk Kim   f2fs: add a sysfs...
21
  #define DEF_MAX_VICTIM_SEARCH 4096 /* covers 8GB */
7bc090034   Jaegeuk Kim   f2fs: add garbage...
22

7bc090034   Jaegeuk Kim   f2fs: add garbage...
23
24
25
  struct f2fs_gc_kthread {
  	struct task_struct *f2fs_gc_task;
  	wait_queue_head_t gc_wait_queue_head;
b59d0bae6   Namjae Jeon   f2fs: add sysfs s...
26
27
  
  	/* for gc sleep time */
d9872a698   Jaegeuk Kim   f2fs: introduce g...
28
  	unsigned int urgent_sleep_time;
b59d0bae6   Namjae Jeon   f2fs: add sysfs s...
29
30
31
  	unsigned int min_sleep_time;
  	unsigned int max_sleep_time;
  	unsigned int no_gc_sleep_time;
d2dc095f4   Namjae Jeon   f2fs: add sysfs e...
32
33
  
  	/* for changing gc mode */
d9872a698   Jaegeuk Kim   f2fs: introduce g...
34
  	unsigned int gc_wake;
7bc090034   Jaegeuk Kim   f2fs: add garbage...
35
  };
7dda2af83   Changman Lee   f2fs: more fast l...
36
37
38
39
  struct gc_inode_list {
  	struct list_head ilist;
  	struct radix_tree_root iroot;
  };
0a8165d7c   Jaegeuk Kim   f2fs: adjust kern...
40
  /*
7bc090034   Jaegeuk Kim   f2fs: add garbage...
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
   * inline functions
   */
  static inline block_t free_user_blocks(struct f2fs_sb_info *sbi)
  {
  	if (free_segments(sbi) < overprovision_segments(sbi))
  		return 0;
  	else
  		return (free_segments(sbi) - overprovision_segments(sbi))
  			<< sbi->log_blocks_per_seg;
  }
  
  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   Chao Yu   f2fs: clean up {i...
63
  static inline void increase_sleep_time(struct f2fs_gc_kthread *gc_th,
b8c502b81   Chao Yu   f2fs: fix potenti...
64
  							unsigned int *wait)
7bc090034   Jaegeuk Kim   f2fs: add garbage...
65
  {
b8c502b81   Chao Yu   f2fs: fix potenti...
66
67
  	unsigned int min_time = gc_th->min_sleep_time;
  	unsigned int max_time = gc_th->max_sleep_time;
88dd89341   Chao Yu   f2fs: clean up {i...
68
69
  	if (*wait == gc_th->no_gc_sleep_time)
  		return;
6cb968d9b   Jaegeuk Kim   f2fs: avoid frequ...
70

b8c502b81   Chao Yu   f2fs: fix potenti...
71
72
73
74
  	if ((long long)*wait + (long long)min_time > (long long)max_time)
  		*wait = max_time;
  	else
  		*wait += min_time;
7bc090034   Jaegeuk Kim   f2fs: add garbage...
75
  }
88dd89341   Chao Yu   f2fs: clean up {i...
76
  static inline void decrease_sleep_time(struct f2fs_gc_kthread *gc_th,
b8c502b81   Chao Yu   f2fs: fix potenti...
77
  							unsigned int *wait)
7bc090034   Jaegeuk Kim   f2fs: add garbage...
78
  {
b8c502b81   Chao Yu   f2fs: fix potenti...
79
  	unsigned int min_time = gc_th->min_sleep_time;
88dd89341   Chao Yu   f2fs: clean up {i...
80
81
  	if (*wait == gc_th->no_gc_sleep_time)
  		*wait = gc_th->max_sleep_time;
6cb968d9b   Jaegeuk Kim   f2fs: avoid frequ...
82

b8c502b81   Chao Yu   f2fs: fix potenti...
83
84
85
86
  	if ((long long)*wait - (long long)min_time < (long long)min_time)
  		*wait = min_time;
  	else
  		*wait -= min_time;
7bc090034   Jaegeuk Kim   f2fs: add garbage...
87
88
89
90
91
92
93
  }
  
  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   arter97   f2fs: fix typo
94
  	 * Background GC is triggered with the following conditions.
7bc090034   Jaegeuk Kim   f2fs: add garbage...
95
96
97
98
99
100
101
102
  	 * 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;
  }