From: Paul Menzel <pmenzel@molgen.mpg.de>
To: Qianfeng Rong <rongqianfeng@vivo.com>
Cc: Tony Nguyen <anthony.l.nguyen@intel.com>,
Przemek Kitszel <przemyslaw.kitszel@intel.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Jesper Dangaard Brouer <hawk@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
Stanislav Fomichev <sdf@fomichev.me>,
intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>,
bpf@vger.kernel.org
Subject: Re: [Intel-wired-lan] [PATCH 1/5] ethtool: use vmalloc_array() to simplify code
Date: Thu, 14 Aug 2025 08:28:42 +0200 [thread overview]
Message-ID: <2ec36cd7-7378-4e44-894a-93008348a96a@molgen.mpg.de> (raw)
In-Reply-To: <abc66ec5-85a4-47e1-9759-2f60ab111971@vivo.com>
Dear Quianfeng,
Thank you very much for your reply.
Am 14.08.25 um 06:05 schrieb Qianfeng Rong:
>
> 在 2025/8/13 0:34, Paul Menzel 写道:
[…]
>> Am 12.08.25 um 15:32 schrieb Qianfeng Rong:
>>> Remove array_size() calls and replace vmalloc() with vmalloc_array() to
>>> simplify the code and maintain consistency with existing kmalloc_array()
>>> usage.
>>
>> You could build it without and with your patch and look if the assembler
>> code changes.
>
> Very good point, the following experiment was done:
> //before apply patch:
> objdump -dSl --prefix-addresses fm10k_ethtool.o > original.dis
>
> //after apply patch:
> objdump -dSl --prefix-addresses fm10k_ethtool.o > patched.dis
>
> diff -u original.dis patched.dis | diffstat
> patched.dis | 1578 ... 1 file changed, 785 insertions(+), 793 deletions(-)
>
> From the above results, we can see that the assembly instructions are
> reduced after applying the patch.
>
>
> #define array_size(a, b) size_mul(a, b)
>
> static inline size_t __must_check size_mul(size_t factor1, size_t factor2)
> {
> size_t bytes;
>
> if (check_mul_overflow(factor1, factor2, &bytes))
> return SIZE_MAX;
>
> return bytes;
> }
>
> void *__vmalloc_array_noprof(size_t n, size_t size, gfp_t flags)
> {
> size_t bytes;
>
> if (unlikely(check_mul_overflow(n, size, &bytes)))
> return NULL;
> return __vmalloc_noprof(bytes, flags);
> }
>
> And from the code, array_size() will return SIZE_MAX after detecting
> overflow. SIZE_MAX is passed to vmalloc for available memory
> verification before exiting and returning NULL. vmalloc_array()
> will directly return NULL after detecting overflow.
Awesome! Thank you for digging that up. Maybe something to add to the
commit message. Maybe something like:
`vmalloc_array()` is also optimized better, resulting in less
instructions being used, which can be verified with:
objdump -dSl --prefix-addresses <changed module>.o
>> Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>
Kind regards,
Paul
next prev parent reply other threads:[~2025-08-14 6:29 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-12 13:32 [PATCH 0/5] net: " Qianfeng Rong
2025-08-12 13:32 ` [PATCH 1/5] ethtool: " Qianfeng Rong
2025-08-12 16:28 ` [Intel-wired-lan] " Loktionov, Aleksandr
2025-08-12 16:34 ` Paul Menzel
2025-08-14 4:05 ` Qianfeng Rong
2025-08-14 6:28 ` Paul Menzel [this message]
2025-08-14 6:41 ` Qianfeng Rong
2025-08-12 20:49 ` Jakub Kicinski
2025-08-13 7:00 ` Qianfeng Rong
2025-08-12 13:32 ` [PATCH 2/5] nfp: flower: " Qianfeng Rong
2025-08-12 13:32 ` [PATCH 3/5] ppp: use vmalloc_array() to simplify Qianfeng Rong
2025-08-12 13:32 ` [PATCH 4/5] wifi: ath5k: use vmalloc_array() to simplify code Qianfeng Rong
2025-08-12 13:32 ` [PATCH 5/5] wifi: mwifiex: " Qianfeng Rong
2025-08-12 13:48 ` Dan Carpenter
2025-08-12 14:13 ` Qianfeng Rong
2025-08-12 14:31 ` Dan Carpenter
2025-08-13 6:52 ` Qianfeng Rong
2025-08-13 9:25 ` Dan Carpenter
2025-08-13 18:35 ` Jeff Johnson
2025-08-14 6:24 ` Dan Carpenter
2025-08-12 20:48 ` [PATCH 0/5] net: " Jakub Kicinski
2025-08-13 1:53 ` Qianfeng Rong
2025-08-13 6:49 ` Qianfeng Rong
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=2ec36cd7-7378-4e44-894a-93008348a96a@molgen.mpg.de \
--to=pmenzel@molgen.mpg.de \
--cc=andrew+netdev@lunn.ch \
--cc=anthony.l.nguyen@intel.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hawk@kernel.org \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=przemyslaw.kitszel@intel.com \
--cc=rongqianfeng@vivo.com \
--cc=sdf@fomichev.me \
/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®