From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: Felix Maurer <fmaurer@redhat.com>
Cc: Ren Wei <n05ec@lzu.edu.cn>,
netdev@vger.kernel.org, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
kees@kernel.org, kexinsun@smail.nju.edu.cn, luka.gejak@linux.dev,
Arvid.Brodin@xdin.com, m-karicheri2@ti.com, yuantan098@gmail.com,
yifanwucs@gmail.com, tomapufckgml@gmail.com, bird@lzu.edu.cn,
xuyuqiabc@gmail.com, royenheart@gmail.com
Subject: Re: [PATCH net v3 1/1] net: hsr: limit node table growth
Date: Wed, 22 Apr 2026 12:58:54 +0200 [thread overview]
Message-ID: <20260422105854.trLbmAmZ@linutronix.de> (raw)
In-Reply-To: <aeiYpkiWUD5MtGEB@thinkpad>
On 2026-04-22 11:45:38 [+0200], Felix Maurer wrote:
> > I don't think the node count exceeds 100 in production. So having a
> > counter which is incremented while adding to the list and decremented
> > while removing items from the list would optimize the "worst case". So
> > instead traversing the list with 1000 we would just give up.
>
> The counter is what I had in mind. I agree that allocating under the
> lock isn't what we want.
>
> I'd argue counting through the whole list is the normal case.
yeah but counting here is just a register increment which is cheap.
> hsr_add_node() is only called after the node table has been searched
> already (without the lock). Here we go through the whole list again
> under the lock to prevent TOCTOU-type situations.
>
> I agree that, overall, it would be optimizing the worst case, but I
> think it may be worth it to prevent the memory allocations and walking
> the whole list. But I'd go along with the (current) on-the-fly counting
> as well.
Yeah. But then you have to manage the counter on add and removal just
for this "we have too many nodes" case. And theoretically you would have
to hold the list_lock while checking the counter because nodes might be
added on both sides in the RX path (unless you check early lockless &
optimistic and then again before adding under the lock).
So overall this looks simpler.
> Thanks,
> Felix
Sebastian
next prev parent reply other threads:[~2026-04-22 10:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-21 14:50 [PATCH net v3 1/1] net: hsr: limit node table growth Ren Wei
2026-04-21 15:18 ` Andrew Lunn
2026-04-22 8:31 ` Felix Maurer
2026-04-22 8:52 ` Sebastian Andrzej Siewior
2026-04-22 9:45 ` Felix Maurer
2026-04-22 10:58 ` Sebastian Andrzej Siewior [this message]
2026-04-22 12:38 ` Felix Maurer
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=20260422105854.trLbmAmZ@linutronix.de \
--to=bigeasy@linutronix.de \
--cc=Arvid.Brodin@xdin.com \
--cc=bird@lzu.edu.cn \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=fmaurer@redhat.com \
--cc=horms@kernel.org \
--cc=kees@kernel.org \
--cc=kexinsun@smail.nju.edu.cn \
--cc=kuba@kernel.org \
--cc=luka.gejak@linux.dev \
--cc=m-karicheri2@ti.com \
--cc=n05ec@lzu.edu.cn \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=royenheart@gmail.com \
--cc=tomapufckgml@gmail.com \
--cc=xuyuqiabc@gmail.com \
--cc=yifanwucs@gmail.com \
--cc=yuantan098@gmail.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