Skip to contentSkip to conversation

cgroup,writeback: don't switch wbs immediately on dead wbs if the memcg is dead

PATCH In review Tejun Heo 5 participants 6 messages Nov 8, 2019 – Nov 11, 2019

Subsystems (4)
lore
Share & tools
lore

Tejun Heo

author maintainer
#0 lore raw

PATCH 1/1 cgroup,writeback: don't switch wbs immediately on dead wbs if the memcg is dead

cgroup writeback tries to refresh the associated wb immediately if the current wb is dead. This is to avoid keeping issuing IOs on the stale wb after memcg - blkcg association has changed (ie. when blkcg got disabled / enabled higher up in the hierarchy).

Unfortunately, the logic gets triggered spuriously on inodes which are associated with dead cgroups. When the logic is triggered on dead cgroups, the attempt fails only after doing quite a bit of work allocating and initializing a new wb.

While c3aab9a0bd91 ("mm/filemap.c: don't initiate writeback if mapping has no dirty pages") alleviated the issue significantly as it now only triggers when the inode has dirty pages. However, the condition can still be triggered before the inode is switched to a different cgroup and the logic simply doesn't make sense.

Skip the immediate switching if the associated memcg is dying.

This is a simplified version of the following two patches:

* https://lore.kernel.org/linux-mm/20190513183053.GA73423@dennisz-mbp/
* http://lkml.kernel.org/r/156355839560.2063.5265687291430814589.stgit@buzz

Cc Dennis Zhou <[email protected]>
Cc Konstantin Khlebnikov <[email protected]>
Fixes e8a7abf5a5bd ("writeback: disassociate inodes from dying bdi_writebacks")
---
 fs/fs-writeback.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
fs/fs-writeback.c +6 -3
index 8461a6322039..335607b8c5c0 100644
@@ -576,10 +576,13 @@ void wbc_attach_and_unlock_inode(struct writeback_control *wbc,
 	spin_unlock(&inode->i_lock);
 
 	/*
-	 * A dying wb indicates that the memcg-blkcg mapping has changed
-	 * and a new wb is already serving the memcg.  Switch immediately.
+	 * A dying wb indicates that either the blkcg associated with the
+	 * memcg changed or the associated memcg is dying.  In the first
+	 * case, a replacement wb should already be available and we should
+	 * refresh the wb immediately.  In the second case, trying to
+	 * refresh will keep failing.
 	 */
-	if (unlikely(wb_dying(wbc->wb)))
+	if (unlikely(wb_dying(wbc->wb) && !css_is_dying(wbc->wb->memcg_css)))
 		inode_switch_wbs(inode, wbc->wb_id);
 }
 EXPORT_SYMBOL_GPL(wbc_attach_and_unlock_inode);
Acked-by on v1 1/1
#1 lore raw
Quoted 42 lines · Tejun Heo

cgroup writeback tries to refresh the associated wb immediately if the current wb is dead. This is to avoid keeping issuing IOs on the stale wb after memcg - blkcg association has changed (ie. when blkcg got disabled / enabled higher up in the hierarchy).

Unfortunately, the logic gets triggered spuriously on inodes which are associated with dead cgroups. When the logic is triggered on dead cgroups, the attempt fails only after doing quite a bit of work allocating and initializing a new wb.

While c3aab9a0bd91 ("mm/filemap.c: don't initiate writeback if mapping has no dirty pages") alleviated the issue significantly as it now only triggers when the inode has dirty pages. However, the condition can still be triggered before the inode is switched to a different cgroup and the logic simply doesn't make sense.

Skip the immediate switching if the associated memcg is dying.

This is a simplified version of the following two patches:

* https://lore.kernel.org/linux-mm/20190513183053.GA73423@dennisz-mbp/
* http://lkml.kernel.org/r/156355839560.2063.5265687291430814589.stgit@buzz

Cc Dennis Zhou <[email protected]>
Cc Konstantin Khlebnikov <[email protected]>
Fixes e8a7abf5a5bd ("writeback: disassociate inodes from dying bdi_writebacks")
---
 fs/fs-writeback.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
fs/fs-writeback.c +1 -2
index 8461a6322039..335607b8c5c0 100644
@@ -576,10 +576,13 @@ void wbc_attach_and_unlock_inode(struct writeback_control *wbc,
 	spin_unlock(&inode->i_lock);
 
 	/*
-	 * A dying wb indicates that the memcg-blkcg mapping has changed
-	 * and a new wb is already serving the memcg.  Switch immediately.
+	 * A dying wb indicates that either the blkcg associated with the

fs/fs-writeback.c void wbc_attach_and_unlock_inode(struct writeback_control *wbc, · line 588

Quoted 10 lines
fs/fs-writeback.c +5 -1
+	 * memcg changed or the associated memcg is dying.  In the first
+	 * case, a replacement wb should already be available and we should
+	 * refresh the wb immediately.  In the second case, trying to
+	 * refresh will keep failing.
 	 */
-	if (unlikely(wb_dying(wbc->wb)))
+	if (unlikely(wb_dying(wbc->wb) && !css_is_dying(wbc->wb->memcg_css)))
 		inode_switch_wbs(inode, wbc->wb_id);
 }
 EXPORT_SYMBOL_GPL(wbc_attach_and_unlock_inode);

