From: Przemek Kitszel <przemyslaw.kitszel@intel.com>
To: Dan Carpenter <dan.carpenter@linaro.org>,
Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: intel-wired-lan@lists.osuosl.org,
kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org,
Alexander Lobakin <aleksander.lobakin@intel.com>,
Eric Dumazet <edumazet@google.com>,
Pavan Kumar Linga <pavan.kumar.linga@intel.com>,
Tony Nguyen <anthony.l.nguyen@intel.com>,
netdev@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
"David S. Miller" <davem@davemloft.net>
Subject: Re: [Intel-wired-lan] [PATCH net-next] idpf: Slightly simplify memory management in idpf_add_del_mac_filters()
Date: Mon, 26 Aug 2024 11:15:47 +0200 [thread overview]
Message-ID: <2896a4b2-2297-44cd-b4c7-a4d320298740@intel.com> (raw)
In-Reply-To: <c786a345-9ec4-4e41-8e69-506239db291c@stanley.mountain>
On 8/23/24 11:10, Dan Carpenter wrote:
> On Fri, Aug 23, 2024 at 08:23:29AM +0200, Christophe JAILLET wrote:
>> In idpf_add_del_mac_filters(), filters are chunked up into multiple
>> messages to avoid sending a control queue message buffer that is too large.
>>
>> Each chunk has up to IDPF_NUM_FILTERS_PER_MSG entries. So except for the
>> last iteration which can be smaller, space for exactly
>> IDPF_NUM_FILTERS_PER_MSG entries is allocated.
>>
>> There is no need to free and reallocate a smaller array just for the last
>> iteration.
>>
>> This slightly simplifies the code and avoid an (unlikely) memory allocation
>> failure.
>>
Thanks, that is indeed an improvement.
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> ---
>> drivers/net/ethernet/intel/idpf/idpf_virtchnl.c | 7 +++++--
>> 1 file changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
>> index 70986e12da28..b6f4b58e1094 100644
>> --- a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
>> +++ b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
>> @@ -3669,12 +3669,15 @@ int idpf_add_del_mac_filters(struct idpf_vport *vport,
>> entries_size = sizeof(struct virtchnl2_mac_addr) * num_entries;
>> buf_size = struct_size(ma_list, mac_addr_list, num_entries);
>>
>> - if (!ma_list || num_entries != IDPF_NUM_FILTERS_PER_MSG) {
>> - kfree(ma_list);
>> + if (!ma_list) {
>> ma_list = kzalloc(buf_size, GFP_ATOMIC);
>> if (!ma_list)
>> return -ENOMEM;
>> } else {
>> + /* ma_list was allocated in the first iteration
>> + * so IDPF_NUM_FILTERS_PER_MSG entries are
>> + * available
>> + */
>> memset(ma_list, 0, buf_size);
>> }
>
> It would be even nicer to move the ma_list allocation outside the loop:
>
> buf_size = struct_size(ma_list, mac_addr_list, IDPF_NUM_FILTERS_PER_MSG);
> ma_list = kmalloc(buf_size, GFP_ATOMIC);
good point
I've opened whole function for inspection and it asks for even more,
as of now, we allocate an array in atomic context, just to have a copy
of some stuff from the spinlock-protected list.
It would be good to have allocation as pointed by Dan prior to iteration
and fill it on the fly, sending when new message would not fit plus once
at the end. Sending procedure is safe to be called under a spinlock.
CCing author; CCing Olek to ask if there are already some refactors that
would conflict with this.
>
> regards,
> dan carpenter
>
next prev parent reply other threads:[~2024-08-26 9:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-23 6:23 [Intel-wired-lan] [PATCH net-next] idpf: Slightly simplify memory management in idpf_add_del_mac_filters() Christophe JAILLET
2024-08-23 9:10 ` Dan Carpenter
2024-08-26 9:15 ` Przemek Kitszel [this message]
2024-08-26 17:14 ` Christophe JAILLET
2024-08-27 6:58 ` Przemek Kitszel
2024-08-27 14:09 ` Alexander Lobakin
2024-08-23 16:12 ` Simon Horman
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=2896a4b2-2297-44cd-b4c7-a4d320298740@intel.com \
--to=przemyslaw.kitszel@intel.com \
--cc=aleksander.lobakin@intel.com \
--cc=anthony.l.nguyen@intel.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=dan.carpenter@linaro.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pavan.kumar.linga@intel.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