diff options
author | Steven Whitehouse <swhiteho@redhat.com> | 2013-10-02 09:42:45 -0400 |
---|---|---|
committer | Steven Whitehouse <swhiteho@redhat.com> | 2013-10-02 09:42:45 -0400 |
commit | 9e07f2cb3d7a93f4b1b18fc6e4dd6911dcba2442 (patch) | |
tree | ce2de09b90926f81d7e118f2a14ec3dc2dbc12be | |
parent | 7b9cff467144c8c62268db1b0948df089caa0999 (diff) |
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: Steven Whitehouse <swhiteho@redhat.com>
-rw-r--r-- | fs/gfs2/rgrp.c | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index 4f0984a607b3..4d83abdd5635 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c | |||
@@ -2134,6 +2134,35 @@ out: | |||
2134 | } | 2134 | } |
2135 | 2135 | ||
2136 | /** | 2136 | /** |
2137 | * gfs2_set_alloc_start - Set starting point for block allocation | ||
2138 | * @rbm: The rbm which will be set to the required location | ||
2139 | * @ip: The gfs2 inode | ||
2140 | * @dinode: Flag to say if allocation includes a new inode | ||
2141 | * | ||
2142 | * This sets the starting point from the reservation if one is active | ||
2143 | * otherwise it falls back to guessing a start point based on the | ||
2144 | * inode's goal block or the last allocation point in the rgrp. | ||
2145 | */ | ||
2146 | |||
2147 | static void gfs2_set_alloc_start(struct gfs2_rbm *rbm, | ||
2148 | const struct gfs2_inode *ip, bool dinode) | ||
2149 | { | ||
2150 | u64 goal; | ||
2151 | |||
2152 | if (gfs2_rs_active(ip->i_res)) { | ||
2153 | *rbm = ip->i_res->rs_rbm; | ||
2154 | return; | ||
2155 | } | ||
2156 | |||
2157 | if (!dinode && rgrp_contains_block(rbm->rgd, ip->i_goal)) | ||
2158 | goal = ip->i_goal; | ||
2159 | else | ||
2160 | goal = rbm->rgd->rd_last_alloc + rbm->rgd->rd_data0; | ||
2161 | |||
2162 | gfs2_rbm_from_block(rbm, goal); | ||
2163 | } | ||
2164 | |||
2165 | /** | ||
2137 | * gfs2_alloc_blocks - Allocate one or more blocks of data and/or a dinode | 2166 | * gfs2_alloc_blocks - Allocate one or more blocks of data and/or a dinode |
2138 | * @ip: the inode to allocate the block for | 2167 | * @ip: the inode to allocate the block for |
2139 | * @bn: Used to return the starting block number | 2168 | * @bn: Used to return the starting block number |
@@ -2151,22 +2180,14 @@ int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *nblocks, | |||
2151 | struct buffer_head *dibh; | 2180 | struct buffer_head *dibh; |
2152 | struct gfs2_rbm rbm = { .rgd = ip->i_rgd, }; | 2181 | struct gfs2_rbm rbm = { .rgd = ip->i_rgd, }; |
2153 | unsigned int ndata; | 2182 | unsigned int ndata; |
2154 | u64 goal; | ||
2155 | u64 block; /* block, within the file system scope */ | 2183 | u64 block; /* block, within the file system scope */ |
2156 | int error; | 2184 | int error; |
2157 | 2185 | ||
2158 | if (gfs2_rs_active(ip->i_res)) | 2186 | gfs2_set_alloc_start(&rbm, ip, dinode); |
2159 | goal = gfs2_rbm_to_block(&ip->i_res->rs_rbm); | ||
2160 | else if (!dinode && rgrp_contains_block(rbm.rgd, ip->i_goal)) | ||
2161 | goal = ip->i_goal; | ||
2162 | else | ||
2163 | goal = rbm.rgd->rd_last_alloc + rbm.rgd->rd_data0; | ||
2164 | |||
2165 | gfs2_rbm_from_block(&rbm, goal); | ||
2166 | error = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, 0, ip, false); | 2187 | error = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, 0, ip, false); |
2167 | 2188 | ||
2168 | if (error == -ENOSPC) { | 2189 | if (error == -ENOSPC) { |
2169 | gfs2_rbm_from_block(&rbm, goal); | 2190 | gfs2_set_alloc_start(&rbm, ip, dinode); |
2170 | error = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, 0, NULL, false); | 2191 | error = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, 0, NULL, false); |
2171 | } | 2192 | } |
2172 | 2193 | ||