Commit e7fdf004 authored by Andreas Gruenbacher's avatar Andreas Gruenbacher Committed by Bob Peterson

gfs2: Remove minor gfs2_journaled_truncate inefficiencies

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: default avatarAndreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: default avatarBob Peterson <rpeterso@redhat.com>
parent 8b5860a3
...@@ -1003,11 +1003,24 @@ static int gfs2_journaled_truncate(struct inode *inode, u64 oldsize, u64 newsize ...@@ -1003,11 +1003,24 @@ static int gfs2_journaled_truncate(struct inode *inode, u64 oldsize, u64 newsize
int error; int error;
while (oldsize != newsize) { while (oldsize != newsize) {
struct gfs2_trans *tr;
unsigned int offs;
chunk = oldsize - newsize; chunk = oldsize - newsize;
if (chunk > max_chunk) if (chunk > max_chunk)
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); truncate_pagecache(inode, oldsize - chunk);
oldsize -= chunk; oldsize -= chunk;
tr = current->journal_info;
if (!test_bit(TR_TOUCHED, &tr->tr_flags))
continue;
gfs2_trans_end(sdp); gfs2_trans_end(sdp);
error = gfs2_trans_begin(sdp, RES_DINODE, GFS2_JTRUNC_REVOKES); error = gfs2_trans_begin(sdp, RES_DINODE, GFS2_JTRUNC_REVOKES);
if (error) if (error)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment