Skip to content

Commit 5cb8b82

Browse files
htejunaxboe
authored andcommitted
writeback: use unlocked_inode_to_wb transaction in inode_congested()
Similar to wb stat updates, inode_congested() accesses the associated wb of an inode locklessly, which will break with foreign inode wb switching. This path updates inode_congested() to use unlocked inode wb access transaction introduced by the previous patch. Combined with the previous two patches, this makes all wb list and access operations to be protected by either of inode->i_lock, wb->list_lock, or mapping->tree_lock while wb switching is in progress. Signed-off-by: Tejun Heo <[email protected]> Cc: Jens Axboe <[email protected]> Cc: Jan Kara <[email protected]> Cc: Wu Fengguang <[email protected]> Cc: Greg Thelen <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 682aa8e commit 5cb8b82

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

fs/fs-writeback.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,10 +618,18 @@ void wbc_account_io(struct writeback_control *wbc, struct page *page,
618618
*/
619619
int inode_congested(struct inode *inode, int cong_bits)
620620
{
621-
if (inode) {
622-
struct bdi_writeback *wb = inode_to_wb(inode);
623-
if (wb)
624-
return wb_congested(wb, cong_bits);
621+
/*
622+
* Once set, ->i_wb never becomes NULL while the inode is alive.
623+
* Start transaction iff ->i_wb is visible.
624+
*/
625+
if (inode && inode_to_wb(inode)) {
626+
struct bdi_writeback *wb;
627+
bool locked, congested;
628+
629+
wb = unlocked_inode_to_wb_begin(inode, &locked);
630+
congested = wb_congested(wb, cong_bits);
631+
unlocked_inode_to_wb_end(inode, locked);
632+
return congested;
625633
}
626634

627635
return wb_congested(&inode_to_bdi(inode)->wb, cong_bits);

0 commit comments

Comments
 (0)