GFS2: optimize rbm_from_block wrt bi_start
PATCH 1/5 GFS2: optimize rbm_from_block wrt bi_start
In function gfs2_rbm_from_block, it starts by checking if the block falls within the first bitmap. It does so by checking if the rbm's offset is less than (rbm->bi->bi_start + rbm->bi->bi_len) * GFS2_NBBY. However, the first bitmap will always have bi_start==0. Therefore this is an unnecessary calculation in a function that gets called billions of times. This patch removes the reference to bi_start.
--- fs/gfs2/rgrp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/gfs2/rgrp.c +1 -1
@@ -262,7 +262,7 @@ static int gfs2_rbm_from_block(struct gfs2_rbm *rbm, u64 block) rbm->bi = rbm->rgd->rd_bits; rbm->offset = (u32)(rblock);/* Check if the block is within the first block */ -if (rbm->offset < (rbm->bi->bi_start + rbm->bi->bi_len) *GFS2_NBBY ) +if (rbm->offset < rbm->bi->bi_len *GFS2_NBBY )return 0 ;/* Adjust for the size diff between gfs2_meta_header and gfs2_rgrp */
Signature · 1 line
1.8.3.1
PATCH 2/5 GFS2: introduce bi_blocks for optimization
This patch introduces a new field in the bitmap structure called bi_blocks. Its purpose is to save us from constantly multiplying bi_len by the constant GFS2_NBBY. It also paves the way for more optimization in a future patch.
--- fs/gfs2/incore.h | 1 + fs/gfs2/rgrp.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-)
fs/gfs2/incore.h +1 -0
@@ -71,6 +71,7 @@ struct gfs2_bitmap {u32 bi_offset;u32 bi_start;u32 bi_len; +u32 bi_blocks; };struct gfs2_rgrpd {
fs/gfs2/rgrp.c +5 -1
@@ -262,7 +262,7 @@ static int gfs2_rbm_from_block(struct gfs2_rbm *rbm, u64 block) rbm->bi = rbm->rgd->rd_bits; rbm->offset = (u32)(rblock);/* Check if the block is within the first block */ -if (rbm->offset < rbm->bi->bi_len *GFS2_NBBY ) +if (rbm->offset < rbm->bi->bi_blocks)return 0 ;/* Adjust for the size diff between gfs2_meta_header and gfs2_rgrp */
@@ -743,18 +743,21 @@ static int compute_bitstructs(struct gfs2_rgrpd *rgd) bi->bi_offset =sizeof (struct gfs2_rgrp ); bi->bi_start =0 ; bi->bi_len = bytes; + bi->bi_blocks = bytes *GFS2_NBBY ;/* header block */ }else if (x ==0 ) { bytes = sdp->sd_sb.sb_bsize -sizeof (struct gfs2_rgrp ); bi->bi_offset =sizeof (struct gfs2_rgrp ); bi->bi_start =0 ; bi->bi_len = bytes; + bi->bi_blocks = bytes *GFS2_NBBY ;/* last block */ }else if (x +1 == length) { bytes = bytes_left; bi->bi_offset =sizeof (struct gfs2_meta_header ); bi->bi_start = rgd->rd_bitbytes - bytes_left; bi->bi_len = bytes; + bi->bi_blocks = bytes *GFS2_NBBY ;/* other blocks */ }else { bytes = sdp->sd_sb.sb_bsize -
@@ -762,6 +765,7 @@ static int compute_bitstructs(struct gfs2_rgrpd *rgd) bi->bi_offset =sizeof (struct gfs2_meta_header ); bi->bi_start = rgd->rd_bitbytes - bytes_left; bi->bi_len = bytes; + bi->bi_blocks = bytes *GFS2_NBBY ; } bytes_left -= bytes;
Signature · 1 line
1.8.3.1
PATCH 3/5 GFS2: Introduce rbm field bii
In reply to Bob PetersonThis patch adds a new field to the rbm structure, called bii. The purpose of this structure is to keep track of which bitmap the rbm is on (an index into the bitmap array). This is being added to enable optimizations in future patches.
--- fs/gfs2/incore.h | 1 + fs/gfs2/rgrp.c | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 12 deletions(-)
fs/gfs2/incore.h +1 -0
@@ -104,6 +104,7 @@ struct gfs2_rbm {struct gfs2_rgrpd *rgd;struct gfs2_bitmap *bi;/* Bitmap must belong to the rgd */ u32 offset;/* The offset is bitmap relative */ +int bii;/* Bitmap index */ };static inline u64 gfs2_rbm_to_block (const struct gfs2_rbm *rbm)
fs/gfs2/rgrp.c +11 -12
@@ -252,7 +252,6 @@ static u32 gfs2_bitfit(const u8 *buf, const unsigned int len,static int gfs2_rbm_from_block (struct gfs2_rbm *rbm,u64 block) {u64 rblock = block - rbm->rgd->rd_data0; -u32 x;if (WARN_ON_ONCE (rblock >UINT_MAX ))return -EINVAL ;
@@ -260,6 +259,7 @@ static int gfs2_rbm_from_block(struct gfs2_rbm *rbm, u64 block)return -E2BIG ; rbm->bi = rbm->rgd->rd_bits; + rbm->bii =0 ; rbm->offset = (u32)(rblock);/* Check if the block is within the first block */ if (rbm->offset < rbm->bi->bi_blocks)
@@ -268,9 +268,9 @@ static int gfs2_rbm_from_block(struct gfs2_rbm *rbm, u64 block)/* Adjust for the size diff between gfs2_meta_header and gfs2_rgrp */ rbm->offset += (sizeof (struct gfs2_rgrp ) -sizeof (struct gfs2_meta_header )) *GFS2_NBBY ; - x = rbm->offset / rbm->rgd->rd_sbd->sd_blocks_per_bitmap; - rbm->offset -= x * rbm->rgd->rd_sbd->sd_blocks_per_bitmap; - rbm->bi += x; + rbm->bii = rbm->offset / rbm->rgd->rd_sbd->sd_blocks_per_bitmap; + rbm->offset -= rbm->bii * rbm->rgd->rd_sbd->sd_blocks_per_bitmap; + rbm->bi += rbm->bii;return 0 ; }
@@ -1562,7 +1562,6 @@ static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 minext,u32 initial_offset;u32 offset;u8 *buffer; -int index;int n =0 ;int iters = rbm->rgd->rd_length;int ret;
@@ -1601,7 +1600,7 @@ static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 minext, goto next_iter; }if (ret == -E2BIG ) { - index =0 ; + rbm->bii =0 ; rbm->offset =0 ; n += (rbm->bi - initial_bi); goto res_covered_end_of_rgrp;
@@ -1614,13 +1613,13 @@ bitmap_full: /* Mark bitmap as full and fall through */ next_bitmap:/* Find next bitmap in the rgrp */ rbm->offset =0 ; - index = rbm->bi - rbm->rgd->rd_bits; - index++; -if (index == rbm->rgd->rd_length) - index =0 ; + rbm->bii = rbm->bi - rbm->rgd->rd_bits; + rbm->bii++; +if (rbm->bii == rbm->rgd->rd_length) + rbm->bii =0 ; res_covered_end_of_rgrp: - rbm->bi = &rbm->rgd->rd_bits[index]; -if ((index ==0 ) && nowrap) + rbm->bi = &rbm->rgd->rd_bits[rbm->bii]; +if ((rbm->bii ==0 ) && nowrap)break ; n++; next_iter:
Signature · 1 line
1.8.3.1
PATCH 4/5 GFS2: new function gfs2_rbm_incr
In reply to Bob PetersonThis patch adds a new function, gfs2_rbm_incr, which increments an rbm structure. This is more efficient than calling gfs2_rbm_to_block, incrementing, then calling gfs2_rbm_from_block.
--- fs/gfs2/rgrp.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-)
fs/gfs2/rgrp.c +28 -3
@@ -275,6 +275,33 @@ static int gfs2_rbm_from_block(struct gfs2_rbm *rbm, u64 block) }/** +* gfs2_rbm_incr - increment an rbm structure +* @rbm: The rbm with rgd already set correctly +* +* This function takes an existing rbm structure and increments it to the next +* viable block offset. +* +* Returns: If incrementing the offset would cause the rbm to go past the +* end of the rgrp, true is returned, otherwise false. +* +*/ + +static bool gfs2_rbm_incr (struct gfs2_rbm *rbm) +{ +if (rbm->offset +1 < rbm->bi->bi_blocks) {/* in the same bitmap */ + rbm->offset++; +return false; + } +if (rbm->bii == rbm->rgd->rd_length -1 )/* at the last bitmap */ +return true; + + rbm->offset =0 ; + rbm->bii++; + rbm->bi++; +return false; +} + +/** * gfs2_unaligned_extlen - Look for free blocks which are not byte aligned * @rbm: Position to search (value/result) * @n_unaligned: Number of unaligned blocks to check
@@ -285,7 +312,6 @@ static int gfs2_rbm_from_block(struct gfs2_rbm *rbm, u64 block)static bool gfs2_unaligned_extlen (struct gfs2_rbm *rbm,u32 n_unaligned,u32 *len) { -u64 block;u32 n;u8 res;
@@ -296,8 +322,7 @@ static bool gfs2_unaligned_extlen(struct gfs2_rbm *rbm, u32 n_unaligned, u32 *le (*len)--;if (*len ==0 )return true; - block =gfs2_rbm_to_block (rbm); -if (gfs2_rbm_from_block (rbm, block +1 )) +if (gfs2_rbm_incr (rbm))return true; }
Signature · 1 line
1.8.3.1
PATCH 5/5 GFS2: Do not reset flags on active reservations
In reply to Bob PetersonWhen we used try locks for rgrps on block allocations, it was important to clear the flags field so that we used a blocking hold on the glock. Now that we're not doing try locks, clearing flags is unnecessary, and a waste of time. In fact, it's probably doing the wrong thing because it clears the GL_SKIP bit that was set for the lvb tracking purposes.
--- fs/gfs2/rgrp.c | 1 - 1 file changed, 1 deletion(-)
fs/gfs2/rgrp.c +0 -1
@@ -1849,7 +1849,6 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip, u32 requested, u32 aflags)return -EINVAL ;if (gfs2_rs_active (rs)) { begin = rs->rs_rbm.rgd; - flags =0 ;/* Yoda: Do or do not. There is no try */ }else if (ip->i_rgd &&rgrp_contains_block (ip->i_rgd, ip->i_goal)) { rs->rs_rbm.rgd = begin = ip->i_rgd; }else {
Signature · 1 line
1.8.3.1
PATCH 5/5 GFS2: Do not reset flags on active reservations
Hi,
So I've taken patches 1,2 and 5 from this series. I know that you are looking into being able to reduce the rbm size by using just the bii and removing the bitmap pointer, so I'll leave 3 & 4 until thats ready too, if that makes sense?
Steve.
Quoted 21 lines · Bob Peterson
When we used try locks for rgrps on block allocations, it was important to clear the flags field so that we used a blocking hold on the glock. Now that we're not doing try locks, clearing flags is unnecessary, and a waste of time. In fact, it's probably doing the wrong thing because it clears the
GL_SKIPbit that was set for the lvb tracking purposes.--- fs/gfs2/rgrp.c | 1 - 1 file changed, 1 deletion(-)fs/gfs2/rgrp.c +0
-1@@ -1849,7 +1849,6 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip, u32 requested, u32 aflags)return -EINVAL ;if (gfs2_rs_active (rs)) { begin = rs->rs_rbm.rgd; - flags =0 ;/* Yoda: Do or do not. There is no try */ }else if (ip->i_rgd &&rgrp_contains_block (ip->i_rgd, ip->i_goal)) { rs->rs_rbm.rgd = begin = ip->i_rgd; }else {