Skip to contentSkip to conversation

ring-buffer: make the const read-only 'type' static

PATCH In review Colin Ian King 4 participants 4 messages Jul 14, 2025 – Jul 19, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ring-buffer: make the const read-only 'type' static

Don't populate the read-only 'type' on the stack at run time, instead make it static.

---
 kernel/trace/ring_buffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/ring_buffer.c +1 -1
index 00fc38d70e86..39aa1f50274f 100644
@@ -4118,7 +4118,7 @@ EXPORT_SYMBOL_GPL(ring_buffer_unlock_commit);
 
 static const char *show_irq_str(int bits)
 {
-	const char *type[] = {
+	static const char * type[] = {
 		".",	// 0
 		"s",	// 1
 		"h",	// 2
Signature · 1 line
2.50.0
maintainer
#1 lore raw
Quoted 2 lines · On Mon, 14 Jul 2025 17:08:58 +0100 Colin Ian King <[email protected]>…

Don't populate the read-only 'type' on the stack at run time, instead make it static.

Hmm, why not?

-- Steve

#2 lore raw

Le 14/07/2025 à 18:15, Steven Rostedt a écrit :

Quoted 11 lines
Quoted 2 lines · On Mon, 14 Jul 2025 17:08:58 +0100 Colin Ian King <[email protected]>…

Don't populate the read-only 'type' on the stack at run time, instead make it static.

Hmm, why not?

-- Steve

This is more efficient because there is no need to copy things on the stack at run-time.

It also makes binary slightly smaller.

On my x86_64, with allmodconfig:
Before:
======
229194 924492 35104 1188790 1223b6 kernel/trace/ring_buffer.o

After:
=====
228873 924268 35040 1188181 122155 kernel/trace/ring_buffer.o

CJ

#3 lore raw
In reply to Colin Ian King
Quoted 13 lines · On Mon, 14 Jul 2025 17:08:58 +0100 Colin Ian King <[email protected]>…

Don't populate the read-only 'type' on the stack at run time, instead make it static.

---
 kernel/trace/ring_buffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/ring_buffer.c +0 -0
index 00fc38d70e86..39aa1f50274f 100644

kernel/trace/ring_buffer.c EXPORT_SYMBOL_GPL(ring_buffer_unlock_commit); · line 4121

Quoted 5 lines
kernel/trace/ring_buffer.c +1 -1
@@ -4118,7 +4118,7 @@ EXPORT_SYMBOL_GPL(ring_buffer_unlock_commit);
 
 static const char *show_irq_str(int bits)
 {
-	const char *type[] = {
+	static const char * type[] = {

Better would be:

	static const char type[][4] = {

David

Quoted 3 lines
kernel/trace/ring_buffer.c +0 -0
 		".",	// 0
 		"s",	// 1
 		"h",	// 2