From: Daniil Tatianin <d-tatianin@yandex-team.ru>
To: Petr Mladek <pmladek@suse.com>
Cc: linux-kernel@vger.kernel.org,
Steven Rostedt <rostedt@goodmis.org>,
John Ogness <john.ogness@linutronix.de>,
Sergey Senozhatsky <senozhatsky@chromium.org>
Subject: Re: [PATCH v2 1/2] printk_ringbuffer: don't needlessly wrap data blocks around
Date: Fri, 26 Sep 2025 17:35:53 +0300 [thread overview]
Message-ID: <0ffb6fad-20cb-4e87-bfa6-a2e6124c03ad@yandex-team.ru> (raw)
In-Reply-To: <20250905144152.9137-2-d-tatianin@yandex-team.ru>
Hi all!
Now that the fix for large messages is committed, I think this patch
should be good to take,
and the second one we can just drop since it's no longer relevant.
Thanks,
Daniil
On 9/5/25 5:41 PM, Daniil Tatianin wrote:
> Previously, data blocks that perfectly fit the data ring buffer would
> get wrapped around to the beginning for no reason since the calculated
> offset of the next data block would belong to the next wrap. Since this
> offset is not actually part of the data block, but rather the offset of
> where the next data block is going to start, there is no reason to
> include it when deciding whether the current block fits the buffer.
>
> Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
> ---
> kernel/printk/printk_ringbuffer.c | 27 +++++++++++++++++++--------
> 1 file changed, 19 insertions(+), 8 deletions(-)
>
> diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c
> index d9fb053cff67..99989a9ce4b4 100644
> --- a/kernel/printk/printk_ringbuffer.c
> +++ b/kernel/printk/printk_ringbuffer.c
> @@ -1002,6 +1002,17 @@ static bool desc_reserve(struct printk_ringbuffer *rb, unsigned long *id_out)
> return true;
> }
>
> +static bool is_blk_wrapped(struct prb_data_ring *data_ring,
> + unsigned long begin_lpos, unsigned long next_lpos)
> +{
> + /*
> + * Subtract one from next_lpos since it's not actually part of this data
> + * block. This allows perfectly fitting records to not wrap.
> + */
> + return DATA_WRAPS(data_ring, begin_lpos) !=
> + DATA_WRAPS(data_ring, next_lpos - 1);
> +}
> +
> /* Determine the end of a data block. */
> static unsigned long get_next_lpos(struct prb_data_ring *data_ring,
> unsigned long lpos, unsigned int size)
> @@ -1013,7 +1024,7 @@ static unsigned long get_next_lpos(struct prb_data_ring *data_ring,
> next_lpos = lpos + size;
>
> /* First check if the data block does not wrap. */
> - if (DATA_WRAPS(data_ring, begin_lpos) == DATA_WRAPS(data_ring, next_lpos))
> + if (!is_blk_wrapped(data_ring, begin_lpos, next_lpos))
> return next_lpos;
>
> /* Wrapping data blocks store their data at the beginning. */
> @@ -1081,7 +1092,7 @@ static char *data_alloc(struct printk_ringbuffer *rb, unsigned int size,
> blk = to_block(data_ring, begin_lpos);
> blk->id = id; /* LMM(data_alloc:B) */
>
> - if (DATA_WRAPS(data_ring, begin_lpos) != DATA_WRAPS(data_ring, next_lpos)) {
> + if (is_blk_wrapped(data_ring, begin_lpos, next_lpos)) {
> /* Wrapping data blocks store their data at the beginning. */
> blk = to_block(data_ring, 0);
>
> @@ -1125,7 +1136,7 @@ static char *data_realloc(struct printk_ringbuffer *rb, unsigned int size,
> return NULL;
>
> /* Keep track if @blk_lpos was a wrapping data block. */
> - wrapped = (DATA_WRAPS(data_ring, blk_lpos->begin) != DATA_WRAPS(data_ring, blk_lpos->next));
> + wrapped = is_blk_wrapped(data_ring, blk_lpos->begin, blk_lpos->next);
>
> size = to_blk_size(size);
>
> @@ -1151,7 +1162,7 @@ static char *data_realloc(struct printk_ringbuffer *rb, unsigned int size,
>
> blk = to_block(data_ring, blk_lpos->begin);
>
> - if (DATA_WRAPS(data_ring, blk_lpos->begin) != DATA_WRAPS(data_ring, next_lpos)) {
> + if (is_blk_wrapped(data_ring, blk_lpos->begin, next_lpos)) {
> struct prb_data_block *old_blk = blk;
>
> /* Wrapping data blocks store their data at the beginning. */
> @@ -1187,7 +1198,7 @@ static unsigned int space_used(struct prb_data_ring *data_ring,
> if (BLK_DATALESS(blk_lpos))
> return 0;
>
> - if (DATA_WRAPS(data_ring, blk_lpos->begin) == DATA_WRAPS(data_ring, blk_lpos->next)) {
> + if (!is_blk_wrapped(data_ring, blk_lpos->begin, blk_lpos->next)) {
> /* Data block does not wrap. */
> return (DATA_INDEX(data_ring, blk_lpos->next) -
> DATA_INDEX(data_ring, blk_lpos->begin));
> @@ -1234,14 +1245,14 @@ static const char *get_data(struct prb_data_ring *data_ring,
> }
>
> /* Regular data block: @begin less than @next and in same wrap. */
> - if (DATA_WRAPS(data_ring, blk_lpos->begin) == DATA_WRAPS(data_ring, blk_lpos->next) &&
> + if (!is_blk_wrapped(data_ring, blk_lpos->begin, blk_lpos->next) &&
> blk_lpos->begin < blk_lpos->next) {
> db = to_block(data_ring, blk_lpos->begin);
> *data_size = blk_lpos->next - blk_lpos->begin;
>
> /* Wrapping data block: @begin is one wrap behind @next. */
> - } else if (DATA_WRAPS(data_ring, blk_lpos->begin + DATA_SIZE(data_ring)) ==
> - DATA_WRAPS(data_ring, blk_lpos->next)) {
> + } else if (!is_blk_wrapped(data_ring,
> + blk_lpos->begin + DATA_SIZE(data_ring), blk_lpos->next)) {
> db = to_block(data_ring, 0);
> *data_size = DATA_INDEX(data_ring, blk_lpos->next);
>
next prev parent reply other threads:[~2025-09-26 14:36 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-05 14:41 [PATCH v2 0/2] " Daniil Tatianin
2025-09-05 14:41 ` [PATCH v2 1/2] " Daniil Tatianin
2025-09-05 15:27 ` John Ogness
2025-09-05 15:29 ` Daniil Tatianin
2025-09-05 16:10 ` John Ogness
2025-09-11 8:34 ` Daniil Tatianin
2025-09-11 15:33 ` Petr Mladek
2025-09-05 15:30 ` John Ogness
2025-09-26 14:35 ` Daniil Tatianin [this message]
2025-09-26 14:44 ` Petr Mladek
2025-09-26 14:53 ` Daniil Tatianin
2025-10-22 12:46 ` Petr Mladek
2025-09-05 14:41 ` [PATCH v2 2/2] printk_ringbuffer: allow one data block to occupy the entire data ring Daniil Tatianin
2025-09-05 15:27 ` John Ogness
2025-09-11 15:30 ` [PATCH v2 0/2] printk_ringbuffer: don't needlessly wrap data blocks around Petr Mladek
2025-09-11 15:55 ` Petr Mladek
2025-09-11 16:11 ` Petr Mladek
2025-09-11 15:58 ` Petr Mladek
2025-09-11 16:12 ` John Ogness
2025-09-12 9:25 ` Petr Mladek
2025-09-12 9:54 ` Petr Mladek
2025-09-12 14:49 ` Petr Mladek
2025-09-12 15:15 ` Petr Mladek
2025-09-12 18:43 ` John Ogness
2025-09-13 17:38 ` Daniil Tatianin
2025-09-14 9:23 ` John Ogness
2025-09-14 9:56 ` Daniil Tatianin
2025-09-15 15:07 ` John Ogness
2025-09-15 16:00 ` Petr Mladek
2025-09-15 16:07 ` Daniil Tatianin
2025-09-15 15:08 ` Petr Mladek
2025-09-15 15:25 ` John Ogness
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=0ffb6fad-20cb-4e87-bfa6-a2e6124c03ad@yandex-team.ru \
--to=d-tatianin@yandex-team.ru \
--cc=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
/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®