Blame view

fs/f2fs/gc.h 2.78 KB
0a8165d7c   Jaegeuk Kim   f2fs: adjust kern...
1
  /*
7bc090034   Jaegeuk Kim   f2fs: add garbage...
2
3
4
5
6
7
8
9
10
   * fs/f2fs/gc.h
   *
   * Copyright (c) 2012 Samsung Electronics Co., Ltd.
   *             http://www.samsung.com/
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License version 2 as
   * published by the Free Software Foundation.
   */
7bc090034   Jaegeuk Kim   f2fs: add garbage...
11
12
13
14
15
  #define GC_THREAD_MIN_WB_PAGES		1	/*
  						 * a threshold to determine
  						 * whether IO subsystem is idle
  						 * or not
  						 */
b59d0bae6   Namjae Jeon   f2fs: add sysfs s...
16
17
18
  #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...
19
20
21
22
  #define LIMIT_INVALID_BLOCK	40 /* percentage over total user space */
  #define LIMIT_FREE_BLOCK	40 /* percentage over invalid + free space */
  
  /* Search max. number of dirty segments to select a victim segment */
b1c57c1ca   Jaegeuk Kim   f2fs: add a sysfs...
23
  #define DEF_MAX_VICTIM_SEARCH 4096 /* covers 8GB */
7bc090034   Jaegeuk Kim   f2fs: add garbage...
24

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

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

88dd89341   Chao Yu   f2fs: clean up {i...
80
81
82
  	*wait -= gc_th->min_sleep_time;
  	if (*wait <= gc_th->min_sleep_time)
  		*wait = gc_th->min_sleep_time;
7bc090034   Jaegeuk Kim   f2fs: add garbage...
83
84
85
86
87
88
89
  }
  
  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
90
  	 * Background GC is triggered with the following conditions.
7bc090034   Jaegeuk Kim   f2fs: add garbage...
91
92
93
94
95
96
97
98
  	 * 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;
  }