Skip to content

Commit e2de651

Browse files
author
Andreas Gruenbacher
committed
gfs2: Avoid unnecessary transactions in evict_linked_inode
In evict_linked_inode(), the truncate_inode_pages() calls are carried out inside a transaction. This code was added to what was then function gfs2_delete_inode() in commit 16615be ("[GFS2] Clean up journaled data writing"). These transactions are only used for creating revokes for the jdata buffers in the journal, so don't create such transactions when we know that the address space doesn't contain any jdata buffers for this inode and truncate the metadata address space outside of the transaction. Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
1 parent 0ac82bc commit e2de651

1 file changed

Lines changed: 30 additions & 5 deletions

File tree

fs/gfs2/super.c

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,35 @@ static int evict_unlinked_inode(struct inode *inode)
13241324
return ret;
13251325
}
13261326

1327+
static int gfs2_truncate_inode_pages(struct inode *inode)
1328+
{
1329+
struct gfs2_inode *ip = GFS2_I(inode);
1330+
struct gfs2_sbd *sdp = GFS2_SB(inode);
1331+
struct address_space *mapping = &inode->i_data;
1332+
bool need_trans = gfs2_is_jdata(ip) && mapping->nrpages;
1333+
int ret;
1334+
1335+
/*
1336+
* Truncating a jdata inode address space may create revokes in
1337+
* truncate_inode_pages() -> gfs2_invalidate_folio() -> ... ->
1338+
* gfs2_remove_from_journal(), so we need a transaction here.
1339+
*
1340+
* FIXME: During a withdraw, no new transactions can be created.
1341+
* In that case, we skip the truncate, but that doesn't help because
1342+
* truncate_inode_pages_final() will then call gfs2_invalidate_folio()
1343+
* again, and outside of a transaction.
1344+
*/
1345+
if (need_trans) {
1346+
ret = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks);
1347+
if (ret)
1348+
return ret;
1349+
}
1350+
truncate_inode_pages(mapping, 0);
1351+
if (need_trans)
1352+
gfs2_trans_end(sdp);
1353+
return 0;
1354+
}
1355+
13271356
/*
13281357
* evict_linked_inode - evict an inode whose dinode has not been unlinked
13291358
* @inode: The inode to evict
@@ -1346,14 +1375,10 @@ static int evict_linked_inode(struct inode *inode)
13461375
write_inode_now(inode, 1);
13471376
gfs2_ail_flush(ip->i_gl, 0);
13481377

1349-
ret = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks);
1378+
ret = gfs2_truncate_inode_pages(inode);
13501379
if (ret)
13511380
return ret;
1352-
1353-
/* Needs to be done before glock release & also in a transaction */
1354-
truncate_inode_pages(&inode->i_data, 0);
13551381
truncate_inode_pages(metamapping, 0);
1356-
gfs2_trans_end(sdp);
13571382
return 0;
13581383
}
13591384

0 commit comments

Comments
 (0)