2019-04-12 15:29:32

by Huaisheng Ye

[permalink] [raw]
Subject: [PATCH] dm-writecache: add unlikely for returned value of rb_next/prev

From: Huaisheng Ye <[email protected]>

In functions writecache_discard and writecache_find_entry, there is
high probablity that the pointer of structure rb_node doesn't equal
to NULL. Add unlikly for the pointer node.

Signed-off-by: Huaisheng Ye <[email protected]>
---
drivers/md/dm-writecache.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/md/dm-writecache.c b/drivers/md/dm-writecache.c
index 5b4d1c1..cfbbfbc 100644
--- a/drivers/md/dm-writecache.c
+++ b/drivers/md/dm-writecache.c
@@ -571,7 +571,7 @@ static struct wc_entry *writecache_find_entry(struct dm_writecache *wc,
node = rb_prev(&e->rb_node);
else
node = rb_next(&e->rb_node);
- if (!node)
+ if (unlikely(!node))
return e;
e2 = container_of(node, struct wc_entry, rb_node);
if (read_original_sector(wc, e2) != block)
@@ -804,7 +804,7 @@ static void writecache_discard(struct dm_writecache *wc, sector_t start, sector_
writecache_free_entry(wc, e);
}

- if (!node)
+ if (unlikely(!node))
break;

e = container_of(node, struct wc_entry, rb_node);
--
1.8.3.1


2019-04-23 15:52:12

by Mikulas Patocka

[permalink] [raw]
Subject: Re: [PATCH] dm-writecache: add unlikely for returned value of rb_next/prev



On Fri, 12 Apr 2019, Huaisheng Ye wrote:

> From: Huaisheng Ye <[email protected]>
>
> In functions writecache_discard and writecache_find_entry, there is
> high probablity that the pointer of structure rb_node doesn't equal
> to NULL. Add unlikly for the pointer node.
>
> Signed-off-by: Huaisheng Ye <[email protected]>

Acked-by: Mikulas Patocka <[email protected]>

> ---
> drivers/md/dm-writecache.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/md/dm-writecache.c b/drivers/md/dm-writecache.c
> index 5b4d1c1..cfbbfbc 100644
> --- a/drivers/md/dm-writecache.c
> +++ b/drivers/md/dm-writecache.c
> @@ -571,7 +571,7 @@ static struct wc_entry *writecache_find_entry(struct dm_writecache *wc,
> node = rb_prev(&e->rb_node);
> else
> node = rb_next(&e->rb_node);
> - if (!node)
> + if (unlikely(!node))
> return e;
> e2 = container_of(node, struct wc_entry, rb_node);
> if (read_original_sector(wc, e2) != block)
> @@ -804,7 +804,7 @@ static void writecache_discard(struct dm_writecache *wc, sector_t start, sector_
> writecache_free_entry(wc, e);
> }
>
> - if (!node)
> + if (unlikely(!node))
> break;
>
> e = container_of(node, struct wc_entry, rb_node);
> --
> 1.8.3.1
>