backing-dev.h 6.2 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10
/*
 * include/linux/backing-dev.h
 *
 * low-level device information and state which is propagated up through
 * to high-level code.
 */

#ifndef _LINUX_BACKING_DEV_H
#define _LINUX_BACKING_DEV_H

11
#include <linux/kernel.h>
12
#include <linux/fs.h>
13
#include <linux/sched.h>
T
Tejun Heo 已提交
14
#include <linux/blkdev.h>
15
#include <linux/writeback.h>
16
#include <linux/backing-dev-defs.h>
L
Linus Torvalds 已提交
17

M
Mikulas Patocka 已提交
18
int __must_check bdi_init(struct backing_dev_info *bdi);
19 20
void bdi_destroy(struct backing_dev_info *bdi);

21
__printf(3, 4)
22 23 24 25
int bdi_register(struct backing_dev_info *bdi, struct device *parent,
		const char *fmt, ...);
int bdi_register_dev(struct backing_dev_info *bdi, dev_t dev);
void bdi_unregister(struct backing_dev_info *bdi);
26
int __must_check bdi_setup_and_register(struct backing_dev_info *, char *);
27 28
void bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages,
			enum wb_reason reason);
29
void bdi_start_background_writeback(struct backing_dev_info *bdi);
30
void wb_workfn(struct work_struct *work);
31
int bdi_has_dirty_io(struct backing_dev_info *bdi);
32
void wb_wakeup_delayed(struct bdi_writeback *wb);
33

34
extern spinlock_t bdi_lock;
35 36
extern struct list_head bdi_list;

37 38
extern struct workqueue_struct *bdi_wq;

39 40 41 42 43 44 45
static inline int wb_has_dirty_io(struct bdi_writeback *wb)
{
	return !list_empty(&wb->b_dirty) ||
	       !list_empty(&wb->b_io) ||
	       !list_empty(&wb->b_more_io);
}

46 47
static inline void __add_wb_stat(struct bdi_writeback *wb,
				 enum wb_stat_item item, s64 amount)
48
{
49
	__percpu_counter_add(&wb->stat[item], amount, WB_STAT_BATCH);
50 51
}

52 53
static inline void __inc_wb_stat(struct bdi_writeback *wb,
				 enum wb_stat_item item)
54
{
55
	__add_wb_stat(wb, item, 1);
56 57
}

58
static inline void inc_wb_stat(struct bdi_writeback *wb, enum wb_stat_item item)
59 60 61 62
{
	unsigned long flags;

	local_irq_save(flags);
63
	__inc_wb_stat(wb, item);
64 65 66
	local_irq_restore(flags);
}

67 68
static inline void __dec_wb_stat(struct bdi_writeback *wb,
				 enum wb_stat_item item)
69
{
70
	__add_wb_stat(wb, item, -1);
71 72
}

73
static inline void dec_wb_stat(struct bdi_writeback *wb, enum wb_stat_item item)
74 75 76 77
{
	unsigned long flags;

	local_irq_save(flags);
78
	__dec_wb_stat(wb, item);
79 80 81
	local_irq_restore(flags);
}

82
static inline s64 wb_stat(struct bdi_writeback *wb, enum wb_stat_item item)
83
{
84
	return percpu_counter_read_positive(&wb->stat[item]);
85 86
}

87 88
static inline s64 __wb_stat_sum(struct bdi_writeback *wb,
				enum wb_stat_item item)
89
{
90
	return percpu_counter_sum_positive(&wb->stat[item]);
91 92
}

93
static inline s64 wb_stat_sum(struct bdi_writeback *wb, enum wb_stat_item item)
P
Peter Zijlstra 已提交
94
{
95 96 97 98
	s64 sum;
	unsigned long flags;

	local_irq_save(flags);
99
	sum = __wb_stat_sum(wb, item);
100 101 102
	local_irq_restore(flags);

	return sum;
P
Peter Zijlstra 已提交
103 104
}

105
extern void wb_writeout_inc(struct bdi_writeback *wb);
106

107 108 109
/*
 * maximal error of a stat counter.
 */
110
static inline unsigned long wb_stat_error(struct bdi_writeback *wb)
P
Peter Zijlstra 已提交
111
{
112
#ifdef CONFIG_SMP
113
	return nr_cpu_ids * WB_STAT_BATCH;
114 115 116
#else
	return 1;
#endif
P
Peter Zijlstra 已提交
117
}
L
Linus Torvalds 已提交
118

119
int bdi_set_min_ratio(struct backing_dev_info *bdi, unsigned int min_ratio);
120
int bdi_set_max_ratio(struct backing_dev_info *bdi, unsigned int max_ratio);
121