Thanks,
Dennis

maintainer
#2 lore raw
In reply to Tejun Heo
Quoted 16 lines · Tejun Heo

cgroup writeback tries to refresh the associated wb immediately if the current wb is dead. This is to avoid keeping issuing IOs on the stale wb after memcg - blkcg association has changed (ie. when blkcg got disabled / enabled higher up in the hierarchy).

Unfortunately, the logic gets triggered spuriously on inodes which are associated with dead cgroups. When the logic is triggered on dead cgroups, the attempt fails only after doing quite a bit of work allocating and initializing a new wb.

While c3aab9a0bd91 ("mm/filemap.c: don't initiate writeback if mapping has no dirty pages") alleviated the issue significantly as it now only triggers when the inode has dirty pages. However, the condition can still be triggered before the inode is switched to a different cgroup and the logic simply doesn't make sense.

Quoted 6 lines

Skip the immediate switching if the associated memcg is dying.

This is a simplified version of the following two patches:

* https://lore.kernel.org/linux-mm/20190513183053.GA73423@dennisz-mbp/
* http://lkml.kernel.org/r/156355839560.2063.5265687291430814589.stgit@buzz

Applied for 5.4, thanks.

Signature · 1 line
Jens Axboe
#3 lore raw
In reply to Tejun Heo
Quoted 20 lines · Tejun Heo

cgroup writeback tries to refresh the associated wb immediately if the current wb is dead. This is to avoid keeping issuing IOs on the stale wb after memcg - blkcg association has changed (ie. when blkcg got disabled / enabled higher up in the hierarchy).

Unfortunately, the logic gets triggered spuriously on inodes which are associated with dead cgroups. When the logic is triggered on dead cgroups, the attempt fails only after doing quite a bit of work allocating and initializing a new wb.

While c3aab9a0bd91 ("mm/filemap.c: don't initiate writeback if mapping has no dirty pages") alleviated the issue significantly as it now only triggers when the inode has dirty pages. However, the condition can still be triggered before the inode is switched to a different cgroup and the logic simply doesn't make sense.

Skip the immediate switching if the associated memcg is dying.

This is a simplified version of the following two patches:

Quoted 7 lines

* https://lore.kernel.org/linux-mm/20190513183053.GA73423@dennisz-mbp/
* http://lkml.kernel.org/r/156355839560.2063.5265687291430814589.stgit@buzz

Cc Dennis Zhou <[email protected]>
Cc Konstantin Khlebnikov <[email protected]>
Fixes e8a7abf5a5bd ("writeback: disassociate inodes from dying bdi_writebacks")

Is this a stable material?

Signature · 2 lines
Michal Hocko
SUSE Labs
author maintainer
#4 lore raw

Hello, Michal.

Quoted 6 lines · Michal Hocko
Quoted 4 lines
Cc Dennis Zhou <[email protected]>
Cc Konstantin Khlebnikov <[email protected]>
Fixes e8a7abf5a5bd ("writeback: disassociate inodes from dying bdi_writebacks")

Is this a stable material?

c3aab9a0bd91 ("mm/filemap.c: don't initiate writeback if mapping has no dirty pages") likely addresses larger part of the problem, but yeah it prolly makes sense to backport both for -stable.

Greg, Sasha, can you pick the following two commits for -stable?

* c3aab9a0bd91 ("mm/filemap.c: don't initiate writeback if mapping has no dirty pages")

* 65de03e25138 ("cgroup,writeback: don't switch wbs immediately on dead wbs if the memcg is dead")

Both are fixes for e8a7abf5a5bd ("writeback: disassociate inodes from dying bdi_writebacks") - v4.2+.

Thanks.

Signature · 1 line
tejun
#5 lore raw
Quoted 16 lines · Tejun Heo

Hello, Michal.

Quoted 6 lines · Michal Hocko
Quoted 4 lines
Cc Dennis Zhou <[email protected]>
Cc Konstantin Khlebnikov <[email protected]>
Fixes e8a7abf5a5bd ("writeback: disassociate inodes from dying bdi_writebacks")

Is this a stable material?

c3aab9a0bd91 ("mm/filemap.c: don't initiate writeback if mapping has no dirty pages") likely addresses larger part of the problem, but yeah it prolly makes sense to backport both for -stable.

Greg, Sasha, can you pick the following two commits for -stable?

Quoted 8 lines

* c3aab9a0bd91 ("mm/filemap.c: don't initiate writeback if mapping has no dirty pages")

* 65de03e25138 ("cgroup,writeback: don't switch wbs immediately on dead wbs if the memcg is dead")

Both are fixes for e8a7abf5a5bd ("writeback: disassociate inodes from dying bdi_writebacks") - v4.2+.

Now queued up, thanks.

greg k-h