Skip to contentSkip to conversation

printk: fix wrong number of CPUs required to increase the ring buffer

PATCH In review Sang-Heon Jeon 2 participants 3 messages Sep 21 – Sep 27 Printk

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 printk: fix wrong number of CPUs required to increase the ring buffer

The default LOG_BUF_SHIFT is 17, which means 128 KB, and LOG_CPU_MAX_BUF_SHIFT is 12, which means 4 KB per CPU.

By default the ring buffer is increased when (num_possible_cpus() - 1) * 4 KB > 64 KB, which requires 18 or more CPUs.

Fix the wrong comment and help text.

---
 init/Kconfig           | 2 +-
 kernel/printk/printk.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
init/Kconfig +1 -1
index 60448fd4ee12..446cbb59a43b 100644
@@ -843,7 +843,7 @@ config LOG_CPU_MAX_BUF_SHIFT
 	  with more CPUs. Therefore this value is used only when the sum of
 	  contributions is greater than the half of the default kernel ring
 	  buffer as defined by LOG_BUF_SHIFT. The default values are set
-	  so that more than 16 CPUs are needed to trigger the allocation.
+	  so that 18 or more CPUs are needed to trigger the allocation.
 
 	  Also this option is ignored when "log_buf_len" kernel parameter is
 	  used as it forces an exact (power of two) size of the ring buffer.
kernel/printk/printk.c +1 -1
index 00f8e1291564..c7d961256c88 100644
@@ -1087,7 +1087,7 @@ static void __init log_buf_add_cpu(void)
 
 	cpu_extra = (num_possible_cpus() - 1) * __LOG_CPU_MAX_BUF_LEN;
 
-	/* by default this will only continue through for large > 64 CPUs */
+	/* by default this will only continue through for 18 or more CPUs */
 	if (cpu_extra <= __LOG_BUF_LEN / 2)
 		return;
 

base-commit: b03d22ec8186f3f6b40b95a5a678100cf80116cb

Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 5 lines · Sang-Heon Jeon

The default LOG_BUF_SHIFT is 17, which means 128 KB, and LOG_CPU_MAX_BUF_SHIFT is 12, which means 4 KB per CPU.

By default the ring buffer is increased when (num_possible_cpus() - 1) * 4 KB > 64 KB, which requires 18 or more CPUs.

Good catch!

Quoted 13 lines

Fix the wrong comment and help text.

---
 init/Kconfig           | 2 +-
 kernel/printk/printk.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
init/Kconfig +0 -0
index 60448fd4ee12..446cbb59a43b 100644

init/Kconfig config LOG_CPU_MAX_BUF_SHIFT · line 846

Quoted 5 lines
init/Kconfig +1 -1
@@ -843,7 +843,7 @@ config LOG_CPU_MAX_BUF_SHIFT
 	  with more CPUs. Therefore this value is used only when the sum of
 	  contributions is greater than the half of the default kernel ring
 	  buffer as defined by LOG_BUF_SHIFT. The default values are set
-	  so that more than 16 CPUs are needed to trigger the allocation.
+	  so that 18 or more CPUs are needed to trigger the allocation.

The number 18 is pretty ugly. It was supposed to be a power of 2. I would prefer to fix the computation instead.

kernel/printk/printk.c static void __init log_buf_add_cpu(void) · line 1088

Quoted 10 lines
init/Kconfig +0 -0
 	  Also this option is ignored when "log_buf_len" kernel parameter is
 	  used as it forces an exact (power of two) size of the ring buffer.
kernel/printk/printk.c +0 -0
index 00f8e1291564..c7d961256c88 100644
@@ -1087,7 +1087,7 @@ static void __init log_buf_add_cpu(void)
 
 	cpu_extra = (num_possible_cpus() - 1) * __LOG_CPU_MAX_BUF_LEN;

If we remove the minus one:

	cpu_extra = num_possible_cpus() * __LOG_CPU_MAX_BUF_LEN;

The it should be > 16 and we could keep init/Kconfig as is.

kernel/printk/printk.c static void __init log_buf_add_cpu(void) · line 1090

Quoted 2 lines
kernel/printk/printk.c +1 -1
-	/* by default this will only continue through for large > 64 CPUs */
+	/* by default this will only continue through for 18 or more CPUs */

Right, this should be > 16 with the current defaults.

kernel/printk/printk.c static void __init log_buf_add_cpu(void) · line 1092

Quoted 2 lines
kernel/printk/printk.c +0 -0
 	if (cpu_extra <= __LOG_BUF_LEN / 2)
 		return;

Would you like to prepare v2?

Best Regards,
Petr

#2 lore raw

Hi,

2026년 9월 23일 (수) 오후 8:57, Petr Mladek <[email protected]>님이 작성:

Quoted 9 lines · Sang-Heon Jeon
Quoted 5 lines

The default LOG_BUF_SHIFT is 17, which means 128 KB, and LOG_CPU_MAX_BUF_SHIFT is 12, which means 4 KB per CPU.

By default the ring buffer is increased when (num_possible_cpus() - 1) * 4 KB > 64 KB, which requires 18 or more CPUs.

Good catch!

Thanks for the review, Petr.

Quoted 8 lines
Quoted 8 lines

Fix the wrong comment and help text.

---
 init/Kconfig           | 2 +-
 kernel/printk/printk.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Quoted 13 lines

init/Kconfig config LOG_CPU_MAX_BUF_SHIFT · line 846

Quoted 10 lines
init/Kconfig +1 -1
index 60448fd4ee12..446cbb59a43b 100644
@@ -843,7 +843,7 @@ config LOG_CPU_MAX_BUF_SHIFT
        with more CPUs. Therefore this value is used only when the sum of
        contributions is greater than the half of the default kernel ring
        buffer as defined by LOG_BUF_SHIFT. The default values are set
-       so that more than 16 CPUs are needed to trigger the allocation.
+       so that 18 or more CPUs are needed to trigger the allocation.

The number 18 is pretty ugly. It was supposed to be a power of 2. I would prefer to fix the computation instead.

I agree. If possible, I also prefer that too.

Quoted 13 lines

kernel/printk/printk.c static void __init log_buf_add_cpu(void) · line 1088

Quoted 10 lines
init/Kconfig +0 -0
        Also this option is ignored when "log_buf_len" kernel parameter is
        used as it forces an exact (power of two) size of the ring buffer.
kernel/printk/printk.c +0 -0
index 00f8e1291564..c7d961256c88 100644
@@ -1087,7 +1087,7 @@ static void __init log_buf_add_cpu(void)
 
      cpu_extra = (num_possible_cpus() - 1) * __LOG_CPU_MAX_BUF_LEN;

If we remove the minus one:

Quoted 8 lines
        cpu_extra = num_possible_cpus() * __LOG_CPU_MAX_BUF_LEN;

The it should be > 16 and we could keep init/Kconfig as is.

kernel/printk/printk.c static void __init log_buf_add_cpu(void) · line 1090

Quoted 2 lines
kernel/printk/printk.c +1 -1
-     /* by default this will only continue through for large > 64 CPUs */
+     /* by default this will only continue through for 18 or more CPUs */

Right, this should be > 16 with the current defaults.

Ditto.

Quoted 4 lines

kernel/printk/printk.c static void __init log_buf_add_cpu(void) · line 1092

Quoted 2 lines
kernel/printk/printk.c +0 -0
      if (cpu_extra <= __LOG_BUF_LEN / 2)
              return;

Would you like to prepare v2?

Sure, I'll send the v2 patch soon.

Quoted 2 lines

Best Regards,
Petr

Best regards,
Sang-Heon Jeon