Don't start unnecessary transactions during log flush
Andreas Gruenbacher
maintainercover Don't start unnecessary transactions during log flush
This patch set fixes a gfs2_logd lockup scenario during log flush which was indroduced by commit 8d391972ae2d ("gfs2: Remove __gfs2_writepage()").
Thanks,
Andreas
Andreas Gruenbacher (3):
gfs2: Rename jdata_dirty_folio to gfs2_jdata_dirty_folio
gfs2: Move gfs2_trans_add_databufs
gfs2: Don't start transactions during log flush
fs/gfs2/aops.c | 58 +++++++++++++++++++++++++++++-------------------- fs/gfs2/aops.h | 3 +-- fs/gfs2/bmap.c | 3 ++- fs/gfs2/log.c | 7 +++++- fs/gfs2/trans.c | 21 ++++++++++++++++++ fs/gfs2/trans.h | 2 ++ 6 files changed, 66 insertions(+), 28 deletions(-)
Signature · 1 line
2.49.0
Andreas Gruenbacher
maintainerPATCH 1/3 gfs2: Rename jdata_dirty_folio to gfs2_jdata_dirty_folio
--- fs/gfs2/aops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/gfs2/aops.c +2 -2
@@ -532,7 +532,7 @@ void adjust_fs_space(struct inode *inode)gfs2_trans_end (sdp); } -static bool jdata_dirty_folio (struct address_space *mapping, +static bool gfs2_jdata_dirty_folio (struct address_space *mapping,struct folio *folio) {if (current->journal_info)
@@ -714,7 +714,7 @@ static const struct address_space_operations gfs2_jdata_aops = { .writepages = gfs2_jdata_writepages, .read_folio = gfs2_read_folio, .readahead = gfs2_readahead, - .dirty_folio = jdata_dirty_folio, + .dirty_folio = gfs2_jdata_dirty_folio, .bmap = gfs2_bmap, .migrate_folio = buffer_migrate_folio, .invalidate_folio = gfs2_invalidate_folio,
Signature · 1 line
2.49.0
Andreas Gruenbacher
maintainerPATCH 1/3 Rename jdata_dirty_folio to gfs2_jdata_dirty_folio
In reply to Andreas Gruenbacher--- fs/gfs2/aops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/gfs2/aops.c +2 -2
@@ -532,7 +532,7 @@ void adjust_fs_space(struct inode *inode)gfs2_trans_end (sdp); } -static bool jdata_dirty_folio (struct address_space *mapping, +static bool gfs2_jdata_dirty_folio (struct address_space *mapping,struct folio *folio) {if (current->journal_info)
@@ -714,7 +714,7 @@ static const struct address_space_operations gfs2_jdata_aops = { .writepages = gfs2_jdata_writepages, .read_folio = gfs2_read_folio, .readahead = gfs2_readahead, - .dirty_folio = jdata_dirty_folio, + .dirty_folio = gfs2_jdata_dirty_folio, .bmap = gfs2_bmap, .migrate_folio = buffer_migrate_folio, .invalidate_folio = gfs2_invalidate_folio,
Signature · 1 line
2.49.0
Andreas Gruenbacher
maintainerRe: [PATCH 1/3] Rename jdata_dirty_folio to gfs2_jdata_dirty_folio
Hmm, please ignore this duplicate.
Thanks,
Andreas
Quoted 31 lines · Andreas Gruenbacher
Signed-off-by Andreas Gruenbacher <[email protected]>--- fs/gfs2/aops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/gfs2/aops.c +2
-3@@ -532,7 +532,7 @@ void adjust_fs_space(struct inode *inode)gfs2_trans_end (sdp); } -static bool jdata_dirty_folio (struct address_space *mapping, +static bool gfs2_jdata_dirty_folio (struct address_space *mapping,struct folio *folio) {if (current->journal_info)@@ -714,7 +714,7 @@ static const struct address_space_operations gfs2_jdata_aops = { .writepages = gfs2_jdata_writepages, .read_folio = gfs2_read_folio, .readahead = gfs2_readahead, - .dirty_folio = jdata_dirty_folio, + .dirty_folio = gfs2_jdata_dirty_folio, .bmap = gfs2_bmap, .migrate_folio = buffer_migrate_folio, .invalidate_folio = gfs2_invalidate_folio, --2.49.0
Andreas Gruenbacher
maintainerPATCH 2/3 gfs2: Move gfs2_trans_add_databufs
In reply to Andreas GruenbacherMove gfs2_trans_add_databufs() to trans.c. Pass in a glock instead of a gfs2_inode.
--- fs/gfs2/aops.c | 23 +---------------------- fs/gfs2/aops.h | 2 -- fs/gfs2/bmap.c | 3 ++- fs/gfs2/trans.c | 21 +++++++++++++++++++++ fs/gfs2/trans.h | 2 ++ 5 files changed, 26 insertions(+), 25 deletions(-)
fs/gfs2/aops.c +1 -22
@@ -37,27 +37,6 @@#include "aops.h" -void gfs2_trans_add_databufs (struct gfs2_inode *ip,struct folio *folio, -size_t from,size_t len) -{ -struct buffer_head *head =folio_buffers (folio); -unsigned int bsize = head->b_size; -struct buffer_head *bh; -size_t to = from + len; -size_t start, end; - -for (bh = head, start =0 ; bh != head || !start; - bh = bh->b_this_page, start = end) { - end = start + bsize; -if (end <= from) -continue ; -if (start >= to) -break ; -set_buffer_uptodate (bh); -gfs2_trans_add_data (ip->i_gl, bh); - } -} -/** * gfs2_get_block_noalloc - Fills in a buffer head with details about a block * @inode: The inode
@@ -133,7 +112,7 @@ static int __gfs2_jdata_write_folio(struct folio *folio, inode->i_sb->s_blocksize, BIT(BH_Dirty)|BIT(BH_Uptodate)); } -gfs2_trans_add_databufs (ip, folio,0 ,folio_size (folio)); +gfs2_trans_add_databufs (ip->i_gl, folio,0 ,folio_size (folio)); }return gfs2_write_jdata_folio (folio, wbc); }
fs/gfs2/aops.h +0 -2
@@ -9,7 +9,5 @@#include "incore.h" void adjust_fs_space (struct inode *inode); -void gfs2_trans_add_databufs (struct gfs2_inode *ip,struct folio *folio, -size_t from,size_t len);#endif /* __AOPS_DOT_H__ */
fs/gfs2/bmap.c +2 -1
@@ -988,7 +988,8 @@ static void gfs2_iomap_put_folio(struct inode *inode, loff_t pos,struct gfs2_sbd *sdp =GFS2_SB (inode);if (!gfs2_is_stuffed (ip)) -gfs2_trans_add_databufs (ip, folio,offset_in_folio (folio, pos), +gfs2_trans_add_databufs (ip->i_gl, folio, +offset_in_folio (folio, pos), copied);folio_unlock (folio);
fs/gfs2/trans.c +21 -0
@@ -226,6 +226,27 @@ void gfs2_trans_add_data(struct gfs2_glock *gl, struct buffer_head *bh)unlock_buffer (bh); } +void gfs2_trans_add_databufs (struct gfs2_glock *gl,struct folio *folio, +size_t from,size_t len) +{ +struct buffer_head *head =folio_buffers (folio); +unsigned int bsize = head->b_size; +struct buffer_head *bh; +size_t to = from + len; +size_t start, end; + +for (bh = head, start =0 ; bh != head || !start; + bh = bh->b_this_page, start = end) { + end = start + bsize; +if (end <= from) +continue ; +if (start >= to) +break ; +set_buffer_uptodate (bh); +gfs2_trans_add_data (gl, bh); + } +} +void gfs2_trans_add_meta (struct gfs2_glock *gl,struct buffer_head *bh) {
fs/gfs2/trans.h +2 -0
@@ -42,6 +42,8 @@ int gfs2_trans_begin(struct gfs2_sbd *sdp, unsigned int blocks,void gfs2_trans_end (struct gfs2_sbd *sdp);void gfs2_trans_add_data (struct gfs2_glock *gl,struct buffer_head *bh); +void gfs2_trans_add_databufs (struct gfs2_glock *gl,struct folio *folio, +size_t from,size_t len);void gfs2_trans_add_meta (struct gfs2_glock *gl,struct buffer_head *bh);void gfs2_trans_add_revoke (struct gfs2_sbd *sdp,struct gfs2_bufdata *bd);void gfs2_trans_remove_revoke (struct gfs2_sbd *sdp,u64 blkno,unsigned int len);
Signature · 1 line
2.49.0
Andreas Gruenbacher
maintainerPATCH 3/3 gfs2: Don't start unnecessary transactions during log flush
In reply to Andreas GruenbacherCommit 8d391972ae2d ("gfs2: Remove __gfs2_writepage()") changed the log flush code in gfs2_ail1_start_one() to call aops->writepages() instead of aops->writepage(). For jdata inodes, this means that we will now try to reserve log space and start a transaction before we can determine that the pages in question have already been journaled. When this happens in the context of gfs2_logd(), it can now appear that not enough log space is available for freeing up log space, and we will lock up.
Fix that by issuing journal writes directly instead of going through aops->writepages() in the log flush code.
--- fs/gfs2/aops.c | 31 +++++++++++++++++++++++++++++++ fs/gfs2/aops.h | 1 + fs/gfs2/log.c | 7 ++++++- 3 files changed, 38 insertions(+), 1 deletion(-)
fs/gfs2/aops.c +31 -0
@@ -117,6 +117,37 @@ static int __gfs2_jdata_write_folio(struct folio *folio,return gfs2_write_jdata_folio (folio, wbc); } +/** +* gfs2_jdata_writeback - Write jdata folios to the log +* @mapping: The mapping to write +* @wbc: The writeback control +* +* Returns: errno +*/ +int gfs2_jdata_writeback (struct address_space *mapping,struct writeback_control *wbc) +{ +struct inode *inode = mapping->host; +struct gfs2_inode *ip =GFS2_I (inode); +struct gfs2_sbd *sdp =GFS2_SB (mapping->host); +struct folio *folio =NULL ; +int error; + +BUG_ON (current->journal_info); +if (gfs2_assert_withdraw (sdp, ip->i_gl->gl_state ==LM_ST_EXCLUSIVE )) +return 0 ; + +while ((folio =writeback_iter (mapping, wbc, folio, &error))) { +if (folio_test_checked (folio)) { +folio_redirty_for_writepage (wbc, folio); +folio_unlock (folio); +continue ; + } + error =__gfs2_jdata_write_folio (folio, wbc); + } + +return error; +} +/** * gfs2_writepages - Write a bunch of dirty pages back to disk * @mapping: The mapping to write
fs/gfs2/aops.h +1 -0
@@ -9,5 +9,6 @@#include "incore.h" void adjust_fs_space (struct inode *inode); +int gfs2_jdata_writeback (struct address_space *mapping,struct writeback_control *wbc);#endif /* __AOPS_DOT_H__ */
fs/gfs2/log.c +6 -1
@@ -31,6 +31,7 @@#include "dir.h" #include "trace_gfs2.h" #include "trans.h" +#include "aops.h" static void gfs2_log_shutdown (struct gfs2_sbd *sdp);
@@ -131,7 +132,11 @@ __acquires(&sdp->sd_ail_lock)if (!mapping)continue ;spin_unlock (&sdp->sd_ail_lock); - ret = mapping->a_ops->writepages (mapping, wbc); +BUG_ON (GFS2_SB (mapping->host) != sdp); +if (gfs2_is_jdata (GFS2_I (mapping->host))) + ret =gfs2_jdata_writeback (mapping, wbc); +else + ret = mapping->a_ops->writepages (mapping, wbc);if (need_resched ()) {blk_finish_plug (plug);cond_resched ();
Signature · 1 line
2.49.0