public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: "Isaac J. Manjarres" <isaacmanjarres@google.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	John Ogness <john.ogness@linutronix.de>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	surenb@google.com, kernel-team@android.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1] printk: Improve memory usage logging during boot
Date: Mon, 30 Sep 2024 15:38:46 +0200	[thread overview]
Message-ID: <Zvqp5jNa7XCRfSu9@pathway.suse.cz> (raw)
In-Reply-To: <20240926011203.1472798-1-isaacmanjarres@google.com>

On Wed 2024-09-25 18:12:01, Isaac J. Manjarres wrote:
> When the initial printk ring buffer size is updated, setup_log_buf()
> allocates a new ring buffer, as well as a set of meta-data structures
> for the new ring buffer. The function also emits the new size of the
> ring buffer, but not the size of the meta-data structures.
> 
> This makes it difficult to assess how changing the log buffer size
> impacts memory usage during boot.
> 
> For instance, increasing the ring buffer size from 512 KB to 1 MB
> through the command line yields an increase of 2304 KB in reserved
> memory at boot, while the only obvious change is the 512 KB
> difference in the ring buffer sizes:

Good point.

> --- 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,
>  
>  static char setup_text_buf[PRINTKRB_RECORD_MAX] __initdata;
>  
> +static void print_log_buf_usage_stats(void)
> +{
> +	unsigned int descs_count = log_buf_len >> PRB_AVGBITS;
> +	size_t descs_size = descs_count * sizeof(struct prb_desc);
> +	size_t infos_size = descs_count * sizeof(struct printk_info);
> +
> +	pr_info("log_buf_len: %u bytes\n", log_buf_len);
> +	pr_info("prb_descs size: %zu bytes\n", descs_size);
> +	pr_info("printk_infos size: %zu bytes\n", infos_size);
> +}

I would make the information more user friendly. Also a single line
might be enough. Something like:

static void print_log_buf_usage_stats(void)
{
	unsigned int descs_count = log_buf_len >> PRB_AVGBITS;
	size_t meta_data_size;

	meta_data_size = descs_count *
		(sizeof(struct prb_desc) + sizeof(struct printk_info));

	pr_info("log buffer data + meta data: %u + %zu = %zu bytes\n",
		log_buf_len, meta_data_size, log_buf_len + meta_data_size);
}

> +
>  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;
	}

>  	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;
> +		goto out;
>  	}
>  

Best Regards,
Petr

  reply	other threads:[~2024-09-30 13:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-26  1:12 [PATCH v1] printk: Improve memory usage logging during boot Isaac J. Manjarres
2024-09-30 13:38 ` Petr Mladek [this message]
2024-09-30 18:33   ` Isaac Manjarres
2024-10-01 15:48     ` Petr Mladek

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=Zvqp5jNa7XCRfSu9@pathway.suse.cz \
    --to=pmladek@suse.com \
    --cc=isaacmanjarres@google.com \
    --cc=john.ogness@linutronix.de \
    --cc=kernel-team@android.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.org \
    --cc=surenb@google.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