16 #include <linux/kernel.h>
17 #include <linux/export.h>
19 #include <linux/slab.h>
20 #include <linux/sched.h>
35 #define MIN_WRITEBACK_PAGES (4096UL >> (PAGE_CACHE_SHIFT - 10))
73 return inode->
i_mapping->backing_dev_info;
88 #define CREATE_TRACE_POINTS
108 trace_writeback_queue(bdi, work);
113 trace_writeback_nothread(bdi, work);
114 bdi_wakeup_flusher(bdi);
131 trace_writeback_nowork(bdi);
142 bdi_queue_work(bdi, work);
160 __bdi_start_writeback(bdi, nr_pages,
true, reason);
179 trace_writeback_wake_background(bdi);
181 bdi_wakeup_flusher(bdi);
192 spin_lock(&bdi->
wb.list_lock);
194 spin_unlock(&bdi->
wb.list_lock);
206 static void redirty_tail(
struct inode *inode,
struct bdi_writeback *
wb)
209 if (!list_empty(&wb->
b_dirty)) {
212 tail = wb_inode(wb->
b_dirty.next);
222 static void requeue_io(
struct inode *inode,
struct bdi_writeback *wb)
228 static void inode_sync_complete(
struct inode *inode)
238 static bool inode_dirtied_after(
struct inode *inode,
unsigned long t)
257 static int move_expired_inodes(
struct list_head *delaying_queue,
268 while (!list_empty(delaying_queue)) {
269 inode = wb_inode(delaying_queue->
prev);
273 if (sb && sb != inode->
i_sb)
282 list_splice(&
tmp, dispatch_queue);
287 while (!list_empty(&
tmp)) {
288 sb = wb_inode(
tmp.prev)->i_sb;
290 inode = wb_inode(pos);
291 if (inode->
i_sb == sb)
292 list_move(&inode->
i_wb_list, dispatch_queue);
315 moved = move_expired_inodes(&wb->
b_dirty, &wb->
b_io, work);
316 trace_writeback_queue_io(wb, work, moved);
322 return inode->
i_sb->s_op->write_inode(inode, wbc);
330 static void __inode_wait_for_writeback(
struct inode *inode)
339 spin_unlock(&inode->
i_lock);
341 spin_lock(&inode->
i_lock);
350 spin_lock(&inode->
i_lock);
351 __inode_wait_for_writeback(inode);
352 spin_unlock(&inode->
i_lock);
360 static void inode_sleep_on_writeback(
struct inode *inode)
369 spin_unlock(&inode->
i_lock);
383 static void requeue_inode(
struct inode *inode,
struct bdi_writeback *wb,
403 redirty_tail(inode, wb);
414 requeue_io(inode, wb);
423 redirty_tail(inode, wb);
431 redirty_tail(inode, wb);
471 spin_lock(&inode->
i_lock);
477 spin_unlock(&inode->
i_lock);
480 int err = write_inode(inode, wbc);
484 trace_writeback_single_inode(inode, wbc, nr_to_write);
497 writeback_single_inode(
struct inode *inode,
struct bdi_writeback *wb,
502 spin_lock(&inode->
i_lock);
516 __inode_wait_for_writeback(inode);
529 spin_unlock(&inode->
i_lock);
531 ret = __writeback_single_inode(inode, wbc);
534 spin_lock(&inode->
i_lock);
542 inode_sync_complete(inode);
544 spin_unlock(&inode->
i_lock);
584 static long writeback_sb_inodes(
struct super_block *sb,
601 while (!list_empty(&wb->
b_io)) {
602 struct inode *inode = wb_inode(wb->
b_io.prev);
604 if (inode->
i_sb != sb) {
611 redirty_tail(inode, wb);
628 spin_lock(&inode->
i_lock);
630 spin_unlock(&inode->
i_lock);
631 redirty_tail(inode, wb);
644 spin_unlock(&inode->
i_lock);
645 requeue_io(inode, wb);
646 trace_writeback_sb_inodes_requeue(inode);
658 inode_sleep_on_writeback(inode);
664 spin_unlock(&inode->
i_lock);
666 write_chunk = writeback_chunk_size(wb->
bdi, work);
674 __writeback_single_inode(inode, &wbc);
679 spin_lock(&inode->
i_lock);
682 requeue_inode(inode, wb, &wbc);
683 inode_sync_complete(inode);
684 spin_unlock(&inode->
i_lock);
703 unsigned long start_time =
jiffies;
706 while (!list_empty(&wb->
b_io)) {
707 struct inode *inode = wb_inode(wb->
b_io.prev);
716 redirty_tail(inode, wb);
719 wrote += writeback_sb_inodes(sb, wb, work);
745 if (list_empty(&wb->
b_io))
747 __writeback_inodes_wb(wb, &work);
755 unsigned long background_thresh, dirty_thresh;
775 unsigned long start_time)
798 unsigned long wb_start =
jiffies;
800 unsigned long oldest_jif;
822 !list_empty(&wb->
bdi->work_list))
844 trace_writeback_start(wb->
bdi, work);
845 if (list_empty(&wb->
b_io))
848 progress = writeback_sb_inodes(work->
sb, wb, work);
850 progress = __writeback_inodes_wb(wb, work);
851 trace_writeback_written(wb->
bdi, work);
853 wb_update_bandwidth(wb, wb_start);
876 trace_writeback_wait(wb->
bdi, work);
878 spin_lock(&inode->
i_lock);
881 inode_sleep_on_writeback(inode);
902 list_del_init(&work->
list);
912 static unsigned long get_nr_dirty_pages(
void)
919 static long wb_check_background_flush(
struct bdi_writeback *wb)
921 if (over_bground_thresh(wb->
bdi)) {
931 return wb_writeback(wb, &work);
937 static long wb_check_old_data_flush(
struct bdi_writeback *wb)
939 unsigned long expired;
954 nr_pages = get_nr_dirty_pages();
965 return wb_writeback(wb, &work);
981 while ((work = get_next_work_item(bdi)) !=
NULL) {
989 trace_writeback_exec(bdi, work);
991 wrote += wb_writeback(wb, work);
1006 wrote += wb_check_old_data_flush(wb);
1007 wrote += wb_check_background_flush(wb);
1032 trace_writeback_thread_start(bdi);
1043 trace_writeback_pages_written(pages_written);
1070 trace_writeback_thread_stop(bdi);
1092 __bdi_start_writeback(bdi, nr_pages,
false, reason);
1097 static noinline void block_dump___mark_inode_dirty(
struct inode *inode)
1101 const char *
name =
"?";
1105 spin_lock(&dentry->
d_lock);
1106 name = (
const char *) dentry->
d_name.name;
1109 "%s(%d): dirtied inode %lu (%s) on %s\n",
1111 name, inode->
i_sb->s_id);
1113 spin_unlock(&dentry->
d_lock);
1153 if (sb->
s_op->dirty_inode)
1154 sb->
s_op->dirty_inode(inode, flags);
1164 if ((inode->
i_state & flags) == flags)
1168 block_dump___mark_inode_dirty(inode);
1170 spin_lock(&inode->
i_lock);
1171 if ((inode->
i_state & flags) != flags) {
1182 goto out_unlock_inode;
1189 if (inode_unhashed(inode))
1190 goto out_unlock_inode;
1193 goto out_unlock_inode;
1200 bool wakeup_bdi =
false;
1201 bdi = inode_to_bdi(inode);
1203 if (bdi_cap_writeback_dirty(bdi)) {
1205 "bdi-%s not registered\n", bdi->
name);
1213 if (!wb_has_dirty_io(&bdi->
wb))
1217 spin_unlock(&inode->
i_lock);
1218 spin_lock(&bdi->
wb.list_lock);
1221 spin_unlock(&bdi->
wb.list_lock);
1229 spin_unlock(&inode->
i_lock);
1234 static void wait_sb_inodes(
struct super_block *sb)
1244 spin_lock(&inode_sb_list_lock);
1256 spin_lock(&inode->
i_lock);
1259 spin_unlock(&inode->
i_lock);
1263 spin_unlock(&inode->
i_lock);
1264 spin_unlock(&inode_sb_list_lock);
1281 spin_lock(&inode_sb_list_lock);
1283 spin_unlock(&inode_sb_list_lock);
1305 .tagged_writepages = 1,
1314 bdi_queue_work(sb->
s_bdi, &work);
1401 bdi_queue_work(sb->
s_bdi, &work);
1428 if (!mapping_cap_writeback_dirty(inode->
i_mapping))
1432 return writeback_single_inode(inode, wb, &wbc);
1449 return writeback_single_inode(inode, &inode_to_bdi(inode)->wb, wbc);