aboutsummaryrefslogtreecommitdiffstats
path: root/fs/fs-writeback.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/fs-writeback.c')
-rw-r--r--fs/fs-writeback.c107
1 files changed, 61 insertions, 46 deletions
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 5581122bd2c..aed881a76b2 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -72,22 +72,16 @@ int writeback_in_progress(struct backing_dev_info *bdi)
72static inline struct backing_dev_info *inode_to_bdi(struct inode *inode) 72static inline struct backing_dev_info *inode_to_bdi(struct inode *inode)
73{ 73{
74 struct super_block *sb = inode->i_sb; 74 struct super_block *sb = inode->i_sb;
75 struct backing_dev_info *bdi = inode->i_mapping->backing_dev_info;
76 75
77 /* 76 if (strcmp(sb->s_type->name, "bdev") == 0)
78 * For inodes on standard filesystems, we use superblock's bdi. For 77 return inode->i_mapping->backing_dev_info;
79 * inodes on virtual filesystems, we want to use inode mapping's bdi 78
80 * because they can possibly point to something useful (think about 79 return sb->s_bdi;
81 * block_dev filesystem). 80}
82 */ 81
83 if (sb->s_bdi && sb->s_bdi != &noop_backing_dev_info) { 82static inline struct inode *wb_inode(struct list_head *head)
84 /* Some device inodes could play dirty tricks. Catch them... */ 83{
85 WARN(bdi != sb->s_bdi && bdi_cap_writeback_dirty(bdi), 84 return list_entry(head, struct inode, i_wb_list);
86 "Dirtiable inode bdi %s != sb bdi %s\n",
87 bdi->name, sb->s_bdi->name);
88 return sb->s_bdi;
89 }
90 return bdi;
91} 85}
92 86
93static void bdi_queue_work(struct backing_dev_info *bdi, 87static void bdi_queue_work(struct backing_dev_info *bdi,
@@ -183,11 +177,11 @@ static void redirty_tail(struct inode *inode)
183 if (!list_empty(&wb->b_dirty)) { 177 if (!list_empty(&wb->b_dirty)) {
184 struct inode *tail; 178 struct inode *tail;
185 179
186 tail = list_entry(wb->b_dirty.next, struct inode, i_list); 180 tail = wb_inode(wb->b_dirty.next);
187 if (time_before(inode->dirtied_when, tail->dirtied_when)) 181 if (time_before(inode->dirtied_when, tail->dirtied_when))
188 inode->dirtied_when = jiffies; 182 inode->dirtied_when = jiffies;
189 } 183 }
190 list_move(&inode->i_list, &wb->b_dirty); 184 list_move(&inode->i_wb_list, &wb->b_dirty);
191} 185}
192 186
193/* 187/*
@@ -197,7 +191,7 @@ static void requeue_io(struct inode *inode)
197{ 191{
198 struct bdi_writeback *wb = &inode_to_bdi(inode)->wb; 192 struct bdi_writeback *wb = &inode_to_bdi(inode)->wb;
199 193
200 list_move(&inode->i_list, &wb->b_more_io); 194 list_move(&inode->i_wb_list, &wb->b_more_io);
201} 195}
202 196
203static void inode_sync_complete(struct inode *inode) 197static void inode_sync_complete(struct inode *inode)
@@ -238,14 +232,14 @@ static void move_expired_inodes(struct list_head *delaying_queue,
238 int do_sb_sort = 0; 232 int do_sb_sort = 0;
239 233
240 while (!list_empty(delaying_queue)) { 234 while (!list_empty(delaying_queue)) {
241 inode = list_entry(delaying_queue->prev, struct inode, i_list); 235 inode = wb_inode(delaying_queue->prev);
242 if (older_than_this && 236 if (older_than_this &&
243 inode_dirtied_after(inode, *older_than_this)) 237 inode_dirtied_after(inode, *older_than_this))
244 break; 238 break;
245 if (sb && sb != inode->i_sb) 239 if (sb && sb != inode->i_sb)
246 do_sb_sort = 1; 240 do_sb_sort = 1;
247 sb = inode->i_sb; 241 sb = inode->i_sb;
248 list_move(&inode->i_list, &tmp); 242 list_move(&inode->i_wb_list, &tmp);
249 } 243 }
250 244
251 /* just one sb in list, splice to dispatch_queue and we're done */ 245 /* just one sb in list, splice to dispatch_queue and we're done */
@@ -256,12 +250,11 @@ static void move_expired_inodes(struct list_head *delaying_queue,
256 250
257 /* Move inodes from one superblock together */ 251 /* Move inodes from one superblock together */
258 while (!list_empty(&tmp)) { 252 while (!list_empty(&tmp)) {
259 inode = list_entry(tmp.prev, struct inode, i_list); 253 sb = wb_inode(tmp.prev)->i_sb;
260 sb = inode->i_sb;
261 list_for_each_prev_safe(pos, node, &tmp) { 254 list_for_each_prev_safe(pos, node, &tmp) {
262 inode = list_entry(pos, struct inode, i_list); 255 inode = wb_inode(pos);
263 if (inode->i_sb == sb) 256 if (inode->i_sb == sb)
264 list_move(&inode->i_list, dispatch_queue); 257 list_move(&inode->i_wb_list, dispatch_queue);
265 } 258 }
266 } 259 }
267} 260}
@@ -419,16 +412,13 @@ writeback_single_inode(struct inode *inode, struct writeback_control *wbc)
419 * completion. 412 * completion.
420 */ 413 */
421 redirty_tail(inode); 414 redirty_tail(inode);
422 } else if (atomic_read(&inode->i_count)) {
423 /*
424 * The inode is clean, inuse
425 */
426 list_move(&inode->i_list, &inode_in_use);
427 } else { 415 } else {
428 /* 416 /*
429 * The inode is clean, unused 417 * The inode is clean. At this point we either have
418 * a reference to the inode or it's on it's way out.
419 * No need to add it back to the LRU.
430 */ 420 */
431 list_move(&inode->i_list, &inode_unused); 421 list_del_init(&inode->i_wb_list);
432 } 422 }
433 } 423 }
434 inode_sync_complete(inode); 424 inode_sync_complete(inode);
@@ -476,8 +466,7 @@ static int writeback_sb_inodes(struct super_block *sb, struct bdi_writeback *wb,
476{ 466{
477 while (!list_empty(&wb->b_io)) { 467 while (!list_empty(&wb->b_io)) {
478 long pages_skipped; 468 long pages_skipped;
479 struct inode *inode = list_entry(wb->b_io.prev, 469 struct inode *inode = wb_inode(wb->b_io.prev);
480 struct inode, i_list);
481 470
482 if (inode->i_sb != sb) { 471 if (inode->i_sb != sb) {
483 if (only_this_sb) { 472 if (only_this_sb) {
@@ -498,10 +487,16 @@ static int writeback_sb_inodes(struct super_block *sb, struct bdi_writeback *wb,
498 return 0; 487 return 0;
499 } 488 }
500 489
501 if (inode->i_state & (I_NEW | I_WILL_FREE)) { 490 /*
491 * Don't bother with new inodes or inodes beeing freed, first
492 * kind does not need peridic writeout yet, and for the latter
493 * kind writeout is handled by the freer.
494 */
495 if (inode->i_state & (I_NEW | I_FREEING | I_WILL_FREE)) {
502 requeue_io(inode); 496 requeue_io(inode);
503 continue; 497 continue;
504 } 498 }
499
505 /* 500 /*
506 * Was this inode dirtied after sync_sb_inodes was called? 501 * Was this inode dirtied after sync_sb_inodes was called?
507 * This keeps sync from extra jobs and livelock. 502 * This keeps sync from extra jobs and livelock.
@@ -509,7 +504,6 @@ static int writeback_sb_inodes(struct super_block *sb, struct bdi_writeback *wb,
509 if (inode_dirtied_after(inode, wbc->wb_start)) 504 if (inode_dirtied_after(inode, wbc->wb_start))
510 return 1; 505 return 1;
511 506
512 BUG_ON(inode->i_state & I_FREEING);
513 __iget(inode); 507 __iget(inode);
514 pages_skipped = wbc->pages_skipped; 508 pages_skipped = wbc->pages_skipped;
515 writeback_single_inode(inode, wbc); 509 writeback_single_inode(inode, wbc);
@@ -547,8 +541,7 @@ void writeback_inodes_wb(struct bdi_writeback *wb,
547 queue_io(wb, wbc->older_than_this); 541 queue_io(wb, wbc->older_than_this);
548 542
549 while (!list_empty(&wb->b_io)) { 543 while (!list_empty(&wb->b_io)) {
550 struct inode *inode = list_entry(wb->b_io.prev, 544 struct inode *inode = wb_inode(wb->b_io.prev);
551 struct inode, i_list);
552 struct super_block *sb = inode->i_sb; 545 struct super_block *sb = inode->i_sb;
553 546
554 if (!pin_sb_for_writeback(sb)) { 547 if (!pin_sb_for_writeback(sb)) {
@@ -593,7 +586,7 @@ static inline bool over_bground_thresh(void)
593 global_dirty_limits(&background_thresh, &dirty_thresh); 586 global_dirty_limits(&background_thresh, &dirty_thresh);
594 587
595 return (global_page_state(NR_FILE_DIRTY) + 588 return (global_page_state(NR_FILE_DIRTY) +
596 global_page_state(NR_UNSTABLE_NFS) >= background_thresh); 589 global_page_state(NR_UNSTABLE_NFS) > background_thresh);
597} 590}
598 591
599/* 592/*
@@ -686,8 +679,7 @@ static long wb_writeback(struct bdi_writeback *wb,
686 */ 679 */
687 spin_lock(&inode_lock); 680 spin_lock(&inode_lock);
688 if (!list_empty(&wb->b_more_io)) { 681 if (!list_empty(&wb->b_more_io)) {
689 inode = list_entry(wb->b_more_io.prev, 682 inode = wb_inode(wb->b_more_io.prev);
690 struct inode, i_list);
691 trace_wbc_writeback_wait(&wbc, wb->bdi); 683 trace_wbc_writeback_wait(&wbc, wb->bdi);
692 inode_wait_for_writeback(inode); 684 inode_wait_for_writeback(inode);
693 } 685 }
@@ -732,9 +724,13 @@ static long wb_check_old_data_flush(struct bdi_writeback *wb)
732 return 0; 724 return 0;
733 725
734 wb->last_old_flush = jiffies; 726 wb->last_old_flush = jiffies;
727 /*
728 * Add in the number of potentially dirty inodes, because each inode
729 * write can dirty pagecache in the underlying blockdev.
730 */
735 nr_pages = global_page_state(NR_FILE_DIRTY) + 731 nr_pages = global_page_state(NR_FILE_DIRTY) +
736 global_page_state(NR_UNSTABLE_NFS) + 732 global_page_state(NR_UNSTABLE_NFS) +
737 (inodes_stat.nr_inodes - inodes_stat.nr_unused); 733 get_nr_dirty_inodes();
738 734
739 if (nr_pages) { 735 if (nr_pages) {
740 struct wb_writeback_work work = { 736 struct wb_writeback_work work = {
@@ -801,7 +797,7 @@ int bdi_writeback_thread(void *data)
801 struct backing_dev_info *bdi = wb->bdi; 797 struct backing_dev_info *bdi = wb->bdi;
802 long pages_written; 798 long pages_written;
803 799
804 current->flags |= PF_FLUSHER | PF_SWAPWRITE; 800 current->flags |= PF_SWAPWRITE;
805 set_freezable(); 801 set_freezable();
806 wb->last_active = jiffies; 802 wb->last_active = jiffies;
807 803
@@ -973,7 +969,7 @@ void __mark_inode_dirty(struct inode *inode, int flags)
973 * dirty list. Add blockdev inodes as well. 969 * dirty list. Add blockdev inodes as well.
974 */ 970 */
975 if (!S_ISBLK(inode->i_mode)) { 971 if (!S_ISBLK(inode->i_mode)) {
976 if (hlist_unhashed(&inode->i_hash)) 972 if (inode_unhashed(inode))
977 goto out; 973 goto out;
978 } 974 }
979 if (inode->i_state & I_FREEING) 975 if (inode->i_state & I_FREEING)
@@ -1001,7 +997,7 @@ void __mark_inode_dirty(struct inode *inode, int flags)
1001 } 997 }
1002 998
1003 inode->dirtied_when = jiffies; 999 inode->dirtied_when = jiffies;
1004 list_move(&inode->i_list, &bdi->wb.b_dirty); 1000 list_move(&inode->i_wb_list, &bdi->wb.b_dirty);
1005 } 1001 }
1006 } 1002 }
1007out: 1003out:
@@ -1101,8 +1097,7 @@ void writeback_inodes_sb(struct super_block *sb)
1101 1097
1102 WARN_ON(!rwsem_is_locked(&sb->s_umount)); 1098 WARN_ON(!rwsem_is_locked(&sb->s_umount));
1103 1099
1104 work.nr_pages = nr_dirty + nr_unstable + 1100 work.nr_pages = nr_dirty + nr_unstable + get_nr_dirty_inodes();
1105 (inodes_stat.nr_inodes - inodes_stat.nr_unused);
1106 1101
1107 bdi_queue_work(sb->s_bdi, &work); 1102 bdi_queue_work(sb->s_bdi, &work);
1108 wait_for_completion(&done); 1103 wait_for_completion(&done);
@@ -1209,3 +1204,23 @@ int sync_inode(struct inode *inode, struct writeback_control *wbc)
1209 return ret; 1204 return ret;
1210} 1205}
1211EXPORT_SYMBOL(sync_inode); 1206EXPORT_SYMBOL(sync_inode);
1207
1208/**
1209 * sync_inode - write an inode to disk
1210 * @inode: the inode to sync
1211 * @wait: wait for I/O to complete.
1212 *
1213 * Write an inode to disk and adjust it's dirty state after completion.
1214 *
1215 * Note: only writes the actual inode, no associated data or other metadata.
1216 */
1217int sync_inode_metadata(struct inode *inode, int wait)
1218{
1219 struct writeback_control wbc = {
1220 .sync_mode = wait ? WB_SYNC_ALL : WB_SYNC_NONE,
1221 .nr_to_write = 0, /* metadata-only */
1222 };
1223
1224 return sync_inode(inode, &wbc);
1225}
1226EXPORT_SYMBOL(sync_inode_metadata);