bcache: add comments for mutex_lock(&b->write_lock)
authorColy Li <colyli@suse.de>
Fri, 28 Jun 2019 11:59:56 +0000 (19:59 +0800)
committerJens Axboe <axboe@kernel.dk>
Fri, 28 Jun 2019 13:39:17 +0000 (07:39 -0600)
When accessing or modifying BTREE_NODE_dirty bit, it is not always
necessary to acquire b->write_lock. In bch_btree_cache_free() and
mca_reap() acquiring b->write_lock is necessary, and this patch adds
comments to explain why mutex_lock(&b->write_lock) is necessary for
checking or clearing BTREE_NODE_dirty bit there.

Signed-off-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/md/bcache/btree.c

index 88e5aa3fbb078155e725ff46cf0e12f844ea9a99..846306c3a887ec1b61309b98628e2a6aaaf6a190 100644 (file)
@@ -659,6 +659,11 @@ static int mca_reap(struct btree *b, unsigned int min_order, bool flush)
                up(&b->io_mutex);
        }
 
+       /*
+        * BTREE_NODE_dirty might be cleared in btree_flush_btree() by
+        * __bch_btree_node_write(). To avoid an extra flush, acquire
+        * b->write_lock before checking BTREE_NODE_dirty bit.
+        */
        mutex_lock(&b->write_lock);
        if (btree_node_dirty(b))
                __bch_btree_node_write(b, &cl);
@@ -782,6 +787,11 @@ void bch_btree_cache_free(struct cache_set *c)
        while (!list_empty(&c->btree_cache)) {
                b = list_first_entry(&c->btree_cache, struct btree, list);
 
+               /*
+                * This function is called by cache_set_free(), no I/O
+                * request on cache now, it is unnecessary to acquire
+                * b->write_lock before clearing BTREE_NODE_dirty anymore.
+                */
                if (btree_node_dirty(b)) {
                        btree_complete_write(b, btree_current_write(b));
                        clear_bit(BTREE_NODE_dirty, &b->flags);