2 #include <linux/wait.h>
9 #include <linux/sched.h>
10 #include <linux/module.h>
12 #include <linux/device.h>
31 static struct class *bdi_class;
53 #ifdef CONFIG_DEBUG_FS
57 static struct dentry *bdi_debug_root;
59 static void bdi_debug_init(
void)
64 static int bdi_debug_stats_show(
struct seq_file *
m,
void *
v)
68 unsigned long background_thresh;
69 unsigned long dirty_thresh;
70 unsigned long bdi_thresh;
71 unsigned long nr_dirty, nr_io, nr_more_io;
74 nr_dirty = nr_io = nr_more_io = 0;
87 #define K(x) ((x) << (PAGE_SHIFT - 10))
89 "BdiWriteback: %10lu kB\n"
90 "BdiReclaimable: %10lu kB\n"
91 "BdiDirtyThresh: %10lu kB\n"
92 "DirtyThresh: %10lu kB\n"
93 "BackgroundThresh: %10lu kB\n"
94 "BdiDirtied: %10lu kB\n"
95 "BdiWritten: %10lu kB\n"
96 "BdiWriteBandwidth: %10lu kBps\n"
106 K(background_thresh),
109 (
unsigned long)
K(bdi->write_bandwidth),
113 !list_empty(&bdi->bdi_list), bdi->state);
119 static int bdi_debug_stats_open(
struct inode *inode,
struct file *
file)
125 .
open = bdi_debug_stats_open,
135 bdi, &bdi_debug_stats_fops);
144 static inline void bdi_debug_init(
void)
161 unsigned long read_ahead_kb;
164 ret = kstrtoul(buf, 10, &read_ahead_kb);
173 #define K(pages) ((pages) << (PAGE_SHIFT - 10))
175 #define BDI_SHOW(name, expr) \
176 static ssize_t name##_show(struct device *dev, \
177 struct device_attribute *attr, char *page) \
179 struct backing_dev_info *bdi = dev_get_drvdata(dev); \
181 return snprintf(page, PAGE_SIZE-1, "%lld\n", (long long)expr); \
224 #define __ATTR_RW(attr) __ATTR(attr, 0644, attr##_show, attr##_store)
233 static __init int bdi_class_init(
void)
236 if (IS_ERR(bdi_class))
237 return PTR_ERR(bdi_class);
245 static int __init default_bdi_init(
void)
249 err =
bdi_init(&default_backing_dev_info);
252 err =
bdi_init(&noop_backing_dev_info);
260 return wb_has_dirty_io(&bdi->
wb);
263 static void wakeup_timer_fn(
unsigned long data)
269 trace_writeback_wake_thread(bdi);
271 }
else if (bdi->
dev) {
277 trace_writeback_wake_forker_thread(bdi);
306 static unsigned long bdi_longest_inactive(
void)
311 return max(5
UL * 60 *
HZ, interval);
325 static int bdi_forker_thread(
void *
ptr)
350 if (wb_has_dirty_io(me) || !list_empty(&me->
bdi->work_list)) {
355 spin_lock_bh(&bdi_lock);
367 if (!bdi_cap_writeback_dirty(bdi) ||
368 bdi_cap_flush_forker(bdi))
372 "bdi %p/%s is not registered!\n", bdi, bdi->
name);
374 have_dirty_io = !list_empty(&bdi->
work_list) ||
375 wb_has_dirty_io(&bdi->
wb);
381 if (!bdi->
wb.task && have_dirty_io) {
399 if (bdi->
wb.task && !have_dirty_io &&
401 bdi_longest_inactive())) {
411 spin_unlock_bh(&bdi_lock);
414 if (!list_empty(&me->
bdi->work_list))
421 "flush-%s", dev_name(bdi->
dev));
442 bdi_clear_pending(bdi);
448 bdi_clear_pending(bdi);
476 spin_lock_bh(&bdi_lock);
478 spin_unlock_bh(&bdi_lock);
484 const char *
fmt, ...)
505 if (bdi_cap_flush_forker(bdi)) {
510 if (IS_ERR(wb->
task))
511 return PTR_ERR(wb->
task);
514 bdi_debug_register(bdi, dev_name(dev));
521 trace_writeback_bdi_register(bdi);
539 if (!bdi_cap_writeback_dirty(bdi))
545 bdi_remove_from_list(bdi);
575 if (sb->
s_bdi == bdi)
578 spin_unlock(&sb_lock);
587 trace_writeback_bdi_unregister(bdi);
591 if (!bdi_cap_flush_forker(bdi))
592 bdi_wb_shutdown(bdi);
593 bdi_debug_unregister(bdi);
606 memset(wb, 0,
sizeof(*wb));
611 INIT_LIST_HEAD(&wb->
b_io);
620 #define INIT_BW (100 << (20 - PAGE_SHIFT))
635 bdi_wb_init(&bdi->
wb, bdi);
638 err = percpu_counter_init(&bdi->
bdi_stat[i], 0);
677 list_splice(&bdi->
wb.b_dirty, &dst->
b_dirty);
678 list_splice(&bdi->
wb.b_io, &dst->
b_io);
680 spin_unlock(&bdi->
wb.list_lock);
717 sprintf(tmp,
"%.28s%s", name,
"-%d");
732 static atomic_t nr_bdi_congested[2];
743 if (waitqueue_active(wqh))
816 !zone_is_reclaim_congested(zone)) {
841 void __user *
buffer,
size_t *lenp, loff_t *ppos)