Skip to content

Commit

Permalink
bcache: only clear BTREE_NODE_dirty bit when it is set
Browse files Browse the repository at this point in the history
In bch_btree_cache_free() and btree_node_free(), BTREE_NODE_dirty is
always set no matter btree node is dirty or not. The code looks like
this,
	if (btree_node_dirty(b))
		btree_complete_write(b, btree_current_write(b));
	clear_bit(BTREE_NODE_dirty, &b->flags);

Indeed if btree_node_dirty(b) returns false, it means BTREE_NODE_dirty
bit is cleared, then it is unnecessary to clear the bit again.

This patch only clears BTREE_NODE_dirty when btree_node_dirty(b) is
true (the bit is set), to save a few CPU cycles.

Signed-off-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Coly Li authored and Jens Axboe committed Jun 28, 2019
1 parent 249a5f6 commit e5ec5f4
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions drivers/md/bcache/btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -782,10 +782,10 @@ 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);

if (btree_node_dirty(b))
if (btree_node_dirty(b)) {
btree_complete_write(b, btree_current_write(b));
clear_bit(BTREE_NODE_dirty, &b->flags);

clear_bit(BTREE_NODE_dirty, &b->flags);
}
mca_data_free(b);
}

Expand Down Expand Up @@ -1073,9 +1073,10 @@ static void btree_node_free(struct btree *b)

mutex_lock(&b->write_lock);

if (btree_node_dirty(b))
if (btree_node_dirty(b)) {
btree_complete_write(b, btree_current_write(b));
clear_bit(BTREE_NODE_dirty, &b->flags);
clear_bit(BTREE_NODE_dirty, &b->flags);
}

mutex_unlock(&b->write_lock);

Expand Down

0 comments on commit e5ec5f4

Please sign in to comment.