Re: [PATCH v1] printk: Improve memory usage logging during boot

From: Petr Mladek
Date: Tue Oct 01 2024 - 11:49:04 EST


On Mon 2024-09-30 11:33:52, Isaac Manjarres wrote:
> On Mon, Sep 30, 2024 at 03:38:46PM +0200, Petr Mladek wrote:
> > > --- a/kernel/printk/printk.c
> > > +++ b/kernel/printk/printk.c
> > > @@ -1156,6 +1156,17 @@ static unsigned int __init add_to_rb(struct printk_ringbuffer *rb,
> > > +
> > > void __init setup_log_buf(int early)
> > > {
> > > struct printk_info *new_infos;
> > > @@ -1186,19 +1197,19 @@ void __init setup_log_buf(int early)
> > > log_buf_add_cpu();
> > >
> > > if (!new_log_buf_len)
> > > - return;
> > > + goto out;
> >
> > The same information is printed twice when the default buffer is used.
> > We should do something like:
> >
> > if (!new_log_buf_len) {
> > if (early)
> > goto out;
> > return;
> > }
> >
> Thank you for pointing this out. I'll do something very similar to this
> in the 2nd version of the patch, but I'll use "!early" instead. The
> rationale is that if I use just use "early", then the memory usage
> stats don't get emitted at all on my machine (arm64) when it uses the
> default buffer, because setup_log_buf() is called only once with
> early == 0.

I see. setup_log_buf(1) is used only on x86_64. Great catch!

> Using !early in the check there should fix that, and also emit the
> memory stats only once on machines that invoke setup_log_buf()
> multiple times and end up using the default buffer.

Yup.

Best Regards,
Petr