Skip to contentSkip to conversation

Increase kmsg buffer from 16K to 32K, kernel/printk.c

PATCH/REQ David Ford 7 participants 8 messages Jan 27, 2001 – Feb 5, 2001

lore
Share & tools
lore

David Ford

author
#0 lore raw

Does Linus or anyone object to raising the ksmg buffer from 16K to 32K? 4/5 systems I have now overflow the buffer during boot before init is even launched.

kernel/printk.c Fri Jan 26 23:59:31 2001 renamed from kernel/printk.c~ Fri Jan 26 18:50:28 2001 +1 -1
@@ -22,7 +22,7 @@
 
 #include <asm/uaccess.h>
 
-#define LOG_BUF_LEN    (16384)
+#define LOG_BUF_LEN    (32768)
 #define LOG_BUF_MASK   (LOG_BUF_LEN-1)
 
 static char buf[1024];

-d

--
There is a natural aristocracy among men. The grounds of this are virtue and talents. Thomas Jefferson The good thing about standards is that there are so many to choose from. Andrew S. Tanenbaum

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#1 lore raw
Quoted 3 lines

Does Linus or anyone object to raising the ksmg buffer from 16K to 32K? 4/5 systems I have now overflow the buffer during boot before init is even launched.

Thats just an indication that 2.4.x is currently printking too much crap on boot
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#4 lore raw
In reply to David Ford
Quoted 6 lines · Alan Cox
Quoted 3 lines

Does Linus or anyone object to raising the ksmg buffer from 16K to 32K? 4/5 systems I have now overflow the buffer during boot before init is even launched.

Thats just an indication that 2.4.x is currently printking too much crap on boot

Would it be possible to grow and shring that buffer on demand? Let's say we have a default size and let it grow to a maximum value. After some timeout, buffer size can be shrinked to default value if it's enough at that moment. Or something similar.

Signature · 7 lines
 --[ Gábor Lénárt ]---[ Vivendi Telecom Hungary ]--[ [email protected] ]--
 U have 8 bit comp or chip of them and it's unused or to be sold? Call me!
 -------[ +36 30 2270823 ]------> LGB <-----[ Linux/UNIX/8bit 4ever ]-----
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/
#2 lore raw
In reply to Alan Cox
Quoted 6 lines · Alan Cox
Quoted 3 lines

Does Linus or anyone object to raising the ksmg buffer from 16K to 32K? 4/5 systems I have now overflow the buffer during boot before init is even launched.

Thats just an indication that 2.4.x is currently printking too much crap on boot

We could probably get rid of much of the crap for i386 by #undef
APIC_DEBUG in include/asm-i386/apic.h. Too bad broken SMP systems get reported every now and then and the crap proves useful in getting what actually is wrong.

Signature · 8 lines
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: [email protected], PGP key available        +

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/
#5 lore raw
In reply to Gabor Lenart
Quoted 5 lines · Gabor Lenart
Quoted 4 lines · Alan Cox
Quoted 3 lines

Does Linus or anyone object to raising the ksmg buffer from 16K to 32K? 4/5 systems I have now overflow the buffer during boot before init is even launched.

Quoted 8 lines
Quoted 2 lines

Thats just an indication that 2.4.x is currently printking too much crap on boot

Would it be possible to grow and shring that buffer on demand? Let's say we have a default size and let it grow to a maximum value. After some timeout, buffer size can be shrinked to default value if it's enough at that moment. Or something similar.

And when you can't allocate memory for expanding the printk() ringbuffer? Print a message? ;)

Rik
--
Virtual memory is like a game you can't win; However, without VM there's truly nothing to lose...

		http://www.surriel.com/

http://www.conectiva.com/ http://distro.conectiva.com.br/

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#6 lore raw
Quoted 8 lines
Quoted 5 lines

Would it be possible to grow and shring that buffer on demand? Let's say we have a default size and let it grow to a maximum value. After some timeout, buffer size can be shrinked to default value if it's enough at that moment. Or something similar.

And when you can't allocate memory for expanding the printk() ringbuffer? Print a message? ;)

;)
but seriously, we normally need a big printk buffer only because of boot messages. no reason I know we couldn't shrink it down to something quite modest (4k? plenty for a few oopses) after boot.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

author
#3 lore raw
In reply to Maciej W. Rozycki
Quoted 6 lines · Maciej W. Rozycki
Quoted 4 lines · Alan Cox
Quoted 3 lines

Does Linus or anyone object to raising the ksmg buffer from 16K to 32K? 4/5 systems I have now overflow the buffer during boot before init is even launched.

Quoted 7 lines
Quoted 2 lines

Thats just an indication that 2.4.x is currently printking too much crap on boot

We could probably get rid of much of the crap for i386 by #undef
APIC_DEBUG in include/asm-i386/apic.h. Too bad broken SMP systems get reported every now and then and the crap proves useful in getting what actually is wrong.

The largest bodies of text come from scsi, irda, usb, and udf.

The LP/parport could stand being trimmed too.

The fatfs barfs out bogus cluster size messages when I don't have any FAT type filesystems.

Question is, If I submit patches to tidy up the boot messages, when will(can) they be applied? 2.4 or 2.5?

-d

--
There is a natural aristocracy among men. The grounds of this are virtue and talents. Thomas Jefferson The good thing about standards is that there are so many to choose from. Andrew S. Tanenbaum

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#7 lore raw
In reply to David Ford
Quoted 6 lines · Gabor Lenart
Quoted 4 lines · Alan Cox
Quoted 3 lines

Does Linus or anyone object to raising the ksmg buffer from 16K to 32K? 4/5 systems I have now overflow the buffer during boot before init is even launched.

Quoted 7 lines
Quoted 2 lines

Thats just an indication that 2.4.x is currently printking too much crap on boot

Would it be possible to grow and shring that buffer on demand? Let's say we have a default size and let it grow to a maximum value. After some timeout, buffer size can be shrinked to default value if it's enough at that moment. Or something similar.

I agree that 16k is too much crap being dumped to the console, as people will just zone out as it scrolls by at 100lines/sec. However, it is possible to cut it down in size - here is something I have in store for 2.5 (posted a while ago, the zero initializer for bootlog_buf can go).

Paul.

|Date: Mon, 21 Aug 2000 05:36:18 -0400
|From: Paul Gortmaker <[email protected]>
|To: [email protected]
|Subject: [PATCH] resizeable printk ring buffer

The printk ring buffer has doubled in size several times to accomodate the amount of boot messages spewed out by kernels with lots of drivers. This always seemed like a bit of a waste to me since after the boot messages had been logged to disk, the original 4k buffer is more than adequate during normal operation. To others, the idea of having a big 128k ring buffer might be appealing. Hence this patch.

The buffer used at bootstrap is marked initdata and an initcall is used to bounce the messages into a kmalloc'd region before the initdata is freed. With a minor extension to the dmesg program (and kernel syscall) the admin can resise the ring buffer from 4k to 128k. Messages in the buffer are preserved if the buffer hasn't wrapped yet and if they will fit in the new size.

To resize without yet having the modified dmesg, you essentially do:

i = syscall(103 /*syslog*/ , 9, NULL, kbytes);

where kbytes is 4, 8, 16 ... 128.

I'm not advocating this for 2.4 as it isn't a bugfix, but thought others might want to play with it between now and 2.5.x

Paul.

kernel/printk.c +61 -10
@@ -12,18 +12,20 @@
  * Modified for sysctl support, 1/8/97, Chris Horn.
  * Fixed SMP synchronization, 08/08/99, Manfred Spraul 
  *     [email protected]
+ * Dynamically resizeable printk ring buffer, 07/2000, Paul Gortmaker.
  */
 
 #include <linux/mm.h>
 #include <linux/tty_driver.h>
 #include <linux/smp_lock.h>
 #include <linux/console.h>
+#include <linux/slab.h>
 #include <linux/init.h>
 
 #include <asm/uaccess.h>
 
-#define LOG_BUF_LEN	(16384)
-#define LOG_BUF_MASK	(LOG_BUF_LEN-1)
+#define BOOTLOG_BUF_LEN	(16384)
+#define LOG_BUF_MASK	(log_buf_len-1)
 
 static char buf[1024];
 
