From: Paolo Abeni <pabeni@redhat.com>
To: Tian Tao <tiantao6@hisilicon.com>,
davem@davemloft.net, kuba@kernel.org, linmiaohe@huawei.com,
martin.varghese@nokia.com, pshelar@ovn.org, fw@strlen.de,
viro@zeniv.linux.org.uk, gnault@redhat.com,
steffen.klassert@secunet.com, kyk.segfault@gmail.com,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net/core: use xx_zalloc instead xx_alloc and memset
Date: Wed, 18 Nov 2020 11:47:00 +0100 [thread overview]
Message-ID: <f29be74792c7711e0a157a6a024d3998d30be4dd.camel@redhat.com> (raw)
In-Reply-To: <1605687308-57318-1-git-send-email-tiantao6@hisilicon.com>
On Wed, 2020-11-18 at 16:15 +0800, Tian Tao wrote:
> use kmem_cache_zalloc instead kmem_cache_alloc and memset.
>
> Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
> ---
> net/core/skbuff.c | 10 +++-------
> 1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> index c9a5a3c..3449c1c 100644
> --- a/net/core/skbuff.c
> +++ b/net/core/skbuff.c
> @@ -313,12 +313,10 @@ struct sk_buff *__build_skb(void *data, unsigned int frag_size)
> {
> struct sk_buff *skb;
>
> - skb = kmem_cache_alloc(skbuff_head_cache, GFP_ATOMIC);
> + skb = kmem_cache_zalloc(skbuff_head_cache, GFP_ATOMIC);
This will zeroed a slighly larger amount of data compared to the
existing code: offsetof(struct sk_buff, tail) == 182, sizeof(struct
sk_buff) == 224.
> if (unlikely(!skb))
> return NULL;
>
> - memset(skb, 0, offsetof(struct sk_buff, tail));
Additionally this leverages constant argument optimizations.
Possibly overall not noticeable, but this code path is quite critical
performance wise.
I would avoid the above.
> -
> return __build_skb_around(skb, data, frag_size);
> }
>
> @@ -6170,12 +6168,10 @@ static void *skb_ext_get_ptr(struct skb_ext *ext, enum skb_ext_id id)
> */
> struct skb_ext *__skb_ext_alloc(gfp_t flags)
> {
> - struct skb_ext *new = kmem_cache_alloc(skbuff_ext_cache, flags);
> + struct skb_ext *new = kmem_cache_zalloc(skbuff_ext_cache, flags);
>
> - if (new) {
> - memset(new->offset, 0, sizeof(new->offset));
Similar to the above, but additionally here the number of zeroed bytes
changes a lot and a few additional cachelines will be touched. The
performance impact is likely relevant.
Overall I think we should not do this.
Thanks,
Paolo
prev parent reply other threads:[~2020-11-18 10:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-18 8:15 Tian Tao
2020-11-18 8:31 ` Joe Perches
2020-11-18 10:47 ` Paolo Abeni [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f29be74792c7711e0a157a6a024d3998d30be4dd.camel@redhat.com \
--to=pabeni@redhat.com \
--cc=davem@davemloft.net \
--cc=fw@strlen.de \
--cc=gnault@redhat.com \
--cc=kuba@kernel.org \
--cc=kyk.segfault@gmail.com \
--cc=linmiaohe@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.varghese@nokia.com \
--cc=netdev@vger.kernel.org \
--cc=pshelar@ovn.org \
--cc=steffen.klassert@secunet.com \
--cc=tiantao6@hisilicon.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®