debug-pagealloc improvements
Subsystems (5)
cover debug-pagealloc improvements
This patch series includes three improvements for the debug-pagealloc feature for no-architecture support (!ARCH_SUPPORTS_DEBUG_PAGEALLOC) and one introduction of the new string library function (memchr_inv).
Akinobu Mita (4):
debug-pagealloc: use plain __ratelimit() instead of
printk_ratelimit()
debug-pagealloc: add support for highmem pages
string: introduce memchr_inv
debug-pagealloc: use memchr_inv
fs/logfs/logfs.h | 1 - fs/logfs/super.c | 22 -------------- include/linux/string.h | 1 + lib/string.c | 54 +++++++++++++++++++++++++++++++++++ mm/debug-pagealloc.c | 73 +++++++++++++++++++++++------------------------ mm/slub.c | 47 +----------------------------- 6 files changed, 93 insertions(+), 105 deletions(-)
Signature · 8 lines
1.7.4.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 1/4 debug-pagealloc: use plain __ratelimit() instead of printk_ratelimit()
printk_ratelimit() should not be used, because it shares ratelimiting state with all other unrelated printk_ratelimit() callsites.
--- mm/debug-pagealloc.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
mm/debug-pagealloc.c +3 -1
@@ -2,6 +2,7 @@#include <linux/mm.h> #include <linux/page-debug-flags.h> #include <linux/poison.h> +#include <linux/ratelimit.h> static inline void set_page_poison (struct page *page) {
@@ -59,6 +60,7 @@ static bool single_bit_flip(unsigned char a, unsigned char b)static void check_poison_mem (unsigned char *mem,size_t bytes) { + static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 10);unsigned char *start;unsigned char *end;
@@ -74,7 +76,7 @@ static void check_poison_mem(unsigned char *mem, size_t bytes)break ; } -if (!printk_ratelimit ()) +if (!__ratelimit (&ratelimit))return ;else if (start == end &&single_bit_flip (*start,PAGE_POISON ))printk (KERN_ERR "pagealloc: single bit error\n" );
Signature · 8 lines
1.7.4.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/4 debug-pagealloc: add support for highmem pages
In reply to Akinobu MitaThis adds support for highmem pages poisoning and verification to the debug-pagealloc feature for no-architecture support.
--- mm/debug-pagealloc.c | 61 ++++++++++++++++++++++++------------------------- 1 files changed, 30 insertions(+), 31 deletions(-)
mm/debug-pagealloc.c +30 -31
@@ -1,5 +1,6 @@#include <linux/kernel.h> #include <linux/mm.h> +#include <linux/highmem.h> #include <linux/page-debug-flags.h> #include <linux/poison.h> #include <linux/ratelimit.h>
@@ -19,28 +20,25 @@ static inline bool page_poison(struct page *page)return test_bit (PAGE_DEBUG_FLAG_POISON , &page->debug_flags); } -static void poison_highpage (struct page *page) -{ -/* -* Page poisoning for highmem pages is not implemented. -* -* This can be called from interrupt contexts. -* So we need to create a new kmap_atomic slot for this -* application and it will need interrupt protection. -*/ -} -static void poison_page (struct page *page) {void *addr; - -if (PageHighMem (page)) { -poison_highpage (page); -return ; +unsigned long flags; +bool highmem =PageHighMem (page); + +if (highmem) { +local_irq_save (flags); + addr =kmap_atomic (page); + }else { + addr =page_address (page); }set_page_poison (page); - addr =page_address (page);memset (addr,PAGE_POISON ,PAGE_SIZE ); + +if (highmem) { +kunmap_atomic (addr); +local_irq_restore (flags); + } }static void poison_pages (struct page *page,int n)
@@ -88,26 +86,27 @@ static void check_poison_mem(unsigned char *mem, size_t bytes)dump_stack (); } -static void unpoison_highpage (struct page *page) -{ -/* -* See comment in poison_highpage(). -* Highmem pages should not be poisoned for now -*/ -BUG_ON (page_poison (page)); -} -static void unpoison_page (struct page *page) { -if (PageHighMem (page)) { -unpoison_highpage (page); +void *addr; +unsigned long flags; +bool highmem =PageHighMem (page); + +if (!page_poison (page))return ; + +if (highmem) { +local_irq_save (flags); + addr =kmap_atomic (page); + }else { + addr =page_address (page); } -if (page_poison (page)) { -void *addr =page_address (page); +check_poison_mem (addr,PAGE_SIZE ); +clear_page_poison (page); -check_poison_mem (addr,PAGE_SIZE ); -clear_page_poison (page); +if (highmem) { +kunmap_atomic (addr); +local_irq_restore (flags); } }
Signature · 8 lines
1.7.4.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 3/4 string: introduce memchr_inv
In reply to Akinobu Mitamemchr_inv() is mainly used to check whether the whole buffer is filled with just a specified byte.
The function name and prototype are stolen from logfs and the implementation is from SLUB.
--- fs/logfs/logfs.h | 1 - fs/logfs/super.c | 22 ------------------- include/linux/string.h | 1 + lib/string.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ mm/slub.c | 47 +---------------------------------------- 5 files changed, 57 insertions(+), 68 deletions(-)
fs/logfs/logfs.h +0 -1
@@ -618,7 +618,6 @@ static inline int logfs_buf_recover(struct logfs_area *area, u64 ofs,struct page *emergency_read_begin (struct address_space *mapping,pgoff_t index);void emergency_read_end (struct page *page);void logfs_crash_dump (struct super_block *sb); -void *memchr_inv (const void *s,int c,size_t n);int logfs_statfs (struct dentry *dentry,struct kstatfs *stats);int logfs_check_ds (struct logfs_disk_super *ds);int logfs_write_sb (struct super_block *sb);
fs/logfs/super.c +0 -22
@@ -91,28 +91,6 @@ void logfs_crash_dump(struct super_block *sb) }/* -* TODO: move to lib/string.c -*/ -/** -* memchr_inv - Find a character in an area of memory. -* @s: The memory area -* @c: The byte to search for -* @n: The size of the area. -* -* returns the address of the first character other than @c, or %NULL -* if the whole buffer contains just @c. -*/ -void *memchr_inv (const void *s,int c,size_t n) -{ -const unsigned char *p = s; -while (n-- !=0 ) -if ((unsigned char )c != *p++) -return (void *)(p -1 ); - -return NULL ; -} - -/* * FIXME: There should be a reserve for root, similar to ext2. */ int logfs_statfs (struct dentry *dentry,struct kstatfs *stats)
include/linux/string.h +1 -0
@@ -114,6 +114,7 @@ extern int memcmp(const void *,const void *,__kernel_size_t);#ifndef __HAVE_ARCH_MEMCHRextern void *memchr (const void *,int ,__kernel_size_t );#endif +void *memchr_inv (const void *s,int c,size_t n);extern char *kstrdup (const char *s,gfp_t gfp);extern char *kstrndup (const char *s,size_t len,gfp_t gfp);
lib/string.c +54 -0
57 lines not on this page · raw message
mm/slub.c +2 -45
65 lines not on this page · raw message
Signature · 8 lines
1.7.4.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 4/4 debug-pagealloc: use memchr_inv
In reply to Akinobu MitaUse newly introduced memchr_inv for page verification.
--- mm/debug-pagealloc.c | 8 +++----- 1 files changed, 3 insertions(+), 5 deletions(-)
mm/debug-pagealloc.c +3 -5
@@ -1,4 +1,5 @@#include <linux/kernel.h> +#include <linux/string.h> #include <linux/mm.h> #include <linux/highmem.h> #include <linux/page-debug-flags.h>
@@ -62,11 +63,8 @@ static void check_poison_mem(unsigned char *mem, size_t bytes)unsigned char *start;unsigned char *end; -for (start = mem; start < mem + bytes; start++) { -if (*start !=PAGE_POISON ) -break ; - } -if (start == mem + bytes) + start =memchr_inv (mem,PAGE_POISON , bytes); +if (!start)return ;for (end = mem + bytes -1 ; end > start; end--) {
Signature · 8 lines
1.7.4.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 3/4] string: introduce memchr_inv
In reply to Akinobu MitaQuoted 6 lines · Akinobu Mita
memchr_inv()is mainly used to check whether the whole buffer is filled with just a specified byte.The function name and prototype are stolen from logfs and the implementation is from SLUB.
Quoted 9 lines
Signed-off-by Akinobu Mita <[email protected]>Cc Christoph Lameter <[email protected]>Cc Pekka Enberg <[email protected]>Cc Matt Mackall <[email protected]>Cc Joern Engel <[email protected]>Cc Marcin Slusarz <[email protected]>Cc Eric Dumazet <[email protected]>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jörn Engel
Acked-byRe: [PATCH 3/4] string: introduce memchr_inv
Quoted 17 lines · Pekka Enberg
Quoted 6 lines · Akinobu Mita
memchr_inv()is mainly used to check whether the whole buffer is filled with just a specified byte.The function name and prototype are stolen from logfs and the implementation is from SLUB.
Quoted 9 lines
Signed-off-by Akinobu Mita <[email protected]>Cc Christoph Lameter <[email protected]>Cc Pekka Enberg <[email protected]>Cc Matt Mackall <[email protected]>Cc Joern Engel <[email protected]>Cc Marcin Slusarz <[email protected]>Cc Eric Dumazet <[email protected]>
Quoted 1 line
Acked-by Pekka Enberg <[email protected]>
JA?rn
Signature · 9 lines
He who knows that enough is enough will always have enough. -- Lao Tsu -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerRe: [PATCH 2/4] debug-pagealloc: add support for highmem pages
In reply to Akinobu MitaQuoted 20 lines · On Tue, 23 Aug 2011 01:29:06 +0900 Akinobu Mita <[email protected]> wrote:
This adds support for highmem pages poisoning and verification to the debug-pagealloc feature for no-architecture support.
...
static void
poison_page(struct page *page)
{mm/debug-pagealloc.c +8
-4void *addr; - -if (PageHighMem (page)) { -poison_highpage (page); -return ; +unsigned long flags; +bool highmem =PageHighMem (page); + +if (highmem) { +local_irq_save (flags); + addr =kmap_atomic (page); + }else { + addr =page_address (page);
mm/debug-pagealloc.c static inline bool page_poison(struct page *page) · line 42
Quoted 10 lines
mm/debug-pagealloc.c +5
-1}set_page_poison (page); - addr =page_address (page);memset (addr,PAGE_POISON ,PAGE_SIZE ); + +if (highmem) { +kunmap_atomic (addr); +local_irq_restore (flags); + } }
This seems more complicated than is needed. Couldn't we just do
static void poison_page(struct page *page)
{
void *addr;
preempt_disable();
addr = kmap_atomic(page);
set_page_poison(page);
memset(addr, PAGE_POISON, PAGE_SIZE);
kunmap_atomic(addr);
preempt_enable();
}?
Review
Quoted 1 line
(quoted diff) +1
-0+ addr = kmap_atomic(page);
That reminds me - we need to convert every "kmap_atomic(p, foo)" to "kmap_atomic(p)" then remove the kmap_atomic back-compatibility macro.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerRe: [PATCH 3/4] string: introduce memchr_inv
In reply to Akinobu MitaQuoted 6 lines · On Tue, 23 Aug 2011 01:29:07 +0900 Akinobu Mita <[email protected]> wrote:
memchr_inv()is mainly used to check whether the whole buffer is filled with just a specified byte.The function name and prototype are stolen from logfs and the implementation is from SLUB.
Quoted 7 lines
...
+/**
+ *memchr_inv- Find a character in an area of memory.
+ * @s: The memory area
+ * @c: The byte to search for
+ * @n: The size of the area.
This text seems to be stolen from memchr(). I guess it's close enough.
Quoted 18 lines
+ * returns the address of the first character other than @c, or %NULL
+ * if the whole buffer contains just @c.
+ */lib/string.c +15
-0+void *memchr_inv (const void *start,int c,size_t bytes) +{ +u8 value = c; +u64 value64; +unsigned int words, prefix; + +if (bytes <=16 ) +return check_bytes8 (start, value, bytes); + + value64 = value | value <<8 | value <<16 | value <<24 ; + value64 = (value64 &0xffffffff ) | value64 <<32 ; + prefix =8 - ((unsigned long )start) %8 ; + +if (prefix) { +u8 *r =check_bytes8 (start, value, prefix);
lib/string.c void *memchr(const void *s, int c, size_t n) · line 804
Quoted 10 lines
lib/string.c +10
-0+if (r) +return r; + start += prefix; + bytes -= prefix; + } + + words = bytes /8 ; + +while (words) { +if (*(u64 *)start != value64)
OK, problem. This will explode if passed a misaligned address on certain (non-x86) architectures. This is nasty because people will develop and test code on x86 and it works. Much later, the alpha/ia64/etc guys discover the problem.
One fix would be to use get_unaligned(). This might be slow on some architectures, I don't know. Another fix is to restrict the caller's alignment freedom; document this and add a runtime WARN_ON().
lib/string.c void *memchr(const void *s, int c, size_t n) · line 812
Quoted 8 lines
lib/string.c +8
-0+return check_bytes8 (start, value,8 ); + start +=8 ; + words--; + } + +return check_bytes8 (start, value, bytes %8 ); +} +EXPORT_SYMBOL (memchr_inv);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 3/4] string: introduce memchr_inv
In reply to Akinobu MitaQuoted 2 lines · Akinobu Mita
+/**
+ *memchr_inv- Find a character in an area of memory.
This description doesn't really match.
Quoted 3 lines
+ * @s: The memory area
+ * @c: The byte to search for
+ * @n: The size of the area.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerRe: [PATCH 3/4] string: introduce memchr_inv
In reply to Andrew MortonQuoted 11 lines · On Mon, 22 Aug 2011 13:52:18 -0700 Andrew Morton <[email protected]>…
Quoted 11 lines
lib/string.c +11
-0+ value64 = value | value <<8 | value <<16 | value <<24 ; + value64 = (value64 &0xffffffff ) | value64 <<32 ; + prefix =8 - ((unsigned long )start) %8 ; + +if (prefix) { +u8 *r =check_bytes8 (start, value, prefix); +if (r) +return r; + start += prefix; + bytes -= prefix; + }
Quoted 8 lines
lib/string.c void *memchr(const void *s, int c, size_t n) · line 804
Quoted 5 lines
lib/string.c +5
-0+ + words = bytes /8 ; + +while (words) { +if (*(u64 *)start != value64)OK, problem. This will explode if passed a misaligned address on certain (non-x86) architectures.
pls ignore. As Marcin points out, I can't read.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerRe: [PATCH 3/4] string: introduce memchr_inv
In reply to Andrew MortonQuoted 11 lines · On Mon, 22 Aug 2011 13:52:18 -0700 Andrew Morton <[email protected]>…
Quoted 11 lines
lib/string.c +11
-0+ value64 = value | value <<8 | value <<16 | value <<24 ; + value64 = (value64 &0xffffffff ) | value64 <<32 ; + prefix =8 - ((unsigned long )start) %8 ; + +if (prefix) { +u8 *r =check_bytes8 (start, value, prefix); +if (r) +return r; + start += prefix; + bytes -= prefix; + }
Quoted 8 lines
lib/string.c void *memchr(const void *s, int c, size_t n) · line 804
Quoted 5 lines
lib/string.c +5
-0+ + words = bytes /8 ; + +while (words) { +if (*(u64 *)start != value64)OK, problem. This will explode if passed a misaligned address on certain (non-x86) architectures.
pls ignore. As Marcin points out, I can't read.
Re: [PATCH 3/4] string: introduce memchr_inv
In reply to Andrew MortonQuoted 35 lines · Andrew Morton
Quoted 6 lines · On Tue, 23 Aug 2011 01:29:07 +0900 Akinobu Mita <[email protected]> wrote:
memchr_inv()is mainly used to check whether the whole buffer is filled with just a specified byte.The function name and prototype are stolen from logfs and the implementation is from SLUB.
Quoted 7 lines
...
+/**
+ *memchr_inv- Find a character in an area of memory.
+ * @s: The memory area
+ * @c: The byte to search for
+ * @n: The size of the area.This text seems to be stolen from
memchr(). I guess it's close enough.Quoted 16 lines
+ * returns the address of the first character other than @c, or %NULL
+ * if the whole buffer contains just @c.
+ */lib/string.c +13
-0+void *memchr_inv (const void *start,int c,size_t bytes) +{ +u8 value = c; +u64 value64; +unsigned int words, prefix; + +if (bytes <=16 ) +return check_bytes8 (start, value, bytes); + + value64 = value | value <<8 | value <<16 | value <<24 ; + value64 = (value64 &0xffffffff ) | value64 <<32 ; + prefix =8 - ((unsigned long )start) %8 ; +
<snip>
Quoted 7 lines
lib/string.c void *memchr(const void *s, int c, size_t n) · line 799
Quoted 7 lines
lib/string.c +7
-0+if (prefix) { +u8 *r =check_bytes8 (start, value, prefix); +if (r) +return r; + start += prefix; + bytes -= prefix; + }
</snip>
Please note Andrew the previous code just make sure 'start' is aligned on 8 bytes boundary. (It is suboptimal because if 'start' was already aligned, we call the slow check_bytes(start, value, 8))
Code should probably do
prefix = (unsigned long)start % 8;
if (prefix) {
prefix = 8 - prefix;
r = check_bytes8(start, value, prefix);
...Quoted 5 lines
lib/string.c void *memchr(const void *s, int c, size_t n) · line 804
Quoted 5 lines
lib/string.c +5
-0+ + words = bytes /8 ; + +while (words) { +if (*(u64 *)start != value64)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Christoph Lameter
Acked-byRe: [PATCH 3/4] string: introduce memchr_inv
In reply to Geert UytterhoevenQuoted 5 lines · Geert Uytterhoeven
Quoted 2 lines · Akinobu Mita
+/**
+ *memchr_inv- Find a character in an area of memory.This description doesn't really match.
Seconded. If you fix that then
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 2/4] debug-pagealloc: add support for highmem pages
In reply to Andrew Morton2011/8/23 Andrew Morton <[email protected]>:
Quoted 14 lines
This seems more complicated than is needed. Couldn't we just do
static void
poison_page(struct page *page)
{
void *addr;preempt_disable();
addr =kmap_atomic(page);
set_page_poison(page);
memset(addr,PAGE_POISON,PAGE_SIZE);
kunmap_atomic(addr);
preempt_enable();
}
Quoted 1 line
?
This code looks much better. I'll update the patch.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>