Re: [PATCH 1/3] bcache: add dirty_data in struct bcache_device

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

 



On Mon, Dec 12, 2022 at 11:20:48AM +0800, mingzhe.zou@xxxxxxxxxxxx wrote:
> From: mingzhe <mingzhe.zou@xxxxxxxxxxxx>
> 
> Currently, the dirty_data of cached_dev and flash_dev depend on the stripe.
> 
> Since the flash device supports resize, it may cause a bug (resize the flash
> from 1T to 2T, and nr_stripes from 1 to 2).
> 
> The patch add dirty_data in struct bcache_device, we can get the value of
> dirty_data quickly and fixes the bug of resize flash device.
> 
> Signed-off-by: mingzhe <mingzhe.zou@xxxxxxxxxxxx>
> ---
>  drivers/md/bcache/bcache.h    | 1 +
>  drivers/md/bcache/writeback.c | 2 ++
>  drivers/md/bcache/writeback.h | 7 +------
>  3 files changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h
> index 621a2ae1767b..5da991505b45 100644
> --- a/drivers/md/bcache/bcache.h
> +++ b/drivers/md/bcache/bcache.h
> @@ -268,6 +268,7 @@ struct bcache_device {
>  	unsigned int		stripe_size;
>  	atomic_t		*stripe_sectors_dirty;
>  	unsigned long		*full_dirty_stripes;
> +	atomic_long_t		dirty_sectors;
>  
>  	struct bio_set		bio_split;
>  
> diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c
> index f21295dea71b..7b5009e8b4ff 100644
> --- a/drivers/md/bcache/writeback.c
> +++ b/drivers/md/bcache/writeback.c
> @@ -769,6 +769,8 @@ void bcache_dev_sectors_dirty_add(struct cache_set *c, unsigned int inode,
>  	if (stripe < 0)
>  		return;
>  
> +	atomic_long_add(nr_sectors, &d->dirty_sectors);
> +
>  	if (UUID_FLASH_ONLY(&c->uuids[inode]))
>  		atomic_long_add(nr_sectors, &c->flash_dev_dirty_sectors);
> 

Indeed, if the bcache device is a flash only volume, all the rested code since
here to the end of bcache_dev_sectors_dirty_add() can be ignored. Setting
stripe_sectors_dirty and full_dirty_stripes is for writeback related stuffs,
for flsh only device there is no writeback.

And then you may add atomic_long_add(nr_sectors, &d->dirty_sectors) after
atomic_long_add(nr_sectors, &c->flash_dev_dirty_sectors). After this, for
flash only device, its stripe_sectors_dirty and full_dirty_stripes can be
always 0, and its dirty sectors are counted in flash_dev_dirty_sectors.

Yes current code still allocate memory for stripes counter when it is flash
only device. I will fix this firstly.

 
> diff --git a/drivers/md/bcache/writeback.h b/drivers/md/bcache/writeback.h
> index 7e5a2fe03429..12765c0dfd5c 100644
> --- a/drivers/md/bcache/writeback.h
> +++ b/drivers/md/bcache/writeback.h
> @@ -56,12 +56,7 @@ struct bch_dirty_init_state {
>  
>  static inline uint64_t bcache_dev_sectors_dirty(struct bcache_device *d)
>  {
> -	uint64_t i, ret = 0;
> -
> -	for (i = 0; i < d->nr_stripes; i++)
> -		ret += atomic_read(d->stripe_sectors_dirty + i);
> -
> -	return ret;
> +	return atomic_long_read(&d->dirty_sectors);
>  }
>  

This looks really nice.

>  static inline int offset_to_stripe(struct bcache_device *d,
> -- 
> 2.17.1
> 

-- 
Coly Li



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux ARM Kernel]     [Linux Filesystem Development]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux