Skip to contentSkip to conversation

mm: Fix printk format strings

PATCH In review Vegard Nossum 2 participants 5 messages Oct 11, 2007

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

PATCH 1/1 mm: Fix printk format strings

This makes sure printk format strings contain no more than a single line.

---
 mm/page_alloc.c |   20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)
mm/page_alloc.c +11 -9
index 1a8c595..96f0b33 100644
@@ -198,13 +198,15 @@ static inline int bad_range(struct zone *zone, struct page *page)
 
 static void bad_page(struct page *page)
 {
-	printk(KERN_EMERG "Bad page state in process '%s'\n"
-		KERN_EMERG "page:%p flags:0x%0*lx mapping:%p mapcount:%d count:%d\n"
-		KERN_EMERG "Trying to fix it up, but a reboot is needed\n"
-		KERN_EMERG "Backtrace:\n",
-		current->comm, page, (int)(2*sizeof(unsigned long)),
-		(unsigned long)page->flags, page->mapping,
+	printk(KERN_EMERG "Bad page state in process '%s'\n", current->comm);
+	printk(KERN_EMERG
+		"page:%p flags:0x%0*lx mapping:%p mapcount:%d count:%d\n",
+		page, (int) (2 * sizeof(unsigned long)),
+		(unsigned long) page->flags, page->mapping,
 		page_mapcount(page), page_count(page));
+	printk(KERN_EMERG "Trying to fix it up, but a reboot is needed\n");
+	printk(KERN_EMERG "Backtrace:\n");
+
 	dump_stack();
 	page->flags &= ~(1 << PG_lru	|
 			1 << PG_private |
@@ -1575,13 +1577,13 @@ void show_free_areas(void)
 		}
 	}
 
-	printk("Active:%lu inactive:%lu dirty:%lu writeback:%lu unstable:%lu\n"
-		" free:%lu slab:%lu mapped:%lu pagetables:%lu bounce:%lu\n",
+	printk("Active:%lu inactive:%lu dirty:%lu writeback:%lu unstable:%lu\n",
 		global_page_state(NR_ACTIVE),
 		global_page_state(NR_INACTIVE),
 		global_page_state(NR_FILE_DIRTY),
 		global_page_state(NR_WRITEBACK),
-		global_page_state(NR_UNSTABLE_NFS),
+		global_page_state(NR_UNSTABLE_NFS));
+	printk(" free:%lu slab:%lu mapped:%lu pagetables:%lu bounce:%lu\n",
 		global_page_state(NR_FREE_PAGES),
 		global_page_state(NR_SLAB_RECLAIMABLE) +
 			global_page_state(NR_SLAB_UNRECLAIMABLE),
Signature · 1 line
1.5.2.4
maintainer
#1 lore raw
Quoted 41 lines · On Thu, 11 Oct 2007 08:47:01 +0200 Vegard Nossum <[email protected]>…

This makes sure printk format strings contain no more than a single line.

---
 mm/page_alloc.c |   20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)
mm/page_alloc.c +9 -8
index 1a8c595..96f0b33 100644
@@ -198,13 +198,15 @@ static inline int bad_range(struct zone *zone, struct page *page)
 
 static void bad_page(struct page *page)
 {
-	printk(KERN_EMERG "Bad page state in process '%s'\n"
-		KERN_EMERG "page:%p flags:0x%0*lx mapping:%p mapcount:%d count:%d\n"
-		KERN_EMERG "Trying to fix it up, but a reboot is needed\n"
-		KERN_EMERG "Backtrace:\n",
-		current->comm, page, (int)(2*sizeof(unsigned long)),
-		(unsigned long)page->flags, page->mapping,
+	printk(KERN_EMERG "Bad page state in process '%s'\n", current->comm);
+	printk(KERN_EMERG
+		"page:%p flags:0x%0*lx mapping:%p mapcount:%d count:%d\n",
+		page, (int) (2 * sizeof(unsigned long)),
+		(unsigned long) page->flags, page->mapping,
 		page_mapcount(page), page_count(page));
+	printk(KERN_EMERG "Trying to fix it up, but a reboot is needed\n");
+	printk(KERN_EMERG "Backtrace:\n");
+
 	dump_stack();
 	page->flags &= ~(1 << PG_lru	|
 			1 << PG_private |
@@ -1575,13 +1577,13 @@ void show_free_areas(void)
 		}
 	}
 
-	printk("Active:%lu inactive:%lu dirty:%lu writeback:%lu unstable:%lu\n"
-		" free:%lu slab:%lu mapped:%lu pagetables:%lu bounce:%lu\n",
+	printk("Active:%lu inactive:%lu dirty:%lu writeback:%lu unstable:%lu\n",

mm/page_alloc.c void show_free_areas(void) · line 1589

Quoted 10 lines
mm/page_alloc.c +2 -1
 		global_page_state(NR_ACTIVE),
 		global_page_state(NR_INACTIVE),
 		global_page_state(NR_FILE_DIRTY),
 		global_page_state(NR_WRITEBACK),
-		global_page_state(NR_UNSTABLE_NFS),
+		global_page_state(NR_UNSTABLE_NFS));
+	printk(" free:%lu slab:%lu mapped:%lu pagetables:%lu bounce:%lu\n",
 		global_page_state(NR_FREE_PAGES),
 		global_page_state(NR_SLAB_RECLAIMABLE) +
 			global_page_state(NR_SLAB_UNRECLAIMABLE),

I don't understand the reason for this change.

#2 lore raw
Quoted 40 lines · Andrew Morton
Quoted 38 lines · On Thu, 11 Oct 2007 08:47:01 +0200 Vegard Nossum <[email protected]>…

This makes sure printk format strings contain no more than a single line.

---
 mm/page_alloc.c |   20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)
mm/page_alloc.c +8 -6
index 1a8c595..96f0b33 100644
@@ -198,13 +198,15 @@ static inline int bad_range(struct zone *zone, struct page *page)
 
 static void bad_page(struct page *page)
 {
-     printk(KERN_EMERG "Bad page state in process '%s'\n"
-             KERN_EMERG "page:%p flags:0x%0*lx mapping:%p mapcount:%d count:%d\n"
-             KERN_EMERG "Trying to fix it up, but a reboot is needed\n"
-             KERN_EMERG "Backtrace:\n",
-             current->comm, page, (int)(2*sizeof(unsigned long)),
-             (unsigned long)page->flags, page->mapping,
+     printk(KERN_EMERG "Bad page state in process '%s'\n", current->comm);
+     printk(KERN_EMERG
+             "page:%p flags:0x%0*lx mapping:%p mapcount:%d count:%d\n",
+             page, (int) (2 * sizeof(unsigned long)),
+             (unsigned long) page->flags, page->mapping,
              page_mapcount(page), page_count(page));
+     printk(KERN_EMERG "Trying to fix it up, but a reboot is needed\n");
+     printk(KERN_EMERG "Backtrace:\n");
+
      dump_stack();
      page->flags &= ~(1 << PG_lru    |
                      1 << PG_private |
@@ -1575,13 +1577,13 @@ void show_free_areas(void)
              }
      }
 
Quoted 15 lines

mm/page_alloc.c void show_free_areas(void) · line 1589

Quoted 13 lines
mm/page_alloc.c +3 -3
-     printk("Active:%lu inactive:%lu dirty:%lu writeback:%lu unstable:%lu\n"
-             " free:%lu slab:%lu mapped:%lu pagetables:%lu bounce:%lu\n",
+     printk("Active:%lu inactive:%lu dirty:%lu writeback:%lu unstable:%lu\n",
              global_page_state(NR_ACTIVE),
              global_page_state(NR_INACTIVE),
              global_page_state(NR_FILE_DIRTY),
              global_page_state(NR_WRITEBACK),
-             global_page_state(NR_UNSTABLE_NFS),
+             global_page_state(NR_UNSTABLE_NFS));
+     printk(" free:%lu slab:%lu mapped:%lu pagetables:%lu bounce:%lu\n",
              global_page_state(NR_FREE_PAGES),
              global_page_state(NR_SLAB_RECLAIMABLE) +
                      global_page_state(NR_SLAB_UNRECLAIMABLE),

I don't understand the reason for this change.

I'm sorry :). It helps to make one line per call only, since this allows changing the printk internals for the better by reducing some complexity. I believe this is a good thing. I have a patch that changes printk, but it assumes that each format string only contains a single line. Is this a very bad assumption to make? Or maybe I should have sent that change first and made a reference to it?

But don't you also agree, on the grounds of principle, that a single line per call is better style?

Vegard

maintainer
#3 lore raw
Quoted 23 lines · On Thu, 11 Oct 2007 09:04:57 +0200 "Vegard Nossum" <[email protected]>…
Quoted 14 lines

mm/page_alloc.c void show_free_areas(void) · line 1589

Quoted 13 lines
mm/page_alloc.c +3 -3
-     printk("Active:%lu inactive:%lu dirty:%lu writeback:%lu unstable:%lu\n"
-             " free:%lu slab:%lu mapped:%lu pagetables:%lu bounce:%lu\n",
+     printk("Active:%lu inactive:%lu dirty:%lu writeback:%lu unstable:%lu\n",
              global_page_state(NR_ACTIVE),
              global_page_state(NR_INACTIVE),
              global_page_state(NR_FILE_DIRTY),
              global_page_state(NR_WRITEBACK),
-             global_page_state(NR_UNSTABLE_NFS),
+             global_page_state(NR_UNSTABLE_NFS));
+     printk(" free:%lu slab:%lu mapped:%lu pagetables:%lu bounce:%lu\n",
              global_page_state(NR_FREE_PAGES),
              global_page_state(NR_SLAB_RECLAIMABLE) +
                      global_page_state(NR_SLAB_UNRECLAIMABLE),
Quoted 1 line

I don't understand the reason for this change.

I'm sorry :). It helps to make one line per call only, since this allows changing the printk internals for the better by reducing some complexity. I believe this is a good thing. I have a patch that changes printk, but it assumes that each format string only contains a single line. Is this a very bad assumption to make? Or maybe I should have sent that change first and made a reference to it?

Quoted 2 lines

But don't you also agree, on the grounds of principle, that a single line per call is better style?

Well we do multiple-lines-per-printk in rather a lot of places and it has two advantages:

- less text size (I expect)

- the printk is "atomic" in that the logically-connected output lines won't get tangled up with an intervening printk from another CPU, or from an interrupt handler on this CPU.

Those are pretty modest advantages and I guess we could live without them if we got a significant gain from doing so. But it'd take quite some effort hunting down all the callsites, and preventing new ones from occuring.

#4 lore raw
Quoted 33 lines · Andrew Morton
Quoted 23 lines · On Thu, 11 Oct 2007 09:04:57 +0200 "Vegard Nossum" <[email protected]>…
Quoted 14 lines

mm/page_alloc.c void show_free_areas(void) · line 1589

Quoted 13 lines
mm/page_alloc.c +3 -3
-     printk("Active:%lu inactive:%lu dirty:%lu writeback:%lu unstable:%lu\n"
-             " free:%lu slab:%lu mapped:%lu pagetables:%lu bounce:%lu\n",
+     printk("Active:%lu inactive:%lu dirty:%lu writeback:%lu unstable:%lu\n",
              global_page_state(NR_ACTIVE),
              global_page_state(NR_INACTIVE),
              global_page_state(NR_FILE_DIRTY),
              global_page_state(NR_WRITEBACK),
-             global_page_state(NR_UNSTABLE_NFS),
+             global_page_state(NR_UNSTABLE_NFS));
+     printk(" free:%lu slab:%lu mapped:%lu pagetables:%lu bounce:%lu\n",
              global_page_state(NR_FREE_PAGES),
              global_page_state(NR_SLAB_RECLAIMABLE) +
                      global_page_state(NR_SLAB_UNRECLAIMABLE),
Quoted 1 line

I don't understand the reason for this change.

I'm sorry :). It helps to make one line per call only, since this allows changing the printk internals for the better by reducing some complexity. I believe this is a good thing. I have a patch that changes printk, but it assumes that each format string only contains a single line. Is this a very bad assumption to make? Or maybe I should have sent that change first and made a reference to it?

Quoted 2 lines

But don't you also agree, on the grounds of principle, that a single line per call is better style?

Well we do multiple-lines-per-printk in rather a lot of places and it has two advantages:

- less text size (I expect)

Quoted 8 lines

- the printk is "atomic" in that the logically-connected output lines won't get tangled up with an intervening printk from another CPU, or from an interrupt handler on this CPU.

Those are pretty modest advantages and I guess we could live without them if we got a significant gain from doing so. But it'd take quite some effort hunting down all the callsites, and preventing new ones from occuring.

I have written a sparse program to detect all callers that don't use single-line literal strings for the printk format (posted to sparse mailing list yesterday). So in fact, what I was doing was just that, hunting them down and cleaning it up.

It so happens that my other patch also introduce a buffered printk that supports atomic line continuations and multiple uninterrupted lines, though this requires of course that the callers use these functions. Other benefits include writing directly to the ring-buffer, saving a 1K temporary buffer. The printk patch(es) can be viewed at
http://folk.uio.no/vegardno/xprintf/

Vegard