Use list_for_each_entry_safe
cover Use list_for_each_entry_safe
This patch-series replaces the while loop containing list_empty and list_entry with list_for_each_entry_safe.
simran singhal (5):
staging: lustre: Use list_for_each_entry_safe
staging: lustre: ptlrpc: Use list_for_each_entry_safe
staging: lustre: osc: Use list_for_each_entry_safe
staging: lustre: llite: Use list_for_each_entry_safe
staging: lustre: osc_page.c: Use list_for_each_entry_safe
drivers/staging/lustre/lustre/llite/statahead.c | 5 ++--- drivers/staging/lustre/lustre/osc/osc_cache.c | 5 ++--- drivers/staging/lustre/lustre/osc/osc_page.c | 11 ++++------- drivers/staging/lustre/lustre/ptlrpc/sec_gc.c | 5 ++--- drivers/staging/lustre/lustre/ptlrpc/service.c | 5 ++--- 5 files changed, 12 insertions(+), 19 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/5 staging: lustre: Use list_for_each_entry_safe
Doubly linked lists which are iterated using list_empty and list_entry macros have been replaced with list_for_each_entry_safe macro.
This makes the iteration simpler and more readable.
This patch replaces the while loop containing list_empty and list_entry with list_for_each_entry_safe.
This was done with Coccinelle.
@@
expression E1;
identifier I1, I2;
type T;
iterator name list_for_each_entry_safe;
@@
T *I1;
+ T *tmp;
...
- while (list_empty(&E1) == 0)
+ list_for_each_entry_safe (I1, tmp, &E1, I2)
{
...when != T *I1;
- I1 = list_entry(E1.next, T, I2);
...
}
--- drivers/staging/lustre/lustre/ptlrpc/service.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/staging/lustre/lustre/ptlrpc/service.c +2 -3
@@ -2314,6 +2314,7 @@ static void ptlrpc_svcpt_stop_threads(struct ptlrpc_service_part *svcpt) {struct l_wait_info lwi = {0 };struct ptlrpc_thread *thread; +struct ptlrpc_thread *tmp;LIST_HEAD (zombie); CDEBUG(D_INFO, "Stopping threads for service %s\n",
@@ -2329,9 +2330,7 @@ static void ptlrpc_svcpt_stop_threads(struct ptlrpc_service_part *svcpt)wake_up_all (&svcpt->scp_waitq); -while (!list_empty (&svcpt->scp_threads)) { - thread =list_entry (svcpt->scp_threads.next, - struct ptlrpc_thread, t_link); +list_for_each_entry_safe (thread, tmp, &svcpt->scp_threads, t_link) {if (thread_is_stopped (thread)) {list_del (&thread->t_link);list_add (&thread->t_link, &zombie);
Signature · 1 line
2.7.4
Re: [Outreachy kernel] [PATCH 1/5] staging: lustre: Use list_for_each_entry_safe
Quoted 17 lines · simran singhal
Doubly linked lists which are iterated using
list_emptyandlist_entrymacros have been replaced withlist_for_each_entry_safemacro.
This makes the iteration simpler and more readable.This patch replaces the while loop containing
list_emptyandlist_entrywithlist_for_each_entry_safe.This was done with Coccinelle.
@@
expression E1;
identifier I1, I2;
type T;
iterator namelist_for_each_entry_safe;
@@
Quoted 3 lines
T *I1;
+ T *tmp;
...
The function that is modified in this patch actually has another opportunity. That doesn't get transformed because with ... Coccinelle matches the shortest path between what comes before and what comes after, and so it only matches the first while loop.
You could sort of fix the problem by putting when any on the ... That allows anything in the path, including other while loops.
That though will mean that you will try to add two instances of the tmp declaration after the declaration of I1. Coccinelle allows adding only one thing, unless the + is replaced by ++. But if you do that, you will get two decarations of tmp.
So either make the second change by hand, or let Coccinelle do it an remove the second declaration of tmp by hand.
julia
Quoted 46 lines
- while (
list_empty(&E1)== 0)
+list_for_each_entry_safe(I1, tmp, &E1, I2)
{
...when != T *I1;
- I1 =list_entry(E1.next, T, I2);
...
}Signed-off-by simran singhal <[email protected]>--- drivers/staging/lustre/lustre/ptlrpc/service.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/staging/lustre/lustre/ptlrpc/service.c +2
-4@@ -2314,6 +2314,7 @@ static void ptlrpc_svcpt_stop_threads(struct ptlrpc_service_part *svcpt) {struct l_wait_info lwi = {0 };struct ptlrpc_thread *thread; +struct ptlrpc_thread *tmp;LIST_HEAD (zombie); CDEBUG(D_INFO, "Stopping threads for service %s\n",@@ -2329,9 +2330,7 @@ static void ptlrpc_svcpt_stop_threads(struct ptlrpc_service_part *svcpt)wake_up_all (&svcpt->scp_waitq); -while (!list_empty (&svcpt->scp_threads)) { - thread =list_entry (svcpt->scp_threads.next, - struct ptlrpc_thread, t_link); +list_for_each_entry_safe (thread, tmp, &svcpt->scp_threads, t_link) {if (thread_is_stopped (thread)) {list_del (&thread->t_link);list_add (&thread->t_link, &zombie); --2.7.4
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe at googlegroups.com. To post to this group, send email to outreachy-kernel at googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1488733610-22289-2-git-send-email-singhalsimran0%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
PATCH 2/5 staging: lustre: ptlrpc: Use list_for_each_entry_safe
In reply to simran singhalDoubly linked lists which are iterated using list_empty and list_entry macros have been replaced with list_for_each_entry_safe macro.
This makes the iteration simpler and more readable.
This patch replaces the while loop containing list_empty and list_entry with list_for_each_entry_safe.
This was done with Coccinelle.
@@
expression E1;
identifier I1, I2;
type T;
iterator name list_for_each_entry_safe;
@@
T *I1;
+ T *tmp;
...
- while (list_empty(&E1) == 0)
+ list_for_each_entry_safe (I1, tmp, &E1, I2)
{
...when != T *I1;
- I1 = list_entry(E1.next, T, I2);
...
}
--- drivers/staging/lustre/lustre/ptlrpc/sec_gc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/staging/lustre/lustre/ptlrpc/sec_gc.c +2 -3
@@ -98,12 +98,11 @@ void sptlrpc_gc_del_sec(struct ptlrpc_sec *sec)static void sec_process_ctx_list (void ) {struct ptlrpc_cli_ctx *ctx; +struct ptlrpc_cli_ctx *tmp;spin_lock (&sec_gc_ctx_list_lock); -while (!list_empty (&sec_gc_ctx_list)) { - ctx =list_entry (sec_gc_ctx_list.next, - struct ptlrpc_cli_ctx, cc_gc_chain); +list_for_each_entry_safe (ctx, tmp, &sec_gc_ctx_list, cc_gc_chain) {list_del_init (&ctx->cc_gc_chain);spin_unlock (&sec_gc_ctx_list_lock);
Signature · 1 line
2.7.4
Re: [Outreachy kernel] [PATCH 2/5] staging: lustre: ptlrpc: Use list_for_each_entry_safe
Quoted 38 lines · simran singhal
Doubly linked lists which are iterated using
list_emptyandlist_entrymacros have been replaced withlist_for_each_entry_safemacro.
This makes the iteration simpler and more readable.This patch replaces the while loop containing
list_emptyandlist_entrywithlist_for_each_entry_safe.This was done with Coccinelle.
@@
expression E1;
identifier I1, I2;
type T;
iterator namelist_for_each_entry_safe;
@@T *I1;
+ T *tmp;
...
- while (list_empty(&E1)== 0)
+list_for_each_entry_safe(I1, tmp, &E1, I2)
{
...when != T *I1;
- I1 =list_entry(E1.next, T, I2);
...
}Signed-off-by simran singhal <[email protected]>--- drivers/staging/lustre/lustre/ptlrpc/sec_gc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/staging/lustre/lustre/ptlrpc/sec_gc.c +0
-0
drivers/staging/lustre/lustre/ptlrpc/sec_gc.c void sptlrpc_gc_del_sec(struct ptlrpc_sec *sec) · line 101
Quoted 4 lines
drivers/staging/lustre/lustre/ptlrpc/sec_gc.c +1
-0@@ -98,12 +98,11 @@ void sptlrpc_gc_del_sec(struct ptlrpc_sec *sec)static void sec_process_ctx_list (void ) {struct ptlrpc_cli_ctx *ctx; +struct ptlrpc_cli_ctx *tmp;
Another improvement would be to define both variables at once:
T *I1
+ , *tmp
;
julia
Quoted 20 lines
drivers/staging/lustre/lustre/ptlrpc/sec_gc.c +1
-4spin_lock (&sec_gc_ctx_list_lock); -while (!list_empty (&sec_gc_ctx_list)) { - ctx =list_entry (sec_gc_ctx_list.next, - struct ptlrpc_cli_ctx, cc_gc_chain); +list_for_each_entry_safe (ctx, tmp, &sec_gc_ctx_list, cc_gc_chain) {list_del_init (&ctx->cc_gc_chain);spin_unlock (&sec_gc_ctx_list_lock); --2.7.4
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe at googlegroups.com. To post to this group, send email to outreachy-kernel at googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1488733610-22289-3-git-send-email-singhalsimran0%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Re: [Outreachy kernel] [PATCH 2/5] staging: lustre: ptlrpc: Use list_for_each_entry_safe
Quoted 49 lines · Julia Lawall
Quoted 38 lines · simran singhal
Doubly linked lists which are iterated using
list_emptyandlist_entrymacros have been replaced withlist_for_each_entry_safemacro.
This makes the iteration simpler and more readable.This patch replaces the while loop containing
list_emptyandlist_entrywithlist_for_each_entry_safe.This was done with Coccinelle.
@@
expression E1;
identifier I1, I2;
type T;
iterator namelist_for_each_entry_safe;
@@T *I1;
+ T *tmp;
...
- while (list_empty(&E1)== 0)
+list_for_each_entry_safe(I1, tmp, &E1, I2)
{
...when != T *I1;
- I1 =list_entry(E1.next, T, I2);
...
}Signed-off-by simran singhal <[email protected]>--- drivers/staging/lustre/lustre/ptlrpc/sec_gc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/staging/lustre/lustre/ptlrpc/sec_gc.c +0
-0drivers/staging/lustre/lustre/ptlrpc/sec_gc.c void sptlrpc_gc_del_sec(struct ptlrpc_sec *sec) · line 101
Quoted 4 lines
drivers/staging/lustre/lustre/ptlrpc/sec_gc.c +1
-0@@ -98,12 +98,11 @@ void sptlrpc_gc_del_sec(struct ptlrpc_sec *sec)static void sec_process_ctx_list (void ) {struct ptlrpc_cli_ctx *ctx; +struct ptlrpc_cli_ctx *tmp;Another improvement would be to define both variables at once:
Quoted 4 lines
T *I1
+ , *tmp
;
This is particulary for this patch or for all the patches of this patch-series.
Quoted 22 lines
julia
Quoted 20 lines
drivers/staging/lustre/lustre/ptlrpc/sec_gc.c +1
-4spin_lock (&sec_gc_ctx_list_lock); -while (!list_empty (&sec_gc_ctx_list)) { - ctx =list_entry (sec_gc_ctx_list.next, - struct ptlrpc_cli_ctx, cc_gc_chain); +list_for_each_entry_safe (ctx, tmp, &sec_gc_ctx_list, cc_gc_chain) {list_del_init (&ctx->cc_gc_chain);spin_unlock (&sec_gc_ctx_list_lock); --2.7.4
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1488733610-22289-3-git-send-email-singhalsimran0%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Re: [Outreachy kernel] [PATCH 2/5] staging: lustre: ptlrpc: Use list_for_each_entry_safe
Quoted 50 lines · SIMRAN SINGHAL
Quoted 49 lines · Julia Lawall
Quoted 38 lines · simran singhal
Doubly linked lists which are iterated using
list_emptyandlist_entrymacros have been replaced withlist_for_each_entry_safemacro.
This makes the iteration simpler and more readable.This patch replaces the while loop containing
list_emptyandlist_entrywithlist_for_each_entry_safe.This was done with Coccinelle.
@@
expression E1;
identifier I1, I2;
type T;
iterator namelist_for_each_entry_safe;
@@T *I1;
+ T *tmp;
...
- while (list_empty(&E1)== 0)
+list_for_each_entry_safe(I1, tmp, &E1, I2)
{
...when != T *I1;
- I1 =list_entry(E1.next, T, I2);
...
}Signed-off-by simran singhal <[email protected]>--- drivers/staging/lustre/lustre/ptlrpc/sec_gc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/staging/lustre/lustre/ptlrpc/sec_gc.c +0
-0drivers/staging/lustre/lustre/ptlrpc/sec_gc.c void sptlrpc_gc_del_sec(struct ptlrpc_sec *sec) · line 101
Quoted 4 lines
drivers/staging/lustre/lustre/ptlrpc/sec_gc.c +1
-0@@ -98,12 +98,11 @@ void sptlrpc_gc_del_sec(struct ptlrpc_sec *sec)static void sec_process_ctx_list (void ) {struct ptlrpc_cli_ctx *ctx; +struct ptlrpc_cli_ctx *tmp;Another improvement would be to define both variables at once:
Quoted 5 lines
Quoted 4 lines
T *I1
+ , *tmp
;This is particulary for this patch or for all the patches of this patch-series.
All, I would guess. Unless the line gets too long.
julia
Quoted 24 lines
Quoted 23 lines
julia
Quoted 20 lines
drivers/staging/lustre/lustre/ptlrpc/sec_gc.c +1
-4spin_lock (&sec_gc_ctx_list_lock); -while (!list_empty (&sec_gc_ctx_list)) { - ctx =list_entry (sec_gc_ctx_list.next, - struct ptlrpc_cli_ctx, cc_gc_chain); +list_for_each_entry_safe (ctx, tmp, &sec_gc_ctx_list, cc_gc_chain) {list_del_init (&ctx->cc_gc_chain);spin_unlock (&sec_gc_ctx_list_lock); --2.7.4
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe at googlegroups.com. To post to this group, send email to outreachy-kernel at googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1488733610-22289-3-git-send-email-singhalsimran0%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
PATCH 3/5 staging: lustre: osc: Use list_for_each_entry_safe
In reply to simran singhalDoubly linked lists which are iterated using list_empty and list_entry macros have been replaced with list_for_each_entry_safe macro.
This makes the iteration simpler and more readable.
This patch replaces the while loop containing list_empty and list_entry with list_for_each_entry_safe.
This was done with Coccinelle.
@@
expression E1;
identifier I1, I2;
type T;
iterator name list_for_each_entry_safe;
@@
T *I1;
+ T *tmp;
...
- while (list_empty(&E1) == 0)
+ list_for_each_entry_safe (I1, tmp, &E1, I2)
{
...when != T *I1;
- I1 = list_entry(E1.next, T, I2);
...
}
--- drivers/staging/lustre/lustre/osc/osc_cache.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/staging/lustre/lustre/osc/osc_cache.c +2 -3
@@ -1996,6 +1996,7 @@ static unsigned int get_write_extents(struct osc_object *obj, {struct client_obd *cli =osc_cli (obj);struct osc_extent *ext; +struct osc_extent *tmp;struct osc_extent *temp;struct extent_rpc_data data = { .erd_rpc_list = rpclist,
@@ -2014,9 +2015,7 @@ static unsigned int get_write_extents(struct osc_object *obj,if (data.erd_page_count == data.erd_max_pages)return data.erd_page_count; -while (!list_empty (&obj->oo_urgent_exts)) { - ext =list_entry (obj->oo_urgent_exts.next, - struct osc_extent, oe_link); +list_for_each_entry_safe (ext, tmp, &obj->oo_urgent_exts, oe_link) {if (!try_to_add_extent_for_io (cli, ext, &data))return data.erd_page_count;
Signature · 1 line
2.7.4
PATCH 4/5 staging: lustre: llite: Use list_for_each_entry_safe
In reply to simran singhalDoubly linked lists which are iterated using list_empty and list_entry macros have been replaced with list_for_each_entry_safe macro.
This makes the iteration simpler and more readable.
This patch replaces the while loop containing list_empty and list_entry with list_for_each_entry_safe.
This was done with Coccinelle.
@@
expression E1;
identifier I1, I2;
type T;
iterator name list_for_each_entry_safe;
@@
T *I1;
+ T *tmp;
...
- while (list_empty(&E1) == 0)
+ list_for_each_entry_safe (I1, tmp, &E1, I2)
{
...when != T *I1;
- I1 = list_entry(E1.next, T, I2);
...
}
--- drivers/staging/lustre/lustre/llite/statahead.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/staging/lustre/lustre/llite/statahead.c +2 -3
@@ -860,6 +860,7 @@ static int ll_agl_thread(void *arg)struct inode *dir =d_inode (parent);struct ll_inode_info *plli =ll_i2info (dir);struct ll_inode_info *clli; +struct ll_inode_info *tmp;struct ll_sb_info *sbi =ll_i2sbi (dir);struct ll_statahead_info *sai;struct ptlrpc_thread *thread;
@@ -909,9 +910,7 @@ static int ll_agl_thread(void *arg)spin_lock (&plli->lli_agl_lock); sai->sai_agl_valid =0 ; -while (!list_empty (&sai->sai_agls)) { - clli =list_entry (sai->sai_agls.next, - struct ll_inode_info, lli_agl_list); +list_for_each_entry_safe (clli, tmp, &sai->sai_agls, lli_agl_list) {list_del_init (&clli->lli_agl_list);spin_unlock (&plli->lli_agl_lock); clli->lli_agl_index =0 ;
Signature · 1 line
2.7.4
PATCH 5/5 staging: lustre: osc_page.c: Use list_for_each_entry_safe
In reply to simran singhalDoubly linked lists which are iterated using list_empty and list_entry macros have been replaced with list_for_each_entry_safe macro.
This makes the iteration simpler and more readable.
This patch replaces the while loop containing list_empty and list_entry with list_for_each_entry_safe.
This was done with Coccinelle.
@@
expression E1;
identifier I1, I2;
type T;
iterator name list_for_each_entry_safe;
@@
T *I1;
+ T *tmp;
...
- while (list_empty(&E1) == 0)
+ list_for_each_entry_safe (I1, tmp, &E1, I2)
{
...when != T *I1;
- I1 = list_entry(E1.next, T, I2);
...
}
--- drivers/staging/lustre/lustre/osc/osc_page.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/staging/lustre/lustre/osc/osc_page.c +4 -7
@@ -542,6 +542,7 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,struct cl_object *clobj =NULL ;struct cl_page **pvec;struct osc_page *opg; +struct osc_page *tmp;int maxscan =0 ;long count =0 ;int index =0 ;
@@ -572,7 +573,7 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,if (force) cli->cl_lru_reclaim++; maxscan =min (target <<1 ,atomic_long_read (&cli->cl_lru_in_list)); -while (!list_empty (&cli->cl_lru_list)) { +list_for_each_entry_safe (opg, tmp, &cli->cl_lru_list, ops_lru) {struct cl_page *page;bool will_free = false;
@@ -582,8 +583,6 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,if (--maxscan <0 )break ; - opg = list_entry(cli->cl_lru_list.next, struct osc_page, - ops_lru); page = opg->ops_cl.cpl_page;if (lru_page_busy (cli, page)) {list_move_tail (&opg->ops_lru, &cli->cl_lru_list);
@@ -1043,6 +1042,7 @@ unsigned long osc_cache_shrink_scan(struct shrinker *sk, {struct client_obd *stop_anchor =NULL ;struct client_obd *cli; +struct client_obd *tmp;struct lu_env *env;long shrank =0 ;u16 refcheck;
@@ -1059,10 +1059,7 @@ unsigned long osc_cache_shrink_scan(struct shrinker *sk,return SHRINK_STOP ;spin_lock (&osc_shrink_lock); -while (!list_empty (&osc_shrink_list)) { - cli = list_entry(osc_shrink_list.next, struct client_obd, - cl_shrink_list); - +list_for_each_entry_safe (cli, tmp, &osc_shrink_list, cl_shrink_list) {if (!stop_anchor) stop_anchor = cli;else if (cli == stop_anchor)
Signature · 1 line
2.7.4
Re: [Outreachy kernel] [PATCH 5/5] staging: lustre: osc_page.c: Use list_for_each_entry_safe
Quoted 7 lines · simran singhal
Doubly linked lists which are iterated using
list_emptyandlist_entrymacros have been replaced withlist_for_each_entry_safemacro.
This makes the iteration simpler and more readable.This patch replaces the while loop containing
list_emptyandlist_entrywithlist_for_each_entry_safe.
list_for_each_entry_safe is only needed when the current element is removed from the list within the loop body. If that is not the case, you can just use list_for_each_entry.
julia
Quoted 86 lines
This was done with Coccinelle.
@@
expression E1;
identifier I1, I2;
type T;
iterator namelist_for_each_entry_safe;
@@T *I1;
+ T *tmp;
...
- while (list_empty(&E1)== 0)
+list_for_each_entry_safe(I1, tmp, &E1, I2)
{
...when != T *I1;
- I1 =list_entry(E1.next, T, I2);
...
}Signed-off-by simran singhal <[email protected]>--- drivers/staging/lustre/lustre/osc/osc_page.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)drivers/staging/lustre/lustre/osc/osc_page.c +4
-8@@ -542,6 +542,7 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,struct cl_object *clobj =NULL ;struct cl_page **pvec;struct osc_page *opg; +struct osc_page *tmp;int maxscan =0 ;long count =0 ;int index =0 ;@@ -572,7 +573,7 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,if (force) cli->cl_lru_reclaim++; maxscan =min (target <<1 ,atomic_long_read (&cli->cl_lru_in_list)); -while (!list_empty (&cli->cl_lru_list)) { +list_for_each_entry_safe (opg, tmp, &cli->cl_lru_list, ops_lru) {struct cl_page *page;bool will_free = false;@@ -582,8 +583,6 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,if (--maxscan <0 )break ; - opg = list_entry(cli->cl_lru_list.next, struct osc_page, - ops_lru); page = opg->ops_cl.cpl_page;if (lru_page_busy (cli, page)) {list_move_tail (&opg->ops_lru, &cli->cl_lru_list);@@ -1043,6 +1042,7 @@ unsigned long osc_cache_shrink_scan(struct shrinker *sk, {struct client_obd *stop_anchor =NULL ;struct client_obd *cli; +struct client_obd *tmp;struct lu_env *env;long shrank =0 ;u16 refcheck;@@ -1059,10 +1059,7 @@ unsigned long osc_cache_shrink_scan(struct shrinker *sk,return SHRINK_STOP ;spin_lock (&osc_shrink_lock); -while (!list_empty (&osc_shrink_list)) { - cli = list_entry(osc_shrink_list.next, struct client_obd, - cl_shrink_list); - +list_for_each_entry_safe (cli, tmp, &osc_shrink_list, cl_shrink_list) {if (!stop_anchor) stop_anchor = cli;else if (cli == stop_anchor) --2.7.4
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe at googlegroups.com. To post to this group, send email to outreachy-kernel at googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1488733610-22289-6-git-send-email-singhalsimran0%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Re: [Outreachy kernel] [PATCH 5/5] staging: lustre: osc_page.c: Use list_for_each_entry_safe
Quoted 9 lines · Julia Lawall
Quoted 5 lines · simran singhal
Doubly linked lists which are iterated using
list_emptyandlist_entrymacros have been replaced withlist_for_each_entry_safemacro.
This makes the iteration simpler and more readable.
Quoted 6 lines
Quoted 2 lines
This patch replaces the while loop containing
list_emptyandlist_entrywithlist_for_each_entry_safe.
list_for_each_entry_safeis only needed when the current element is removed from the list within the loop body. If that is not the case, you can just uselist_for_each_entry.
Sorry, my comment was likely completely off the mark here. I was thinking that the original code was using list_for_each. With the while (!list_empty pattern, the safe version is definitely needed.
julia
Quoted 91 lines
julia
Quoted 86 lines
This was done with Coccinelle.
@@
expression E1;
identifier I1, I2;
type T;
iterator namelist_for_each_entry_safe;
@@T *I1;
+ T *tmp;
...
- while (list_empty(&E1)== 0)
+list_for_each_entry_safe(I1, tmp, &E1, I2)
{
...when != T *I1;
- I1 =list_entry(E1.next, T, I2);
...
}Signed-off-by simran singhal <[email protected]>--- drivers/staging/lustre/lustre/osc/osc_page.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)drivers/staging/lustre/lustre/osc/osc_page.c +4
-8@@ -542,6 +542,7 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,struct cl_object *clobj =NULL ;struct cl_page **pvec;struct osc_page *opg; +struct osc_page *tmp;int maxscan =0 ;long count =0 ;int index =0 ;@@ -572,7 +573,7 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,if (force) cli->cl_lru_reclaim++; maxscan =min (target <<1 ,atomic_long_read (&cli->cl_lru_in_list)); -while (!list_empty (&cli->cl_lru_list)) { +list_for_each_entry_safe (opg, tmp, &cli->cl_lru_list, ops_lru) {struct cl_page *page;bool will_free = false;@@ -582,8 +583,6 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,if (--maxscan <0 )break ; - opg = list_entry(cli->cl_lru_list.next, struct osc_page, - ops_lru); page = opg->ops_cl.cpl_page;if (lru_page_busy (cli, page)) {list_move_tail (&opg->ops_lru, &cli->cl_lru_list);@@ -1043,6 +1042,7 @@ unsigned long osc_cache_shrink_scan(struct shrinker *sk, {struct client_obd *stop_anchor =NULL ;struct client_obd *cli; +struct client_obd *tmp;struct lu_env *env;long shrank =0 ;u16 refcheck;@@ -1059,10 +1059,7 @@ unsigned long osc_cache_shrink_scan(struct shrinker *sk,return SHRINK_STOP ;spin_lock (&osc_shrink_lock); -while (!list_empty (&osc_shrink_list)) { - cli = list_entry(osc_shrink_list.next, struct client_obd, - cl_shrink_list); - +list_for_each_entry_safe (cli, tmp, &osc_shrink_list, cl_shrink_list) {if (!stop_anchor) stop_anchor = cli;else if (cli == stop_anchor) --2.7.4
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe at googlegroups.com. To post to this group, send email to outreachy-kernel at googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1488733610-22289-6-git-send-email-singhalsimran0%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Re: [Outreachy kernel] [PATCH 5/5] staging: lustre: osc_page.c: Use list_for_each_entry_safe
In reply to simran singhalBy the way, the above subject line is not correct. Normally one does not put .c/.h in the subject line. Indeed, there is not really any deterministic algorithm for choosing the subject line. You need to run git log --oneline filename to see what others have done.
julia
Quoted 93 lines · simran singhal
Doubly linked lists which are iterated using
list_emptyandlist_entrymacros have been replaced withlist_for_each_entry_safemacro.
This makes the iteration simpler and more readable.This patch replaces the while loop containing
list_emptyandlist_entrywithlist_for_each_entry_safe.This was done with Coccinelle.
@@
expression E1;
identifier I1, I2;
type T;
iterator namelist_for_each_entry_safe;
@@T *I1;
+ T *tmp;
...
- while (list_empty(&E1)== 0)
+list_for_each_entry_safe(I1, tmp, &E1, I2)
{
...when != T *I1;
- I1 =list_entry(E1.next, T, I2);
...
}Signed-off-by simran singhal <[email protected]>--- drivers/staging/lustre/lustre/osc/osc_page.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)drivers/staging/lustre/lustre/osc/osc_page.c +4
-8@@ -542,6 +542,7 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,struct cl_object *clobj =NULL ;struct cl_page **pvec;struct osc_page *opg; +struct osc_page *tmp;int maxscan =0 ;long count =0 ;int index =0 ;@@ -572,7 +573,7 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,if (force) cli->cl_lru_reclaim++; maxscan =min (target <<1 ,atomic_long_read (&cli->cl_lru_in_list)); -while (!list_empty (&cli->cl_lru_list)) { +list_for_each_entry_safe (opg, tmp, &cli->cl_lru_list, ops_lru) {struct cl_page *page;bool will_free = false;@@ -582,8 +583,6 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,if (--maxscan <0 )break ; - opg = list_entry(cli->cl_lru_list.next, struct osc_page, - ops_lru); page = opg->ops_cl.cpl_page;if (lru_page_busy (cli, page)) {list_move_tail (&opg->ops_lru, &cli->cl_lru_list);@@ -1043,6 +1042,7 @@ unsigned long osc_cache_shrink_scan(struct shrinker *sk, {struct client_obd *stop_anchor =NULL ;struct client_obd *cli; +struct client_obd *tmp;struct lu_env *env;long shrank =0 ;u16 refcheck;@@ -1059,10 +1059,7 @@ unsigned long osc_cache_shrink_scan(struct shrinker *sk,return SHRINK_STOP ;spin_lock (&osc_shrink_lock); -while (!list_empty (&osc_shrink_list)) { - cli = list_entry(osc_shrink_list.next, struct client_obd, - cl_shrink_list); - +list_for_each_entry_safe (cli, tmp, &osc_shrink_list, cl_shrink_list) {if (!stop_anchor) stop_anchor = cli;else if (cli == stop_anchor) --2.7.4
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe at googlegroups.com. To post to this group, send email to outreachy-kernel at googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1488733610-22289-6-git-send-email-singhalsimran0%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Re: [Outreachy kernel] [PATCH 5/5] staging: lustre: osc_page.c: Use list_for_each_entry_safe
Quoted 4 lines · Julia Lawall
By the way, the above subject line is not correct. Normally one does not put .c/.h in the subject line. Indeed, there is not really any deterministic algorithm for choosing the subject line. You need to run git log --oneline filename to see what others have done.
So this would be fine Subject:-
staging: lustre: osc_page: Use list_for_each_entry_safe
Quoted 98 lines
julia
Quoted 93 lines · simran singhal
Doubly linked lists which are iterated using
list_emptyandlist_entrymacros have been replaced withlist_for_each_entry_safemacro.
This makes the iteration simpler and more readable.This patch replaces the while loop containing
list_emptyandlist_entrywithlist_for_each_entry_safe.This was done with Coccinelle.
@@
expression E1;
identifier I1, I2;
type T;
iterator namelist_for_each_entry_safe;
@@T *I1;
+ T *tmp;
...
- while (list_empty(&E1)== 0)
+list_for_each_entry_safe(I1, tmp, &E1, I2)
{
...when != T *I1;
- I1 =list_entry(E1.next, T, I2);
...
}Signed-off-by simran singhal <[email protected]>--- drivers/staging/lustre/lustre/osc/osc_page.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)drivers/staging/lustre/lustre/osc/osc_page.c +4
-8@@ -542,6 +542,7 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,struct cl_object *clobj =NULL ;struct cl_page **pvec;struct osc_page *opg; +struct osc_page *tmp;int maxscan =0 ;long count =0 ;int index =0 ;@@ -572,7 +573,7 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,if (force) cli->cl_lru_reclaim++; maxscan =min (target <<1 ,atomic_long_read (&cli->cl_lru_in_list)); -while (!list_empty (&cli->cl_lru_list)) { +list_for_each_entry_safe (opg, tmp, &cli->cl_lru_list, ops_lru) {struct cl_page *page;bool will_free = false;@@ -582,8 +583,6 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,if (--maxscan <0 )break ; - opg = list_entry(cli->cl_lru_list.next, struct osc_page, - ops_lru); page = opg->ops_cl.cpl_page;if (lru_page_busy (cli, page)) {list_move_tail (&opg->ops_lru, &cli->cl_lru_list);@@ -1043,6 +1042,7 @@ unsigned long osc_cache_shrink_scan(struct shrinker *sk, {struct client_obd *stop_anchor =NULL ;struct client_obd *cli; +struct client_obd *tmp;struct lu_env *env;long shrank =0 ;u16 refcheck;@@ -1059,10 +1059,7 @@ unsigned long osc_cache_shrink_scan(struct shrinker *sk,return SHRINK_STOP ;spin_lock (&osc_shrink_lock); -while (!list_empty (&osc_shrink_list)) { - cli = list_entry(osc_shrink_list.next, struct client_obd, - cl_shrink_list); - +list_for_each_entry_safe (cli, tmp, &osc_shrink_list, cl_shrink_list) {if (!stop_anchor) stop_anchor = cli;else if (cli == stop_anchor) --2.7.4
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1488733610-22289-6-git-send-email-singhalsimran0%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Re: [Outreachy kernel] [PATCH 5/5] staging: lustre: osc_page.c: Use list_for_each_entry_safe
Quoted 8 lines · SIMRAN SINGHAL
Quoted 4 lines · Julia Lawall
By the way, the above subject line is not correct. Normally one does not put .c/.h in the subject line. Indeed, there is not really any deterministic algorithm for choosing the subject line. You need to run git log --oneline filename to see what others have done.
So this would be fine Subject:-
staging: lustre:osc_page: Uselist_for_each_entry_safe
Looking at the result of git log --oneline, I would say:
staging: lustre: osc:
For example that it what is used by 86df598, which also only changes the file modified by this patch.
julia
Quoted 100 lines
Quoted 99 lines
julia
Quoted 93 lines · simran singhal
Doubly linked lists which are iterated using
list_emptyandlist_entrymacros have been replaced withlist_for_each_entry_safemacro.
This makes the iteration simpler and more readable.This patch replaces the while loop containing
list_emptyandlist_entrywithlist_for_each_entry_safe.This was done with Coccinelle.
@@
expression E1;
identifier I1, I2;
type T;
iterator namelist_for_each_entry_safe;
@@T *I1;
+ T *tmp;
...
- while (list_empty(&E1)== 0)
+list_for_each_entry_safe(I1, tmp, &E1, I2)
{
...when != T *I1;
- I1 =list_entry(E1.next, T, I2);
...
}Signed-off-by simran singhal <[email protected]>--- drivers/staging/lustre/lustre/osc/osc_page.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)drivers/staging/lustre/lustre/osc/osc_page.c +4
-8@@ -542,6 +542,7 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,struct cl_object *clobj =NULL ;struct cl_page **pvec;struct osc_page *opg; +struct osc_page *tmp;int maxscan =0 ;long count =0 ;int index =0 ;@@ -572,7 +573,7 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,if (force) cli->cl_lru_reclaim++; maxscan =min (target <<1 ,atomic_long_read (&cli->cl_lru_in_list)); -while (!list_empty (&cli->cl_lru_list)) { +list_for_each_entry_safe (opg, tmp, &cli->cl_lru_list, ops_lru) {struct cl_page *page;bool will_free = false;@@ -582,8 +583,6 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,if (--maxscan <0 )break ; - opg = list_entry(cli->cl_lru_list.next, struct osc_page, - ops_lru); page = opg->ops_cl.cpl_page;if (lru_page_busy (cli, page)) {list_move_tail (&opg->ops_lru, &cli->cl_lru_list);@@ -1043,6 +1042,7 @@ unsigned long osc_cache_shrink_scan(struct shrinker *sk, {struct client_obd *stop_anchor =NULL ;struct client_obd *cli; +struct client_obd *tmp;struct lu_env *env;long shrank =0 ;u16 refcheck;@@ -1059,10 +1059,7 @@ unsigned long osc_cache_shrink_scan(struct shrinker *sk,return SHRINK_STOP ;spin_lock (&osc_shrink_lock); -while (!list_empty (&osc_shrink_list)) { - cli = list_entry(osc_shrink_list.next, struct client_obd, - cl_shrink_list); - +list_for_each_entry_safe (cli, tmp, &osc_shrink_list, cl_shrink_list) {if (!stop_anchor) stop_anchor = cli;else if (cli == stop_anchor) --2.7.4
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe at googlegroups.com. To post to this group, send email to outreachy-kernel at googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1488733610-22289-6-git-send-email-singhalsimran0%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Re: [Outreachy kernel] [PATCH 5/5] staging: lustre: osc_page.c: Use list_for_each_entry_safe
Quoted 13 lines · Julia Lawall
Quoted 8 lines · SIMRAN SINGHAL
Quoted 4 lines · Julia Lawall
By the way, the above subject line is not correct. Normally one does not put .c/.h in the subject line. Indeed, there is not really any deterministic algorithm for choosing the subject line. You need to run git log --oneline filename to see what others have done.
So this would be fine Subject:-
staging: lustre:osc_page: Uselist_for_each_entry_safe
Quoted 7 lines
Looking at the result of git log --oneline, I would say:
staging: lustre: osc:
For example that it what is used by 86df598, which also only changes the file modified by this patch.
Actually, I can't use this as its already subject of one of a patch of this patch
series.
Quoted 102 lines
julia
Quoted 100 lines
Quoted 99 lines
julia
Quoted 93 lines · simran singhal
Doubly linked lists which are iterated using
list_emptyandlist_entrymacros have been replaced withlist_for_each_entry_safemacro.
This makes the iteration simpler and more readable.This patch replaces the while loop containing
list_emptyandlist_entrywithlist_for_each_entry_safe.This was done with Coccinelle.
@@
expression E1;
identifier I1, I2;
type T;
iterator namelist_for_each_entry_safe;
@@T *I1;
+ T *tmp;
...
- while (list_empty(&E1)== 0)
+list_for_each_entry_safe(I1, tmp, &E1, I2)
{
...when != T *I1;
- I1 =list_entry(E1.next, T, I2);
...
}Signed-off-by simran singhal <[email protected]>--- drivers/staging/lustre/lustre/osc/osc_page.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)drivers/staging/lustre/lustre/osc/osc_page.c +4
-8@@ -542,6 +542,7 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,struct cl_object *clobj =NULL ;struct cl_page **pvec;struct osc_page *opg; +struct osc_page *tmp;int maxscan =0 ;long count =0 ;int index =0 ;@@ -572,7 +573,7 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,if (force) cli->cl_lru_reclaim++; maxscan =min (target <<1 ,atomic_long_read (&cli->cl_lru_in_list)); -while (!list_empty (&cli->cl_lru_list)) { +list_for_each_entry_safe (opg, tmp, &cli->cl_lru_list, ops_lru) {struct cl_page *page;bool will_free = false;@@ -582,8 +583,6 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,if (--maxscan <0 )break ; - opg = list_entry(cli->cl_lru_list.next, struct osc_page, - ops_lru); page = opg->ops_cl.cpl_page;if (lru_page_busy (cli, page)) {list_move_tail (&opg->ops_lru, &cli->cl_lru_list);@@ -1043,6 +1042,7 @@ unsigned long osc_cache_shrink_scan(struct shrinker *sk, {struct client_obd *stop_anchor =NULL ;struct client_obd *cli; +struct client_obd *tmp;struct lu_env *env;long shrank =0 ;u16 refcheck;@@ -1059,10 +1059,7 @@ unsigned long osc_cache_shrink_scan(struct shrinker *sk,return SHRINK_STOP ;spin_lock (&osc_shrink_lock); -while (!list_empty (&osc_shrink_list)) { - cli = list_entry(osc_shrink_list.next, struct client_obd, - cl_shrink_list); - +list_for_each_entry_safe (cli, tmp, &osc_shrink_list, cl_shrink_list) {if (!stop_anchor) stop_anchor = cli;else if (cli == stop_anchor) --2.7.4
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1488733610-22289-6-git-send-email-singhalsimran0%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Re: [Outreachy kernel] [PATCH 5/5] staging: lustre: osc_page.c: Use list_for_each_entry_safe
Quoted 16 lines · SIMRAN SINGHAL
Quoted 15 lines · Julia Lawall
Quoted 8 lines · SIMRAN SINGHAL
Quoted 4 lines · Julia Lawall
By the way, the above subject line is not correct. Normally one does not put .c/.h in the subject line. Indeed, there is not really any deterministic algorithm for choosing the subject line. You need to run git log --oneline filename to see what others have done.
So this would be fine Subject:-
staging: lustre:osc_page: Uselist_for_each_entry_safeLooking at the result of git log --oneline, I would say:
Quoted 8 lines
Quoted 5 lines
staging: lustre: osc:
For example that it what is used by 86df598, which also only changes the file modified by this patch.
Actually, I can't use this as its already subject of one of a patch of this patch
series.
OK, then what you suggested would be ok.
julia
Quoted 104 lines
Quoted 103 lines
julia
Quoted 100 lines
Quoted 99 lines
julia
Quoted 93 lines · simran singhal
Doubly linked lists which are iterated using
list_emptyandlist_entrymacros have been replaced withlist_for_each_entry_safemacro.
This makes the iteration simpler and more readable.This patch replaces the while loop containing
list_emptyandlist_entrywithlist_for_each_entry_safe.This was done with Coccinelle.
@@
expression E1;
identifier I1, I2;
type T;
iterator namelist_for_each_entry_safe;
@@T *I1;
+ T *tmp;
...
- while (list_empty(&E1)== 0)
+list_for_each_entry_safe(I1, tmp, &E1, I2)
{
...when != T *I1;
- I1 =list_entry(E1.next, T, I2);
...
}Signed-off-by simran singhal <[email protected]>--- drivers/staging/lustre/lustre/osc/osc_page.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)drivers/staging/lustre/lustre/osc/osc_page.c +4
-8@@ -542,6 +542,7 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,struct cl_object *clobj =NULL ;struct cl_page **pvec;struct osc_page *opg; +struct osc_page *tmp;int maxscan =0 ;long count =0 ;int index =0 ;@@ -572,7 +573,7 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,if (force) cli->cl_lru_reclaim++; maxscan =min (target <<1 ,atomic_long_read (&cli->cl_lru_in_list)); -while (!list_empty (&cli->cl_lru_list)) { +list_for_each_entry_safe (opg, tmp, &cli->cl_lru_list, ops_lru) {struct cl_page *page;bool will_free = false;@@ -582,8 +583,6 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,if (--maxscan <0 )break ; - opg = list_entry(cli->cl_lru_list.next, struct osc_page, - ops_lru); page = opg->ops_cl.cpl_page;if (lru_page_busy (cli, page)) {list_move_tail (&opg->ops_lru, &cli->cl_lru_list);@@ -1043,6 +1042,7 @@ unsigned long osc_cache_shrink_scan(struct shrinker *sk, {struct client_obd *stop_anchor =NULL ;struct client_obd *cli; +struct client_obd *tmp;struct lu_env *env;long shrank =0 ;u16 refcheck;@@ -1059,10 +1059,7 @@ unsigned long osc_cache_shrink_scan(struct shrinker *sk,return SHRINK_STOP ;spin_lock (&osc_shrink_lock); -while (!list_empty (&osc_shrink_list)) { - cli = list_entry(osc_shrink_list.next, struct client_obd, - cl_shrink_list); - +list_for_each_entry_safe (cli, tmp, &osc_shrink_list, cl_shrink_list) {if (!stop_anchor) stop_anchor = cli;else if (cli == stop_anchor) --2.7.4
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe at googlegroups.com. To post to this group, send email to outreachy-kernel at googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1488733610-22289-6-git-send-email-singhalsimran0%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
James Simmons
NAKRe: [PATCH 5/5] staging: lustre: osc_page.c: Use list_for_each_entry_safe
In reply to simran singhalQuoted 29 lines
Doubly linked lists which are iterated using
list_emptyandlist_entrymacros have been replaced withlist_for_each_entry_safemacro.
This makes the iteration simpler and more readable.This patch replaces the while loop containing
list_emptyandlist_entrywithlist_for_each_entry_safe.This was done with Coccinelle.
@@
expression E1;
identifier I1, I2;
type T;
iterator namelist_for_each_entry_safe;
@@T *I1;
+ T *tmp;
...
- while (list_empty(&E1)== 0)
+list_for_each_entry_safe(I1, tmp, &E1, I2)
{
...when != T *I1;
- I1 =list_entry(E1.next, T, I2);
...
}
Quoted 1 line
Signed-off-by simran singhal <[email protected]>
NAK!!!!!!
This change was reverted in commit
cd15dd6ef4ea11df87f717b8b1b83aaa738ec8af
Doing these while (list_empty(..)) to list_for_entry... are not simple changes and have broken things in lustre before. Unless you really understand the state machine of the lustre code I don't recommend these kinds of change for lustre.
Quoted 58 lines
--- drivers/staging/lustre/lustre/osc/osc_page.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)drivers/staging/lustre/lustre/osc/osc_page.c +4
-7@@ -542,6 +542,7 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,struct cl_object *clobj =NULL ;struct cl_page **pvec;struct osc_page *opg; +struct osc_page *tmp;int maxscan =0 ;long count =0 ;int index =0 ;@@ -572,7 +573,7 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,if (force) cli->cl_lru_reclaim++; maxscan =min (target <<1 ,atomic_long_read (&cli->cl_lru_in_list)); -while (!list_empty (&cli->cl_lru_list)) { +list_for_each_entry_safe (opg, tmp, &cli->cl_lru_list, ops_lru) {struct cl_page *page;bool will_free = false;@@ -582,8 +583,6 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,if (--maxscan <0 )break ; - opg = list_entry(cli->cl_lru_list.next, struct osc_page, - ops_lru); page = opg->ops_cl.cpl_page;if (lru_page_busy (cli, page)) {list_move_tail (&opg->ops_lru, &cli->cl_lru_list);@@ -1043,6 +1042,7 @@ unsigned long osc_cache_shrink_scan(struct shrinker *sk, {struct client_obd *stop_anchor =NULL ;struct client_obd *cli; +struct client_obd *tmp;struct lu_env *env;long shrank =0 ;u16 refcheck;@@ -1059,10 +1059,7 @@ unsigned long osc_cache_shrink_scan(struct shrinker *sk,return SHRINK_STOP ;spin_lock (&osc_shrink_lock); -while (!list_empty (&osc_shrink_list)) { - cli = list_entry(osc_shrink_list.next, struct client_obd, - cl_shrink_list); - +list_for_each_entry_safe (cli, tmp, &osc_shrink_list, cl_shrink_list) {if (!stop_anchor) stop_anchor = cli;else if (cli == stop_anchor)Signature · 1 line
2.7.4
Patrick Farrell
NAKPATCH 5/5 staging: lustre: osc_page.c: Use list_for_each_entry_safe
I would also dispute the logic in this particular Coccinelle script more generally.
list_for_each_entry_safe and while(list_empty(&list) == 0) (or, more clearly, while(!list_empty(&list))) are NOT equivalent.
Unless I've misunderstood the "for" loop used, that will run once for each item in the list, 'while' will run until the list is empty. They just aren't the same thing, and can't be swapped one for one in general. Sure, sometimes the usage is equivalent, but this coccinelle script can at most flag candidates for a change (which must be checked), it can't be used to just generate patches.
- Patrick
________________________________
From: lustre-devel <[email protected]> on behalf of James Simmons <[email protected]>
Sent: Monday, March 6, 2017 9:20:49 AM
To: simran singhal
Cc: devel at driverdev.osuosl.org; gregkh at linuxfoundation.org; linux-kernel at vger.kernel.org; oleg.drokin at intel.com; outreachy-kernel at googlegroups.com; lustre-devel at lists.lustre.org
Subject: Re: [lustre-devel] [PATCH 5/5] staging: lustre: osc_page.c: Use list_for_each_entry_safe
Quoted 28 lines
Doubly linked lists which are iterated using
list_emptyandlist_entrymacros have been replaced withlist_for_each_entry_safemacro.
This makes the iteration simpler and more readable.This patch replaces the while loop containing
list_emptyandlist_entrywithlist_for_each_entry_safe.This was done with Coccinelle.
@@
expression E1;
identifier I1, I2;
type T;
iterator namelist_for_each_entry_safe;
@@T *I1;
+ T *tmp;
...
- while (list_empty(&E1)== 0)
+list_for_each_entry_safe(I1, tmp, &E1, I2)
{
...when != T *I1;
- I1 =list_entry(E1.next, T, I2);
...
}
Quoted 1 line
Signed-off-by simran singhal <[email protected]>
NAK!!!!!!
This change was reverted in commit
cd15dd6ef4ea11df87f717b8b1b83aaa738ec8af
Doing these while (list_empty(..)) to list_for_entry... are not simple changes and have broken things in lustre before. Unless you really understand the state machine of the lustre code I don't recommend these kinds of change for lustre.
Quoted 55 lines
--- drivers/staging/lustre/lustre/osc/osc_page.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)drivers/staging/lustre/lustre/osc/osc_page.c +4
-8@@ -542,6 +542,7 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,struct cl_object *clobj =NULL ;struct cl_page **pvec;struct osc_page *opg; +struct osc_page *tmp;int maxscan =0 ;long count =0 ;int index =0 ;@@ -572,7 +573,7 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,if (force) cli->cl_lru_reclaim++; maxscan =min (target <<1 ,atomic_long_read (&cli->cl_lru_in_list)); -while (!list_empty (&cli->cl_lru_list)) { +list_for_each_entry_safe (opg, tmp, &cli->cl_lru_list, ops_lru) {struct cl_page *page;bool will_free = false;@@ -582,8 +583,6 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,if (--maxscan <0 )break ; - opg = list_entry(cli->cl_lru_list.next, struct osc_page, - ops_lru); page = opg->ops_cl.cpl_page;if (lru_page_busy (cli, page)) {list_move_tail (&opg->ops_lru, &cli->cl_lru_list);@@ -1043,6 +1042,7 @@ unsigned long osc_cache_shrink_scan(struct shrinker *sk, {struct client_obd *stop_anchor =NULL ;struct client_obd *cli; +struct client_obd *tmp;struct lu_env *env;long shrank =0 ;u16 refcheck;@@ -1059,10 +1059,7 @@ unsigned long osc_cache_shrink_scan(struct shrinker *sk,return SHRINK_STOP ;spin_lock (&osc_shrink_lock); -while (!list_empty (&osc_shrink_list)) { - cli = list_entry(osc_shrink_list.next, struct client_obd, - cl_shrink_list); - +list_for_each_entry_safe (cli, tmp, &osc_shrink_list, cl_shrink_list) {if (!stop_anchor) stop_anchor = cli;else if (cli == stop_anchor) --
Quoted 3 lines
2.7.4
_______________________________________________
lustre-devel mailing list
lustre-devel at lists.lustre.org
http://lists.lustre.org/listinfo.cgi/lustre-devel-lustre.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lustre.org/pipermail/lustre-devel-lustre.org/attachments/20170306/fce428a6/attachment.htm>
Re: [PATCH 5/5] staging: lustre: osc_page.c: Use list_for_each_entry_safe
In reply to James SimmonsQuoted 35 lines · James Simmons
Quoted 29 lines
Doubly linked lists which are iterated using
list_emptyandlist_entrymacros have been replaced withlist_for_each_entry_safemacro.
This makes the iteration simpler and more readable.This patch replaces the while loop containing
list_emptyandlist_entrywithlist_for_each_entry_safe.This was done with Coccinelle.
@@
expression E1;
identifier I1, I2;
type T;
iterator namelist_for_each_entry_safe;
@@T *I1;
+ T *tmp;
...
- while (list_empty(&E1)== 0)
+list_for_each_entry_safe(I1, tmp, &E1, I2)
{
...when != T *I1;
- I1 =list_entry(E1.next, T, I2);
...
}Quoted 1 line
Signed-off-by simran singhal <[email protected]>NAK!!!!!!
This change was reverted in commit
Quoted 8 lines
cd15dd6ef4ea11df87f717b8b1b83aaa738ec8afDoing these while (
list_empty(..)) tolist_for_entry... are not simple changes and have broken things in lustre before. Unless you really understand the state machine of the lustre code I don't recommend these kinds of change for lustre.
Is this for this particular patch or for all the patches of this patch-series.
Quoted 58 lines
Quoted 58 lines
--- drivers/staging/lustre/lustre/osc/osc_page.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)drivers/staging/lustre/lustre/osc/osc_page.c +4
-8@@ -542,6 +542,7 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,struct cl_object *clobj =NULL ;struct cl_page **pvec;struct osc_page *opg; +struct osc_page *tmp;int maxscan =0 ;long count =0 ;int index =0 ;@@ -572,7 +573,7 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,if (force) cli->cl_lru_reclaim++; maxscan =min (target <<1 ,atomic_long_read (&cli->cl_lru_in_list)); -while (!list_empty (&cli->cl_lru_list)) { +list_for_each_entry_safe (opg, tmp, &cli->cl_lru_list, ops_lru) {struct cl_page *page;bool will_free = false;@@ -582,8 +583,6 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,if (--maxscan <0 )break ; - opg = list_entry(cli->cl_lru_list.next, struct osc_page, - ops_lru); page = opg->ops_cl.cpl_page;if (lru_page_busy (cli, page)) {list_move_tail (&opg->ops_lru, &cli->cl_lru_list);@@ -1043,6 +1042,7 @@ unsigned long osc_cache_shrink_scan(struct shrinker *sk, {struct client_obd *stop_anchor =NULL ;struct client_obd *cli; +struct client_obd *tmp;struct lu_env *env;long shrank =0 ;u16 refcheck;@@ -1059,10 +1059,7 @@ unsigned long osc_cache_shrink_scan(struct shrinker *sk,return SHRINK_STOP ;spin_lock (&osc_shrink_lock); -while (!list_empty (&osc_shrink_list)) { - cli = list_entry(osc_shrink_list.next, struct client_obd, - cl_shrink_list); - +list_for_each_entry_safe (cli, tmp, &osc_shrink_list, cl_shrink_list) {if (!stop_anchor) stop_anchor = cli;else if (cli == stop_anchor) --2.7.4
Re: [PATCH 5/5] staging: lustre: osc_page.c: Use list_for_each_entry_safe
In reply to James SimmonsQuoted 36 lines · James Simmons
Quoted 30 lines
Doubly linked lists which are iterated using
list_emptyandlist_entrymacros have been replaced withlist_for_each_entry_safemacro.
This makes the iteration simpler and more readable.This patch replaces the while loop containing
list_emptyandlist_entrywithlist_for_each_entry_safe.This was done with Coccinelle.
@@
expression E1;
identifier I1, I2;
type T;
iterator namelist_for_each_entry_safe;
@@T *I1;
+ T *tmp;
...
- while (list_empty(&E1)== 0)
+list_for_each_entry_safe(I1, tmp, &E1, I2)
{
...when != T *I1;
- I1 =list_entry(E1.next, T, I2);
...
}Quoted 1 line
Signed-off-by simran singhal <[email protected]>NAK!!!!!!
This change was reverted in commit
Quoted 7 lines
cd15dd6ef4ea11df87f717b8b1b83aaa738ec8afDoing these while (
list_empty(..)) tolist_for_entry... are not simple changes and have broken things in lustre before. Unless you really understand the state machine of the lustre code I don't recommend these kinds of change for lustre.
It may be useful to add a comment to these cases where the while() loop cannot be replaced by list_for_each_entry_safe() (with details of why that is the case) to avoid such optimization attempts again in the future.
Cheers, Andreas
Quoted 46 lines
Quoted 46 lines
---
drivers/staging/lustre/lustre/osc/osc_page.c| 11 ++++-------1 file changed, 4 insertions(+), 7 deletions(-)drivers/staging/lustre/lustre/osc/osc_page.c +3
-3@@ -542,6 +542,7 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,struct cl_object *clobj =NULL ;struct cl_page **pvec;struct osc_page *opg; +struct osc_page *tmp;int maxscan =0 ;long count =0 ;int index =0 ;@@ -572,7 +573,7 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,if (force) cli->cl_lru_reclaim++; maxscan =min (target <<1 ,atomic_long_read (&cli->cl_lru_in_list)); -while (!list_empty (&cli->cl_lru_list)) { +list_for_each_entry_safe (opg, tmp, &cli->cl_lru_list, ops_lru) {struct cl_page *page;bool will_free = false;@@ -582,8 +583,6 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,if (--maxscan <0 )break ; - opg = list_entry(cli->cl_lru_list.next, struct osc_page, - ops_lru); page = opg->ops_cl.cpl_page;if (lru_page_busy (cli, page)) {list_move_tail (&opg->ops_lru, &cli->cl_lru_list);@@ -1043,6 +1042,7 @@ unsigned long osc_cache_shrink_scan(struct shrinker *sk, {struct client_obd *stop_anchor =NULL ;struct client_obd *cli; +struct client_obd *tmp;struct lu_env *env;long shrank =0 ;u16 refcheck;@@ -1059,10 +1059,7 @@ unsigned long osc_cache_shrink_scan(struct shrinker *sk,return SHRINK_STOP ;
Quoted 11 lines
Quoted 11 lines
drivers/staging/lustre/lustre/osc/osc_page.c +1
-4spin_lock (&osc_shrink_lock); -while (!list_empty (&osc_shrink_list)) { - cli = list_entry(osc_shrink_list.next, struct client_obd, - cl_shrink_list); - +list_for_each_entry_safe (cli, tmp, &osc_shrink_list, cl_shrink_list) {if (!stop_anchor) stop_anchor = cli;else if (cli == stop_anchor)Signature · 1 line
2.7.4
Cheers, Andreas
--
Andreas Dilger
Lustre Principal Architect
Intel Corporation