Commit f8011d33 authored by Mikulas Patocka's avatar Mikulas Patocka Committed by Mike Snitzer

dm writecache: avoid unnecessary lookups in writecache_find_entry()

This is a small optimization in writecache_find_entry().

If we go past the condition "if (unlikely(!node))", we can be certain that
there is no entry in the tree that has the block equal to the "block"
variable.

Consequently, we can return the next entry directly, we don't need to go
to the second part of the function that finds the entry with lowest or
highest seq number that matches the "block" variable.

Also, add some whitespace and cleanup needless braces.
Suggested-by: default avatarHuaisheng Ye <yehs1@lenovo.com>
Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
parent 08a8e804
...@@ -545,21 +545,20 @@ static struct wc_entry *writecache_find_entry(struct dm_writecache *wc, ...@@ -545,21 +545,20 @@ static struct wc_entry *writecache_find_entry(struct dm_writecache *wc,
e = container_of(node, struct wc_entry, rb_node); e = container_of(node, struct wc_entry, rb_node);
if (read_original_sector(wc, e) == block) if (read_original_sector(wc, e) == block)
break; break;
node = (read_original_sector(wc, e) >= block ? node = (read_original_sector(wc, e) >= block ?
e->rb_node.rb_left : e->rb_node.rb_right); e->rb_node.rb_left : e->rb_node.rb_right);
if (unlikely(!node)) { if (unlikely(!node)) {
if (!(flags & WFE_RETURN_FOLLOWING)) { if (!(flags & WFE_RETURN_FOLLOWING))
return NULL; return NULL;
}
if (read_original_sector(wc, e) >= block) { if (read_original_sector(wc, e) >= block) {
break; return e;
} else { } else {
node = rb_next(&e->rb_node); node = rb_next(&e->rb_node);
if (unlikely(!node)) { if (unlikely(!node))
return NULL; return NULL;
}
e = container_of(node, struct wc_entry, rb_node); e = container_of(node, struct wc_entry, rb_node);
break; return e;
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment