From: Jakub Kicinski <kuba@kernel.org>
To: Breno Leitao <leitao@debian.org>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
Jonathan Corbet <corbet@lwn.net>, Shuah Khan <shuah@kernel.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org,
kernel-team@meta.com, max@kutsevol.com, thepacketgeek@gmail.com
Subject: Re: [PATCH net-next v2 3/5] netconsole: add support for sysdata and CPU population
Date: Mon, 20 Jan 2025 11:06:53 -0800 [thread overview]
Message-ID: <20250120110653.693fd5ec@kernel.org> (raw)
In-Reply-To: <20250120-rational-bullfrog-of-tornado-2cd6f4@leitao>
On Mon, 20 Jan 2025 09:30:48 -0800 Breno Leitao wrote:
> > > Not sure I followed. The data ({userdata,extradata}_complete) was always
> > > inside nt field, which belongs to target_list.
> >
> > I mean the buffer we use for formatting. Today it's this:
> >
> > static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */
> > int header_len, msgbody_len;
> > const char *msgbody;
> >
> > right? I missed that "static" actually so it's not on the stack,
> > it's in the .bss section.
>
> Since you raised this topic, I don't think buf needs to be static
> for a functional perspective, since `buf` is completely overwritten
> every time send_msg functions are called.
It may be because it's relatively big and stack space used to be
very limited.
> > My thinking was to handle it like the release.
> > Print it at the send_msg_no_fragmentation() stage directly
> > into the static buffer. Does that get hairy coding-wise?
>
> I suppose the advantage of doing this approach is to reduce a
> memcpy/strcpy, right?
Not really, my main motivation is to try to find a common way
of how various pieces of the output are protected and handled.
> If this is what your motivation, I think we cannot remove it from the
> fragmented case. Let me share my thought process:
>
> 1) sysdata needs to be appended to both send_msg_fragmented() and
> send_msg_no_fragmentation(). The fragmented case is the problem.
>
> 2) It is trivially done in send_msg_fragmented() case.
>
> 3) For the send_msg_no_fragmentation() case, there is no trivial way to
> get it done without using a secondary buffer and then memcpy to `buf`.
>
> Let's suppose sysdata has "cpu=42", and original `buf` has only 5 available
> chars, thus it needs to have 2 msgs to accommodate the full message.
>
> Then the it needs to track that `cpu=4` will be sent in a msg and create
> another message with the missing `2`.
>
> The only way to do it properly is having a extra buffer where we
> have `cpu=42` and copy 5 bytes from there, and then copy the last one in
> the next iteration. I am not sure we can do it in one shot.
FWIW to simplify reasoning about the length I thought we could take the
worst case, assume we'll need len(cpu=) + log10(nr_cpu_ids) of space.
> On top of that, I am planning to increase other features in sysdata
> (such as current task name, modules and even consolidate the release as
> sysdata), which has two implications:
>
> 1) Average messages size will become bigger. Thus, memcpy will be needed
> one way or another.
>
> 2) Unless we can come up with a smart solution, this solution will be
> harder to reason about.
>
> If you want to invest more time in this direction, I am more than happy
> to create a PoC, so we can discuss more concretely.
I don't feel super strongly about this. But hacking around is always
good to get a sense of how hairy the implementation ends up being.
To rephrase my concern is that we have some data as static on the
stack, some dynamically appended at the send_*() stage, now we're
adding a third way of handling things. Perhaps the simplest way to
make me happy would be to move the bufs which are currently static
into nt.
next prev parent reply other threads:[~2025-01-20 19:06 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-15 13:35 [PATCH net-next v2 0/5] netconsole: Add support for CPU population Breno Leitao
2025-01-15 13:35 ` [PATCH net-next v2 1/5] netconsole: Rename userdata to extradata Breno Leitao
2025-01-15 13:35 ` [PATCH net-next v2 2/5] netconsole: Helper to count number of used entries Breno Leitao
2025-01-15 13:35 ` [PATCH net-next v2 3/5] netconsole: add support for sysdata and CPU population Breno Leitao
2025-01-17 1:44 ` Jakub Kicinski
2025-01-17 11:02 ` Breno Leitao
2025-01-18 2:35 ` Jakub Kicinski
2025-01-20 17:30 ` Breno Leitao
2025-01-20 19:06 ` Jakub Kicinski [this message]
2025-01-24 15:28 ` Breno Leitao
2025-01-15 13:35 ` [PATCH net-next v2 4/5] netconsole: selftest: test for sysdata CPU Breno Leitao
2025-01-15 13:35 ` [PATCH net-next v2 5/5] netconsole: docs: Add documentation for CPU number auto-population Breno Leitao
2025-01-15 22:56 ` Randy Dunlap
2025-01-16 9:31 ` Breno Leitao
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=20250120110653.693fd5ec@kernel.org \
--to=kuba@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kernel-team@meta.com \
--cc=leitao@debian.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=max@kutsevol.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
--cc=thepacketgeek@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;
as well as URLs for NNTP newsgroup(s).