Commit 9e07f2cb authored by Steven Whitehouse's avatar Steven Whitehouse

GFS2: Speed up starting point selection for block allocation

When setting the starting point for block allocation, there were calls
to both gfs2_rbm_to_block() and gfs2_rbm_from_block() in the common case
of there being an active reservation. The gfs2_rbm_from_block() function
can be quite slow, and since the two conversions were effectively a
no-op, it makes sense to avoid them entirely in this case.

There is no functional change here, but the code should be a bit more
efficient after this patch.
Signed-off-by: default avatarSteven Whitehouse <swhiteho@redhat.com>
parent 7b9cff46
...@@ -2133,6 +2133,35 @@ static void gfs2_adjust_reservation(struct gfs2_inode *ip, ...@@ -2133,6 +2133,35 @@ static void gfs2_adjust_reservation(struct gfs2_inode *ip,
spin_unlock(&rgd->rd_rsspin); spin_unlock(&rgd->rd_rsspin);
} }
/**
* gfs2_set_alloc_start - Set starting point for block allocation
* @rbm: The rbm which will be set to the required location
* @ip: The gfs2 inode
* @dinode: Flag to say if allocation includes a new inode
*
* This sets the starting point from the reservation if one is active
* otherwise it falls back to guessing a start point based on the
* inode's goal block or the last allocation point in the rgrp.
*/
static void gfs2_set_alloc_start(struct gfs2_rbm *rbm,
const struct gfs2_inode *ip, bool dinode)
{
u64 goal;
if (gfs2_rs_active(ip->i_res)) {
*rbm = ip->i_res->rs_rbm;
return;
}
if (!dinode && rgrp_contains_block(rbm->rgd, ip->i_goal))
goal = ip->i_goal;
else
goal = rbm->rgd->rd_last_alloc + rbm->rgd->rd_data0;
gfs2_rbm_from_block(rbm, goal);
}
/** /**
* gfs2_alloc_blocks - Allocate one or more blocks of data and/or a dinode * gfs2_alloc_blocks - Allocate one or more blocks of data and/or a dinode
* @ip: the inode to allocate the block for * @ip: the inode to allocate the block for
...@@ -2151,22 +2180,14 @@ int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *nblocks, ...@@ -2151,22 +2180,14 @@ int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *nblocks,
struct buffer_head *dibh; struct buffer_head *dibh;
struct gfs2_rbm rbm = { .rgd = ip->i_rgd, }; struct gfs2_rbm rbm = { .rgd = ip->i_rgd, };
unsigned int ndata; unsigned int ndata;
u64 goal;
u64 block; /* block, within the file system scope */ u64 block; /* block, within the file system scope */
int error; int error;
if (gfs2_rs_active(ip->i_res)) gfs2_set_alloc_start(&rbm, ip, dinode);
goal = gfs2_rbm_to_block(&ip->i_res->rs_rbm);
else if (!dinode && rgrp_contains_block(rbm.rgd, ip->i_goal))
goal = ip->i_goal;
else
goal = rbm.rgd->rd_last_alloc + rbm.rgd->rd_data0;
gfs2_rbm_from_block(&rbm, goal);
error = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, 0, ip, false); error = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, 0, ip, false);
if (error == -ENOSPC) { if (error == -ENOSPC) {
gfs2_rbm_from_block(&rbm, goal); gfs2_set_alloc_start(&rbm, ip, dinode);
error = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, 0, NULL, false); error = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, 0, NULL, false);
} }
......
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