From: Petr Mladek <pmladek@suse.com>
To: John Ogness <john.ogness@linutronix.de>
Cc: Andrea Parri <parri.andrea@gmail.com>,
Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
Paul McKenney <paulmck@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
kexec@lists.infradead.org, linux-kernel@vger.kernel.org,
Steven Rostedt <rostedt@goodmis.org>,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: buffer allocation: was: [PATCH v3 3/3] printk: use the lockless ringbuffer
Date: Mon, 29 Jun 2020 16:04:45 +0200 [thread overview]
Message-ID: <20200629140445.GK6156@alley> (raw)
In-Reply-To: <87sgeh3m5j.fsf@jogness.linutronix.de>
On Fri 2020-06-26 17:02:48, John Ogness wrote:
> On 2020-06-25, Petr Mladek <pmladek@suse.com> wrote:
> >> --- a/kernel/printk/printk.c
> >> +++ b/kernel/printk/printk.c
> >> + free = __LOG_BUF_LEN;
> >> + prb_for_each_record(0, &printk_rb_static, seq, &r)
> >> + free -= add_to_rb(&printk_rb_dynamic, &r);
> >> +
> >> + prb = &printk_rb_dynamic;
> >
> > This might deserve a comment that this is safe (no lost message)
> > because it is called early enough when everything is still running
> > on the boot CPU.
>
> I will add a comment and an extra check to make sure.
>
> Once everything is lockless, new messages could appear (for example, due
> to NMI messages). The simple check should probably change to a loop. But
> let us not worry about that at this point.
Yup.
> Below is a new version of the relevant patch snippets against mainline
> just to show you how I plan to make it look for the next version.
>
> John Ogness
>
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ @@
> +#define PRB_AVGBITS 5 /* 32 character average length */
> +
> +#if CONFIG_LOG_BUF_SHIFT <= PRB_AVGBITS
> +#error CONFIG_LOG_BUF_SHIFT value too small.
> +#endif
> +_DEFINE_PRINTKRB(printk_rb_static, CONFIG_LOG_BUF_SHIFT - PRB_AVGBITS,
> + PRB_AVGBITS, PRB_AVGBITS, &__log_buf[0]);
> +
> @@ @@
> void __init setup_log_buf(int early)
> {
> + unsigned int new_descs_count;
> + struct prb_desc *new_descs;
> + struct printk_info info;
> + struct printk_record r;
> + size_t new_descs_size;
> unsigned long flags;
> + char *new_dict_buf;
> char *new_log_buf;
> unsigned int free;
> + u64 seq;
>
> /*
> * Some archs call setup_log_buf() multiple times - first is very
> @@ @@ void __init setup_log_buf(int early)
> if (!new_log_buf_len)
> return;
>
> + new_descs_count = new_log_buf_len >> PRB_AVGBITS;
> + if (new_descs_count == 0) {
> + pr_err("new_log_buf_len: %lu too small\n", new_log_buf_len);
> + return;
> + }
> +
> new_log_buf = memblock_alloc(new_log_buf_len, LOG_ALIGN);
> if (unlikely(!new_log_buf)) {
> - pr_err("log_buf_len: %lu bytes not available\n",
> - new_log_buf_len);
> + pr_err("log_buf_len: %lu text bytes not available\n",
> + new_log_buf_len);
> + return;
> + }
> +
> + new_dict_buf = memblock_alloc(new_log_buf_len, LOG_ALIGN);
> + if (unlikely(!new_dict_buf)) {
> + pr_err("log_buf_len: %lu dict bytes not available\n",
> + new_log_buf_len);
> + memblock_free(__pa(new_log_buf), new_log_buf_len);
> return;
> }
>
> + new_descs_size = new_descs_count * sizeof(struct prb_desc);
> + new_descs = memblock_alloc(new_descs_size, LOG_ALIGN);
> + if (unlikely(!new_descs)) {
> + pr_err("log_buf_len: %lu desc bytes not available\n",
> + new_descs_size);
> + memblock_free(__pa(new_dict_buf), new_log_buf_len);
> + memblock_free(__pa(new_log_buf), new_log_buf_len);
> + return;
> + }
> +
> + prb_rec_init_rd(&r, &info,
> + &setup_text_buf[0], sizeof(setup_text_buf),
> + &setup_dict_buf[0], sizeof(setup_dict_buf));
> +
> + prb_init(&printk_rb_dynamic,
> + new_log_buf, order_base_2(new_log_buf_len),
> + new_dict_buf, order_base_2(new_log_buf_len),
> + new_descs, order_base_2(new_descs_count));
order_base_2() is safe. But the result might be tat some allocated
space is not used.
I would prefer to make sure that new_log_buf_len is rounded, e.g.
by roundup_pow_of_two(), at the beginning of the function. Then we
could use ilog2() here.
Otherwise, it looks fine to me.
Best Regards,
Petr
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
next prev parent reply other threads:[~2020-06-29 14:04 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-18 14:49 [PATCH v3 0/3] printk: replace ringbuffer John Ogness
2020-06-18 14:49 ` [PATCH v3 1/3] crash: add VMCOREINFO macro to define offset in a struct declared by typedef John Ogness
2020-06-24 8:49 ` Petr Mladek
2020-07-04 9:30 ` Baoquan He
2020-06-18 14:49 ` [PATCH v3 2/3] printk: add lockless ringbuffer John Ogness
2020-06-29 15:32 ` Paul E. McKenney
2020-07-02 8:35 ` Petr Mladek
2020-06-18 14:49 ` [PATCH v3 3/3] printk: use the " John Ogness
2020-06-18 18:23 ` kernel test robot
2020-06-18 18:23 ` [RFC PATCH] printk: _printk_rb_static_dict can be static kernel test robot
2020-06-19 6:49 ` John Ogness
2020-06-19 12:29 ` Steven Rostedt
2020-06-25 8:16 ` truncate dict: was: Re: [PATCH v3 3/3] printk: use the lockless ringbuffer Petr Mladek
2020-06-26 13:48 ` John Ogness
2020-06-25 8:28 ` buffer allocation: was: " Petr Mladek
2020-06-26 15:02 ` John Ogness
2020-06-29 14:04 ` Petr Mladek [this message]
2020-06-29 21:57 ` John Ogness
2020-07-02 13:27 ` Petr Mladek
2020-06-25 12:09 ` record_printk_text tricks: " Petr Mladek
2020-06-25 15:25 ` Petr Mladek
2020-06-26 23:25 ` John Ogness
2020-06-25 15:17 ` pending output optimization: " Petr Mladek
2020-07-01 19:58 ` John Ogness
2020-06-25 15:20 ` syslog size unread: " Petr Mladek
2020-06-29 21:51 ` John Ogness
2020-07-02 8:25 ` lijiang
2020-07-02 9:02 ` John Ogness
2020-07-02 9:43 ` lijiang
2020-07-02 13:31 ` Petr Mladek
2020-07-04 1:12 ` lijiang
2020-07-03 11:54 ` John Ogness
2020-07-08 5:50 ` lijiang
2020-06-25 7:19 ` [PATCH v3 0/3] printk: replace ringbuffer Dave Young
2020-06-25 14:13 ` 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=20200629140445.GK6156@alley \
--to=pmladek@suse.com \
--cc=gregkh@linuxfoundation.org \
--cc=john.ogness@linutronix.de \
--cc=kexec@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=parri.andrea@gmail.com \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=sergey.senozhatsky.work@gmail.com \
--cc=sergey.senozhatsky@gmail.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.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