linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] writeback: Lazytime handling fix and cleanups
@ 2020-06-01  9:18 Jan Kara
  2020-06-01  9:18 ` [PATCH 1/3] writeback: Avoid skipping inode writeback Jan Kara
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Jan Kara @ 2020-06-01  9:18 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: Ted Tso, Martijn Coenen, tj, Jan Kara

Hello,

this patch series fixes an issue with handling of lazy inode timestamp
writeback which could result in missed background writeback of an inode
or missed update of inode timestamps during sync(2). It also somewhat
simplifies the writeback code handling of lazy inode timestamp updates.
Review is welcome!

								Honza

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/3] writeback: Avoid skipping inode writeback
  2020-06-01  9:18 [PATCH 0/3] writeback: Lazytime handling fix and cleanups Jan Kara
@ 2020-06-01  9:18 ` Jan Kara
  2020-06-05 14:11   ` Sasha Levin
  2020-06-10 15:02   ` Christoph Hellwig
  2020-06-01  9:18 ` [PATCH 2/3] writeback: Fix sync livelock due to b_dirty_time processing Jan Kara
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 13+ messages in thread
From: Jan Kara @ 2020-06-01  9:18 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: Ted Tso, Martijn Coenen, tj, Jan Kara, stable

Inode's i_io_list list head is used to attach inode to several different
lists - wb->{b_dirty, b_dirty_time, b_io, b_more_io}. When flush worker
prepares a list of inodes to writeback e.g. for sync(2), it moves inodes
to b_io list. Thus it is critical for sync(2) data integrity guarantees
that inode is not requeued to any other writeback list when inode is
queued for processing by flush worker. That's the reason why
writeback_single_inode() does not touch i_io_list (unless the inode is
completely clean) and why __mark_inode_dirty() does not touch i_io_list
if I_SYNC flag is set.

However there are two flaws in the current logic:

1) When inode has only I_DIRTY_TIME set but it is already queued in b_io
list due to sync(2), concurrent __mark_inode_dirty(inode, I_DIRTY_SYNC)
can still move inode back to b_dirty list resulting in skipping
writeback of inode time stamps during sync(2).

2) When inode is on b_dirty_time list and writeback_single_inode() races
with __mark_inode_dirty() like:

writeback_single_inode()		__mark_inode_dirty(inode, I_DIRTY_PAGES)
  inode->i_state |= I_SYNC
  __writeback_single_inode()
					  inode->i_state |= I_DIRTY_PAGES;
					  if (inode->i_state & I_SYNC)
					    bail
  if (!(inode->i_state & I_DIRTY_ALL))
  - not true so nothing done

We end up with I_DIRTY_PAGES inode on b_dirty_time list and thus
standard background writeback will not writeback this inode leading to
possible dirty throttling stalls etc. (thanks to Martijn Coenen for this
analysis).

Fix these problems by tracking whether inode is queued in b_io or
b_more_io lists in a new I_SYNC_QUEUED flag. When this flag is set, we
know flush worker has queued inode and we should not touch i_io_list.
On the other hand we also know that once flush worker is done with the
inode it will requeue the inode to appropriate dirty list. When
I_SYNC_QUEUED is not set, __mark_inode_dirty() can (and must) move inode
to appropriate dirty list.

Reported-by: Martijn Coenen <maco@android.com>
Fixes: 0ae45f63d4ef ("vfs: add support for a lazytime mount option")
CC: stable@vger.kernel.org
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/fs-writeback.c  | 39 +++++++++++++++++++++++++++++----------
 include/linux/fs.h |  8 ++++++--
 2 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 76ac9c7d32ec..855c6611710a 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -144,7 +144,9 @@ static void inode_io_list_del_locked(struct inode *inode,
 				     struct bdi_writeback *wb)
 {
 	assert_spin_locked(&wb->list_lock);
+	assert_spin_locked(&inode->i_lock);
 
+	inode->i_state &= ~I_SYNC_QUEUED;
 	list_del_init(&inode->i_io_list);
 	wb_io_lists_depopulated(wb);
 }
@@ -1123,7 +1125,9 @@ void inode_io_list_del(struct inode *inode)
 	struct bdi_writeback *wb;
 
 	wb = inode_to_wb_and_lock_list(inode);
+	spin_lock(&inode->i_lock);
 	inode_io_list_del_locked(inode, wb);
+	spin_unlock(&inode->i_lock);
 	spin_unlock(&wb->list_lock);
 }
 
@@ -1172,8 +1176,9 @@ void sb_clear_inode_writeback(struct inode *inode)
  * the case then the inode must have been redirtied while it was being written
  * out and we don't reset its dirtied_when.
  */
-static void redirty_tail(struct inode *inode, struct bdi_writeback *wb)
+static void __redirty_tail(struct inode *inode, struct bdi_writeback *wb)
 {
+	assert_spin_locked(&inode->i_lock);
 	if (!list_empty(&wb->b_dirty)) {
 		struct inode *tail;
 
@@ -1182,6 +1187,14 @@ static void redirty_tail(struct inode *inode, struct bdi_writeback *wb)
 			inode->dirtied_when = jiffies;
 	}
 	inode_io_list_move_locked(inode, wb, &wb->b_dirty);
+	inode->i_state &= ~I_SYNC_QUEUED;
+}
+
+static void redirty_tail(struct inode *inode, struct bdi_writeback *wb)
+{
+	spin_lock(&inode->i_lock);
+	__redirty_tail(inode, wb);
+	spin_unlock(&inode->i_lock);
 }
 
 /*
@@ -1250,8 +1263,11 @@ static int move_expired_inodes(struct list_head *delaying_queue,
 			break;
 		list_move(&inode->i_io_list, &tmp);
 		moved++;
+		spin_lock(&inode->i_lock);
 		if (flags & EXPIRE_DIRTY_ATIME)
-			set_bit(__I_DIRTY_TIME_EXPIRED, &inode->i_state);
+			inode->i_state |= I_DIRTY_TIME_EXPIRED;
+		inode->i_state |= I_SYNC_QUEUED;
+		spin_unlock(&inode->i_lock);
 		if (sb_is_blkdev_sb(inode->i_sb))
 			continue;
 		if (sb && sb != inode->i_sb)
@@ -1394,7 +1410,7 @@ static void requeue_inode(struct inode *inode, struct bdi_writeback *wb,
 		 * writeback is not making progress due to locked
 		 * buffers. Skip this inode for now.
 		 */
-		redirty_tail(inode, wb);
+		__redirty_tail(inode, wb);
 		return;
 	}
 
@@ -1414,7 +1430,7 @@ static void requeue_inode(struct inode *inode, struct bdi_writeback *wb,
 			 * retrying writeback of the dirty page/inode
 			 * that cannot be performed immediately.
 			 */
-			redirty_tail(inode, wb);
+			__redirty_tail(inode, wb);
 		}
 	} else if (inode->i_state & I_DIRTY) {
 		/*
@@ -1422,10 +1438,11 @@ static void requeue_inode(struct inode *inode, struct bdi_writeback *wb,
 		 * such as delayed allocation during submission or metadata
 		 * updates after data IO completion.
 		 */
-		redirty_tail(inode, wb);
+		__redirty_tail(inode, wb);
 	} else if (inode->i_state & I_DIRTY_TIME) {
 		inode->dirtied_when = jiffies;
 		inode_io_list_move_locked(inode, wb, &wb->b_dirty_time);
+		inode->i_state &= ~I_SYNC_QUEUED;
 	} else {
 		/* The inode is clean. Remove from writeback lists. */
 		inode_io_list_del_locked(inode, wb);
@@ -1669,8 +1686,9 @@ static long writeback_sb_inodes(struct super_block *sb,
 		 */
 		spin_lock(&inode->i_lock);
 		if (inode->i_state & (I_NEW | I_FREEING | I_WILL_FREE)) {
+			inode->i_state &= ~I_SYNC_QUEUED;
+			__redirty_tail(inode, wb);
 			spin_unlock(&inode->i_lock);
-			redirty_tail(inode, wb);
 			continue;
 		}
 		if ((inode->i_state & I_SYNC) && wbc.sync_mode != WB_SYNC_ALL) {
@@ -2289,11 +2307,12 @@ void __mark_inode_dirty(struct inode *inode, int flags)
 		inode->i_state |= flags;
 
 		/*
-		 * If the inode is being synced, just update its dirty state.
-		 * The unlocker will place the inode on the appropriate
-		 * superblock list, based upon its state.
+		 * If the inode is queued for writeback by flush worker, just
+		 * update its dirty state. Once the flush worker is done with
+		 * the inode it will place it on the appropriate superblock
+		 * list, based upon its state.
 		 */
-		if (inode->i_state & I_SYNC)
+		if (inode->i_state & I_SYNC_QUEUED)
 			goto out_unlock_inode;
 
 		/*
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 45cc10cdf6dd..b02290d19edd 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2156,6 +2156,10 @@ static inline void kiocb_clone(struct kiocb *kiocb, struct kiocb *kiocb_src,
  *
  * I_CREATING		New object's inode in the middle of setting up.
  *
+ * I_SYNC_QUEUED	Inode is queued in b_io or b_more_io writeback lists.
+ *			Used to detect that mark_inode_dirty() should not move
+ * 			inode between dirty lists.
+ *
  * Q: What is the difference between I_WILL_FREE and I_FREEING?
  */
 #define I_DIRTY_SYNC		(1 << 0)
@@ -2173,11 +2177,11 @@ static inline void kiocb_clone(struct kiocb *kiocb, struct kiocb *kiocb_src,
 #define I_DIO_WAKEUP		(1 << __I_DIO_WAKEUP)
 #define I_LINKABLE		(1 << 10)
 #define I_DIRTY_TIME		(1 << 11)
-#define __I_DIRTY_TIME_EXPIRED	12
-#define I_DIRTY_TIME_EXPIRED	(1 << __I_DIRTY_TIME_EXPIRED)
+#define I_DIRTY_TIME_EXPIRED	(1 << 12)
 #define I_WB_SWITCH		(1 << 13)
 #define I_OVL_INUSE		(1 << 14)
 #define I_CREATING		(1 << 15)
+#define I_SYNC_QUEUED		(1 << 16)
 
 #define I_DIRTY_INODE (I_DIRTY_SYNC | I_DIRTY_DATASYNC)
 #define I_DIRTY (I_DIRTY_INODE | I_DIRTY_PAGES)
-- 
2.16.4


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 2/3] writeback: Fix sync livelock due to b_dirty_time processing
  2020-06-01  9:18 [PATCH 0/3] writeback: Lazytime handling fix and cleanups Jan Kara
  2020-06-01  9:18 ` [PATCH 1/3] writeback: Avoid skipping inode writeback Jan Kara
