Read bitmap buffers on demand
Andreas Gruenbacher
maintainercover Read bitmap buffers on demand
Here's a bunch of patches that have accumulated here lately. The most interesting one is likely "gfs2: Read bitmap buffers on demand" which should make filesystems with large resource groups more efficient.
Thanks,
Andreas
Andreas Gruenbacher (11):
gfs2: Fix setting GBF_FULL in gfs2_rbm_find
gfs2: Rename minext => minlen
gfs2: Don't use struct gfs2_rbm in struct gfs2_extent
gfs2: Minor gfs2_free_extlen cleanup
gfs2: Only use struct gfs2_rbm for bitmap manipulations
gfs2: Minor gfs2_adjust_reservation and gfs2_alloc_extent cleanups
gfs2: Minor gfs2_rgrp_send_discards cleanup
gfs2: Add buffer head to struct gfs2_rgrpd
gfs2: Read bitmap buffers on demand
gfs2: Clean up assertion, consistency check, and error reporting
functions
gfs2: Skip gfs2_metatype_check for cached buffers
fs/gfs2/bmap.c | 2 +- fs/gfs2/incore.h | 37 +-- fs/gfs2/lops.c | 3 +- fs/gfs2/meta_io.c | 10 +- fs/gfs2/rgrp.c | 672 +++++++++++++++++++++++++------------------ fs/gfs2/rgrp.h | 3 +- fs/gfs2/trace_gfs2.h | 10 +- fs/gfs2/trans.h | 2 +- fs/gfs2/util.c | 128 ++++----- fs/gfs2/util.h | 85 ++---- 10 files changed, 509 insertions(+), 443 deletions(-)
Signature · 1 line
2.20.1
Andreas Gruenbacher
maintainerPATCH 1/11 gfs2: Fix setting GBF_FULL in gfs2_rbm_find
In gfs2_rbm_find, set the GBF_FULL flag whenever there are no free blocks in an entire bitmap. That requires that gfs2_bitfit scans the entire bitmap (offset == 0), but doesn't depend on initial_offset.
--- fs/gfs2/rgrp.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
fs/gfs2/rgrp.c +5 -8
@@ -1731,7 +1731,6 @@ static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 *minext, {struct buffer_head *bh;int initial_bii; -u32 initial_offset;int first_bii = rbm->bii;u32 first_offset = rbm->offset;u32 offset;
@@ -1761,10 +1760,12 @@ static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 *minext,WARN_ON (!buffer_uptodate (bh));if (state !=GFS2_BLKST_UNLINKED && bi->bi_clone) buffer = bi->bi_clone + bi->bi_offset; - initial_offset = rbm->offset; offset =gfs2_bitfit (buffer, bi->bi_bytes, rbm->offset, state); -if (offset ==BFITNOENT ) - goto bitmap_full; +if (offset ==BFITNOENT ) { +if (state ==GFS2_BLKST_FREE && rbm->offset ==0 ) +set_bit (GBF_FULL , &bi->bi_flags); + goto next_bitmap; + } rbm->offset = offset;if (ip ==NULL )return 0 ;
@@ -1787,10 +1788,6 @@ static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 *minext, }return ret; -bitmap_full:/* Mark bitmap as full and fall through */ -if ((state ==GFS2_BLKST_FREE ) && initial_offset ==0 ) -set_bit (GBF_FULL , &bi->bi_flags); - next_bitmap:/* Find next bitmap in the rgrp */ rbm->offset =0 ; rbm->bii++;
Signature · 1 line
2.20.1
Andreas Gruenbacher
maintainerPATCH 2/11 gfs2: Rename minext => minlen
In reply to Andreas GruenbacherRename the minext parameters which represent extent lengths to minlen to avoid confusion with maxext, which are actual extents.
--- fs/gfs2/rgrp.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
fs/gfs2/rgrp.c +15 -14
@@ -73,7 +73,7 @@ static const char valid_change[16] = { 1, 0, 0, 0 }; -static int gfs2_rbm_find (struct gfs2_rbm *rbm,u8 state,u32 *minext, +static int gfs2_rbm_find (struct gfs2_rbm *rbm,u8 state,u32 *minlen,const struct gfs2_inode *ip,bool nowrap);
@@ -1318,7 +1318,8 @@ void gfs2_rgrp_go_unlock(struct gfs2_holder *gh)int gfs2_rgrp_send_discards (struct gfs2_sbd *sdp,u64 offset,struct buffer_head *bh, -const struct gfs2_bitmap *bi,unsigned minlen,u64 *ptrimmed) +const struct gfs2_bitmap *bi,unsigned minlen, +u64 *ptrimmed) {struct super_block *sb = sdp->sd_vfs;u64 blk;
@@ -1653,7 +1654,7 @@ static u64 gfs2_next_unreserved_block(struct gfs2_rgrpd *rgd, u64 block,* gfs2_reservation_check_and_update - Check for reservations during block alloc * @rbm: The current position in the resource group * @ip: The inode for which we are searching for blocks -* @minext: The minimum extent length +* @minlen: The minimum extent length * @maxext: A pointer to the maximum extent structure * * This checks the current position in the rgrp to see whether there is
@@ -1667,7 +1668,7 @@ static u64 gfs2_next_unreserved_block(struct gfs2_rgrpd *rgd, u64 block,static int gfs2_reservation_check_and_update (struct gfs2_rbm *rbm,const struct gfs2_inode *ip, -u32 minext, +u32 minlen,struct gfs2_extent *maxext) {u64 block =gfs2_rbm_to_block (rbm);
@@ -1679,8 +1680,8 @@ static int gfs2_reservation_check_and_update(struct gfs2_rbm *rbm,* If we have a minimum extent length, then skip over any extent * which is less than the min extent length in size. */ -if (minext) { - extlen =gfs2_free_extlen (rbm, minext); +if (minlen) { + extlen =gfs2_free_extlen (rbm, minlen);if (extlen <= maxext->len) goto fail; }
@@ -1691,7 +1692,7 @@ static int gfs2_reservation_check_and_update(struct gfs2_rbm *rbm,*/ nblock =gfs2_next_unreserved_block (rbm->rgd, block, extlen, ip);if (nblock == block) { -if (!minext || extlen >= minext) +if (!minlen || extlen >= minlen)return 0 ;if (extlen > maxext->len) {
@@ -1711,7 +1712,7 @@ static int gfs2_reservation_check_and_update(struct gfs2_rbm *rbm,* gfs2_rbm_find - Look for blocks of a particular state * @rbm: Value/result starting position and final position * @state: The state which we want to find -* @minext: Pointer to the requested extent length (NULL for a single block) +* @minlen: Pointer to the requested extent length (NULL for a single block) * This is updated to be the actual reservation size. * @ip: If set, check for reservations * @nowrap: Stop looking at the end of the rgrp, rather than wrapping
@@ -1726,7 +1727,7 @@ static int gfs2_reservation_check_and_update(struct gfs2_rbm *rbm,* Returns: 0 on success, -ENOSPC if there is no block of the requested state */ -static int gfs2_rbm_find (struct gfs2_rbm *rbm,u8 state,u32 *minext, +static int gfs2_rbm_find (struct gfs2_rbm *rbm,u8 state,u32 *minlen,const struct gfs2_inode *ip,bool nowrap) {struct buffer_head *bh;
@@ -1772,7 +1773,7 @@ static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 *minext, initial_bii = rbm->bii; ret =gfs2_reservation_check_and_update (rbm, ip, - minext ? *minext :0 , + minlen ? *minlen :0 , &maxext);if (ret ==0 )return 0 ;
@@ -1802,21 +1803,21 @@ static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 *minext,break ; } -if (minext ==NULL || state !=GFS2_BLKST_FREE ) +if (minlen ==NULL || state !=GFS2_BLKST_FREE )return -ENOSPC ;/* If the extent was too small, and it's smaller than the smallest to have failed before, remember for future reference that it's useless to search this rgrp again for this amount or more. */ if ((first_offset ==0 ) && (first_bii ==0 ) && - (*minext < rbm->rgd->rd_extfail_pt)) - rbm->rgd->rd_extfail_pt = *minext; + (*minlen < rbm->rgd->rd_extfail_pt)) + rbm->rgd->rd_extfail_pt = *minlen;/* If the maximum extent we found is big enough to fulfill the minimum requirements, use it anyway. */ if (maxext.len) { *rbm = maxext.rbm; - *minext = maxext.len; + *minlen = maxext.len;return 0 ; }
Signature · 1 line
2.20.1
Andreas Gruenbacher
maintainerPATCH 3/11 gfs2: Don't use struct gfs2_rbm in struct gfs2_extent
In reply to Andreas GruenbacherDon't use struct gfs2_rbm in struct gfs2_extent: the extent will always be in the same resource group, so there is no need to track the resource group separately.
--- fs/gfs2/rgrp.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
fs/gfs2/rgrp.c +7 -4
@@ -61,7 +61,8 @@*/ struct gfs2_extent { -struct gfs2_rbm rbm; +int bii; +u32 offset;u32 len; };
@@ -1696,8 +1697,9 @@ static int gfs2_reservation_check_and_update(struct gfs2_rbm *rbm,return 0 ;if (extlen > maxext->len) { + maxext->bii = rbm->bii; + maxext->offset = rbm->offset; maxext->len = extlen; - maxext->rbm = *rbm; } fail: nblock = block + extlen;
@@ -1740,7 +1742,7 @@ static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 *minlen,int iters = rbm->rgd->rd_length;int ret;struct gfs2_bitmap *bi; -struct gfs2_extent maxext = { .rbm.rgd = rbm->rgd, }; +struct gfs2_extent maxext = { };/* If we are not starting at the beginning of a bitmap, then we * need to add one to the bitmap count to ensure that we search
@@ -1816,7 +1818,8 @@ static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 *minlen,/* If the maximum extent we found is big enough to fulfill the minimum requirements, use it anyway. */ if (maxext.len) { - *rbm = maxext.rbm; + rbm->bii = maxext.bii; + rbm->offset = maxext.offset; *minlen = maxext.len;return 0 ; }
Signature · 1 line
2.20.1
Andreas Gruenbacher
maintainerPATCH 4/11 gfs2: Minor gfs2_free_extlen cleanup
In reply to Andreas GruenbacherLimit the n_unaligned argument of gfs2_unaligned_extlen to the number of blocks to scan so that the len argument can never underrun.
Slightly simplify the unaligned block logic in gfs2_free_extlen.
--- fs/gfs2/rgrp.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-)
fs/gfs2/rgrp.c +13 -17
@@ -335,8 +335,6 @@ static bool gfs2_unaligned_extlen(struct gfs2_rbm *rbm, u32 n_unaligned, u32 *leif (res !=GFS2_BLKST_FREE )return true; (*len)--; -if (*len ==0 ) -return true;if (gfs2_rbm_incr (rbm))return true; }
@@ -362,7 +360,6 @@ static bool gfs2_unaligned_extlen(struct gfs2_rbm *rbm, u32 n_unaligned, u32 *lestatic u32 gfs2_free_extlen (const struct gfs2_rbm *rrbm,u32 len) {struct gfs2_rbm rbm = *rrbm; -u32 n_unaligned = rbm.offset &3 ;u32 size = len;u32 bytes;u32 chunk_size;
@@ -370,11 +367,14 @@ static u32 gfs2_free_extlen(const struct gfs2_rbm *rrbm, u32 len)u64 block;struct gfs2_bitmap *bi; -if (n_unaligned && -gfs2_unaligned_extlen (&rbm,4 - n_unaligned, &len)) - goto out; +/* Deal with unaligned bits at the front */ +if (rbm.offset &3 ) { +u32 n_unaligned =min (4 - (rbm.offset &3 ), len); + +if (gfs2_unaligned_extlen (&rbm, n_unaligned, &len)) + goto out; + } - n_unaligned = len &3 ;/* Start is now byte aligned */ while (len >3 ) { bi =rbm_bi (&rbm);
@@ -392,20 +392,16 @@ static u32 gfs2_free_extlen(const struct gfs2_rbm *rrbm, u32 len)BUG_ON (len < chunk_size); len -= chunk_size; block =gfs2_rbm_to_block (&rbm); -if (gfs2_rbm_from_block (&rbm, block + chunk_size)) { - n_unaligned =0 ; -break ; - } -if (ptr) { - n_unaligned =3 ; +if (gfs2_rbm_from_block (&rbm, block + chunk_size)) + goto out; +if (ptr)break ; - } - n_unaligned = len &3 ; }/* Deal with any bits left over@the end */ -if (n_unaligned) -gfs2_unaligned_extlen (&rbm, n_unaligned, &len); +if (len) +gfs2_unaligned_extlen (&rbm, len, &len); + out:return size - len; }
Signature · 1 line
2.20.1
Andreas Gruenbacher
maintainerPATCH 5/11 gfs2: Only use struct gfs2_rbm for bitmap manipulations
In reply to Andreas GruenbacherGFS2 uses struct gfs2_rbm to represent a filesystem block number as a bit position within a resource group. This representation is used in the bitmap manipulation code to prevent excessive conversions between block numbers and bit positions, but also in struct gfs2_blkreserv which is part of struct gfs2_inode, to mark the start of a reservation. In the inode, the bit position representation makes less sense: first, the start position is used as a block number about as often as a bit position; second, the bit position representation makes the code unnecessarily complicated and difficult to read.
Change struct gfs2_blkreserv to represent the start of a reservation as a block number instead of a bit position. This requires keeping track of the resource group in gfs2_blkreserv separately. With that, struct gfs2_rbm can be moved to rgrp.c.
--- fs/gfs2/bmap.c | 2 +- fs/gfs2/incore.h | 30 +-------- fs/gfs2/rgrp.c | 153 +++++++++++++++++++++++++------------------ fs/gfs2/trace_gfs2.h | 10 +-- fs/gfs2/trans.h | 2 +- 5 files changed, 100 insertions(+), 97 deletions(-)
fs/gfs2/bmap.c +1 -1
@@ -1498,7 +1498,7 @@ static int sweep_bh_for_rgrps(struct gfs2_inode *ip, struct gfs2_holder *rd_gh,/* Must be done with the rgrp glock held: */ if (gfs2_rs_active (&ip->i_res) && - rgd == ip->i_res.rs_rbm.rgd) + rgd == ip->i_res.rs_rgd)gfs2_rs_deltree (&ip->i_res); }
fs/gfs2/incore.h +3 -27
@@ -124,31 +124,6 @@ struct gfs2_rgrpd {struct rb_root rd_rstree;/* multi-block reservation tree */ }; -struct gfs2_rbm { -struct gfs2_rgrpd *rgd; -u32 offset;/* The offset is bitmap relative */ -int bii;/* Bitmap index */ -}; - -static inline struct gfs2_bitmap *rbm_bi (const struct gfs2_rbm *rbm) -{ -return rbm->rgd->rd_bits + rbm->bii; -} - -static inline u64 gfs2_rbm_to_block (const struct gfs2_rbm *rbm) -{ -BUG_ON (rbm->offset >= rbm->rgd->rd_data); -return rbm->rgd->rd_data0 + (rbm_bi (rbm)->bi_start *GFS2_NBBY ) + - rbm->offset; -} - -static inline bool gfs2_rbm_eq (const struct gfs2_rbm *rbm1, -const struct gfs2_rbm *rbm2) -{ -return (rbm1->rgd == rbm2->rgd) && (rbm1->bii == rbm2->bii) && - (rbm1->offset == rbm2->offset); -} -enum gfs2_state_bits { BH_Pinned = BH_PrivateStart, BH_Escaped = BH_PrivateStart +1 ,
@@ -308,8 +283,9 @@ struct gfs2_qadata { /* quota allocation data */*/ struct gfs2_blkreserv { -struct rb_node rs_node;/* link to other block reservations */ -struct gfs2_rbm rs_rbm;/* Start of reservation */ +struct rb_node rs_node;/* node within rd_rstree */ +struct gfs2_rgrpd *rs_rgd; +u64 rs_start;/* start of reservation */ u32 rs_free;/* how many blocks are still free */ };
fs/gfs2/rgrp.c +90 -63
351 lines not on this page · raw message
fs/gfs2/trace_gfs2.h +5 -5
@@ -602,13 +602,13 @@ TRACE_EVENT(gfs2_rs, ), TP_fast_assign( - __entry->dev = rs->rs_rbm.rgd->rd_sbd->sd_vfs->s_dev; - __entry->rd_addr = rs->rs_rbm.rgd->rd_addr; - __entry->rd_free_clone = rs->rs_rbm.rgd->rd_free_clone; - __entry->rd_reserved = rs->rs_rbm.rgd->rd_reserved; + __entry->dev = rs->rs_rgd->rd_sbd->sd_vfs->s_dev; + __entry->rd_addr = rs->rs_rgd->rd_addr; + __entry->rd_free_clone = rs->rs_rgd->rd_free_clone; + __entry->rd_reserved = rs->rs_rgd->rd_reserved; __entry->inum = container_of(rs, struct gfs2_inode, i_res)->i_no_addr; - __entry->start =gfs2_rbm_to_block (&rs->rs_rbm); + __entry->start = rs->rs_start; __entry->free = rs->rs_free; __entry->func = func; ),
fs/gfs2/trans.h +1 -1
@@ -30,7 +30,7 @@ struct gfs2_glock;* block, or all of the blocks in the rg, whichever is smaller */ static inline unsigned int gfs2_rg_blocks (const struct gfs2_inode *ip,unsigned requested) { -struct gfs2_rgrpd *rgd = ip->i_res.rs_rbm.rgd; +struct gfs2_rgrpd *rgd = ip->i_res.rs_rgd;if (requested < rgd->rd_length)return requested +1 ;
Signature · 1 line
2.20.1
Andreas Gruenbacher
maintainerPATCH 6/11 gfs2: Minor gfs2_adjust_reservation and gfs2_alloc_extent cleanups
In reply to Andreas GruenbacherPass the resource group and starting position to gfs2_adjust_reservation directly instead of passing an rbm. With this change, gfs2_alloc_blocks no longer needs the rbm after calling gfs2_alloc_extent, so gfs2_alloc_extent can modify the rbm instead of creating a copy.
--- fs/gfs2/rgrp.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-)
fs/gfs2/rgrp.c +15 -18
@@ -2207,34 +2207,32 @@ void gfs2_inplace_release(struct gfs2_inode *ip)/** * gfs2_alloc_extent - allocate an extent from a given bitmap -* @rbm: the resource group information +* @rbm: The position in the resource group * @dinode: TRUE if the first block we allocate is for a dinode * @n: The extent length (value/result) * +* Side effects: +* - Modifies rbm. +* * Add the bitmap buffer to the transaction. * Set the found bits to @new_state to change block's allocation state. */ -static void gfs2_alloc_extent (const struct gfs2_rbm *rbm,bool dinode, +static void gfs2_alloc_extent (struct gfs2_rbm *rbm,bool dinode,unsigned int *n) { -struct gfs2_rbm pos = { .rgd = rbm->rgd, };const unsigned int elen = *n; -u64 block;int ret; *n =1 ; - block =gfs2_rbm_to_block (rbm);gfs2_trans_add_meta (rbm->rgd->rd_gl,rbm_bi (rbm)->bi_bh);gfs2_setbit (rbm, true, dinode ?GFS2_BLKST_DINODE :GFS2_BLKST_USED ); - block++;while (*n < elen) { - ret =gfs2_rbm_from_block (&pos, block); -if (ret ||gfs2_testbit (&pos, true) !=GFS2_BLKST_FREE ) + ret =gfs2_rbm_incr (rbm); +if (ret ||gfs2_testbit (rbm, true) !=GFS2_BLKST_FREE )break ; -gfs2_trans_add_meta (pos.rgd->rd_gl,rbm_bi (&pos)->bi_bh); -gfs2_setbit (&pos, true,GFS2_BLKST_USED ); +gfs2_trans_add_meta (rbm->rgd->rd_gl,rbm_bi (rbm)->bi_bh); +gfs2_setbit (rbm, true,GFS2_BLKST_USED ); (*n)++; - block++; } }
@@ -2322,7 +2320,8 @@ static void gfs2_rgrp_error(struct gfs2_rgrpd *rgd)/** * gfs2_adjust_reservation - Adjust (or remove) a reservation after allocation * @ip: The inode we have just allocated blocks for -* @rbm: The start of the allocated blocks +* @rgd: The resource group +* @start: The start of the reservation * @len: The extent length * * Adjusts a reservation after an allocation has taken place. If the
@@ -2331,15 +2330,13 @@ static void gfs2_rgrp_error(struct gfs2_rgrpd *rgd)*/ static void gfs2_adjust_reservation (struct gfs2_inode *ip, -const struct gfs2_rbm *rbm,unsigned len) +struct gfs2_rgrpd *rgd, +u64 start,unsigned len) {struct gfs2_blkreserv *rs = &ip->i_res; -struct gfs2_rgrpd *rgd = rbm->rgd;spin_lock (&rgd->rd_rsspin);if (gfs2_rs_active (rs)) { -u64 start =gfs2_rbm_to_block (rbm); -if (rs->rs_start == start) {unsigned int rlen;
@@ -2429,11 +2426,11 @@ int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *nblocks, goto rgrp_error; } -gfs2_alloc_extent (&rbm, dinode, nblocks); block =gfs2_rbm_to_block (&rbm); +gfs2_alloc_extent (&rbm, dinode, nblocks); rbm.rgd->rd_last_alloc = block - rbm.rgd->rd_data0;if (gfs2_rs_active (&ip->i_res)) -gfs2_adjust_reservation (ip, &rbm, *nblocks); +gfs2_adjust_reservation (ip, rbm.rgd, block, *nblocks); ndata = *nblocks;if (dinode) ndata--;
Signature · 1 line
2.20.1
Andreas Gruenbacher
maintainerPATCH 7/11 gfs2: Minor gfs2_rgrp_send_discards cleanup
In reply to Andreas GruenbacherPass the resource group and bitmap index to gfs2_rgrp_send_discards
separately: one of the next patches will remove bi_bh from struct gfs2_bitmap, so we'll need to get it from the resource group in the future.
--- fs/gfs2/lops.c | 3 ++- fs/gfs2/rgrp.c | 11 +++++------ fs/gfs2/rgrp.h | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-)
fs/gfs2/lops.c +2 -1
@@ -81,7 +81,8 @@ static void maybe_release_space(struct gfs2_bufdata *bd)if (bi->bi_clone ==NULL )return ;if (sdp->sd_args.ar_discard) -gfs2_rgrp_send_discards (sdp, rgd->rd_data0, bd->bd_bh, bi,1 ,NULL ); +gfs2_rgrp_send_discards (sdp, rgd->rd_data0, bd->bd_bh, rgd, + index,1 ,NULL );memcpy (bi->bi_clone + bi->bi_offset, bd->bd_bh->b_data + bi->bi_offset, bi->bi_bytes);clear_bit (GBF_FULL , &bi->bi_flags);
fs/gfs2/rgrp.c +5 -6
@@ -1343,10 +1343,10 @@ void gfs2_rgrp_go_unlock(struct gfs2_holder *gh) }int gfs2_rgrp_send_discards (struct gfs2_sbd *sdp,u64 offset, -struct buffer_head *bh, -const struct gfs2_bitmap *bi,unsigned minlen, -u64 *ptrimmed) +struct buffer_head *bh,struct gfs2_rgrpd *rgd, +unsigned int bii,unsigned minlen,u64 *ptrimmed) { +struct gfs2_bitmap *bi = rgd->rd_bits + bii;struct super_block *sb = sdp->sd_vfs;u64 blk;sector_t start =0 ;
@@ -1472,10 +1472,9 @@ int gfs2_fitrim(struct file *filp, void __user *argp)if (!(rgd->rd_flags &GFS2_RGF_TRIMMED )) {/* Trim each bitmap in the rgrp */ for (x =0 ; x < rgd->rd_length; x++) { -struct gfs2_bitmap *bi = rgd->rd_bits + x; ret =gfs2_rgrp_send_discards (sdp, - rgd->rd_data0,NULL , bi, minlen, - &amt); + rgd->rd_data0,NULL , rgd, x, + minlen, &amt);if (ret) {gfs2_glock_dq_uninit (&gh); goto out;
fs/gfs2/rgrp.h +2 -1
@@ -75,7 +75,8 @@ extern u64 gfs2_ri_total(struct gfs2_sbd *sdp);extern void gfs2_rgrp_dump (struct seq_file *seq,struct gfs2_glock *gl);extern int gfs2_rgrp_send_discards (struct gfs2_sbd *sdp,u64 offset,struct buffer_head *bh, -const struct gfs2_bitmap *bi,unsigned minlen,u64 *ptrimmed); +struct gfs2_rgrpd *rgd,unsigned int bii, +unsigned minlen,u64 *ptrimmed);extern int gfs2_fitrim (struct file *filp,void __user *argp);/* This is how to tell if a reservation is in the rgrp tree: */
Signature · 1 line
2.20.1
Andreas Gruenbacher
maintainerPATCH 8/11 gfs2: Add buffer head to struct gfs2_rgrpd
In reply to Andreas GruenbacherPrepare for removing the buffer head from struct gfs2_bitmap by adding a buffer head to struct gfs2_rgrpd for the resource group header.
--- fs/gfs2/incore.h | 1 + fs/gfs2/rgrp.c | 46 +++++++++++++++++++++++++++------------------- 2 files changed, 28 insertions(+), 19 deletions(-)
fs/gfs2/incore.h +1 -0
@@ -99,6 +99,7 @@ struct gfs2_bitmap {struct gfs2_rgrpd {struct rb_node rd_node;/* Link with superblock */ struct gfs2_glock *rd_gl;/* Glock for this rgrp */ +struct buffer_head *rd_bh;u64 rd_addr;/* grp block disk address */ u64 rd_data0;/* first data location */ u32 rd_length;/* length of rgrp header in fs blocks */
fs/gfs2/rgrp.c +27 -19
123 lines not on this page · raw message
Signature · 1 line
2.20.1
Andreas Gruenbacher
maintainerPATCH 9/11 gfs2: Read bitmap buffers on demand
In reply to Andreas GruenbacherBefore this patch, when locking a resource group, gfs2 would read in the resource group header and all the bitmap buffers of the resource group. Those buffers would then be locked into memory until the resource group is unlocked, which will happen when the filesystem is unmounted or when transferring the resource group lock to another node, but not due to memory pressure. Larger resource groups lock more buffers into memory, and cause more unnecessary I/O when resource group locks are transferred between nodes.
With this patch, when locking a resource group, only the resource group header is read in. The other bitmap buffers (the resource group header contains part of the bitmap) are only read in on demand.
It would probably make sense to also only read in the resource group header on demand, when the resource group is modified, but since the header contains the number of free blocks in the resource group, there is a higher incentive to keep the header locked in memory after that.
--- fs/gfs2/incore.h | 1 - fs/gfs2/rgrp.c | 382 ++++++++++++++++++++++++++++++----------------- 2 files changed, 241 insertions(+), 142 deletions(-)
fs/gfs2/incore.h +0 -1
@@ -87,7 +87,6 @@ struct gfs2_log_operations {* be reallocated in that same transaction. */ struct gfs2_bitmap { -struct buffer_head *bi_bh;char *bi_clone;unsigned long bi_flags;u32 bi_offset;
fs/gfs2/rgrp.c +241 -141
736 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 9/11 gfs2: Read bitmap buffers on demand
----- Original Message -----
Quoted 13 lines
Before this patch, when locking a resource group, gfs2 would read in the resource group header and all the bitmap buffers of the resource group. Those buffers would then be locked into memory until the resource group is unlocked, which will happen when the filesystem is unmounted or when transferring the resource group lock to another node, but not due to memory pressure. Larger resource groups lock more buffers into memory, and cause more unnecessary I/O when resource group locks are transferred between nodes.
With this patch, when locking a resource group, only the resource group header is read in. The other bitmap buffers (the resource group header contains part of the bitmap) are only read in on demand.
Quoted 7 lines
It would probably make sense to also only read in the resource group header on demand, when the resource group is modified, but since the header contains the number of free blocks in the resource group, there is a higher incentive to keep the header locked in memory after that.
Signed-off-by Andreas Gruenbacher <[email protected]>---
Hi,
This patch looks good. However, I'm concerned about its performance, at least until we get some bitmap read-ahead in place. (see "/* FIXME: Might want to do read-ahead here. */")
In particular, I'm concerned that it does the exact opposite of this performance enhancement:
So we need to test that 2GB rgrps (33 bitmap blocks) that are fragmented don't have a disproportionate slowdown compared to, say, 128MB rgrps because we end up spending so much time fetching pages out of page cache, only to find them inadequate and doing brelse() again. And by fragmented, I mean all 33 bitmap blocks have a small number of free blocks, thus disqualifying them from having "full" status but still having a large enough number of free blocks that we might consider searching them. Some of the patches we did after that one may have mitigated the problem to some extent, but we need to be sure we're not regressing performance.
Regards,
Bob Peterson
Andreas Gruenbacher
maintainerPATCH 9/11 gfs2: Read bitmap buffers on demand
Bob,
Quoted 33 lines · Bob Peterson
----- Original Message -----
Quoted 13 lines
Before this patch, when locking a resource group, gfs2 would read in the resource group header and all the bitmap buffers of the resource group. Those buffers would then be locked into memory until the resource group is unlocked, which will happen when the filesystem is unmounted or when transferring the resource group lock to another node, but not due to memory pressure. Larger resource groups lock more buffers into memory, and cause more unnecessary I/O when resource group locks are transferred between nodes.
With this patch, when locking a resource group, only the resource group header is read in. The other bitmap buffers (the resource group header contains part of the bitmap) are only read in on demand.
Quoted 7 lines
It would probably make sense to also only read in the resource group header on demand, when the resource group is modified, but since the header contains the number of free blocks in the resource group, there is a higher incentive to keep the header locked in memory after that.
Signed-off-by Andreas Gruenbacher <[email protected]>---
Hi,
This patch looks good. However, I'm concerned about its performance, at least until we get some bitmap read-ahead in place. (see "/* FIXME: Might want to do read-ahead here. */")
In particular, I'm concerned that it does the exact opposite of this performance enhancement:
Quoted 9 lines
So we need to test that 2GB rgrps (33 bitmap blocks) that are fragmented don't have a disproportionate slowdown compared to, say, 128MB rgrps because we end up spending so much time fetching pages out of page cache, only to find them inadequate and doing
brelse()again. And by fragmented, I mean all 33 bitmap blocks have a small number of free blocks, thus disqualifying them from having "full" status but still having a large enough number of free blocks that we might consider searching them. Some of the patches we did after that one may have mitigated the problem to some extent, but we need to be sure we're not regressing performance.
Yes, there are a few ways this patch can still be tuned depending on the performance impact. This should speed up "normal" workloads by requiring fewer reads from disk when acquiring a resource group glock, and less memory is pinned for filesystem metadata, but we do end up with more page cache lookups during allocations, and depending on read-ahead, possibly more smaller reads at inconvenient times.
rd_last_alloc should help limit the performance impact when bitmaps become mostly full. (Forms of rd_last_alloc have been in gfs2 since the mainline merge.)
One way to further reduce the number of page cache lookups would be to cache the buffer head of the last allocation, but it's unclear if this is even an issue, so let's do some performance testing first.
Thanks,
Andreas
Andreas Gruenbacher
maintainerPATCH 9/11 gfs2: Read bitmap buffers on demand
Quoted 54 lines · Andreas Gruenbacher
Bob,
Quoted 33 lines · Bob Peterson
----- Original Message -----
Quoted 13 lines
Before this patch, when locking a resource group, gfs2 would read in the resource group header and all the bitmap buffers of the resource group. Those buffers would then be locked into memory until the resource group is unlocked, which will happen when the filesystem is unmounted or when transferring the resource group lock to another node, but not due to memory pressure. Larger resource groups lock more buffers into memory, and cause more unnecessary I/O when resource group locks are transferred between nodes.
With this patch, when locking a resource group, only the resource group header is read in. The other bitmap buffers (the resource group header contains part of the bitmap) are only read in on demand.
Quoted 7 lines
It would probably make sense to also only read in the resource group header on demand, when the resource group is modified, but since the header contains the number of free blocks in the resource group, there is a higher incentive to keep the header locked in memory after that.
Signed-off-by Andreas Gruenbacher <[email protected]>---
Hi,
This patch looks good. However, I'm concerned about its performance, at least until we get some bitmap read-ahead in place. (see "/* FIXME: Might want to do read-ahead here. */")
In particular, I'm concerned that it does the exact opposite of this performance enhancement:
Quoted 9 lines
So we need to test that 2GB rgrps (33 bitmap blocks) that are fragmented don't have a disproportionate slowdown compared to, say, 128MB rgrps because we end up spending so much time fetching pages out of page cache, only to find them inadequate and doing
brelse()again. And by fragmented, I mean all 33 bitmap blocks have a small number of free blocks, thus disqualifying them from having "full" status but still having a large enough number of free blocks that we might consider searching them. Some of the patches we did after that one may have mitigated the problem to some extent, but we need to be sure we're not regressing performance.Yes, there are a few ways this patch can still be tuned depending on the performance impact. This should speed up "normal" workloads by requiring fewer reads from disk when acquiring a resource group glock, and less memory is pinned for filesystem metadata, but we do end up with more page cache lookups during allocations, and depending on read-ahead, possibly more smaller reads at inconvenient times.
Quoted 3 lines
rd_last_allocshould help limit the performance impact when bitmaps become mostly full. (Forms ofrd_last_allochave been in gfs2 since the mainline merge.)
Hmm, rd_extfail_pt actually, not rd_last_alloc, and that predates the optimization in commit 39b0f1e929 by less than two years.
Quoted 3 lines
One way to further reduce the number of page cache lookups would be to cache the buffer head of the last allocation, but it's unclear if this is even an issue, so let's do some performance testing first.
Andreas
Andreas Gruenbacher
maintainerPATCH 10/11 gfs2: Clean up assertion, consistency check, and error reporting functions
In reply to Andreas GruenbacherInstead of passing the __func__, __FILE__, and __LINE__ pre-processor macros to each of those functions, print the location of the caller via:
printk(%pS", (void *)_RET_IP_).
This gives enough context information to locate where in the code an error occurred, and reduces the code size by about 2 percent.
--- fs/gfs2/util.c | 107 ++++++++++++++++++++----------------------------- fs/gfs2/util.h | 71 +++++++++----------------------- 2 files changed, 62 insertions(+), 116 deletions(-)
fs/gfs2/util.c +44 -63
@@ -88,14 +88,12 @@ int gfs2_lm_withdraw(struct gfs2_sbd *sdp, const char *fmt, ...)* -2 if it was already withdrawn */ -int gfs2_assert_withdraw_i (struct gfs2_sbd *sdp,char *assertion, -const char *function,char *file,unsigned int line) +int gfs2_assert_withdraw_i (struct gfs2_sbd *sdp,char *assertion) {int me; me =gfs2_lm_withdraw (sdp, -"fatal: assertion \"%s\" failed\n" -" function = %s, file = %s, line = %u\n" , - assertion, function, file, line); +"fatal: assertion \"%s\" failed at %pS\n" , + assertion, (void *)_RET_IP_);dump_stack ();return (me) ?-1 :-2 ; }
@@ -106,8 +104,7 @@ int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion,* -2 if we didn't */ -int gfs2_assert_warn_i (struct gfs2_sbd *sdp,char *assertion, -const char *function,char *file,unsigned int line) +int gfs2_assert_warn_i (struct gfs2_sbd *sdp,char *assertion) { if (time_before(jiffies, sdp->sd_last_warning +
@@ -115,8 +112,8 @@ int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,return -2 ;if (sdp->sd_args.ar_errors ==GFS2_ERRORS_WITHDRAW ) -fs_warn (sdp,"warning: assertion \"%s\" failed at function = %s, file = %s, line = %u\n" , - assertion, function, file, line); +fs_warn (sdp,"warning: assertion \"%s\" failed at %pS\n" , + assertion, (void *)_RET_IP_);if (sdp->sd_args.ar_debug)BUG ();
@@ -124,10 +121,8 @@ int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,dump_stack ();if (sdp->sd_args.ar_errors ==GFS2_ERRORS_PANIC ) -panic ("GFS2: fsid=%s: warning: assertion \"%s\" failed\n" -"GFS2: fsid=%s: function = %s, file = %s, line = %u\n" , - sdp->sd_fsname, assertion, - sdp->sd_fsname, function, file, line); +panic ("GFS2: fsid=%s: warning: assertion \"%s\" failed at %pS\n" , + sdp->sd_fsname, assertion, (void *)_RET_IP_); sdp->sd_last_warning = jiffies;
@@ -135,61 +130,56 @@ int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion, }/** -* gfs2_consist_i - Flag a filesystem consistency error and withdraw +* gfs2_consist - Flag a filesystem consistency error and withdraw * Returns: -1 if this call withdrew the machine, * 0 if it was already withdrawn */ -int gfs2_consist_i (struct gfs2_sbd *sdp,int cluster_wide,const char *function, -char *file,unsigned int line) +int gfs2_consist (struct gfs2_sbd *sdp) {int rv; rv =gfs2_lm_withdraw (sdp, -"fatal: filesystem consistency error - function = %s, file = %s, line = %u\n" , - function, file, line); +"fatal: filesystem consistency error at %pS\n" , + (void *)_RET_IP_);return rv; }/** -* gfs2_consist_inode_i - Flag an inode consistency error and withdraw +* gfs2_consist_inode - Flag an inode consistency error and withdraw * Returns: -1 if this call withdrew the machine, * 0 if it was already withdrawn */ -int gfs2_consist_inode_i (struct gfs2_inode *ip,int cluster_wide, -const char *function,char *file,unsigned int line) +int gfs2_consist_inode (struct gfs2_inode *ip) {struct gfs2_sbd *sdp =GFS2_SB (&ip->i_inode);int rv; rv =gfs2_lm_withdraw (sdp, -"fatal: filesystem consistency error\n" -" inode = %llu %llu\n" -" function = %s, file = %s, line = %u\n" , +"fatal: filesystem consistency error at %pS\n" +" inode = %llu %llu\n" , + (void *)_RET_IP_, (unsigned long long )ip->i_no_formal_ino, - (unsigned long long )ip->i_no_addr, - function, file, line); + (unsigned long long )ip->i_no_addr);return rv; }/** -* gfs2_consist_rgrpd_i - Flag a RG consistency error and withdraw +* gfs2_consist_rgrpd - Flag a RG consistency error and withdraw * Returns: -1 if this call withdrew the machine, * 0 if it was already withdrawn */ -int gfs2_consist_rgrpd_i (struct gfs2_rgrpd *rgd,int cluster_wide, -const char *function,char *file,unsigned int line) +int gfs2_consist_rgrpd (struct gfs2_rgrpd *rgd) {struct gfs2_sbd *sdp = rgd->rd_sbd;int rv;gfs2_rgrp_dump (NULL , rgd->rd_gl); rv =gfs2_lm_withdraw (sdp, -"fatal: filesystem consistency error\n" -" RG = %llu\n" -" function = %s, file = %s, line = %u\n" , - (unsigned long long )rgd->rd_addr, - function, file, line); +"fatal: filesystem consistency error at %pS\n" +" RG = %llu\n" , + (void *)_RET_IP_, + (unsigned long long )rgd->rd_addr);return rv; }
@@ -200,16 +190,14 @@ int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide,*/ int gfs2_meta_check_ii (struct gfs2_sbd *sdp,struct buffer_head *bh, -const char *type,const char *function,char *file, -unsigned int line) +const char *type,void *caller) {int me; me =gfs2_lm_withdraw (sdp, -"fatal: invalid metadata block\n" -" bh = %llu (%s)\n" -" function = %s, file = %s, line = %u\n" , - (unsigned long long )bh->b_blocknr, type, - function, file, line); +"fatal: invalid metadata block at %pS\n" +" bh = %llu (%s)\n" , + caller, + (unsigned long long )bh->b_blocknr, type);return (me) ?-1 :-2 ; }
@@ -220,53 +208,46 @@ int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,*/ int gfs2_metatype_check_ii (struct gfs2_sbd *sdp,struct buffer_head *bh, -u16 type,u16 t,const char *function, -char *file,unsigned int line) +u16 type,u16 t,void *caller) {int me; me =gfs2_lm_withdraw (sdp, -"fatal: invalid metadata block\n" -" bh = %llu (type: exp=%u, found=%u)\n" -" function = %s, file = %s, line = %u\n" , - (unsigned long long )bh->b_blocknr, type, t, - function, file, line); +"fatal: invalid metadata block at %pS\n" +" bh = %llu (type: exp=%u, found=%u)\n" , + caller, + (unsigned long long )bh->b_blocknr, type, t);return (me) ?-1 :-2 ; }/** -* gfs2_io_error_i - Flag an I/O error and withdraw +* gfs2_io_error - Flag an I/O error and withdraw * Returns: -1 if this call withdrew the machine, * 0 if it was already withdrawn */ -int gfs2_io_error_i (struct gfs2_sbd *sdp,const char *function,char *file, -unsigned int line) +int gfs2_io_error (struct gfs2_sbd *sdp) {int rv; rv =gfs2_lm_withdraw (sdp, -"fatal: I/O error\n" -" function = %s, file = %s, line = %u\n" , - function, file, line); +"fatal: I/O error at %pS\n" , + (void *)_RET_IP_);return rv; }/** -* gfs2_io_error_bh_i - Flag a buffer I/O error +* gfs2_io_error_bh - Flag a buffer I/O error * @withdraw: withdraw the filesystem */ -void gfs2_io_error_bh_i (struct gfs2_sbd *sdp,struct buffer_head *bh, -const char *function,char *file,unsigned int line, +void __gfs2_io_error_bh (struct gfs2_sbd *sdp,struct buffer_head *bh,bool withdraw) {if (!test_bit (SDF_SHUTDOWN , &sdp->sd_flags))fs_err (sdp, -"fatal: I/O error\n" -" block = %llu\n" -" function = %s, file = %s, line = %u\n" , - (unsigned long long )bh->b_blocknr, - function, file, line); +"fatal: I/O error at %pS\n" +" block = %llu\n" , + (void *)_RET_IP_, + (unsigned long long )bh->b_blocknr);if (withdraw)gfs2_lm_withdraw (sdp,NULL ); } -
fs/gfs2/util.h +18 -53
116 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 10/11 gfs2: Clean up assertion, consistency check, and error reporting functions
----- Original Message -----
Quoted 11 lines
Instead of passing the
__func__,__FILE__, and__LINE__pre-processor macros to
each of those functions, print the location of the caller via:
printk(%pS", (void *)_RET_IP_).This gives enough context information to locate where in the code an error occurred, and reduces the code size by about 2 percent.
Signed-off-by Andreas Gruenbacher <[email protected]>---
Hi,
Sorry, but I don't like this patch at all.
With all the different versions floating around, and further obscured by static function optimization by the compiler, this patch just makes debugging harder. Not impossible, but harder.
In other words, in my opinion, the benefit is not worth the cost.
Plus it has nothing to do with making the rgrp bitmaps read in on-demand.
Regards,
Bob Peterson
Andreas Gruenbacher
maintainerPATCH 11/11 gfs2: Skip gfs2_metatype_check for cached buffers
In reply to Andreas GruenbacherWhen reading in buffers from disk, set a new BH_Verify buffer head flag. In gfs2_metatype_check, skip the check if BH_Verify is cleared and clear the flag when checking. That way, we'll only check the metatype once when reading buffers from disk, and not when the buffers were already in the page cache.
While touching this code, convert two 'be32_to_cpu(magic) == GFS2_MAGIC' checks into 'magic == cpu_to_be32(GFS2_MAGIC)'.
--- fs/gfs2/incore.h | 5 ++++- fs/gfs2/meta_io.c | 10 ++++++++-- fs/gfs2/util.c | 31 ++++++++++++++++++++++++------- fs/gfs2/util.h | 24 ++++++------------------ 4 files changed, 42 insertions(+), 28 deletions(-)
fs/gfs2/incore.h +4 -1
@@ -126,13 +126,16 @@ struct gfs2_rgrpd {enum gfs2_state_bits { BH_Pinned = BH_PrivateStart, - BH_Escaped = BH_PrivateStart +1 , + BH_Escaped, + BH_Verify }; BUFFER_FNS(Pinned, pinned) TAS_BUFFER_FNS(Pinned, pinned) BUFFER_FNS(Escaped, escaped) TAS_BUFFER_FNS(Escaped, escaped) +BUFFER_FNS(Verify, verify) +TAS_BUFFER_FNS(Verify, verify)struct gfs2_bufdata {struct buffer_head *bd_bh;
fs/gfs2/meta_io.c +8 -2
@@ -268,6 +268,7 @@ int gfs2_meta_read(struct gfs2_glock *gl, u64 blkno, int flags, }else { bh->b_end_io = end_buffer_read_sync;get_bh (bh); +set_buffer_verify (bh); bhs[num++] = bh; }
@@ -280,6 +281,7 @@ int gfs2_meta_read(struct gfs2_glock *gl, u64 blkno, int flags,brelse (bh); }else { bh->b_end_io = end_buffer_read_sync; +set_buffer_verify (bh); bhs[num++] = bh; } }
@@ -452,8 +454,10 @@ struct buffer_head *gfs2_meta_ra(struct gfs2_glock *gl, u64 dblock, u32 extlen)if (buffer_uptodate (first_bh)) goto out; -if (!buffer_locked (first_bh)) +if (!buffer_locked (first_bh)) { +set_buffer_verify (first_bh);ll_rw_block (REQ_OP_READ ,REQ_META |REQ_PRIO ,1 , &first_bh); + } dblock++; extlen--;
@@ -461,10 +465,12 @@ struct buffer_head *gfs2_meta_ra(struct gfs2_glock *gl, u64 dblock, u32 extlen)while (extlen) { bh =gfs2_getbuf (gl, dblock,CREATE ); -if (!buffer_uptodate (bh) && !buffer_locked (bh)) +if (!buffer_uptodate (bh) && !buffer_locked (bh)) { +set_buffer_verify (bh);ll_rw_block (REQ_OP_READ ,REQ_RAHEAD |REQ_META |REQ_PRIO ,1 , &bh); + }brelse (bh); dblock++; extlen--;
fs/gfs2/util.c +24 -7
@@ -202,20 +202,37 @@ int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, }/** -* gfs2_metatype_check_ii - Flag a metadata type consistency error and withdraw +* gfs2_metatype_check_ii - Check the metadata type of a block +* +* Report and withdraw on inconsistencies. +* * Returns: -1 if this call withdrew the machine, * -2 if it was already withdrawn */ int gfs2_metatype_check_ii (struct gfs2_sbd *sdp,struct buffer_head *bh, -u16 type,u16 t,void *caller) +u16 type,void *caller) { +struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data;int me; - me =gfs2_lm_withdraw (sdp, -"fatal: invalid metadata block at %pS\n" -" bh = %llu (type: exp=%u, found=%u)\n" , - caller, - (unsigned long long )bh->b_blocknr, type, t); + +clear_buffer_verify (bh); + +if (unlikely (mh->mh_magic !=cpu_to_be32 (GFS2_MAGIC ))) { + me =gfs2_lm_withdraw (sdp, +"fatal: invalid metadata block at %pS\n" +" bh = %llu (magic number)\n" , + caller, + (unsigned long long )bh->b_blocknr); + }else if (unlikely (be32_to_cpu (mh->mh_type) != type)) { + me =gfs2_lm_withdraw (sdp, +"fatal: invalid metadata block at %pS\n" +" bh = %llu (type: exp=%u, found=%u)\n" , + caller, + (unsigned long long )bh->b_blocknr, type, +be32_to_cpu (mh->mh_type)); + }else +return 0 ;return (me) ?-1 :-2 ; }
fs/gfs2/util.h +6 -18
@@ -55,15 +55,11 @@ int gfs2_consist(struct gfs2_sbd *sdp);int gfs2_consist_inode (struct gfs2_inode *ip);int gfs2_consist_rgrpd (struct gfs2_rgrpd *rgd); -int gfs2_meta_check_ii (struct gfs2_sbd *sdp,struct buffer_head *bh, -const char *type,void *caller); -static inline int gfs2_meta_check (struct gfs2_sbd *sdp,struct buffer_head *bh) {struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data; -u32 magic =be32_to_cpu (mh->mh_magic); -if (unlikely (magic !=GFS2_MAGIC )) { +if (unlikely (mh->mh_magic !=cpu_to_be32 (GFS2_MAGIC ))) {fs_err (sdp,"Magic number missing at %llu\n" , (unsigned long long )bh->b_blocknr);return -EIO ;
@@ -72,22 +68,14 @@ static inline int gfs2_meta_check(struct gfs2_sbd *sdp, }int gfs2_metatype_check_ii (struct gfs2_sbd *sdp,struct buffer_head *bh, -u16 type,u16 t, -void *caller); +u16 type,void *caller);static inline int gfs2_metatype_check (struct gfs2_sbd *sdp, -struct buffer_head *bh, -u16 type) +struct buffer_head *bh,u16 type) { -struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data; -u32 magic =be32_to_cpu (mh->mh_magic); -u16 t =be32_to_cpu (mh->mh_type); -if (unlikely (magic !=GFS2_MAGIC )) -return gfs2_meta_check_ii (sdp, bh,"magic number" , (void *)_RET_IP_); -if (unlikely (t != type)) -return gfs2_metatype_check_ii (sdp, bh, type, t, - (void *)_RET_IP_); -return 0 ; +if (!buffer_verify (bh)) +return 0 ; +return gfs2_metatype_check_ii (sdp, bh, type, (void *)_RET_IP_); } static inline void gfs2_metatype_set(struct buffer_head *bh, u16 type,
Signature · 1 line
2.20.1
PATCH 11/11 gfs2: Skip gfs2_metatype_check for cached buffers
----- Original Message -----
Quoted 12 lines
When reading in buffers from disk, set a new
BH_Verifybuffer head flag. Ingfs2_metatype_check, skip the check ifBH_Verifyis cleared and clear the flag
when checking. That way, we'll only check the metatype once when reading buffers from disk, and not when the buffers were already in the page cache.While touching this code, convert two '
be32_to_cpu(magic)==GFS2_MAGIC' checks
into 'magic ==cpu_to_be32(GFS2_MAGIC)'.Signed-off-by Andreas Gruenbacher <[email protected]>---
(snip)
Quoted 7 lines
static inline int gfs2_metatype_check(struct
gfs2_sbd*sdp,fs/gfs2/util.h +1
-4- struct buffer_head *bh, - u16 type) + struct buffer_head *bh, u16 type) { -struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data; -u32 magic =be32_to_cpu (mh->mh_magic);
fs/gfs2/util.h static inline int gfs2_meta_check(struct gfs2_sbd *sdp, · line 78
Quoted 10 lines
fs/gfs2/util.h +3
-7-u16 t =be32_to_cpu (mh->mh_type); -if (unlikely (magic !=GFS2_MAGIC )) -return gfs2_meta_check_ii (sdp, bh,"magic number" , (void *)_RET_IP_); -if (unlikely (t != type)) -return gfs2_metatype_check_ii (sdp, bh, type, t, - (void *)_RET_IP_); -return 0 ; +if (!buffer_verify (bh)) +return 0 ; +return gfs2_metatype_check_ii (sdp, bh, type, (void *)_RET_IP_);
May I suggest simplifying with:
if (!test_clear_buffer_verify(bh))
return 0;
Regards,
Bob Peterson