vfs: introduce try_to_writeback_inodes_sb(_nr)
Subsystems (3)
PATCH 1/4 vfs: introduce try_to_writeback_inodes_sb(_nr)
writeback_inodes_sb(_nr) grabs s_umount lock when it want to start writeback, it may bring us deadlock problem when doing umount. So we introduce new functions -- try_to_writeback_inodes_sb(_nr) -- which use down_read_trylock() instead of down_read() to avoid that deadlock problem.
This idea came from Christoph Hellwig.
Some code is from the patch of Kamal Mostafa.
--- fs/fs-writeback.c | 39 +++++++++++++++++++++++++++++++++++++++ include/linux/writeback.h | 3 +++ 2 files changed, 42 insertions(+), 0 deletions(-)
fs/fs-writeback.c +39 -0
@@ -1291,6 +1291,45 @@ int writeback_inodes_sb_nr_if_idle(struct super_block *sb,EXPORT_SYMBOL (writeback_inodes_sb_nr_if_idle);/** +* try_to_writeback_inodes_sb_nr - try to start writeback if none underway +* @sb: the superblock +* @nr: the number of pages to write +* @reason: the reason of writeback +* +* Invoke writeback_inodes_sb_nr if no writeback is currently underway. +* Returns 1 if writeback was started, 0 if not. +*/ +int try_to_writeback_inodes_sb_nr (struct super_block *sb, +unsigned long nr, +enum wb_reason reason) +{ +if (writeback_in_progress (sb->s_bdi)) +return 1 ; + +if (!down_read_trylock (&sb->s_umount)) +return 0 ; + +writeback_inodes_sb_nr (sb, nr, reason); +up_read (&sb->s_umount); +return 1 ; +} +EXPORT_SYMBOL (try_to_writeback_inodes_sb_nr); + +/** +* try_to_writeback_inodes_sb - try to start writeback if none underway +* @sb: the superblock +* @reason: reason why some writeback work was initiated +* +* Implement by try_to_writeback_inodes_sb_nr() +* Returns 1 if writeback was started, 0 if not. +*/ +int try_to_writeback_inodes_sb (struct super_block *sb,enum wb_reason reason) +{ +return try_to_writeback_inodes_sb_nr (sb,get_nr_dirty_pages (), reason); +} +EXPORT_SYMBOL (try_to_writeback_inodes_sb); + +/** * sync_inodes_sb - sync sb inode pages * @sb: the superblock *
include/linux/writeback.h +3 -0
@@ -89,6 +89,9 @@ void writeback_inodes_sb_nr(struct super_block *, unsigned long nr,int writeback_inodes_sb_if_idle (struct super_block *,enum wb_reason reason);int writeback_inodes_sb_nr_if_idle (struct super_block *,unsigned long nr,enum wb_reason reason); +int try_to_writeback_inodes_sb (struct super_block *,enum wb_reason reason); +int try_to_writeback_inodes_sb_nr (struct super_block *,unsigned long nr, +enum wb_reason reason);void sync_inodes_sb (struct super_block *);long writeback_inodes_wb (struct bdi_writeback *wb,long nr_pages,enum wb_reason reason);
Signature · 1 line
1.7.6.5
Quoted 7 lines · Miao Xie
writeback_inodes_sb(_nr)grabss_umountlock when it want to start writeback, it may bring us deadlock problem when doing umount. So we introduce new functions --try_to_writeback_inodes_sb(_nr)-- which usedown_read_trylock()instead ofdown_read()to avoid that deadlock problem.This idea came from Christoph Hellwig.
Some code is from the patch of Kamal Mostafa.
This just re-implements writeback_inodes_[nr]_sb_if_idle() with a trylock instead of a blocking lock.
Just replace the blocking lock in writeback_inodes_[nr]_sb_if_idle() with a trylock and use that.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 7 lines · Dave Chinner
Quoted 7 lines
writeback_inodes_sb(_nr)grabss_umountlock when it want to start writeback,
it may bring us deadlock problem when doing umount. So we introduce new functions --try_to_writeback_inodes_sb(_nr)-- which usedown_read_trylock()
instead ofdown_read()to avoid that deadlock problem.
Quoted 8 lines
Quoted 2 lines
This idea came from Christoph Hellwig.
Some code is from the patch of Kamal Mostafa.This just re-implements writeback_inodes_[nr]_sb_if_idle() with a trylock instead of a blocking lock.
Just replace the blocking lock in writeback_inodes_[nr]_sb_if_idle() with a trylock and use that.
The change of these two functions is relative to three modules, so I think the patch set now is easy to be reviewed by the developers of each module.
Thanks
Miao
Quoted 11 lines · Xie Miao
Quoted 10 lines · Dave Chinner
Quoted 9 lines
writeback_inodes_sb(_nr)grabss_umountlock when it want to start writeback,
it may bring us deadlock problem when doing umount. So we introduce new functions --try_to_writeback_inodes_sb(_nr)-- which usedown_read_trylock()
instead ofdown_read()to avoid that deadlock problem.This idea came from Christoph Hellwig.
Some code is from the patch of Kamal Mostafa.
Quoted 9 lines
Quoted 5 lines
This just re-implements writeback_inodes_[nr]_sb_if_idle() with a trylock instead of a blocking lock.
Just replace the blocking lock in writeback_inodes_[nr]_sb_if_idle() with a trylock and use that.
The change of these two functions is relative to three modules, so I think the patch set now is easy to be reviewed by the developers of each module.
I agree with David, there's no sense in making something completely seperate, this function was introduced soley to kick off background writeout if we could with no garuntees, if the other users suddenly don't like the behavior they can creating something different for themselves. Thanks,
Josef
=E4=BA=8E 2012=E5=B9=B404=E6=9C=8826=E6=97=A5 23:12, Josef Bacik =E5=86= =99=E9=81=93:
Quoted 2 lines · Xie Miao
Quoted 1 line
On Thu, Apr 26, 2012 at 11:11 AM, Dave Chinner <[email protected]>=
Quoted 3 lines · wrote:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
writeback_inodes_sb(_nr)grabss_umountlock when it want to start writeback,
it may bring us deadlock problem when doing umount. So we introduc=
e new
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 6 lines
functions --
try_to_writeback_inodes_sb(_nr)-- which usedown_read_trylock()
instead ofdown_read()to avoid that deadlock problem.This idea came from Christoph Hellwig.
Some code is from the patch of Kamal Mostafa.This just re-implements writeback_inodes_[nr]_sb_if_idle() with a trylock instead of a blocking lock.
Just replace the blocking lock in writeback_inodes_[nr]_sb_if_idle(=
)
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
with a trylock and use that.
The change of these two functions is relative to three modules, so =
I think
Quoted 1 line
Quoted 1 line
the patch set now is easy to be reviewed by the developers of each m=
odule.
Quoted 3 lines
Quoted 1 line
=20
I agree with David, there's no sense in making something completely s=
eperate,
Quoted 1 line
this function was introduced soley to kick off background writeout if=
we could
Quoted 1 line
with no garuntees, if the other users suddenly don't like the behavio=
r they can
Quoted 1 line
creating something different for themselves. Thanks,
OK, I'll make them together.
Thanks
Miao
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" i= n
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html