@ 2020-06-01  9:18 ` Jan Kara
  2020-06-10 15:06   ` Christoph Hellwig
  2020-06-01  9:18 ` [PATCH 3/3] writeback: Drop I_DIRTY_TIME_EXPIRE Jan Kara
  2020-06-10 10:04 ` [PATCH 0/3] writeback: Lazytime handling fix and cleanups Jan Kara
  3 siblings, 1 reply; 13+ messages in thread
From: Jan Kara @ 2020-06-01  9:18 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: Ted Tso, Martijn Coenen, tj, Jan Kara

When we are processing writeback for sync(2), move_expired_inodes()
didn't set any inode expiry value (older_than_this). This can result in
writeback never completing if there's steady stream of inodes added to
b_dirty_time list as writeback rechecks dirty lists after each writeback
round whether there's more work to be done. Fix the problem by using
sync(2) start time is inode expiry value when processing b_dirty_time
list similarly as for ordinarily dirtied inodes. This requires some
refactoring of older_than_this handling which simplifies the code
noticeably as a bonus.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/fs-writeback.c                | 37 ++++++++++++++-----------------------
 include/trace/events/writeback.h |  9 ++++-----
 2 files changed, 18 insertions(+), 28 deletions(-)

diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 855c6611710a..b9aa4ff83bbd 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -42,7 +42,6 @@
 struct wb_writeback_work {
 	long nr_pages;
 	struct super_block *sb;
-	unsigned long *older_than_this;
 	enum writeback_sync_modes sync_mode;
 	unsigned int tagged_writepages:1;
 	unsigned int for_kupdate:1;
@@ -1233,16 +1232,14 @@ static bool inode_dirtied_after(struct inode *inode, unsigned long t)
 #define EXPIRE_DIRTY_ATIME 0x0001
 
 /*
- * Move expired (dirtied before work->older_than_this) dirty inodes from
+ * Move expired (dirtied before older_than_this) dirty inodes from
  * @delaying_queue to @dispatch_queue.
  */
 static int move_expired_inodes(struct list_head *delaying_queue,
 			       struct list_head *dispatch_queue,
 			       int flags,
-			       struct wb_writeback_work *work)
+			       unsigned long older_than_this)
 {
-	unsigned long *older_than_this = NULL;
-	unsigned long expire_time;
 	LIST_HEAD(tmp);
 	struct list_head *pos, *node;
 	struct super_block *sb = NULL;
@@ -1250,16 +1247,9 @@ static int move_expired_inodes(struct list_head *delaying_queue,
 	int do_sb_sort = 0;
 	int moved = 0;
 
-	if ((flags & EXPIRE_DIRTY_ATIME) == 0)
-		older_than_this = work->older_than_this;
-	else if (!work->for_sync) {
-		expire_time = jiffies - (dirtytime_expire_interval * HZ);
-		older_than_this = &expire_time;
-	}
 	while (!list_empty(delaying_queue)) {
 		inode = wb_inode(delaying_queue->prev);
-		if (older_than_this &&
-		    inode_dirtied_after(inode, *older_than_this))
+		if (inode_dirtied_after(inode, older_than_this))
 			break;
 		list_move(&inode->i_io_list, &tmp);
 		moved++;
@@ -1305,18 +1295,22 @@ static int move_expired_inodes(struct list_head *delaying_queue,
  *                                           |
  *                                           +--> dequeue for IO
  */
-static void queue_io(struct bdi_writeback *wb, struct wb_writeback_work *work)
+static void queue_io(struct bdi_writeback *wb, struct wb_writeback_work *work,
+		     unsigned long older_than_this)
 {
 	int moved;
+	unsigned long time_expire_jif = older_than_this;
 
 	assert_spin_locked(&wb->list_lock);
 	list_splice_init(&wb->b_more_io, &wb->b_io);
-	moved = move_expired_inodes(&wb->b_dirty, &wb->b_io, 0, work);
+	moved = move_expired_inodes(&wb->b_dirty, &wb->b_io, 0, older_than_this);
+	if (!work->for_sync)
+		time_expire_jif = jiffies - dirtytime_expire_interval * HZ;
 	moved += move_expired_inodes(&wb->b_dirty_time, &wb->b_io,
-				     EXPIRE_DIRTY_ATIME, work);
+				     EXPIRE_DIRTY_ATIME, time_expire_jif);
 	if (moved)
 		wb_io_lists_populated(wb);
-	trace_writeback_queue_io(wb, work, moved);
+	trace_writeback_queue_io(wb, work, older_than_this, moved);
 }
 
 static int write_inode(struct inode *inode, struct writeback_control *wbc)
@@ -1829,7 +1823,7 @@ static long writeback_inodes_wb(struct bdi_writeback *wb, long nr_pages,
 	blk_start_plug(&plug);
 	spin_lock(&wb->list_lock);
 	if (list_empty(&wb->b_io))
-		queue_io(wb, &work);
+		queue_io(wb, &work, jiffies);
 	__writeback_inodes_wb(wb, &work);
 	spin_unlock(&wb->list_lock);
 	blk_finish_plug(&plug);
@@ -1857,14 +1851,11 @@ static long wb_writeback(struct bdi_writeback *wb,
 {
 	unsigned long wb_start = jiffies;
 	long nr_pages = work->nr_pages;
-	unsigned long oldest_jif;
+	unsigned long oldest_jif = jiffies;
 	struct inode *inode;
 	long progress;
 	struct blk_plug plug;
 
-	oldest_jif = jiffies;
-	work->older_than_this = &oldest_jif;
-
 	blk_start_plug(&plug);
 	spin_lock(&wb->list_lock);
 	for (;;) {
@@ -1905,7 +1896,7 @@ static long wb_writeback(struct bdi_writeback *wb,
 
 		trace_writeback_start(wb, work);
 		if (list_empty(&wb->b_io))
-			queue_io(wb, work);
+			queue_io(wb, work, oldest_jif);
 		if (work->sb)
 			progress = writeback_sb_inodes(work->sb, wb, work);
 		else
diff --git a/include/trace/events/writeback.h b/include/trace/events/writeback.h
index 85a33bea76f1..b4500bdee2c0 100644
--- a/include/trace/events/writeback.h
+++ b/include/trace/events/writeback.h
@@ -498,8 +498,9 @@ DEFINE_WBC_EVENT(wbc_writepage);
 TRACE_EVENT(writeback_queue_io,
 	TP_PROTO(struct bdi_writeback *wb,
 		 struct wb_writeback_work *work,
+		 unsigned long older_than_this,
 		 int moved),
-	TP_ARGS(wb, work, moved),
+	TP_ARGS(wb, work, older_than_this, moved),
 	TP_STRUCT__entry(
 		__array(char,		name, 32)
 		__field(unsigned long,	older)
@@ -509,11 +510,9 @@ TRACE_EVENT(writeback_queue_io,
 		__field(ino_t,		cgroup_ino)
 	),
 	TP_fast_assign(
-		unsigned long *older_than_this = work->older_than_this;
 		strscpy_pad(__entry->name, bdi_dev_name(wb->bdi), 32);
-		__entry->older	= older_than_this ?  *older_than_this : 0;
-		__entry->age	= older_than_this ?
-				  (jiffies - *older_than_this) * 1000 / HZ : -1;
+		__entry->older	= older_than_this;
+		__entry->age	= (jiffies - older_than_this) * 1000 / HZ;
 		__entry->moved	= moved;
 		__entry->reason	= work->reason;
 		__entry->cgroup_ino	= __trace_wb_assign_cgroup(wb);
-- 
2.16.4


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 3/3] writeback: Drop I_DIRTY_TIME_EXPIRE
  2020-06-01  9:18 [PATCH 0/3] writeback: Lazytime handling fix and cleanups Jan Kara
  2020-06-01  9:18 ` [PATCH 1/3] writeback: Avoid skipping inode writeback Jan Kara
  2020-06-01  9:18 ` [PATCH 2/3] writeback: Fix sync livelock due to b_dirty_time processing Jan Kara
@ 2020-06-01  9:18 ` Jan Kara
  2020-06-10 15:11   ` Christoph Hellwig
  2020-06-10 10:04 ` [PATCH 0/3] writeback: Lazytime handling fix and cleanups Jan Kara
  3 siblings, 1 reply; 13+ messages in thread
From: Jan Kara @ 2020-06-01  9:18 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: Ted Tso, Martijn Coenen, tj, Jan Kara

The only use of I_DIRTY_TIME_EXPIRE is to detect in
__writeback_single_inode() that inode got there because flush worker
decided it's time to writeback the dirty inode time stamps (either
because we are syncing or because of age). However we can detect this
directly in __writeback_single_inode() and there's no need for the
strange propagation with I_DIRTY_TIME_EXPIRE flag.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/ext4/inode.c                  |  2 +-
 fs/fs-writeback.c                | 15 +++++----------
 fs/xfs/libxfs/xfs_trans_inode.c  |  4 ++--
 include/linux/fs.h               |  1 -
 include/trace/events/writeback.h |  1 -
 5 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 2a4aae6acdcb..038cfe85f9cb 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -4881,7 +4881,7 @@ static int other_inode_match(struct inode * inode, unsigned long ino,
 	    (inode->i_state & I_DIRTY_TIME)) {
 		struct ext4_inode_info	*ei = EXT4_I(inode);
 
-		inode->i_state &= ~(I_DIRTY_TIME | I_DIRTY_TIME_EXPIRED);
+		inode->i_state &= ~I_DIRTY_TIME;
 		spin_unlock(&inode->i_lock);
 
 		spin_lock(&ei->i_raw_lock);
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index b9aa4ff83bbd..62e2e1ed345a 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -1237,7 +1237,6 @@ static bool inode_dirtied_after(struct inode *inode, unsigned long t)
  */
 static int move_expired_inodes(struct list_head *delaying_queue,
 			       struct list_head *dispatch_queue,
-			       int flags,
 			       unsigned long older_than_this)
 {
 	LIST_HEAD(tmp);
@@ -1254,8 +1253,6 @@ static int move_expired_inodes(struct list_head *delaying_queue,
 		list_move(&inode->i_io_list, &tmp);
 		moved++;
 		spin_lock(&inode->i_lock);
-		if (flags & EXPIRE_DIRTY_ATIME)
-			inode->i_state |= I_DIRTY_TIME_EXPIRED;
 		inode->i_state |= I_SYNC_QUEUED;
 		spin_unlock(&inode->i_lock);
 		if (sb_is_blkdev_sb(inode->i_sb))
@@ -1303,11 +1300,11 @@ static void queue_io(struct bdi_writeback *wb, struct wb_writeback_work *work,
 
 	assert_spin_locked(&wb->list_lock);
 	list_splice_init(&wb->b_more_io, &wb->b_io);
-	moved = move_expired_inodes(&wb->b_dirty, &wb->b_io, 0, older_than_this);
+	moved = move_expired_inodes(&wb->b_dirty, &wb->b_io, older_than_this);
 	if (!work->for_sync)
 		time_expire_jif = jiffies - dirtytime_expire_interval * HZ;
 	moved += move_expired_inodes(&wb->b_dirty_time, &wb->b_io,
-				     EXPIRE_DIRTY_ATIME, time_expire_jif);
+				     time_expire_jif);
 	if (moved)
 		wb_io_lists_populated(wb);
 	trace_writeback_queue_io(wb, work, older_than_this, moved);
@@ -1485,16 +1482,14 @@ __writeback_single_inode(struct inode *inode, struct writeback_control *wbc)
 	dirty = inode->i_state & I_DIRTY;
 	if (inode->i_state & I_DIRTY_TIME) {
 		if ((dirty & I_DIRTY_INODE) ||
-		    wbc->sync_mode == WB_SYNC_ALL ||
-		    unlikely(inode->i_state & I_DIRTY_TIME_EXPIRED) ||
+		    wbc->sync_mode == WB_SYNC_ALL || wbc->for_sync ||
 		    unlikely(time_after(jiffies,
 					(inode->dirtied_time_when +
 					 dirtytime_expire_interval * HZ)))) {
-			dirty |= I_DIRTY_TIME | I_DIRTY_TIME_EXPIRED;
+			dirty |= I_DIRTY_TIME;
 			trace_writeback_lazytime(inode);
 		}
-	} else
-		inode->i_state &= ~I_DIRTY_TIME_EXPIRED;
+	}
 	inode->i_state &= ~dirty;
 
 	/*
diff --git a/fs/xfs/libxfs/xfs_trans_inode.c b/fs/xfs/libxfs/xfs_trans_inode.c
index 2b8ccb5b975d..3c903f2c498d 100644
--- a/fs/xfs/libxfs/xfs_trans_inode.c
+++ b/fs/xfs/libxfs/xfs_trans_inode.c
@@ -96,9 +96,9 @@ xfs_trans_log_inode(
 	 * to log the timestamps, or will clear already cleared fields in the
 	 * worst case.
 	 */
-	if (inode->i_state & (I_DIRTY_TIME | I_DIRTY_TIME_EXPIRED)) {
+	if (inode->i_state & I_DIRTY_TIME) {
 		spin_lock(&inode->i_lock);
-		inode->i_state &= ~(I_DIRTY_TIME | I_DIRTY_TIME_EXPIRED);
+		inode->i_state &= ~I_DIRTY_TIME;
 		spin_unlock(&inode->i_lock);
 	}
 
diff --git a/include/linux/fs.h b/include/linux/fs.h
index b02290d19edd..2c141d53949f 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2177,7 +2177,6 @@ static inline void kiocb_clone(struct kiocb *kiocb, struct kiocb *kiocb_src,
 #define I_DIO_WAKEUP		(1 << __I_DIO_WAKEUP)
 #define I_LINKABLE		(1 << 10)
 #define I_DIRTY_TIME		(1 << 11)
-#define I_DIRTY_TIME_EXPIRED	(1 << 12)
 #define I_WB_SWITCH		(1 << 13)
 #define I_OVL_INUSE		(1 << 14)
 #define I_CREATING		(1 << 15)
diff --git a/include/trace/events/writeback.h b/include/trace/events/writeback.h
index b4500bdee2c0..a48e1f83fcdc 100644
--- a/include/trace/events/writeback.h
+++ b/include/trace/events/writeback.h
@@ -20,7 +20,6 @@
 		{I_CLEAR,		"I_CLEAR"},		\
 		{I_SYNC,		"I_SYNC"},		\
 		{I_DIRTY_TIME,		"I_DIRTY_TIME"},	\
-		{I_DIRTY_TIME_EXPIRED,	"I_DIRTY_TIME_EXPIRED"}, \
 		{I_REFERENCED,		"I_REFERENCED"}		\
 	)
 
-- 
2.16.4


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/3] writeback: Avoid skipping inode writeback
  2020-06-01  9:18 ` [PATCH 1/3] writeback: Avoid skipping inode writeback Jan Kara
@ 2020-06-05 14:11   ` Sasha Levin
  2020-06-10 15:02   ` Christoph Hellwig
  1 sibling, 0 replies; 13+ messages in thread
From: Sasha Levin @ 2020-06-05 14:11 UTC (permalink / raw)
  To: Sasha Levin, Jan Kara, linux-fsdevel
  Cc: Ted Tso, Martijn Coenen, stable, stable

Hi

[This is an automated email]

This commit has been processed because it contains a "Fixes:" tag
fixing commit: 0ae45f63d4ef ("vfs: add support for a lazytime mount option").

The bot has tested the following trees: v5.6.15, v5.4.43, v4.19.125, v4.14.182, v4.9.225, v4.4.225.

v5.6.15: Build OK!
v5.4.43: Build OK!
v4.19.125: Build OK!
v4.14.182: Failed to apply! Possible dependencies:
    80ea09a002bf ("vfs: factor out inode_insert5()")
    c2b6d621c4ff ("new primitive: discard_new_inode()")

v4.9.225: Failed to apply! Possible dependencies:
    09d8b586731b ("ovl: move __upperdentry to ovl_inode")
    13c72075ac9f ("ovl: move impure to ovl_inode")
    2aff4534b6c4 ("ovl: check lower existence when removing")
    2b8c30e9ef14 ("ovl: use d_is_dir()")
    32a3d848eb91 ("ovl: clean up kstat usage")
    370e55ace59c ("ovl: rename: simplify handling of lower/merged directory")
    38e813db61c3 ("ovl: get rid of PURE type")
    3ee23ff1025a ("ovl: check lower existence of rename target")
    42f269b92540 ("ovl: rearrange code in ovl_copy_up_locked()")
    5cf5b477f0ca ("ovl: opaque cleanup")
    6c02cb59e6fe ("ovl: rename ovl_rename2() to ovl_rename()")
    804032fabb3b ("ovl: don't check rename to self")
    80ea09a002bf ("vfs: factor out inode_insert5()")
    8ee6059c58ea ("ovl: simplify lookup")
    a6c606551141 ("ovl: redirect on rename-dir")
    ad0af7104dad ("vfs: introduce inode 'inuse' lock")
    bbb1e54dd53c ("ovl: split super.c")
    c2b6d621c4ff ("new primitive: discard_new_inode()")
    c412ce498396 ("ovl: add ovl_dentry_is_whiteout()")
    ca4c8a3a8000 ("ovl: treat special files like a regular fs")
    d8514d8edb5b ("ovl: copy up regular file using O_TMPFILE")

v4.4.225: Failed to apply! Possible dependencies:
    09d8b586731b ("ovl: move __upperdentry to ovl_inode")
    1175b6b8d963 ("ovl: do operations on underlying file system in mounter's context")
    13c72075ac9f ("ovl: move impure to ovl_inode")
    2864f3014242 ("iget_locked et.al.: make sure we don't return bad inodes")
    32a3d848eb91 ("ovl: clean up kstat usage")
    38b256973ea9 ("ovl: handle umask and posix_acl_default correctly on creation")
    42f269b92540 ("ovl: rearrange code in ovl_copy_up_locked()")
    6b2553918d8b ("replace ->follow_link() with new method that could stay in RCU mode")
    80ea09a002bf ("vfs: factor out inode_insert5()")
    aa80deab33a8 ("namei: page_getlink() and page_follow_link_light() are the same thing")
    ad0af7104dad ("vfs: introduce inode 'inuse' lock")
    bb0d2b8ad296 ("ovl: fix sgid on directory")
    c2b6d621c4ff ("new primitive: discard_new_inode()")
    d6335d77a762 ("security: Make inode argument of inode_getsecid non-const")
    d8514d8edb5b ("ovl: copy up regular file using O_TMPFILE")
    d8ad8b496184 ("security, overlayfs: provide copy up security hook for unioned files")
    fceef393a538 ("switch ->get_link() to delayed_call, kill ->put_link()")


NOTE: The patch will not be queued to stable trees until it is upstream.

How should we proceed with this patch?

-- 
Thanks
Sasha

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 0/3] writeback: Lazytime handling fix and cleanups
  2020-06-01  9:18 [PATCH 0/3] writeback: Lazytime handling fix and cleanups Jan Kara
                   ` (2 preceding siblings ...)
  2020-06-01  9:18 ` [PATCH 3/3] writeback: Drop I_DIRTY_TIME_EXPIRE Jan Kara
@ 2020-06-10 10:04 ` Jan Kara
  3 siblings, 0 replies; 13+ messages in thread
From: Jan Kara @ 2020-06-10 10:04 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: Ted Tso, Martijn Coenen, tj, Jan Kara

On Mon 01-06-20 11:18:54, Jan Kara wrote:
> Hello,
> 
> this patch series fixes an issue with handling of lazy inode timestamp
> writeback which could result in missed background writeback of an inode
> or missed update of inode timestamps during sync(2). It also somewhat
> simplifies the writeback code handling of lazy inode timestamp updates.
> Review is welcome!

OK, nobody has replied to this and I have positive feedback from Martijn so
I guess I'll pickup the patches to my tree so that they get some testing in
linux-next and push them to Linus sometime next week.

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/3] writeback: Avoid skipping inode writeback
  2020-06-01  9:18 ` [PATCH 1/3] writeback: Avoid skipping inode writeback Jan Kara
  2020-06-05 14:11   ` Sasha Levin
@ 2020-06-10 15:02   ` Christoph Hellwig
  2020-06-10 15:30     ` Jan Kara
  1 sibling, 1 reply; 13+ messages in thread
From: Christoph Hellwig @ 2020-06-10 15:02 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-fsdevel, Ted Tso, Martijn Coenen, tj, stable

This generall looks ok, but a few nitpicks below:

> -static void redirty_tail(struct inode *inode, struct bdi_writeback *wb)
> +static void __redirty_tail(struct inode *inode, struct bdi_writeback *wb)

I think redirty_tail_locked would be a more decriptive name, and also
fit other uses in this file (e.g. inode_io_list_move_locked and
inode_io_list_del_locked).

>  {
> +	assert_spin_locked(&inode->i_lock);
>  	if (!list_empty(&wb->b_dirty)) {

Nit: I find an empty line after asserts and before the real code starts
nice on the eye.

>  			break;
>  		list_move(&inode->i_io_list, &tmp);
>  		moved++;
> +		spin_lock(&inode->i_lock);
>  		if (flags & EXPIRE_DIRTY_ATIME)
> -			set_bit(__I_DIRTY_TIME_EXPIRED, &inode->i_state);
> +			inode->i_state |= I_DIRTY_TIME_EXPIRED;
> +		inode->i_state |= I_SYNC_QUEUED;
> +		spin_unlock(&inode->i_lock);

I wonder if the locking changes should go into a prep patch vs the
actual logic changes related to I_SYNC_QUEUED?  That would untangle
the patch quite a bit and make it easier to follow.

>  #define I_WB_SWITCH		(1 << 13)
>  #define I_OVL_INUSE		(1 << 14)
>  #define I_CREATING		(1 << 15)
> +#define I_SYNC_QUEUED		(1 << 16)

FYI, this conflicts with the I_DONTCAT addition in mainline now.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/3] writeback: Fix sync livelock due to b_dirty_time processing
  2020-06-01  9:18 ` [PATCH 2/3] writeback: Fix sync livelock due to b_dirty_time processing Jan Kara
@ 2020-06-10 15:06   ` Christoph Hellwig
  2020-06-10 15:54     ` Jan Kara
  0 siblings, 1 reply; 13+ messages in thread
From: Christoph Hellwig @ 2020-06-10 15:06 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-fsdevel, Ted Tso, Martijn Coenen, tj

On Mon, Jun 01, 2020 at 11:18:56AM +0200, Jan Kara wrote:
> When we are processing writeback for sync(2), move_expired_inodes()
> didn't set any inode expiry value (older_than_this). This can result in
> writeback never completing if there's steady stream of inodes added to
> b_dirty_time list as writeback rechecks dirty lists after each writeback
> round whether there's more work to be done. Fix the problem by using
> sync(2) start time is inode expiry value when processing b_dirty_time
> list similarly as for ordinarily dirtied inodes. This requires some
> refactoring of older_than_this handling which simplifies the code
> noticeably as a bonus.

Looks sane, but if you touch all the older_than_this users can we
rename it to something more reasonable like oldest or oldest_jif?

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 3/3] writeback: Drop I_DIRTY_TIME_EXPIRE
  2020-06-01  9:18 ` [PATCH 3/3] writeback: Drop I_DIRTY_TIME_EXPIRE Jan Kara
@ 2020-06-10 15:11   ` Christoph Hellwig
  2020-06-10 16:20     ` Jan Kara
  0 siblings, 1 reply; 13+ messages in thread
From: Christoph Hellwig @ 2020-06-10 15:11 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-fsdevel, Ted Tso, Martijn Coenen, tj

On Mon, Jun 01, 2020 at 11:18:57AM +0200, Jan Kara wrote:
> The only use of I_DIRTY_TIME_EXPIRE is to detect in
> __writeback_single_inode() that inode got there because flush worker
> decided it's time to writeback the dirty inode time stamps (either
> because we are syncing or because of age). However we can detect this
> directly in __writeback_single_inode() and there's no need for the
> strange propagation with I_DIRTY_TIME_EXPIRE flag.

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

One nit below:

>  	if (inode->i_state & I_DIRTY_TIME) {
>  		if ((dirty & I_DIRTY_INODE) ||
> -		    wbc->sync_mode == WB_SYNC_ALL ||
> -		    unlikely(inode->i_state & I_DIRTY_TIME_EXPIRED) ||
> +		    wbc->sync_mode == WB_SYNC_ALL || wbc->for_sync ||
>  		    unlikely(time_after(jiffies,
>  					(inode->dirtied_time_when +
>  					 dirtytime_expire_interval * HZ)))) {
> -			dirty |= I_DIRTY_TIME | I_DIRTY_TIME_EXPIRED;
> +			dirty |= I_DIRTY_TIME;
>  			trace_writeback_lazytime(inode);
>  		}
> -	} else
> -		inode->i_state &= ~I_DIRTY_TIME_EXPIRED;
> +	}

We can also drop some indentation here.  And remove the totally silly
unlikely, something like:

	if ((inode->i_state & I_DIRTY_TIME) &&
	    ((dirty & I_DIRTY_INODE) ||
	     wbc->sync_mode == WB_SYNC_ALL || wbc->for_sync ||
	     time_after(jiffies, inode->dirtied_time_when +
			dirtytime_expire_interval * HZ)))) {
		dirty |= I_DIRTY_TIME;
		trace_writeback_lazytime(inode);
	}

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/3] writeback: Avoid skipping inode writeback
  2020-06-10 15:02   ` Christoph Hellwig
@ 2020-06-10 15:30     ` Jan Kara
  0 siblings, 0 replies; 13+ messages in thread
From: Jan Kara @ 2020-06-10 15:30 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jan Kara, linux-fsdevel, Ted Tso, Martijn Coenen, tj, stable

On Wed 10-06-20 08:02:03, Christoph Hellwig wrote:
> This generall looks ok, but a few nitpicks below:
> 
> > -static void redirty_tail(struct inode *inode, struct bdi_writeback *wb)
> > +static void __redirty_tail(struct inode *inode, struct bdi_writeback *wb)
> 
> I think redirty_tail_locked would be a more decriptive name, and also
> fit other uses in this file (e.g. inode_io_list_move_locked and
> inode_io_list_del_locked).

Fair enough, will do.

> >  {
> > +	assert_spin_locked(&inode->i_lock);
> >  	if (!list_empty(&wb->b_dirty)) {
> 
> Nit: I find an empty line after asserts and before the real code starts
> nice on the eye.

Sure.

> >  			break;
> >  		list_move(&inode->i_io_list, &tmp);
> >  		moved++;
> > +		spin_lock(&inode->i_lock);
> >  		if (flags & EXPIRE_DIRTY_ATIME)
> > -			set_bit(__I_DIRTY_TIME_EXPIRED, &inode->i_state);
> > +			inode->i_state |= I_DIRTY_TIME_EXPIRED;
> > +		inode->i_state |= I_SYNC_QUEUED;
> > +		spin_unlock(&inode->i_lock);
> 
> I wonder if the locking changes should go into a prep patch vs the
> actual logic changes related to I_SYNC_QUEUED?  That would untangle
> the patch quite a bit and make it easier to follow.

OK, will do.
 
> >  #define I_WB_SWITCH		(1 << 13)
> >  #define I_OVL_INUSE		(1 << 14)
> >  #define I_CREATING		(1 << 15)
> > +#define I_SYNC_QUEUED		(1 << 16)
> 
> FYI, this conflicts with the I_DONTCAT addition in mainline now.

Yup, I've already found out when rebasing...

Thanks for review!

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/3] writeback: Fix sync livelock due to b_dirty_time processing
  2020-06-10 15:06   ` Christoph Hellwig
@ 2020-06-10 15:54     ` Jan Kara
  2020-06-10 15:58       ` Christoph Hellwig
  0 siblings, 1 reply; 13+ messages in thread
From: Jan Kara @ 2020-06-10 15:54 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Jan Kara, linux-fsdevel, Ted Tso, Martijn Coenen, tj

On Wed 10-06-20 08:06:14, Christoph Hellwig wrote:
> On Mon, Jun 01, 2020 at 11:18:56AM +0200, Jan Kara wrote:
> > When we are processing writeback for sync(2), move_expired_inodes()
> > didn't set any inode expiry value (older_than_this). This can result in
> > writeback never completing if there's steady stream of inodes added to
> > b_dirty_time list as writeback rechecks dirty lists after each writeback
> > round whether there's more work to be done. Fix the problem by using
> > sync(2) start time is inode expiry value when processing b_dirty_time
> > list similarly as for ordinarily dirtied inodes. This requires some
> > refactoring of older_than_this handling which simplifies the code
> > noticeably as a bonus.
> 
> Looks sane, but if you touch all the older_than_this users can we
> rename it to something more reasonable like oldest or oldest_jif?

OK, I can certainly rename this. I've just realized that 'oldest' is really
misleading since we are in fact processing inodes that were dirtied before
the given time. So maybe name that 'dirtied_before'?

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/3] writeback: Fix sync livelock due to b_dirty_time processing
  2020-06-10 15:54     ` Jan Kara
@ 2020-06-10 15:58       ` Christoph Hellwig
  0 siblings, 0 replies; 13+ messages in thread
From: Christoph Hellwig @ 2020-06-10 15:58 UTC (permalink / raw)
  To: Jan Kara; +Cc: Christoph Hellwig, linux-fsdevel, Ted Tso, Martijn Coenen, tj

On Wed, Jun 10, 2020 at 05:54:56PM +0200, Jan Kara wrote:
> On Wed 10-06-20 08:06:14, Christoph Hellwig wrote:
> > On Mon, Jun 01, 2020 at 11:18:56AM +0200, Jan Kara wrote:
> > > When we are processing writeback for sync(2), move_expired_inodes()
> > > didn't set any inode expiry value (older_than_this). This can result in
> > > writeback never completing if there's steady stream of inodes added to
> > > b_dirty_time list as writeback rechecks dirty lists after each writeback
> > > round whether there's more work to be done. Fix the problem by using
> > > sync(2) start time is inode expiry value when processing b_dirty_time
> > > list similarly as for ordinarily dirtied inodes. This requires some
> > > refactoring of older_than_this handling which simplifies the code
> > > noticeably as a bonus.
> > 
> > Looks sane, but if you touch all the older_than_this users can we
> > rename it to something more reasonable like oldest or oldest_jif?
> 
> OK, I can certainly rename this. I've just realized that 'oldest' is really
> misleading since we are in fact processing inodes that were dirtied before
> the given time. So maybe name that 'dirtied_before'?

Sounds good to me.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 3/3] writeback: Drop I_DIRTY_TIME_EXPIRE
  2020-06-10 15:11   ` Christoph Hellwig
@ 2020-06-10 16:20     ` Jan Kara
  0 siblings, 0 replies; 13+ messages in thread
From: Jan Kara @ 2020-06-10 16:20 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Jan Kara, linux-fsdevel, Ted Tso, Martijn Coenen, tj

On Wed 10-06-20 08:11:41, Christoph Hellwig wrote:
> On Mon, Jun 01, 2020 at 11:18:57AM +0200, Jan Kara wrote:
> > The only use of I_DIRTY_TIME_EXPIRE is to detect in
> > __writeback_single_inode() that inode got there because flush worker
> > decided it's time to writeback the dirty inode time stamps (either
> > because we are syncing or because of age). However we can detect this
> > directly in __writeback_single_inode() and there's no need for the
> > strange propagation with I_DIRTY_TIME_EXPIRE flag.
> 
> Looks good:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> 
> One nit below:
> 
> >  	if (inode->i_state & I_DIRTY_TIME) {
> >  		if ((dirty & I_DIRTY_INODE) ||
> > -		    wbc->sync_mode == WB_SYNC_ALL ||
> > -		    unlikely(inode->i_state & I_DIRTY_TIME_EXPIRED) ||
> > +		    wbc->sync_mode == WB_SYNC_ALL || wbc->for_sync ||
> >  		    unlikely(time_after(jiffies,
> >  					(inode->dirtied_time_when +
> >  					 dirtytime_expire_interval * HZ)))) {
> > -			dirty |= I_DIRTY_TIME | I_DIRTY_TIME_EXPIRED;
> > +			dirty |= I_DIRTY_TIME;
> >  			trace_writeback_lazytime(inode);
> >  		}
> > -	} else
> > -		inode->i_state &= ~I_DIRTY_TIME_EXPIRED;
> > +	}
> 
> We can also drop some indentation here.  And remove the totally silly
> unlikely, something like:
> 
> 	if ((inode->i_state & I_DIRTY_TIME) &&
> 	    ((dirty & I_DIRTY_INODE) ||
> 	     wbc->sync_mode == WB_SYNC_ALL || wbc->for_sync ||
> 	     time_after(jiffies, inode->dirtied_time_when +
> 			dirtytime_expire_interval * HZ)))) {
> 		dirty |= I_DIRTY_TIME;
> 		trace_writeback_lazytime(inode);
> 	}

Sure, I've done this. Once fstests run passes, I'll send v2 (likely
tomorrow).

								Honza

-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-06-10 16:20 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-01  9:18 [PATCH 0/3] writeback: Lazytime handling fix and cleanups Jan Kara
2020-06-01  9:18 ` [PATCH 1/3] writeback: Avoid skipping inode writeback Jan Kara
2020-06-05 14:11   ` Sasha Levin
2020-06-10 15:02   ` Christoph Hellwig
2020-06-10 15:30     ` Jan Kara
2020-06-01  9:18 ` [PATCH 2/3] writeback: Fix sync livelock due to b_dirty_time processing Jan Kara
2020-06-10 15:06   ` Christoph Hellwig
2020-06-10 15:54     ` Jan Kara
2020-06-10 15:58       ` Christoph Hellwig
2020-06-01  9:18 ` [PATCH 3/3] writeback: Drop I_DIRTY_TIME_EXPIRE Jan Kara
2020-06-10 15:11   ` Christoph Hellwig
2020-06-10 16:20     ` Jan Kara
2020-06-10 10:04 ` [PATCH 0/3] writeback: Lazytime handling fix and cleanups Jan Kara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).