Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] clean up kernel messages

Arrange for all kernel printks to be no-ops. Only available if
CONFIG_EMBEDDED.

This patch saves about 375k on my laptop config and nearly 100k on minimal
configs.

Signed-off-by: Matt Mackall <mpm@selenic.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Matt Mackall and committed by
Linus Torvalds
d59745ce cd7619d6

+43 -6
+2
arch/i386/kernel/head.S
··· 380 380 ALIGN 381 381 ignore_int: 382 382 cld 383 + #ifdef CONFIG_PRINTK 383 384 pushl %eax 384 385 pushl %ecx 385 386 pushl %edx ··· 401 400 popl %edx 402 401 popl %ecx 403 402 popl %eax 403 + #endif 404 404 iret 405 405 406 406 /*
+9
include/linux/kernel.h
··· 115 115 extern int kernel_text_address(unsigned long addr); 116 116 extern int session_of_pgrp(int pgrp); 117 117 118 + #ifdef CONFIG_PRINTK 118 119 asmlinkage int vprintk(const char *fmt, va_list args) 119 120 __attribute__ ((format (printf, 1, 0))); 120 121 asmlinkage int printk(const char * fmt, ...) 121 122 __attribute__ ((format (printf, 1, 2))); 123 + #else 124 + static inline int vprintk(const char *s, va_list args) 125 + __attribute__ ((format (printf, 1, 0))); 126 + static inline int vprintk(const char *s, va_list args) { return 0; } 127 + static inline int printk(const char *s, ...) 128 + __attribute__ ((format (printf, 1, 2))); 129 + static inline int printk(const char *s, ...) { return 0; } 130 + #endif 122 131 123 132 unsigned long int_sqrt(unsigned long); 124 133
+11
init/Kconfig
··· 275 275 reported. KALLSYMS_EXTRA_PASS is only a temporary workaround while 276 276 you wait for kallsyms to be fixed. 277 277 278 + 279 + config PRINTK 280 + default y 281 + bool "Enable support for printk" if EMBEDDED 282 + help 283 + This option enables normal printk support. Removing it 284 + eliminates most of the message strings from the kernel image 285 + and makes the kernel more or less silent. As this makes it 286 + very difficult to diagnose system problems, saying N here is 287 + strongly discouraged. 288 + 278 289 config BUG 279 290 bool "BUG() support" if EMBEDDED 280 291 default y
+21 -6
kernel/printk.c
··· 85 85 */ 86 86 static DEFINE_SPINLOCK(logbuf_lock); 87 87 88 - static char __log_buf[__LOG_BUF_LEN]; 89 - static char *log_buf = __log_buf; 90 - static int log_buf_len = __LOG_BUF_LEN; 91 - 92 88 #define LOG_BUF_MASK (log_buf_len-1) 93 89 #define LOG_BUF(idx) (log_buf[(idx) & LOG_BUF_MASK]) 94 90 ··· 95 99 static unsigned long log_start; /* Index into log_buf: next char to be read by syslog() */ 96 100 static unsigned long con_start; /* Index into log_buf: next char to be sent to consoles */ 97 101 static unsigned long log_end; /* Index into log_buf: most-recently-written-char + 1 */ 98 - static unsigned long logged_chars; /* Number of chars produced since last read+clear operation */ 99 102 100 103 /* 101 104 * Array of consoles built from command line options (console=) ··· 114 119 115 120 /* Flag: console code may call schedule() */ 116 121 static int console_may_schedule; 122 + 123 + #ifdef CONFIG_PRINTK 124 + 125 + static char __log_buf[__LOG_BUF_LEN]; 126 + static char *log_buf = __log_buf; 127 + static int log_buf_len = __LOG_BUF_LEN; 128 + static unsigned long logged_chars; /* Number of chars produced since last read+clear operation */ 117 129 118 130 /* 119 131 * Setup a list of consoles. Called from init/main.c ··· 537 535 * then changes console_loglevel may break. This is because console_loglevel 538 536 * is inspected when the actual printing occurs. 539 537 */ 538 + 540 539 asmlinkage int printk(const char *fmt, ...) 541 540 { 542 541 va_list args; ··· 657 654 } 658 655 EXPORT_SYMBOL(printk); 659 656 EXPORT_SYMBOL(vprintk); 657 + 658 + #else 659 + 660 + asmlinkage long sys_syslog(int type, char __user * buf, int len) 661 + { 662 + return 0; 663 + } 664 + 665 + int do_syslog(int type, char __user * buf, int len) { return 0; } 666 + static void call_console_drivers(unsigned long start, unsigned long end) {} 667 + 668 + #endif 660 669 661 670 /** 662 671 * acquire_console_sem - lock the console system for exclusive use. ··· 946 931 return res; 947 932 } 948 933 EXPORT_SYMBOL(unregister_console); 949 - 934 + 950 935 /** 951 936 * tty_write_message - write a message to a certain tty, not just the console. 952 937 *