How much is the default log_buf_len size?
Environment
- Red Hat Enterprise Linux 7 / 8 / 9
Issue
- How much is the default
log_buf_len size? - How much is the default
kernel ring buffer size?
Resolution
- The default size for
log_buf_lenon RHEL is 1048576 (1MB).
On RHEL 8 and 9 this is automatically increased by the number of CPUs:
129-257 CPUs - 2097152 (2MB)
258-769 CPUs - 4194304 (4MB)
770+1793 CPUs - 8388608 (8MB)
- If
log_buf_len=is specified on kernel command line and is larger than default size, the specified value rounded up to power of two is used instead (i.e 10M is rounded up to 16M), up to maximum 2G
Root Cause
- In
kernel/printk.c(RHEL7) OR inkernel/printk/printk.c(RHEL 8 / 9), it's defined as below:
#define __LOG_BUF_LEN (1 << CONFIG_LOG_BUF_SHIFT)
static u32 log_buf_len = __LOG_BUF_LEN;
CONFIG_LOG_BUF_SHIFT is set to 20 for RHEL 7, 8 and 9.
This means log_buf_len is set to 1MB (1 << 20 = 1048576)
On RHEL 8 and 9 this gets later adjusted by:
#define __LOG_CPU_MAX_BUF_LEN (1 << CONFIG_LOG_CPU_MAX_BUF_SHIFT)
static void __init log_buf_add_cpu(void)
{
unsigned int cpu_extra;
/*
* archs should set up cpu_possible_bits properly with
* set_cpu_possible() after setup_arch() but just in
* case lets ensure this is valid.
*/
if (num_possible_cpus() == 1)
return;
cpu_extra = (num_possible_cpus() - 1) * __LOG_CPU_MAX_BUF_LEN;
/* by default this will only continue through for large > 64 CPUs */
if (cpu_extra <= __LOG_BUF_LEN / 2)
return;
pr_info("log_buf_len individual max cpu contribution: %d bytes\n",
__LOG_CPU_MAX_BUF_LEN);
pr_info("log_buf_len total cpu_extra contributions: %d bytes\n",
cpu_extra);
pr_info("log_buf_len min size: %d bytes\n", __LOG_BUF_LEN);
log_buf_len_update(cpu_extra + __LOG_BUF_LEN);
}
CONFIG_LOG_CPU_MAX_BUF_SHIFT is set to 12 on RHEL 8 and 9 .
Therefore 1MB is indeed log_buf_len minimal size. Extra space is added for systems with more than 128 CPUs.
The final calculation for log_buf_len is:
1-128 CPUs = 1MB
129+ CPUs = roundup_pow_of_two(1MB + CPU count * 4kB)
SBR
Product(s)
Components
Category
Tags
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.