Skip to contentSkip to conversation

bcache: Don't reinvent the wheel but use existing llist API

PATCH RESEND Superseded Byungchul Park 3 participants 8 messages Aug 7, 2017 – Aug 9, 2017

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 bcache: Don't reinvent the wheel but use existing llist API

Although llist provides proper APIs, they are not used. Make them used.

---
 drivers/md/bcache/closure.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)
drivers/md/bcache/closure.c +3 -14
index 864e673..1841d03 100644
@@ -64,27 +64,16 @@ void closure_put(struct closure *cl)
 void __closure_wake_up(struct closure_waitlist *wait_list)
 {
 	struct llist_node *list;
-	struct closure *cl;
+	struct closure *cl, *t;
 	struct llist_node *reverse = NULL;
 
 	list = llist_del_all(&wait_list->list);
 
 	/* We first reverse the list to preserve FIFO ordering and fairness */
-
-	while (list) {
-		struct llist_node *t = list;
-		list = llist_next(list);
-
-		t->next = reverse;
-		reverse = t;
-	}
+	reverse = llist_reverse_order(list);
 
 	/* Then do the wakeups */
-
-	while (reverse) {
-		cl = container_of(reverse, struct closure, list);
-		reverse = llist_next(reverse);
-
+	llist_for_each_entry_safe(cl, t, reverse, list) {
 		closure_set_waiting(cl, 0);
 		closure_sub(cl, CLOSURE_WAITING + 1);
 	}
Signature · 1 line
1.9.1
Acked-by on v1 1/1
#1 lore raw
Quoted 3 lines · Byungchul Park

Although llist provides proper APIs, they are not used. Make them used.

Only have a question about why not using llist_for_each_entry(), it's still OK with llist_for_each_entry_safe(). The rested part is good to me.

Quoted 26 lines
---
 drivers/md/bcache/closure.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)
drivers/md/bcache/closure.c +1 -8
index 864e673..1841d03 100644
@@ -64,27 +64,16 @@ void closure_put(struct closure *cl)
 void __closure_wake_up(struct closure_waitlist *wait_list)
 {
 	struct llist_node *list;
-	struct closure *cl;
+	struct closure *cl, *t;
 	struct llist_node *reverse = NULL;
 
 	list = llist_del_all(&wait_list->list);
 
 	/* We first reverse the list to preserve FIFO ordering and fairness */
-
-	while (list) {
-		struct llist_node *t = list;
-		list = llist_next(list);
-
-		t->next = reverse;
-		reverse = t;

drivers/md/bcache/closure.c void closure_put(struct closure *cl) · line 76

Quoted 10 lines
drivers/md/bcache/closure.c +2 -6
-	}
+	reverse = llist_reverse_order(list);
 
 	/* Then do the wakeups */
-
-	while (reverse) {
-		cl = container_of(reverse, struct closure, list);
-		reverse = llist_next(reverse);
-
+	llist_for_each_entry_safe(cl, t, reverse, list) {

Just wondering why not using llist_for_each_entry(), or you use the _safe version on purpose ?

Quoted 4 lines
drivers/md/bcache/closure.c +0 -0
 		closure_set_waiting(cl, 0);
 		closure_sub(cl, CLOSURE_WAITING + 1);
 	}
Signature · 1 line
Coly Li
#2 lore raw
Quoted 5 lines · Coly Li
Quoted 3 lines · Byungchul Park

Although llist provides proper APIs, they are not used. Make them used.

Only have a question about why not using llist_for_each_entry(), it's

Hello,

The reason is to keep the original logic unchanged. The logic already does as if it's the safe version against removal.

Quoted 33 lines

still OK with llist_for_each_entry_safe(). The rested part is good to me.

Quoted 29 lines
---
 drivers/md/bcache/closure.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)
drivers/md/bcache/closure.c +2 -9
index 864e673..1841d03 100644
@@ -64,27 +64,16 @@ void closure_put(struct closure *cl)
 void __closure_wake_up(struct closure_waitlist *wait_list)
 {
 	struct llist_node *list;
-	struct closure *cl;
+	struct closure *cl, *t;
 	struct llist_node *reverse = NULL;
 
 	list = llist_del_all(&wait_list->list);
 
 	/* We first reverse the list to preserve FIFO ordering and fairness */
-
-	while (list) {
-		struct llist_node *t = list;
-		list = llist_next(list);
-
-		t->next = reverse;
-		reverse = t;
-	}
+	reverse = llist_reverse_order(list);
 
Quoted 10 lines

drivers/md/bcache/closure.c void closure_put(struct closure *cl) · line 76

Quoted 7 lines
drivers/md/bcache/closure.c +1 -5
 	/* Then do the wakeups */
-
-	while (reverse) {
-		cl = container_of(reverse, struct closure, list);
-		reverse = llist_next(reverse);
-
+	llist_for_each_entry_safe(cl, t, reverse, list) {

Just wondering why not using llist_for_each_entry(), or you use the _safe version on purpose ?

If I use llist_for_each_entry(), then it would change the original behavior. Is it ok?

Thank you,
Byungchul

#3 lore raw
Quoted 56 lines · Byungchul Park
Quoted 5 lines · Coly Li
Quoted 3 lines · Byungchul Park

Although llist provides proper APIs, they are not used. Make them used.

Only have a question about why not using llist_for_each_entry(), it's

Hello,

The reason is to keep the original logic unchanged. The logic already does as if it's the safe version against removal.

Quoted 33 lines

still OK with llist_for_each_entry_safe(). The rested part is good to me.

Quoted 29 lines
---
 drivers/md/bcache/closure.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)
drivers/md/bcache/closure.c +2 -9
index 864e673..1841d03 100644
@@ -64,27 +64,16 @@ void closure_put(struct closure *cl)
 void __closure_wake_up(struct closure_waitlist *wait_list)
 {
 	struct llist_node *list;
-	struct closure *cl;
+	struct closure *cl, *t;
 	struct llist_node *reverse = NULL;
 
 	list = llist_del_all(&wait_list->list);
 
 	/* We first reverse the list to preserve FIFO ordering and fairness */
-
-	while (list) {
-		struct llist_node *t = list;
-		list = llist_next(list);
-
-		t->next = reverse;
-		reverse = t;
-	}
+	reverse = llist_reverse_order(list);
 
Quoted 10 lines

drivers/md/bcache/closure.c void closure_put(struct closure *cl) · line 76

Quoted 7 lines
drivers/md/bcache/closure.c +1 -5
 	/* Then do the wakeups */
-
-	while (reverse) {
-		cl = container_of(reverse, struct closure, list);
-		reverse = llist_next(reverse);
-
+	llist_for_each_entry_safe(cl, t, reverse, list) {

Just wondering why not using llist_for_each_entry(), or you use the _safe version on purpose ?

Quoted 3 lines

If I use llist_for_each_entry(), then it would change the original behavior. Is it ok?

I feel llist_for_each_entry() keeps the original behavior, and variable 't' can be removed. Anyway, either llist_for_each_entry() or llist_for_each_entry_safe() works correctly and well here. Any one you use is OK to me, thanks for your informative reply :-)

Signature · 1 line
Coly Li
#4 lore raw
Quoted 10 lines · Coly Li
Quoted 8 lines
Quoted 4 lines

drivers/md/bcache/closure.c void closure_put(struct closure *cl) · line 76

Quoted 1 line
drivers/md/bcache/closure.c +1 -0
+	llist_for_each_entry_safe(cl, t, reverse, list) {

Just wondering why not using llist_for_each_entry(), or you use the _safe version on purpose ?

If I use llist_for_each_entry(), then it would change the original behavior. Is it ok?

I feel llist_for_each_entry() keeps the original behavior, and variable

Ah.. I see. Then.. Can I change it into non-safe version? Is it still ok with non-safe one? I will change it at the next spin, if yes.

Quoted 3 lines

't' can be removed. Anyway, either llist_for_each_entry() or llist_for_each_entry_safe() works correctly and well here. Any one you use is OK to me, thanks for your informative reply :-)

I rather appriciate it.

Thank you,
Byungchul

#5 lore raw
Quoted 12 lines · Byungchul Park
Quoted 10 lines · Coly Li
Quoted 8 lines
Quoted 4 lines

drivers/md/bcache/closure.c void closure_put(struct closure *cl) · line 76

Quoted 1 line
drivers/md/bcache/closure.c +1 -0
+	llist_for_each_entry_safe(cl, t, reverse, list) {

Just wondering why not using llist_for_each_entry(), or you use the _safe version on purpose ?

If I use llist_for_each_entry(), then it would change the original behavior. Is it ok?

I feel llist_for_each_entry() keeps the original behavior, and variable

Quoted 9 lines

Ah.. I see. Then.. Can I change it into non-safe version? Is it still ok with non-safe one? I will change it at the next spin, if yes.

Quoted 3 lines

't' can be removed. Anyway, either llist_for_each_entry() or llist_for_each_entry_safe() works correctly and well here. Any one you use is OK to me, thanks for your informative reply :-)

I rather appriciate it.

Yes, please. And you have my Acked-by :-)

Signature · 1 line
Coly Li
#6 lore raw
In reply to Byungchul Park
Quoted 8 lines · Byungchul Park
Quoted 7 lines · Coly Li
Quoted 7 lines
Quoted 4 lines

drivers/md/bcache/closure.c void closure_put(struct closure *cl) · line 76

Quoted 1 line
drivers/md/bcache/closure.c +1 -0
+	llist_for_each_entry_safe(cl, t, reverse, list) {

Just wondering why not using llist_for_each_entry(), or you use the _safe version on purpose ?

If I use llist_for_each_entry(), then it would change the original behavior. Is it ok?

Generally, _safe versions of list primitives is used when you are going to perform removal in the iteration. I haven't looked at the code in bcache but if it's removing entries from the list then _safe version is required. If you are only iterating - then non-safe version is fine.

Quoted 16 lines
Quoted 3 lines
Quoted 1 line

I feel llist_for_each_entry() keeps the original behavior, and variable

Ah.. I see. Then.. Can I change it into non-safe version? Is it still ok with non-safe one? I will change it at the next spin, if yes.

Quoted 3 lines

't' can be removed. Anyway, either llist_for_each_entry() or llist_for_each_entry_safe() works correctly and well here. Any one you use is OK to me, thanks for your informative reply :-)

I rather appriciate it.

Thank you,
Byungchul

#7 lore raw
Quoted 9 lines · Nikolay Borisov
Quoted 6 lines · Byungchul Park
Quoted 5 lines · Coly Li
Quoted 5 lines
Quoted 4 lines

drivers/md/bcache/closure.c void closure_put(struct closure *cl) · line 76

Quoted 1 line
drivers/md/bcache/closure.c +1 -0
+	llist_for_each_entry_safe(cl, t, reverse, list) {

Just wondering why not using llist_for_each_entry(), or you use the _safe version on purpose ?

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

If I use llist_for_each_entry(), then it would change the original behavior. Is it ok?

Generally, _safe versions of list primitives is used when you are going to perform removal in the iteration. I haven't looked at the code in bcache but if it's removing entries from the list then _safe version is required. If you are only iterating - then non-safe version is fine.

Thank you~ :)