linux-stable/kernel/printk
Isaac J. Manjarres a961ec4e28 printk: Improve memory usage logging during boot
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:

log_buf_len=512K:

printk: log_buf_len: 524288 bytes
Memory: ... (... 733252K reserved ...)

log_buf_len=1M:

printk: log_buf_len: 1048576 bytes
Memory: ... (... 735556K reserved ...)

This is because of how the size of the meta-data structures scale with
the size of the ring buffer.

Even when there aren't changes to the printk ring buffer size (i.e. the
initial size ==  1 << CONFIG_LOG_BUF_SHIFT), it is impossible to tell
how much memory is consumed by the printk ring buffer during boot.

Therefore, unconditionally log the sizes of the printk ring buffer
and its meta-data structures, so that it's easier to understand
how changing the log buffer size (either through the command line or
by changing CONFIG_LOG_BUF_SHIFT) affects boot time memory usage.

With the new logs, it is much easier to see exactly why the memory
increased by 2304 KB:

log_buf_len=512K:

printk: log buffer data + meta data: 524288 + 1835008 = 2359296 bytes
Memory: ... (... 733252K reserved ...)

log_buf_len=1M:

printk: log buffer data + meta data: 1048576 + 3670016 = 4718592 bytes
Memory: ... (... 735556K reserved ...)

Signed-off-by: Isaac J. Manjarres <isaacmanjarres@google.com>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Tested-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20240930184826.3595221-1-isaacmanjarres@google.com
[pmladek@suse.com: Updated the examples in the commit message, simplified comment for default buffer.]
Signed-off-by: Petr Mladek <pmladek@suse.com>
2024-10-16 11:36:19 +02:00
..
braille.c printk: Replace strncmp() with str_has_prefix() 2019-08-16 09:54:08 +02:00
braille.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
console_cmdline.h printk: Add match_devname_and_update_preferred_console() 2024-07-04 15:41:44 +02:00
index.c kernel/printk/index.c: fix memory leak with using debugfs_lookup() 2023-02-03 10:42:02 +01:00
internal.h printk: Implement legacy printer kthread for PREEMPT_RT 2024-09-04 15:56:33 +02:00
Makefile Revert "printk: Save console options for add_preferred_console_match()" 2024-06-25 07:58:10 +02:00
nbcon.c printk: nbcon: Assign nice -20 for printing threads 2024-09-04 15:56:33 +02:00
printk_ringbuffer.c printk: ringbuffer: Skip non-finalized records in panic 2024-02-07 17:23:18 +01:00
printk_ringbuffer.h printk: nbcon: Init @nbcon_seq to highest possible 2024-09-04 15:56:32 +02:00
printk_safe.c printk: Implement legacy printer kthread for PREEMPT_RT 2024-09-04 15:56:33 +02:00
printk.c printk: Improve memory usage logging during boot 2024-10-16 11:36:19 +02:00
sysctl.c sysctl: treewide: constify the ctl_table argument of proc_handlers 2024-07-24 20:59:29 +02:00