mm: add a new command-line kmemcheck value
Subsystems (4)
PATCH 1/1 mm: add a new command-line kmemcheck value
Add a new command-line kmemcheck value: kmemcheck=3 (disable the feature), this is the same effect as CONFIG_KMEMCHECK disabled.
After doing this, we can enable/disable kmemcheck feature in one vmlinux.
--- arch/x86/mm/init.c | 11 ++++++ arch/x86/mm/kmemcheck/kmemcheck.c | 62 ++++++++++++++++++++++++++----------- arch/x86/mm/kmemcheck/shadow.c | 13 +++++--- include/linux/kmemcheck.h | 2 + mm/kmemcheck.c | 12 +++++-- mm/page_alloc.c | 2 + 6 files changed, 76 insertions(+), 26 deletions(-)
arch/x86/mm/init.c +11 -0
@@ -135,6 +135,15 @@ static void __init probe_page_size_mask(void) page_size_mask |=1 <<PG_LEVEL_2M ;#endif +#if defined(CONFIG_KMEMCHECK ) +if (!kmemcheck_on) { +if (direct_gbpages) + page_size_mask |=1 <<PG_LEVEL_1G ; +if (cpu_has_pse) + page_size_mask |=1 <<PG_LEVEL_2M ; + } +#endif +/* Enable PSE if available */ if (cpu_has_pse)set_in_cr4 (X86_CR4_PSE );
@@ -331,6 +340,8 @@ bool pfn_range_is_mapped(unsigned long start_pfn, unsigned long end_pfn)return false; } +extern int kmemcheck_on; +/* * Setup the direct mapping of the physical memory at PAGE_OFFSET. * This runs before bootmem is initialized and gets pages directly from
arch/x86/mm/kmemcheck/kmemcheck.c +44 -18
120 lines not on this page · raw message
arch/x86/mm/kmemcheck/shadow.c +8 -5
@@ -90,7 +90,8 @@ void kmemcheck_mark_uninitialized(void *address, unsigned int n)*/ void kmemcheck_mark_initialized (void *address,unsigned int n) { -mark_shadow (address, n,KMEMCHECK_SHADOW_INITIALIZED ); +if (kmemcheck_on) +mark_shadow (address, n,KMEMCHECK_SHADOW_INITIALIZED ); }EXPORT_SYMBOL_GPL (kmemcheck_mark_initialized);
@@ -103,16 +104,18 @@ void kmemcheck_mark_unallocated_pages(struct page *p, unsigned int n) {unsigned int i; -for (i =0 ; i < n; ++i) -kmemcheck_mark_unallocated (page_address (&p[i]),PAGE_SIZE ); +if (kmemcheck_on) +for (i =0 ; i < n; ++i) +kmemcheck_mark_unallocated (page_address (&p[i]),PAGE_SIZE ); }void kmemcheck_mark_uninitialized_pages (struct page *p,unsigned int n) {unsigned int i; -for (i =0 ; i < n; ++i) -kmemcheck_mark_uninitialized (page_address (&p[i]),PAGE_SIZE ); +if (kmemcheck_on) +for (i =0 ; i < n; ++i) +kmemcheck_mark_uninitialized (page_address (&p[i]),PAGE_SIZE ); }void kmemcheck_mark_initialized_pages (struct page *p,unsigned int n)
include/linux/kmemcheck.h +2 -0
@@ -6,6 +6,7 @@#ifdef CONFIG_KMEMCHECK extern int kmemcheck_enabled; +extern int kmemcheck_on;/* The slab-related functions. */ void kmemcheck_alloc_shadow (struct page *page,int order,gfp_t flags,int node);
@@ -88,6 +89,7 @@ bool kmemcheck_is_obj_initialized(unsigned long addr, size_t size);#else #define kmemcheck_enabled 0 +#define kmemcheck_on 0static inline void kmemcheck_alloc_shadow (struct page *page,int order,gfp_t flags,int node)
mm/kmemcheck.c +9 -3
@@ -10,6 +10,9 @@ void kmemcheck_alloc_shadow(struct page *page, int order, gfp_t flags, int node)int pages;int i; +if (!kmemcheck_on) +return ; + pages =1 << order;/*
@@ -41,6 +44,9 @@ void kmemcheck_free_shadow(struct page *page, int order)int pages;int i; +if (!kmemcheck_on) +return ; +if (!kmemcheck_page_is_tracked (page))return ;
@@ -63,7 +69,7 @@ void kmemcheck_slab_alloc(struct kmem_cache *s, gfp_t gfpflags, void *object,* Has already been memset(), which initializes the shadow for us * as well. */ -if (gfpflags & __GFP_ZERO) +if (!kmemcheck_on || gfpflags & __GFP_ZERO)return ;/* No need to initialize the shadow of a non-tracked slab. */
@@ -92,7 +98,7 @@ void kmemcheck_slab_alloc(struct kmem_cache *s, gfp_t gfpflags, void *object,void kmemcheck_slab_free (struct kmem_cache *s,void *object,size_t size) {/* TODO: RCU freeing is unsupported for now; hide false positives. */ -if (!s->ctor && !(s->flags &SLAB_DESTROY_BY_RCU )) +if (kmemcheck_on && !s->ctor && !(s->flags &SLAB_DESTROY_BY_RCU ))kmemcheck_mark_freed (object, size); }
@@ -101,7 +107,7 @@ void kmemcheck_pagealloc_alloc(struct page *page, unsigned int order, {int pages; -if (gfpflags & (__GFP_HIGHMEM | __GFP_NOTRACK)) +if (!kmemcheck_on || (gfpflags & (__GFP_HIGHMEM | __GFP_NOTRACK)))return ; pages =1 << order;
mm/page_alloc.c +2 -0
@@ -2716,6 +2716,8 @@ retry_cpuset: page =get_page_from_freelist (gfp_mask|__GFP_HARDWALL, nodemask, order, zonelist, high_zoneidx, alloc_flags, preferred_zone, migratetype); +if (kmemcheck_on && kmemcheck_enabled && page) +kmemcheck_pagealloc_alloc (page, order, gfp_mask);if (unlikely (!page)) {/* * Runtime PM, block IO and its error handling path
Signature · 1 line
1.7.1
(Oops, resend to restore Cc.)
Hi,
Quoted 3 lines · Xishi Qiu
Add a new command-line kmemcheck value: kmemcheck=3 (disable the feature), this is the same effect as
CONFIG_KMEMCHECKdisabled.
After doing this, we can enable/disable kmemcheck feature in one vmlinux.
Could you please explain what exactly the difference is between the existing kmemcheck=0 parameter and the new kmemcheck=3?
Thanks,
Vegard
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 9 lines · Vegard Nossum
(Oops, resend to restore Cc.)
Hi,
Quoted 3 lines · Xishi Qiu
Add a new command-line kmemcheck value: kmemcheck=3 (disable the feature), this is the same effect as
CONFIG_KMEMCHECKdisabled.
After doing this, we can enable/disable kmemcheck feature in one vmlinux.
Quoted 8 lines
Could you please explain what exactly the difference is between the existing kmemcheck=0 parameter and the new kmemcheck=3?
Thanks,
Vegard
Hi Vegard,
kmemcheck=0: enable kmemcheck feature, but don't check the memory.
and the OS use only one cpu.(setup_max_cpus = 1)
kmemcheck=3: disable kmemcheck feature.
this is the same effect as CONFIG_KMEMCHECK disabled. OS will use cpus as many as possible.
Thanks,
Xishi Qiu
Quoted 6 lines · Xishi Qiu
Quoted 5 lines · Vegard Nossum
Quoted 3 lines · Xishi Qiu
Add a new command-line kmemcheck value: kmemcheck=3 (disable the feature), this is the same effect as
CONFIG_KMEMCHECKdisabled.
After doing this, we can enable/disable kmemcheck feature in one vmlinux.
Quoted 9 lines
Quoted 2 lines
Could you please explain what exactly the difference is between the existing kmemcheck=0 parameter and the new kmemcheck=3?
kmemcheck=0: enable kmemcheck feature, but don't check the memory.
and the OS use only one cpu.(setup_max_cpus = 1)
kmemcheck=3: disable kmemcheck feature.
this is the same effect asCONFIG_KMEMCHECKdisabled. OS will use cpus as many as possible.
I see. In that case, I think it's better to allow all the CPUs to keep running while kmemcheck is disabled with kmemcheck=0 boot parameter, and offline them when/if kmemcheck is reenabled via /proc/sys/kernel/kmemcheck.
Vegard
Quoted 17 lines · Vegard Nossum
Quoted 6 lines · Xishi Qiu
Quoted 5 lines · Vegard Nossum
Quoted 3 lines · Xishi Qiu
Add a new command-line kmemcheck value: kmemcheck=3 (disable the feature), this is the same effect as
CONFIG_KMEMCHECKdisabled.
After doing this, we can enable/disable kmemcheck feature in one vmlinux.Quoted 9 lines
Quoted 2 lines
Could you please explain what exactly the difference is between the existing kmemcheck=0 parameter and the new kmemcheck=3?
kmemcheck=0: enable kmemcheck feature, but don't check the memory.
and the OS use only one cpu.(setup_max_cpus = 1)
kmemcheck=3: disable kmemcheck feature.
this is the same effect asCONFIG_KMEMCHECKdisabled. OS will use cpus as many as possible.
Quoted 9 lines
I see. In that case, I think it's better to allow all the CPUs to keep running while kmemcheck is disabled with kmemcheck=0 boot parameter, and offline them when/if kmemcheck is reenabled via
/proc/sys/kernel/kmemcheck.Vegard
Hi Vegard,
In some scenes, user want to check memory dynamicly, this "dynamically" means we can turn on/off the feature at boottime, not runtime. Without this patch, if user want to use this feature, he should change config and build the kernel, then reboot. This is impossilbe if user has no kernel code or he don't know how to build the kernel.
boottime: kmemcheck=0/1/2/3 (command-line)
runtime: kmemcheck=0/1/2 (/proc/sys/kernel/kmemcheck)
The main different between kmemcheck=0 and 3 is the used memory. Kmemcheck will use about twice as much memory as normal.
Thanks,
Xishi Qiu
Quoted 12 lines · Xishi Qiu
Hi Vegard,
In some scenes, user want to check memory dynamicly, this "dynamically" means we can turn on/off the feature at boottime, not runtime. Without this patch, if user want to use this feature, he should change config and build the kernel, then reboot. This is impossilbe if user has no kernel code or he don't know how to build the kernel.
boottime: kmemcheck=0/1/2/3 (command-line)
runtime: kmemcheck=0/1/2 (/proc/sys/kernel/kmemcheck)
Quoted 7 lines
The main different between kmemcheck=0 and 3 is the used memory. Kmemcheck will use about twice as much memory as normal.
Thanks,
Xishi Qiu--
Hi Vegard,
What do you think of this feature?
Add a command-line "kmemcheck=3", then the kernel runs as the same as CONFIG_KMEMCHECK=off even CONFIG_KMEMCHECK is turn on. "kmemcheck=0/1/2" is the same as originally. In another word, "kmemcheck=3" is the same as:
1) turn off CONFIG_KMEMCHECK
2) rebuild the kernel
3) reboot
The different between kmemcheck=0 and 3 is the used memory and nr_cpus. Also kmemcheck=0 can used in runtime, and kmemcheck=3 is only used in boot.
I think this feature can help users to debug the kernel quickly, It is no need to open CONFIG_KMEMCHECK and rebuild it. Especially sometimes users don't have the kernel source code or the code is different from www.kernel.org. e.g. some private features were added to the kernel source code, and usually users can not have the source code.
Thanks,
Xishi Qiu