gc.h 2.94 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 */
Jaegeuk Kim's avatar
Jaegeuk Kim committed
2
/*
3 4 5 6 7 8 9 10 11 12
 * fs/f2fs/gc.h
 *
 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
 *             http://www.samsung.com/
 */
#define GC_THREAD_MIN_WB_PAGES		1	/*
						 * a threshold to determine
						 * whether IO subsystem is idle
						 * or not
						 */
13
#define DEF_GC_THREAD_URGENT_SLEEP_TIME	500	/* 500 ms */
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 */
17 18 19
#define LIMIT_INVALID_BLOCK	40 /* percentage over total user space */
#define LIMIT_FREE_BLOCK	40 /* percentage over invalid + free space */

20 21
#define DEF_GC_FAILED_PINNED_FILES	2048

22
/* Search max. number of dirty segments to select a victim segment */
23
#define DEF_MAX_VICTIM_SEARCH 4096 /* covers 8GB */
24 25 26 27

struct f2fs_gc_kthread {
	struct task_struct *f2fs_gc_task;
	wait_queue_head_t gc_wait_queue_head;
28 29

	/* for gc sleep time */
30
	unsigned int urgent_sleep_time;
31 32 33
	unsigned int min_sleep_time;
	unsigned int max_sleep_time;
	unsigned int no_gc_sleep_time;
34 35

	/* for changing gc mode */
36
	unsigned int gc_wake;
37 38
};

39 40 41 42 43
struct gc_inode_list {
	struct list_head ilist;
	struct radix_tree_root iroot;
};

Jaegeuk Kim's avatar
Jaegeuk Kim committed
44
/*
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
 * 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;
}

68
static inline void increase_sleep_time(struct f2fs_gc_kthread *gc_th,
69
							unsigned int *wait)
70
{
71 72 73
	unsigned int min_time = gc_th->min_sleep_time;
	unsigned int max_time = gc_th->max_sleep_time;

74 75
	if (*wait == gc_th->no_gc_sleep_time)
		return;
76

77 78 79 80
	if ((long long)*wait + (long long)min_time > (long long)max_time)
		*wait = max_time;
	else
		*wait += min_time;
81 82
}

83
static inline void decrease_sleep_time(struct f2fs_gc_kthread *gc_th,
84
							unsigned int *wait)
85
{
86 87
	unsigned int min_time = gc_th->min_sleep_time;

88 89
	if (*wait == gc_th->no_gc_sleep_time)
		*wait = gc_th->max_sleep_time;
90

91 92 93 94
	if ((long long)*wait - (long long)min_time < (long long)min_time)
		*wait = min_time;
	else
		*wait -= min_time;
95 96 97 98 99 100 101
}

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);
	/*
arter97's avatar
arter97 committed
102
	 * Background GC is triggered with the following conditions.
103 104 105 106 107 108 109 110
	 * 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;
}