From: Andreas Gruenbacher Date: Fri, 22 Dec 2017 15:35:00 +0100 Subject: [Cluster-devel] [PATCH 05/12] gfs2: Remove minor gfs2_journaled_truncate inefficiencies In-Reply-To: <20171222143507.26680-1-agruenba@redhat.com> References: <20171222143507.26680-1-agruenba@redhat.com> Message-ID: <20171222143507.26680-6-agruenba@redhat.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit First, this function truncates the file in chunks. When the original file size isn't block aligned, each chunk that is truncated will remain be misaligned. This is inefficient. Second, this function doesn't recognize where holes are, so it loops through them. For each chunk of a hole, it creates a new transaction. At least avoid creating another transactions whe the current one is still empty. (An better fix would be to skip large holes, of course.) Signed-off-by: Andreas Gruenbacher --- fs/gfs2/bmap.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 963117f704bf..921bf33faa96 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -1003,11 +1003,25 @@ static int gfs2_journaled_truncate(struct inode *inode, u64 oldsize, u64 newsize int error; while (oldsize != newsize) { + struct gfs2_trans *tr; + unsigned int offs; + chunk = oldsize - newsize; if (chunk > max_chunk) chunk = max_chunk; + + offs = oldsize & ~PAGE_MASK; + if (offs && chunk > PAGE_SIZE) + chunk = offs + ((chunk - offs) & PAGE_MASK); + truncate_pagecache(inode, oldsize - chunk); oldsize -= chunk; + + /* XXX Is this check sufficient? */ + tr = current->journal_info; + if (!tr->tr_num_revoke) + continue; + gfs2_trans_end(sdp); error = gfs2_trans_begin(sdp, RES_DINODE, GFS2_JTRUNC_REVOKES); if (error) -- 2.14.3