bcache: simplify the calculation of the total amount of flash dirty data
authorTang Junhui <tang.junhui@zte.com.cn>
Thu, 26 Jul 2018 04:17:33 +0000 (12:17 +0800)
committerJens Axboe <axboe@kernel.dk>
Fri, 27 Jul 2018 15:15:46 +0000 (09:15 -0600)
Currently we calculate the total amount of flash only devices dirty data
by adding the dirty data of each flash only device under registering
locker. It is very inefficient.

In this patch, we add a member flash_dev_dirty_sectors in struct cache_set
to record the total amount of flash only devices dirty data in real time,
so we didn't need to calculate the total amount of dirty data any more.

Signed-off-by: Tang Junhui <tang.junhui@zte.com.cn>
Signed-off-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/md/bcache/bcache.h
drivers/md/bcache/super.c
drivers/md/bcache/writeback.c
drivers/md/bcache/writeback.h

index d6bf294f3907dafc035ba7f4e460ea6a4fe1ab22..3226d38bf8594e385002bdea5fee1896ea6acc9d 100644 (file)
@@ -525,6 +525,7 @@ struct cache_set {
        unsigned                devices_max_used;
        struct list_head        cached_devs;
        uint64_t                cached_dev_sectors;
+       atomic_long_t           flash_dev_dirty_sectors;
        struct closure          caching;
 
        struct closure          sb_write;
index fa4058e4320289b11968f754526931f46079408a..cea2a42ea2762a879046721cf0ff6ee6397cfaad 100644 (file)
@@ -1311,6 +1311,8 @@ static void flash_dev_free(struct closure *cl)
 {
        struct bcache_device *d = container_of(cl, struct bcache_device, cl);
        mutex_lock(&bch_register_lock);
+       atomic_long_sub(bcache_dev_sectors_dirty(d),
+                       &d->c->flash_dev_dirty_sectors);
        bcache_device_free(d);
        mutex_unlock(&bch_register_lock);
        kobject_put(&d->kobj);
index ad45ebe1a74b46348b7967b090e6077389b56f86..0d2a05074a816908018fe691c67ca3ec2852e7a8 100644 (file)
@@ -27,7 +27,7 @@ static uint64_t __calc_target_rate(struct cached_dev *dc)
         * flash-only devices
         */
        uint64_t cache_sectors = c->nbuckets * c->sb.bucket_size -
-                               bcache_flash_devs_sectors_dirty(c);
+                               atomic_long_read(&c->flash_dev_dirty_sectors);
 
        /*
         * Unfortunately there is no control of global dirty data.  If the
@@ -476,6 +476,9 @@ void bcache_dev_sectors_dirty_add(struct cache_set *c, unsigned inode,
        if (!d)
                return;
 
+       if (UUID_FLASH_ONLY(&c->uuids[inode]))
+               atomic_long_add(nr_sectors, &c->flash_dev_dirty_sectors);
+
        stripe = offset_to_stripe(d, offset);
        stripe_offset = offset & (d->stripe_size - 1);
 
index 610fb01de629c9612209ed4ef38a4bbea7a3d247..3745d7004c478c5612bdb19137145ce2ab96ba79 100644 (file)
@@ -28,25 +28,6 @@ static inline uint64_t bcache_dev_sectors_dirty(struct bcache_device *d)
        return ret;
 }
 
-static inline uint64_t  bcache_flash_devs_sectors_dirty(struct cache_set *c)
-{
-       uint64_t i, ret = 0;
-
-       mutex_lock(&bch_register_lock);
-
-       for (i = 0; i < c->devices_max_used; i++) {
-               struct bcache_device *d = c->devices[i];
-
-               if (!d || !UUID_FLASH_ONLY(&c->uuids[i]))
-                       continue;
-               ret += bcache_dev_sectors_dirty(d);
-       }
-
-       mutex_unlock(&bch_register_lock);
-
-       return ret;
-}
-
 static inline unsigned offset_to_stripe(struct bcache_device *d,
                                        uint64_t offset)
 {