Skip to content

Commit 0dc83bd

Browse files
committed
Revert "writeback: do not sync data dirtied after sync start"
This reverts commit c4a391b. Dave Chinner <david@fromorbit.com> has reported the commit may cause some inodes to be left out from sync(2). This is because we can call redirty_tail() for some inode (which sets i_dirtied_when to current time) after sync(2) has started or similarly requeue_inode() can set i_dirtied_when to current time if writeback had to skip some pages. The real problem is in the functions clobbering i_dirtied_when but fixing that isn't trivial so revert is a safer choice for now. CC: stable@vger.kernel.org # >= 3.13 Signed-off-by: Jan Kara <jack@suse.cz>
1 parent 1362f4e commit 0dc83bd

5 files changed

Lines changed: 22 additions & 36 deletions

File tree

‎fs/fs-writeback.c‎

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,13 @@
4040
struct wb_writeback_work {
4141
long nr_pages;
4242
struct super_block *sb;
43-
/*
44-
* Write only inodes dirtied before this time. Don't forget to set
45-
* older_than_this_is_set when you set this.
46-
*/
47-
unsigned long older_than_this;
43+
unsigned long *older_than_this;
4844
enum writeback_sync_modes sync_mode;
4945
unsigned int tagged_writepages:1;
5046
unsigned int for_kupdate:1;
5147
unsigned int range_cyclic:1;
5248
unsigned int for_background:1;
5349
unsigned int for_sync:1; /* sync(2) WB_SYNC_ALL writeback */
54-
unsigned int older_than_this_is_set:1;
5550
enum wb_reason reason; /* why was writeback initiated? */
5651

5752
struct list_head list; /* pending work list */
@@ -252,10 +247,10 @@ static int move_expired_inodes(struct list_head *delaying_queue,
252247
int do_sb_sort = 0;
253248
int moved = 0;
254249

255-
WARN_ON_ONCE(!work->older_than_this_is_set);
256250
while (!list_empty(delaying_queue)) {
257251
inode = wb_inode(delaying_queue->prev);
258-
if (inode_dirtied_after(inode, work->older_than_this))
252+
if (work->older_than_this &&
253+
inode_dirtied_after(inode, *work->older_than_this))
259254
break;
260255
list_move(&inode->i_wb_list, &tmp);
261256
moved++;
@@ -742,8 +737,6 @@ static long writeback_inodes_wb(struct bdi_writeback *wb, long nr_pages,
742737
.sync_mode = WB_SYNC_NONE,
743738
.range_cyclic = 1,
744739
.reason = reason,
745-
.older_than_this = jiffies,
746-
.older_than_this_is_set = 1,
747740
};
748741

749742
spin_lock(&wb->list_lock);
@@ -802,13 +795,12 @@ static long wb_writeback(struct bdi_writeback *wb,
802795
{
803796
unsigned long wb_start = jiffies;
804797
long nr_pages = work->nr_pages;
798+
unsigned long oldest_jif;
805799
struct inode *inode;
806800
long progress;
807801

808-
if (!work->older_than_this_is_set) {
809-
work->older_than_this = jiffies;
810-
work->older_than_this_is_set = 1;
811-
}
802+
oldest_jif = jiffies;
803+
work->older_than_this = &oldest_jif;
812804

813805
spin_lock(&wb->list_lock);
814806
for (;;) {
@@ -842,10 +834,10 @@ static long wb_writeback(struct bdi_writeback *wb,
842834
* safe.
843835
*/
844836
if (work->for_kupdate) {
845-
work->older_than_this = jiffies -
837+
oldest_jif = jiffies -
846838
msecs_to_jiffies(dirty_expire_interval * 10);
847839
} else if (work->for_background)
848-
work->older_than_this = jiffies;
840+
oldest_jif = jiffies;
849841

850842
trace_writeback_start(wb->bdi, work);
851843
if (list_empty(&wb->b_io))
@@ -1357,21 +1349,18 @@ EXPORT_SYMBOL(try_to_writeback_inodes_sb);
13571349

13581350
/**
13591351
* sync_inodes_sb - sync sb inode pages
1360-
* @sb: the superblock
1361-
* @older_than_this: timestamp
1352+
* @sb: the superblock
13621353
*
13631354
* This function writes and waits on any dirty inode belonging to this
1364-
* superblock that has been dirtied before given timestamp.
1355+
* super_block.
13651356
*/
1366-
void sync_inodes_sb(struct super_block *sb, unsigned long older_than_this)
1357+
void sync_inodes_sb(struct super_block *sb)
13671358
{
13681359
DECLARE_COMPLETION_ONSTACK(done);
13691360
struct wb_writeback_work work = {
13701361
.sb = sb,
13711362
.sync_mode = WB_SYNC_ALL,
13721363
.nr_pages = LONG_MAX,
1373-
.older_than_this = older_than_this,
1374-
.older_than_this_is_set = 1,
13751364
.range_cyclic = 0,
13761365
.done = &done,
13771366
.reason = WB_REASON_SYNC,

‎fs/sync.c‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@
2727
* wait == 1 case since in that case write_inode() functions do
2828
* sync_dirty_buffer() and thus effectively write one block at a time.
2929
*/
30-
static int __sync_filesystem(struct super_block *sb, int wait,
31-
unsigned long start)
30+
static int __sync_filesystem(struct super_block *sb, int wait)
3231
{
3332
if (wait)
34-
sync_inodes_sb(sb, start);
33+
sync_inodes_sb(sb);
3534
else
3635
writeback_inodes_sb(sb, WB_REASON_SYNC);
3736

@@ -48,7 +47,6 @@ static int __sync_filesystem(struct super_block *sb, int wait,
4847
int sync_filesystem(struct super_block *sb)
4948
{
5049
int ret;
51-
unsigned long start = jiffies;
5250

5351
/*
5452
* We need to be protected against the filesystem going from
@@ -62,17 +60,17 @@ int sync_filesystem(struct super_block *sb)
6260
if (sb->s_flags & MS_RDONLY)
6361
return 0;
6462

65-
ret = __sync_filesystem(sb, 0, start);
63+
ret = __sync_filesystem(sb, 0);
6664
if (ret < 0)
6765
return ret;
68-
return __sync_filesystem(sb, 1, start);
66+
return __sync_filesystem(sb, 1);
6967
}
7068
EXPORT_SYMBOL_GPL(sync_filesystem);
7169

7270
static void sync_inodes_one_sb(struct super_block *sb, void *arg)
7371
{
7472
if (!(sb->s_flags & MS_RDONLY))
75-
sync_inodes_sb(sb, *((unsigned long *)arg));
73+
sync_inodes_sb(sb);
7674
}
7775

7876
static void sync_fs_one_sb(struct super_block *sb, void *arg)
@@ -104,10 +102,9 @@ static void fdatawait_one_bdev(struct block_device *bdev, void *arg)
104102
SYSCALL_DEFINE0(sync)
105103
{
106104
int nowait = 0, wait = 1;
107-
unsigned long start = jiffies;
108105

109106
wakeup_flusher_threads(0, WB_REASON_SYNC);
110-
iterate_supers(sync_inodes_one_sb, &start);
107+
iterate_supers(sync_inodes_one_sb, NULL);
111108
iterate_supers(sync_fs_one_sb, &nowait);
112109
iterate_supers(sync_fs_one_sb, &wait);
113110
iterate_bdevs(fdatawrite_one_bdev, NULL);

‎fs/xfs/xfs_super.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ xfs_flush_inodes(
913913
struct super_block *sb = mp->m_super;
914914

915915
if (down_read_trylock(&sb->s_umount)) {
916-
sync_inodes_sb(sb, jiffies);
916+
sync_inodes_sb(sb);
917917
up_read(&sb->s_umount);
918918
}
919919
}

‎include/linux/writeback.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void writeback_inodes_sb_nr(struct super_block *, unsigned long nr,
9797
int try_to_writeback_inodes_sb(struct super_block *, enum wb_reason reason);
9898
int try_to_writeback_inodes_sb_nr(struct super_block *, unsigned long nr,
9999
enum wb_reason reason);
100-
void sync_inodes_sb(struct super_block *sb, unsigned long older_than_this);
100+
void sync_inodes_sb(struct super_block *);
101101
void wakeup_flusher_threads(long nr_pages, enum wb_reason reason);
102102
void inode_wait_for_writeback(struct inode *inode);
103103

‎include/trace/events/writeback.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,11 @@ TRACE_EVENT(writeback_queue_io,
287287
__field(int, reason)
288288
),
289289
TP_fast_assign(
290-
unsigned long older_than_this = work->older_than_this;
290+
unsigned long *older_than_this = work->older_than_this;
291291
strncpy(__entry->name, dev_name(wb->bdi->dev), 32);
292-
__entry->older = older_than_this;
292+
__entry->older = older_than_this ? *older_than_this : 0;
293293
__entry->age = older_than_this ?
294-
(jiffies - older_than_this) * 1000 / HZ : -1;
294+
(jiffies - *older_than_this) * 1000 / HZ : -1;
295295
__entry->moved = moved;
296296
__entry->reason = work->reason;
297297
),

0 commit comments

Comments
 (0)