From: Kuniyuki Iwashima <kuniyu@google.com>
To: Eric Dumazet <edumazet@google.com>
Cc: "David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org, eric.dumazet@gmail.com,
Alexander Lobakin <aleksander.lobakin@intel.com>
Subject: Re: [PATCH net-next] net: shrink napi_skb_cache_put()
Date: Wed, 15 Oct 2025 17:14:21 -0700 [thread overview]
Message-ID: <CAAVpQUCsYsvZG76xvR9iCdd_4bjo0iLCRXPmHMidGOAJQc0Jhg@mail.gmail.com> (raw)
In-Reply-To: <20251015233801.2977044-1-edumazet@google.com>
On Wed, Oct 15, 2025 at 4:38 PM Eric Dumazet <edumazet@google.com> wrote:
>
> Following loop in napi_skb_cache_put() is unrolled by the compiler
> even if CONFIG_KASAN is not enabled:
>
> for (i = NAPI_SKB_CACHE_HALF; i < NAPI_SKB_CACHE_SIZE; i++)
> kasan_mempool_unpoison_object(nc->skb_cache[i],
> kmem_cache_size(net_hotdata.skbuff_cache));
>
> We have 32 times this sequence, for a total of 384 bytes.
>
> 48 8b 3d 00 00 00 00 net_hotdata.skbuff_cache,%rdi
> e8 00 00 00 00 call kmem_cache_size
>
> This is because kmem_cache_size() is an extern function,
> and kasan_unpoison_object_data() is an inline function.
>
> Cache kmem_cache_size() result in a temporary variable, and
> make the loop conditional to CONFIG_KASAN.
>
> After this patch, napi_skb_cache_put() is inlined in its callers.
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Oh exactly, it's interesting that the compiler cannot optimise out
unused retval even though kmem_cache_size() is a single load :o
$ grep KASAN .config
CONFIG_HAVE_ARCH_KASAN=y
CONFIG_HAVE_ARCH_KASAN_VMALLOC=y
CONFIG_CC_HAS_KASAN_GENERIC=y
CONFIG_CC_HAS_KASAN_SW_TAGS=y
# CONFIG_KASAN is not set
$ objdump --disassemble=napi_skb_cache_put vmlinux
...
ffffffff81e9fe10 <napi_skb_cache_put>:
...
ffffffff81e9fe40: 48 8b 3d 89 bd d6 00 mov 0xd6bd89(%rip),%rdi
# ffffffff82c0bbd0 <net_hotdata+0x150>
ffffffff81e9fe47: e8 a4 79 60 ff call ffffffff814a77f0 <kmem_cache_size>
ffffffff81e9fe4c: 83 eb 01 sub $0x1,%ebx
ffffffff81e9fe4f: 75 ef jne ffffffff81e9fe40
<napi_skb_cache_put+0x30>
next prev parent reply other threads:[~2025-10-16 0:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-15 23:38 [PATCH net-next] net: shrink napi_skb_cache_put() Eric Dumazet
2025-10-16 0:14 ` Kuniyuki Iwashima [this message]
2025-10-16 10:20 ` Alexander Lobakin
2025-10-16 10:31 ` Eric Dumazet
2025-10-16 11:07 ` Alexander Lobakin
2025-10-16 12:56 ` Eric Dumazet
2025-10-16 13:29 ` Eric Dumazet
2025-10-16 13:36 ` Eric Dumazet
2025-10-16 15:24 ` Alexander Lobakin
2025-10-16 15:27 ` Eric Dumazet
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=CAAVpQUCsYsvZG76xvR9iCdd_4bjo0iLCRXPmHMidGOAJQc0Jhg@mail.gmail.com \
--to=kuniyu@google.com \
--cc=aleksander.lobakin@intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=eric.dumazet@gmail.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/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;
as well as URLs for NNTP newsgroup(s).