diff mbox series

[net-next] net_sched: make qdisc_reset() smaller

Message ID 20220414011004.2378350-1-eric.dumazet@gmail.com (mailing list archive)
State Accepted
Commit c9a40d1c87e9b5c74b5ac73e81ed3d5be4d1b1af
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net_sched: make qdisc_reset() smaller | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 9 this patch: 9
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 24 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Eric Dumazet April 14, 2022, 1:10 a.m. UTC
From: Eric Dumazet <edumazet@google.com>

For some unknown reason qdisc_reset() is using
a convoluted way of freeing two lists of skbs.

Use __skb_queue_purge() instead.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/sched/sch_generic.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

Comments

Jamal Hadi Salim April 14, 2022, 4:08 p.m. UTC | #1
On 2022-04-13 21:10, Eric Dumazet wrote:
> From: Eric Dumazet <edumazet@google.com>
> 
> For some unknown reason qdisc_reset() is using
> a convoluted way of freeing two lists of skbs.
> 
> Use __skb_queue_purge() instead.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> ---
>   net/sched/sch_generic.c | 12 ++----------
>   1 file changed, 2 insertions(+), 10 deletions(-)
> 
> diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
> index 5bab9f8b8f453526185c3b6df57065450b1e3d89..dba0b3e24af5e84f7116ae9b6fdb6f66b01a896c 100644
> --- a/net/sched/sch_generic.c
> +++ b/net/sched/sch_generic.c
> @@ -1019,22 +1019,14 @@ EXPORT_SYMBOL(qdisc_create_dflt);
>   void qdisc_reset(struct Qdisc *qdisc)
>   {
>   	const struct Qdisc_ops *ops = qdisc->ops;
> -	struct sk_buff *skb, *tmp;
>   
>   	trace_qdisc_reset(qdisc);
>   
>   	if (ops->reset)
>   		ops->reset(qdisc);
>   
> -	skb_queue_walk_safe(&qdisc->gso_skb, skb, tmp) {
> -		__skb_unlink(skb, &qdisc->gso_skb);
> -		kfree_skb_list(skb);
> -	}
> -
> -	skb_queue_walk_safe(&qdisc->skb_bad_txq, skb, tmp) {
> -		__skb_unlink(skb, &qdisc->skb_bad_txq);
> -		kfree_skb_list(skb);
> -	}
> +	__skb_queue_purge(&qdisc->gso_skb);
> +	__skb_queue_purge(&qdisc->skb_bad_txq);
>   

Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>

cheers,
jamal
patchwork-bot+netdevbpf@kernel.org April 15, 2022, 9:30 p.m. UTC | #2
Hello:

This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 13 Apr 2022 18:10:04 -0700 you wrote:
> From: Eric Dumazet <edumazet@google.com>
> 
> For some unknown reason qdisc_reset() is using
> a convoluted way of freeing two lists of skbs.
> 
> Use __skb_queue_purge() instead.
> 
> [...]

Here is the summary with links:
  - [net-next] net_sched: make qdisc_reset() smaller
    https://git.kernel.org/netdev/net-next/c/c9a40d1c87e9

You are awesome, thank you!
Cong Wang April 17, 2022, 10:30 p.m. UTC | #3
On Wed, Apr 13, 2022 at 6:11 PM Eric Dumazet <eric.dumazet@gmail.com> wrote:
>
> From: Eric Dumazet <edumazet@google.com>
>
> For some unknown reason qdisc_reset() is using
> a convoluted way of freeing two lists of skbs.
>
> Use __skb_queue_purge() instead.
[...]
>
> -       skb_queue_walk_safe(&qdisc->gso_skb, skb, tmp) {
> -               __skb_unlink(skb, &qdisc->gso_skb);
> -               kfree_skb_list(skb);

Isn't it precisely because of this kfree_skb_list()?

Thanks.
Eric Dumazet April 17, 2022, 10:41 p.m. UTC | #4
On Sun, Apr 17, 2022 at 3:30 PM Cong Wang <xiyou.wangcong@gmail.com> wrote:
>
> On Wed, Apr 13, 2022 at 6:11 PM Eric Dumazet <eric.dumazet@gmail.com> wrote:
> >
> > From: Eric Dumazet <edumazet@google.com>
> >
> > For some unknown reason qdisc_reset() is using
> > a convoluted way of freeing two lists of skbs.
> >
> > Use __skb_queue_purge() instead.
> [...]
> >
> > -       skb_queue_walk_safe(&qdisc->gso_skb, skb, tmp) {
> > -               __skb_unlink(skb, &qdisc->gso_skb);
> > -               kfree_skb_list(skb);
>
> Isn't it precisely because of this kfree_skb_list()?

Note the __skb_unlink(skb, &qdisc->gso_skb) which happens at the line above.

__skb_unlink(...)
{
...
skb->next  = skb->prev = NULL;
...
}

This means skb->next is NULL, thus there is no list of skb attached to @skb ?

kfree_skb_list(skb) is thus a convoluted way to call kfree_skb(skb)

It seems to me that this construct had been copy/pasted from elsewhere.
diff mbox series

Patch

diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
index 5bab9f8b8f453526185c3b6df57065450b1e3d89..dba0b3e24af5e84f7116ae9b6fdb6f66b01a896c 100644
--- a/net/sched/sch_generic.c
+++ b/net/sched/sch_generic.c
@@ -1019,22 +1019,14 @@  EXPORT_SYMBOL(qdisc_create_dflt);
 void qdisc_reset(struct Qdisc *qdisc)
 {
 	const struct Qdisc_ops *ops = qdisc->ops;
-	struct sk_buff *skb, *tmp;
 
 	trace_qdisc_reset(qdisc);
 
 	if (ops->reset)
 		ops->reset(qdisc);
 
-	skb_queue_walk_safe(&qdisc->gso_skb, skb, tmp) {
-		__skb_unlink(skb, &qdisc->gso_skb);
-		kfree_skb_list(skb);
-	}
-
-	skb_queue_walk_safe(&qdisc->skb_bad_txq, skb, tmp) {
-		__skb_unlink(skb, &qdisc->skb_bad_txq);
-		kfree_skb_list(skb);
-	}
+	__skb_queue_purge(&qdisc->gso_skb);
+	__skb_queue_purge(&qdisc->skb_bad_txq);
 
 	qdisc->q.qlen = 0;
 	qdisc->qstats.backlog = 0;