L
Linus Torvalds 已提交
122 123
/*
 * Flags in backing_dev_info::capability
124 125 126 127 128 129 130 131 132 133 134 135
 *
 * The first three flags control whether dirty pages will contribute to the
 * VM's accounting and whether writepages() should be called for dirty pages
 * (something that would not, for example, be appropriate for ramfs)
 *
 * WARNING: these flags are closely related and should not normally be
 * used separately.  The BDI_CAP_NO_ACCT_AND_WRITEBACK combines these
 * three flags into a single convenience macro.
 *
 * BDI_CAP_NO_ACCT_DIRTY:  Dirty pages shouldn't contribute to accounting
 * BDI_CAP_NO_WRITEBACK:   Don't write pages back
 * BDI_CAP_NO_ACCT_WB:     Don't automatically account writeback pages
136
 * BDI_CAP_STRICTLIMIT:    Keep number of dirty pages below bdi threshold.
L
Linus Torvalds 已提交
137
 */
138 139
#define BDI_CAP_NO_ACCT_DIRTY	0x00000001
#define BDI_CAP_NO_WRITEBACK	0x00000002
140 141 142
#define BDI_CAP_NO_ACCT_WB	0x00000004
#define BDI_CAP_STABLE_WRITES	0x00000008
#define BDI_CAP_STRICTLIMIT	0x00000010
L
Linus Torvalds 已提交
143

144 145 146
#define BDI_CAP_NO_ACCT_AND_WRITEBACK \
	(BDI_CAP_NO_WRITEBACK | BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_ACCT_WB)

J
Jörn Engel 已提交
147
extern struct backing_dev_info noop_backing_dev_info;
L
Linus Torvalds 已提交
148 149 150

int writeback_in_progress(struct backing_dev_info *bdi);

T
Tejun Heo 已提交
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
static inline struct backing_dev_info *inode_to_bdi(struct inode *inode)
{
	struct super_block *sb;

	if (!inode)
		return &noop_backing_dev_info;

	sb = inode->i_sb;
#ifdef CONFIG_BLOCK
	if (sb_is_blkdev_sb(sb))
		return blk_get_backing_dev_info(I_BDEV(inode));
#endif
	return sb->s_bdi;
}

L
Linus Torvalds 已提交
166 167 168 169
static inline int bdi_congested(struct backing_dev_info *bdi, int bdi_bits)
{
	if (bdi->congested_fn)
		return bdi->congested_fn(bdi->congested_data, bdi_bits);
170
	return (bdi->wb.congested->state & bdi_bits);
L
Linus Torvalds 已提交
171 172 173 174
}

static inline int bdi_read_congested(struct backing_dev_info *bdi)
{
175
	return bdi_congested(bdi, 1 << WB_sync_congested);
L
Linus Torvalds 已提交
176 177 178 179
}

static inline int bdi_write_congested(struct backing_dev_info *bdi)
{
180
	return bdi_congested(bdi, 1 << WB_async_congested);
L
Linus Torvalds 已提交
181 182 183 184
}

static inline int bdi_rw_congested(struct backing_dev_info *bdi)
{
185 186
	return bdi_congested(bdi, (1 << WB_sync_congested) |
				  (1 << WB_async_congested));
L
Linus Torvalds 已提交
187 188
}

189
long congestion_wait(int sync, long timeout);
190
long wait_iff_congested(struct zone *zone, int sync, long timeout);
191 192
int pdflush_proc_obsolete(struct ctl_table *table, int write,
		void __user *buffer, size_t *lenp, loff_t *ppos);
L
Linus Torvalds 已提交
193

194 195 196 197 198
static inline bool bdi_cap_stable_pages_required(struct backing_dev_info *bdi)
{
	return bdi->capabilities & BDI_CAP_STABLE_WRITES;
}

199 200 201 202 203 204 205 206 207
static inline bool bdi_cap_writeback_dirty(struct backing_dev_info *bdi)
{
	return !(bdi->capabilities & BDI_CAP_NO_WRITEBACK);
}

static inline bool bdi_cap_account_dirty(struct backing_dev_info *bdi)
{
	return !(bdi->capabilities & BDI_CAP_NO_ACCT_DIRTY);
}
L
Linus Torvalds 已提交
208

209 210 211 212 213 214
static inline bool bdi_cap_account_writeback(struct backing_dev_info *bdi)
{
	/* Paranoia: BDI_CAP_NO_WRITEBACK implies BDI_CAP_NO_ACCT_WB */
	return !(bdi->capabilities & (BDI_CAP_NO_ACCT_WB |
				      BDI_CAP_NO_WRITEBACK));
}
L
Linus Torvalds 已提交
215

216 217
static inline bool mapping_cap_writeback_dirty(struct address_space *mapping)
{
218
	return bdi_cap_writeback_dirty(inode_to_bdi(mapping->host));
219
}
L
Linus Torvalds 已提交
220

221 222
static inline bool mapping_cap_account_dirty(struct address_space *mapping)
{
223
	return bdi_cap_account_dirty(inode_to_bdi(mapping->host));
224
}
L
Linus Torvalds 已提交
225

226 227 228 229 230 231
static inline int bdi_sched_wait(void *word)
{
	schedule();
	return 0;
}

L
Linus Torvalds 已提交
232
#endif		/* _LINUX_BACKING_DEV_H */