1
2
3
4#ifndef WRITEBACK_H
5#define WRITEBACK_H
6
7#include <linux/sched.h>
8#include <linux/workqueue.h>
9#include <linux/fs.h>
10#include <linux/flex_proportions.h>
11#include <linux/backing-dev-defs.h>
12
13DECLARE_PER_CPU(int, dirty_throttle_leaks);
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28#define DIRTY_SCOPE 8
29#define DIRTY_FULL_SCOPE (DIRTY_SCOPE / 2)
30
31struct backing_dev_info;
32
33
34
35
36enum writeback_sync_modes {
37 WB_SYNC_NONE,
38 WB_SYNC_ALL,
39};
40
41
42
43
44enum wb_reason {
45 WB_REASON_BACKGROUND,
46 WB_REASON_TRY_TO_FREE_PAGES,
47 WB_REASON_SYNC,
48 WB_REASON_PERIODIC,
49 WB_REASON_LAPTOP_TIMER,
50 WB_REASON_FREE_MORE_MEM,
51 WB_REASON_FS_FREE_SPACE,
52
53
54
55
56
57
58 WB_REASON_FORKER_THREAD,
59
60 WB_REASON_MAX,
61};
62
63
64
65
66
67
68struct writeback_control {
69 long nr_to_write;
70
71 long pages_skipped;
72
73
74
75
76
77
78 loff_t range_start;
79 loff_t range_end;
80
81 enum writeback_sync_modes sync_mode;
82
83 unsigned for_kupdate:1;
84 unsigned for_background:1;
85 unsigned tagged_writepages:1;
86 unsigned for_reclaim:1;
87 unsigned range_cyclic:1;
88 unsigned for_sync:1;
89#ifdef CONFIG_CGROUP_WRITEBACK
90 struct bdi_writeback *wb;
91 struct inode *inode;
92
93
94 int wb_id;
95 int wb_lcand_id;
96 int wb_tcand_id;
97 size_t wb_bytes;
98 size_t wb_lcand_bytes;
99 size_t wb_tcand_bytes;
100#endif
101};
102
103
104
105
106
107
108
109
110struct wb_domain {
111 spinlock_t lock;
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130 struct fprop_global completions;
131 struct timer_list period_timer;
132 unsigned long period_time;
133
134
135
136
137
138
139
140
141
142
143
144 unsigned long dirty_limit_tstamp;
145 unsigned long dirty_limit;
146};
147
148
149
150
151
152
153
154
155
156
157
158
159
160static inline void wb_domain_size_changed(struct wb_domain *dom)
161{
162 spin_lock(&dom->lock);
163 dom->dirty_limit_tstamp = jiffies;
164 dom->dirty_limit = 0;
165 spin_unlock(&dom->lock);
166}
167
168
169
170
171struct bdi_writeback;
172void writeback_inodes_sb(struct super_block *, enum wb_reason reason);
173void writeback_inodes_sb_nr(struct super_block *, unsigned long nr,
174 enum wb_reason reason);
175bool try_to_writeback_inodes_sb(struct super_block *, enum wb_reason reason);
176bool try_to_writeback_inodes_sb_nr(struct super_block *, unsigned long nr,
177 enum wb_reason reason);
178void sync_inodes_sb(struct super_block *);
179void wakeup_flusher_threads(long nr_pages, enum wb_reason reason);
180void inode_wait_for_writeback(struct inode *inode);
181
182
183static inline void wait_on_inode(struct inode *inode)
184{
185 might_sleep();
186 wait_on_bit(&inode->i_state, __I_NEW, TASK_UNINTERRUPTIBLE);
187}
188
189#ifdef CONFIG_CGROUP_WRITEBACK
190
191#include <linux/cgroup.h>
192#include <linux/bio.h>
193
194void __inode_attach_wb(struct inode *inode, struct page *page);
195void wbc_attach_and_unlock_inode(struct writeback_control *wbc,
196 struct inode *inode)
197 __releases(&inode->i_lock);
198void wbc_detach_inode(struct writeback_control *wbc);
199void wbc_account_io(struct writeback_control *wbc, struct page *page,
200 size_t bytes);
201void cgroup_writeback_umount(void);
202
203
204
205
206
207
208
209
210
211
212static inline void inode_attach_wb(struct inode *inode, struct page *page)
213{
214 if (!inode->i_wb)
215 __inode_attach_wb(inode, page);
216}
217
218
219
220
221
222
223
224static inline void inode_detach_wb(struct inode *inode)
225{
226 if (inode->i_wb) {
227 wb_put(inode->i_wb);
228 inode->i_wb = NULL;
229 }
230}
231
232
233
234
235
236
237
238
239
240
241static inline void wbc_attach_fdatawrite_inode(struct writeback_control *wbc,
242 struct inode *inode)
243{
244 spin_lock(&inode->i_lock);
245 inode_attach_wb(inode, NULL);
246 wbc_attach_and_unlock_inode(wbc, inode);
247}
248
249
250
251
252
253
254
255
256
257
258static inline void wbc_init_bio(struct writeback_control *wbc, struct bio *bio)
259{
260
261
262
263
264
265
266 if (wbc->wb)
267 bio_associate_blkcg(bio, wbc->wb->blkcg_css);
268}
269
270#else
271
272static inline void inode_attach_wb(struct inode *inode, struct page *page)
273{
274}
275
276static inline void inode_detach_wb(struct inode *inode)
277{
278}
279
280static inline void wbc_attach_and_unlock_inode(struct writeback_control *wbc,
281 struct inode *inode)
282 __releases(&inode->i_lock)
283{
284 spin_unlock(&inode->i_lock);
285}
286
287static inline void wbc_attach_fdatawrite_inode(struct writeback_control *wbc,
288 struct inode *inode)
289{
290}
291
292static inline void wbc_detach_inode(struct writeback_control *wbc)
293{
294}
295
296static inline void wbc_init_bio(struct writeback_control *wbc, struct bio *bio)
297{
298}
299
300static inline void wbc_account_io(struct writeback_control *wbc,
301 struct page *page, size_t bytes)
302{
303}
304
305static inline void cgroup_writeback_umount(void)
306{
307}
308
309#endif
310
311
312
313
314#ifdef CONFIG_BLOCK
315void laptop_io_completion(struct backing_dev_info *info);
316void laptop_sync_completion(void);
317void laptop_mode_sync(struct work_struct *work);
318void laptop_mode_timer_fn(unsigned long data);
319#else
320static inline void laptop_sync_completion(void) { }
321#endif
322bool node_dirty_ok(struct pglist_data *pgdat);
323int wb_domain_init(struct wb_domain *dom, gfp_t gfp);
324#ifdef CONFIG_CGROUP_WRITEBACK
325void wb_domain_exit(struct wb_domain *dom);
326#endif
327
328extern struct wb_domain global_wb_domain;
329
330
331extern int dirty_background_ratio;
332extern unsigned long dirty_background_bytes;
333extern int vm_dirty_ratio;
334extern unsigned long vm_dirty_bytes;
335extern unsigned int dirty_writeback_interval;
336extern unsigned int dirty_expire_interval;
337extern unsigned int dirtytime_expire_interval;
338extern int vm_highmem_is_dirtyable;
339extern int block_dump;
340extern int laptop_mode;
341
342extern int dirty_background_ratio_handler(struct ctl_table *table, int write,
343 void __user *buffer, size_t *lenp,
344 loff_t *ppos);
345extern int dirty_background_bytes_handler(struct ctl_table *table, int write,
346 void __user *buffer, size_t *lenp,
347 loff_t *ppos);
348extern int dirty_ratio_handler(struct ctl_table *table, int write,
349 void __user *buffer, size_t *lenp,
350 loff_t *ppos);
351extern int dirty_bytes_handler(struct ctl_table *table, int write,
352 void __user *buffer, size_t *lenp,
353 loff_t *ppos);
354int dirtytime_interval_handler(struct ctl_table *table, int write,
355 void __user *buffer, size_t *lenp, loff_t *ppos);
356
357struct ctl_table;
358int dirty_writeback_centisecs_handler(struct ctl_table *, int,
359 void __user *, size_t *, loff_t *);
360
361void global_dirty_limits(unsigned long *pbackground, unsigned long *pdirty);
362unsigned long wb_calc_thresh(struct bdi_writeback *wb, unsigned long thresh);
363
364void wb_update_bandwidth(struct bdi_writeback *wb, unsigned long start_time);
365void page_writeback_init(void);
366void balance_dirty_pages_ratelimited(struct address_space *mapping);
367bool wb_over_bg_thresh(struct bdi_writeback *wb);
368
369typedef int (*writepage_t)(struct page *page, struct writeback_control *wbc,
370 void *data);
371
372int generic_writepages(struct address_space *mapping,
373 struct writeback_control *wbc);
374void tag_pages_for_writeback(struct address_space *mapping,
375 pgoff_t start, pgoff_t end);
376int write_cache_pages(struct address_space *mapping,
377 struct writeback_control *wbc, writepage_t writepage,
378 void *data);
379int do_writepages(struct address_space *mapping, struct writeback_control *wbc);
380void writeback_set_ratelimit(void);
381void tag_pages_for_writeback(struct address_space *mapping,
382 pgoff_t start, pgoff_t end);
383
384void account_page_redirty(struct page *page);
385
386void sb_mark_inode_writeback(struct inode *inode);
387void sb_clear_inode_writeback(struct inode *inode);
388
389#endif
390