@@ -46,7 +48,9 @@
 spinlock_t console_lock = SPIN_LOCK_UNLOCKED;
 
 struct console *console_drivers = NULL;
-static char log_buf[LOG_BUF_LEN];
+static char bootlog_buf[BOOTLOG_BUF_LEN] __initdata = {0, };
+static unsigned int log_buf_len = BOOTLOG_BUF_LEN;
+static char *log_buf = bootlog_buf;
 static unsigned long log_start;
 static unsigned long logged_chars;
 struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES];
@@ -119,13 +123,13 @@
  * 	6 -- Disable printk's to console
  * 	7 -- Enable printk's to console
  *	8 -- Set level of messages printed to console
+ *	9 -- Set ring buffer size in kB (4k -> 128k, 2^n)
  */
 int do_syslog(int type, char * buf, int len)
 {
 	unsigned long i, j, limit, count;
-	int do_clear = 0;
-	char c;
-	int error = -EPERM;
+	int error, do_clear = 0;
+	char c, *new_buf;
 
 	error = 0;
 	switch (type) {
@@ -175,8 +179,8 @@
 		if (error)
 			goto out;
 		count = len;
-		if (count > LOG_BUF_LEN)
-			count = LOG_BUF_LEN;
+		if (count > log_buf_len)
+			count = log_buf_len;
 		spin_lock_irq(&console_lock);
 		if (count > logged_chars)
 			count = logged_chars;
@@ -191,7 +195,7 @@
 		 */
 		for(i=0;i < count;i++) {
 			j = limit-1-i;
-			if (j+LOG_BUF_LEN < log_start+log_size)
+			if (j+log_buf_len < log_start+log_size)
 				break;
 			c = log_buf[ j  & LOG_BUF_MASK ];
 			spin_unlock_irq(&console_lock);
@@ -236,6 +240,30 @@
 		spin_unlock_irq(&console_lock);
 		error = 0;
 		break;
+	case 9:	
+		error = -EINVAL;
+		i = 128;
+		while (i != len && i != 4) i>>=1;
+		if (i != len)
+			goto out;
+		error = -ENOMEM;
+		new_buf = kmalloc(len*1024, GFP_KERNEL);
+		if (new_buf == NULL) 
+			goto out;
+		memset(new_buf, 0, len*1024);
+		spin_lock_irq(&console_lock);
+		limit = log_start + log_size;
+		/* Copy iff it hasn't wrapped & will fit.  */
+		if (limit < log_buf_len && logged_chars <= len*1024)
+			memcpy(new_buf, log_buf, logged_chars);
+		else
+			logged_chars = log_size = log_start = 0;
+		kfree(log_buf);
+		log_buf = new_buf;
+		log_buf_len = len*1024;
+		spin_unlock_irq(&console_lock);
+		error = 0;
+		break;
 	default:
 		error = -EINVAL;
 		break;
@@ -285,7 +313,7 @@
 		line_feed = 0;
 		for (; p < buf_end; p++) {
 			log_buf[(log_start+log_size) & LOG_BUF_MASK] = *p;
-			if (log_size < LOG_BUF_LEN)
+			if (log_size < log_buf_len)
 				log_size++;
 			else
 				log_start++;
@@ -495,3 +523,26 @@
 		tty->driver.write(tty, 0, msg, strlen(msg));
 	return;
 }
+
+/*
+ * Kernel boot messages are 1st stored in __initdata, then copied to
+ * kmalloc so you can use do_syslog() above to resize buffer later.
+ */
+static int __init printk_ring_copy(void)
+{
+	char *new_buf;
+	unsigned long flags;
+
+	new_buf = kmalloc(BOOTLOG_BUF_LEN, GFP_KERNEL);
+	if (new_buf == NULL) {
+		printk(KERN_EMERG "No memory for new printk buffer!?!\n");
+		return -ENOMEM;
+	}
+	spin_lock_irqsave(&console_lock, flags);
+	memcpy(new_buf, log_buf, BOOTLOG_BUF_LEN);
+	log_buf = new_buf;
+	spin_unlock_irqrestore(&console_lock, flags);
+	return 0;
+}
+
+__initcall(printk_ring_copy);

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/