[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Cluster-devel] [GFS2 PATCH TRY2] GFS2: split function rgblk_search



Hi,

On Fri, 2011-11-18 at 13:15 -0500, Bob Peterson wrote:
> ----- Original Message -----
> | Hi,
> | 
> | On Wed, 2011-11-16 at 14:59 -0500, Bob Peterson wrote:
> | > ----- Original Message -----
> | > | Hi,
> | > | 
> | > | As a follow up to this patch, I'd quite like to see rgblk_search
> | > | split
> | > | into two functions. One to do the search and another to actually
> | > | make
> | > | changes to the bitmap when a block is found. That should help
> | > | development of further alloc changes on top.
> | > 
> | > Hi,
> | > 
> | > So something like the patch that follows?
> | > 
> | > This patch splits function rgblk_search into two functions:
> | > the finding and the bit setting function, now called
> | > gfs2_alloc_extent.
> | > 
> | Yes, but lets make gfs2_alloc_extent() a totally separate function
> | and
> | not call it from rgblk_search, that way when looking for unlinked
> | inodes
> | we don't need to care about gfs2_alloc_extent at all. The only issue
> | is
> | passing a couple of things from rgblk_search to gfs2_alloc_extent
> | (the
> | bi (either by index or by pointer) and the current position in the
> | bitmap.
> | 
> | However my thought was to separate these two completely rather than
> | leaving one calling the other,
> | 
> | Steve.
> 
> Hi,
> 
> This is another revision of a previously posted patch based on Steve's
> suggestions. The idea here is to split function rgblk_search into two
> functions: one to search for a block in the proper state and another
> to assign multiple blocks starting at that location.
> 
> Splitting the two allowed for some code optimizations.
> 
> Regards,
> 
> Bob Peterson
> Red Hat File Systems
> 
> Signed-off-by: Bob Peterson <rpeterso redhat com> 
> --
> GFS2: split function rgblk_search
> 
> This patch splits function rgblk_search into a function that finds
> blocks to allocate (rgblk_search) and a function that assigns those
> blocks (gfs2_alloc_extent).
> 
> diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
> index b8935af..8f87cd0 100644
> --- a/fs/gfs2/rgrp.c
> +++ b/fs/gfs2/rgrp.c
> @@ -65,8 +65,8 @@ static const char valid_change[16] = {
>  };
>  
>  static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal,
> -                        unsigned char old_state, bool dinode,
> -			unsigned int *ndata);
> +			unsigned char old_state, bool dinode,
> +			struct gfs2_bitmap **rbi);
>  
>  /**
>   * gfs2_setbit - Set a bit in the bitmaps
> @@ -912,19 +912,20 @@ static void try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, u64 skip
>  	u32 goal = 0, block;
>  	u64 no_addr;
>  	struct gfs2_sbd *sdp = rgd->rd_sbd;
> -	unsigned int n;
>  	struct gfs2_glock *gl;
>  	struct gfs2_inode *ip;
>  	int error;
>  	int found = 0;
> +	struct gfs2_bitmap *bi;
>  
>  	while (goal < rgd->rd_data) {
>  		down_write(&sdp->sd_log_flush_lock);
> -		n = 1;
> -		block = rgblk_search(rgd, goal, GFS2_BLKST_UNLINKED, 0, &n);
> +		block = rgblk_search(rgd, goal, GFS2_BLKST_UNLINKED, 0, &bi);
>  		up_write(&sdp->sd_log_flush_lock);
>  		if (block == BFITNOENT)
>  			break;
> +
> +		block = GFS2_BI2RGD_BLK(bi, block);
>  		/* rgblk_search can return a block < goal, so we need to
>  		   keep it marching forward. */
>  		no_addr = block + rgd->rd_data0;
> @@ -1109,38 +1110,35 @@ static unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, u64 block)
>  }
>  
>  /**
> - * rgblk_search - find a block in @old_state, change allocation
> - *           state to @new_state
> + * rgblk_search - find a block in @old_state
>   * @rgd: the resource group descriptor
>   * @goal: the goal block within the RG (start here to search for avail block)
>   * @old_state: GFS2_BLKST_XXX the before-allocation state to find
>   * @dinode: TRUE if the first block we allocate is for a dinode
> - * @n: The extent length
> + * @rbi: address of the pointer to the bitmap containing the block found
>   *
>   * Walk rgrp's bitmap to find bits that represent a block in @old_state.
> - * Add the found bitmap buffer to the transaction.
> - * Set the found bits to @new_state to change block's allocation state.
>   *
>   * This function never fails, because we wouldn't call it unless we
>   * know (from reservation results, etc.) that a block is available.
>   *
> - * Scope of @goal and returned block is just within rgrp, not the whole
> - * filesystem.
> + * Scope of @goal is just within rgrp, not the whole filesystem.
> + * Scope of @returned block is just within bitmap, not the whole filesystem.
>   *
> - * Returns:  the block number allocated
> + * Returns: the block number found relative to the bitmap rbi
>   */
>  
>  static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal,
> -			unsigned char old_state, bool dinode, unsigned int *n)
> +			unsigned char old_state, bool dinode,
> +			struct gfs2_bitmap **rbi)
>  {
>  	struct gfs2_bitmap *bi = NULL;
>  	const u32 length = rgd->rd_length;
>  	u32 blk = BFITNOENT;
>  	unsigned int buf, x;
> -	const unsigned int elen = *n;
>  	const u8 *buffer = NULL;
>  
> -	*n = 0;
> +	*rbi = NULL;
>  	/* Find bitmap block that contains bits for goal block */
>  	for (buf = 0; buf < length; buf++) {
>  		bi = rgd->rd_bits + buf;
> @@ -1187,12 +1185,31 @@ skip:
>  		goal = 0;
>  	}
>  
> -	if (blk == BFITNOENT)
> -		return blk;
> +	if (blk != BFITNOENT)
> +		*rbi = bi;
> +
Since bi is set to NULL above, this could presumably be unconditional

> +	return blk;
> +}
>  
> -	if (old_state == GFS2_BLKST_UNLINKED)
> -		goto out;
> +/**
> + * gfs2_alloc_extent - allocate an extent from a given bitmap
> + * @rgd: the resource group descriptor
> + * @bi: the bitmap within the rgrp
> + * @blk: the block within the bitmap
> + * @dinode: TRUE if the first block we allocate is for a dinode
> + * @n: The extent length
> + *
> + * Add the found bitmap buffer to the transaction.
> + * Set the found bits to @new_state to change block's allocation state.
> + */
> +static void gfs2_alloc_extent(struct gfs2_rgrpd *rgd, struct gfs2_bitmap *bi,
> +			      u32 blk, bool dinode, unsigned int *n)
> +{
> +	const unsigned int elen = *n;
> +	u32 goal;
> +	const u8 *buffer = NULL;
>  
> +	buffer = bi->bi_bh->b_data + bi->bi_offset;
>  	gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1);
>  	gfs2_setbit(rgd, bi->bi_bh->b_data, bi->bi_clone, bi->bi_offset,
>  		    bi, blk, dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED);
> @@ -1210,8 +1227,6 @@ skip:
>  			    bi, goal, GFS2_BLKST_USED);
>  		(*n)++;
>  	}
> -out:
> -	return (bi->bi_start * GFS2_NBBY) + blk;
>  }
>  
>  /**
> @@ -1319,6 +1334,7 @@ int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *ndata,
>  	u32 goal, extlen, blk; /* block, within the rgrp scope */
>  	u64 block; /* block, within the file system scope */
>  	int error;
> +	struct gfs2_bitmap *bi;
>  
>  	/* Only happens if there is a bug in gfs2, return something distinctive
>  	 * to ensure that it is noticed.
> @@ -1333,12 +1349,16 @@ int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *ndata,
>  	else
>  		goal = rgd->rd_last_alloc;
>  
> -	blk = rgblk_search(rgd, goal, GFS2_BLKST_FREE, dinode, ndata);
> +	blk = rgblk_search(rgd, goal, GFS2_BLKST_FREE, dinode, &bi);
>  
> +	*ndata = 0;
>  	/* Since all blocks are reserved in advance, this shouldn't happen */
>  	if (blk == BFITNOENT)
>  		goto rgrp_error;
>  
> +	gfs2_alloc_extent(rgd, bi, blk, dinode, ndata);
> +
> +	blk = GFS2_BI2RGD_BLK(bi, blk);
>  	rgd->rd_last_alloc = blk;
>  	block = rgd->rd_data0 + blk;
If rd_last_alloc was set in gfs2_alloc_extent() then it could be set
(correctly) to the end of the extent, and not the beginning. Also
gfs2_alloc_extent could then return the starting block of the extent, so
these lines would just become:

block = gfs2_alloc_extent(rgd, bi, blk, dinode, ndata);

which would be a bit neater.

>  	if (!dinode) {
> diff --git a/fs/gfs2/rgrp.h b/fs/gfs2/rgrp.h
> index b3b61b8..aacb3fd 100644
> --- a/fs/gfs2/rgrp.h
> +++ b/fs/gfs2/rgrp.h
> @@ -12,6 +12,8 @@
>  
>  #include <linux/slab.h>
>  
> +#define GFS2_BI2RGD_BLK(bi, blk) (bi->bi_start * GFS2_NBBY) + blk
> +

Could you make this an inline function in rgrp.c, since it is not needed
outside of that file? A macro written like this can potentially have
some nasty side effects, as there are not enough brackets in the
expression,

Steve.


>  struct gfs2_rgrpd;
>  struct gfs2_sbd;
>  struct gfs2_holder;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]