kmemtrace
Subsystems (4)
cover kmemtrace
Hi everybody,
As usual, the kmemtrace userspace repo is located atgit://repo.or.cz/kmemtrace-user.git
It's not updated now, but I will rebase it. So re-clone it, don't just git-rebase it. The changes were too extensive and I'd like to keep the revision history clean.
Changes in kmemtrace:
- new ABI, supports variable sized packets and it's much shorter (it has specific fields for allocations)
- we'll use splice() in userspace
- replaced timestamps with sequence numbers, since timestamps don't have a good enough resolution (though they could be added as an additional feature)
- used relay_reserve() as Mathieu Desnoyers suggested
- moved additional docs into a different commit and documented the replacement of inline with __always_inline in those commits
Please have a look and let me know what you think.
Eduard - Gabriel Munteanu (5):
kmemtrace: Core implementation.
kmemtrace: Additional documentation.
kmemtrace: SLAB hooks.
kmemtrace: SLUB hooks.
kmemtrace: SLOB hooks.
Documentation/ABI/testing/debugfs-kmemtrace | 71 ++++++ Documentation/kernel-parameters.txt | 10 + Documentation/vm/kmemtrace.txt | 126 ++++++++++ MAINTAINERS | 6 + include/linux/kmemtrace.h | 85 +++++++ include/linux/slab_def.h | 68 +++++- include/linux/slob_def.h | 9 +- include/linux/slub_def.h | 53 ++++- init/main.c | 2 + lib/Kconfig.debug | 28 +++ mm/Makefile | 2 +- mm/kmemtrace.c | 335 +++++++++++++++++++++++++++ mm/slab.c | 71 +++++- mm/slob.c | 37 +++- mm/slub.c | 66 +++++- 15 files changed, 933 insertions(+), 36 deletions(-) create mode 100644 Documentation/ABI/testing/debugfs-kmemtrace create mode 100644 Documentation/vm/kmemtrace.txt create mode 100644 include/linux/kmemtrace.h create mode 100644 mm/kmemtrace.c
--
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>
PATCH 1/5 kmemtrace: Core implementation.
kmemtrace provides tracing for slab allocator functions, such as kmalloc, kfree, kmem_cache_alloc, kmem_cache_free etc.. Collected data is then fed to the userspace application in order to analyse allocation hotspots, internal fragmentation and so on, making it possible to see how well an allocator performs, as well as debug and profile kernel code.
--- Documentation/kernel-parameters.txt | 10 + MAINTAINERS | 6 + include/linux/kmemtrace.h | 85 +++++++++ init/main.c | 2 + lib/Kconfig.debug | 28 +++ mm/Makefile | 2 +- mm/kmemtrace.c | 335 +++++++++++++++++++++++++++++++++++ 7 files changed, 467 insertions(+), 1 deletions(-) create mode 100644 include/linux/kmemtrace.h create mode 100644 mm/kmemtrace.c
Documentation/kernel-parameters.txt +10 -0
@@ -49,6 +49,7 @@ parameter is applicable: ISAPNP ISA PnP code is enabled. ISDN Appropriate ISDN support is enabled. JOY Appropriate joystick support is enabled. + KMEMTRACE kmemtrace is enabled. LIBATA Libata driver is enabled LP Printer support is enabled. LOOP Loopback device support is enabled.
@@ -941,6 +942,15 @@ and is between 256 and 4096 characters. It is defined in the file use the HighMem zone if it exists, and the Normal zone if it does not. + kmemtrace.enable= [KNL,KMEMTRACE] Format: { yes | no } + Controls whether kmemtrace is enabled + at boot-time. + + kmemtrace.subbufs=n [KNL,KMEMTRACE] Overrides the number of + subbufs kmemtrace's relay channel has. Set this + higher than default (KMEMTRACE_N_SUBBUFS in code) if + you experience buffer overruns. + movablecore=nn[KMG] [KNL,X86-32,IA-64,PPC,X86-64] This parameter is similar to kernelcore except it specifies the amount of memory used for migratable allocations.
MAINTAINERS +6 -0
@@ -2425,6 +2425,12 @@ M: [email protected] L: [email protected] S: Maintained +KMEMTRACE +P: Eduard - Gabriel Munteanu +M: [email protected] +L: [email protected] +S: Maintained + KPROBES P: Ananth N Mavinakayanahalli M: [email protected]
include/linux/kmemtrace.h new file +85 -0
85 lines not on this page · raw message
init/main.c +2 -0
@@ -66,6 +66,7 @@#include <asm/setup.h> #include <asm/sections.h> #include <asm/cacheflush.h> +#include <linux/kmemtrace.h> #ifdef CONFIG_X86_LOCAL_APIC #include <asm/smp.h>
@@ -641,6 +642,7 @@ asmlinkage void __init start_kernel(void)enable_debug_pagealloc ();cpu_hotplug_init ();kmem_cache_init (); +kmemtrace_init ();debug_objects_mem_init ();idr_init_cache ();setup_per_cpu_pageset ();
lib/Kconfig.debug +28 -0
@@ -674,6 +674,34 @@ config FIREWIRE_OHCI_REMOTE_DMA If unsure, say N. +config KMEMTRACE + bool "Kernel memory tracer (kmemtrace)" + depends on RELAY && DEBUG_FS && MARKERS + help + kmemtrace provides tracing for slab allocator functions, such as + kmalloc, kfree, kmem_cache_alloc, kmem_cache_free etc.. Collected + data is then fed to the userspace application in order to analyse + allocation hotspots, internal fragmentation and so on, making it + possible to see how well an allocator performs, as well as debug + and profile kernel code. + + This requires an userspace application to use. See + Documentation/vm/kmemtrace.txt for more information. + + Saying Y will make the kernel somewhat larger and slower. However, + if you disable kmemtrace at run-time or boot-time, the performance + impact is minimal (depending on the arch the kernel is built for). + + If unsure, say N. + +config KMEMTRACE_DEFAULT_ENABLED + bool "Enabled by default at boot" + depends on KMEMTRACE + help + Say Y here to enable kmemtrace at boot-time by default. Whatever + the choice, the behavior can be overridden by a kernel parameter, + as described in documentation. + source "samples/Kconfig" source "lib/Kconfig.kgdb"
mm/Makefile +1 -1
@@ -33,4 +33,4 @@ obj-$(CONFIG_MIGRATION) += migrate.o obj-$(CONFIG_SMP) += allocpercpu.o obj-$(CONFIG_QUICKLIST) += quicklist.o obj-$(CONFIG_CGROUP_MEM_RES_CTLR) += memcontrol.o - +obj-$(CONFIG_KMEMTRACE) += kmemtrace.o
mm/kmemtrace.c new file +335 -0
335 lines not on this page · raw message
Signature · 7 lines
1.5.6.1 -- 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>
PATCH 2/5 kmemtrace: Additional documentation.
Documented kmemtrace's ABI, purpose and design. Also includes a short usage guide, FAQ, as well as a link to the userspace application's Git repository, which is currently hosted at repo.or.cz.
--- Documentation/ABI/testing/debugfs-kmemtrace | 71 +++++++++++++++ Documentation/vm/kmemtrace.txt | 126 +++++++++++++++++++++++++++ 2 files changed, 197 insertions(+), 0 deletions(-) create mode 100644 Documentation/ABI/testing/debugfs-kmemtrace create mode 100644 Documentation/vm/kmemtrace.txt
Documentation/ABI/testing/debugfs-kmemtrace new file +71 -0
@@ -0,0 +1,71 @@ +What: /sys/kernel/debug/kmemtrace/ +Date: July 2008 +Contact: Eduard - Gabriel Munteanu <[email protected]> +Description: + +In kmemtrace-enabled kernels, the following files are created: + +/sys/kernel/debug/kmemtrace/ + cpu<n> (0400) Per-CPU tracing data, see below. (binary) + total_overruns (0400) Total number of bytes which were dropped from + cpu<n> files because of full buffer condition, + non-binary. (text) + abi_version (0400) Kernel's kmemtrace ABI version. (text) + +Each per-CPU file should be read according to the relay interface. That is, +the reader should set affinity to that specific CPU and, as currently done by +the userspace application (though there are other methods), use poll() with +an infinite timeout before every read(). Otherwise, erroneous data may be +read. The binary data has the following _core_ format: + + Event ID (1 byte) Unsigned integer, one of: + 0 - represents an allocation (KMEMTRACE_EVENT_ALLOC) + 1 - represents a freeing of previously allocated memory + (KMEMTRACE_EVENT_FREE) + Type ID (1 byte) Unsigned integer, one of: + 0 - this is a kmalloc() / kfree() + 1 - this is a kmem_cache_alloc() / kmem_cache_free() + 2 - this is a __get_free_pages() et al. + Event size (2 bytes) Unsigned integer representing the + size of this event. Used to extend + kmemtrace. Discard the bytes you + don't know about. + Sequence number (4 bytes) Signed integer used to reorder data + logged on SMP machines. Wraparound + must be taken into account, although + it is unlikely. + Caller address (8 bytes) Return address to the caller. + Pointer to mem (8 bytes) Pointer to target memory area. Can be + NULL, but not all such calls might be + recorded. + +In case of KMEMTRACE_EVENT_ALLOC events, the next fields follow: + + Requested bytes (8 bytes) Total number of requested bytes, + unsigned, must not be zero. + Allocated bytes (8 bytes) Total number of actually allocated + bytes, unsigned, must not be lower + than requested bytes. + Requested flags (4 bytes) GFP flags supplied by the caller. + Target CPU (4 bytes) Signed integer, valid for event id 1. + If equal to -1, target CPU is the same + as origin CPU, but the reverse might + not be true. + +The data is made available in the same endianness the machine has. + +Other event ids and type ids may be defined and added. Other fields may be +added by increasing event size, but see below for details. +Every modification to the ABI, including new id definitions, are followed +by bumping the ABI version by one. + +Adding new data to the packet (features) is done at the end of the mandatory +data: + Feature size (2 byte) + Feature ID (1 byte) + Feature data (Feature size - 4 bytes) + + +Users: + kmemtrace-user - git://repo.or.cz/kmemtrace-user.git +
Documentation/vm/kmemtrace.txt new file +126 -0
126 lines not on this page · raw message
Signature · 7 lines
1.5.6.1 -- 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>
PATCH 3/5 kmemtrace: SLAB hooks.
This adds hooks for the SLAB allocator, to allow tracing with kmemtrace.
We also convert some inline functions to __always_inline to make sure _RET_IP_, which expands to __builtin_return_address(0), always works as expected.
--- include/linux/slab_def.h | 68 ++++++++++++++++++++++++++++++++++++++------ mm/slab.c | 71 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 123 insertions(+), 16 deletions(-)
include/linux/slab_def.h +59 -9
@@ -14,6 +14,7 @@#include <asm/page.h> /* kmalloc_sizes.h needs PAGE_SIZE */ #include <asm/cache.h> /* kmalloc_sizes.h needs L1_CACHE_BYTES */ #include <linux/compiler.h> +#include <linux/kmemtrace.h> /* Size description struct for general caches. */ struct cache_sizes {
@@ -28,8 +29,26 @@ extern struct cache_sizes malloc_sizes[];void *kmem_cache_alloc (struct kmem_cache *,gfp_t );void *__kmalloc (size_t size,gfp_t flags); -static inline void *kmalloc (size_t size,gfp_t flags) +#ifdef CONFIG_KMEMTRACE +extern void *kmem_cache_alloc_notrace (struct kmem_cache *cachep,gfp_t flags); +extern size_t slab_buffer_size (struct kmem_cache *cachep); +#else +static __always_inline void * +kmem_cache_alloc_notrace (struct kmem_cache *cachep,gfp_t flags) { +return kmem_cache_alloc (cachep, flags); +} +static inline size_t slab_buffer_size (struct kmem_cache *cachep) +{ +return 0 ; +} +#endif + +static __always_inline void *kmalloc(size_t size, gfp_t flags) +{ +struct kmem_cache *cachep; +void *ret; +if (__builtin_constant_p (size)) {int i =0 ;
@@ -50,10 +69,17 @@ static inline void *kmalloc(size_t size, gfp_t flags) found:#ifdef CONFIG_ZONE_DMA if (flags &GFP_DMA ) -return kmem_cache_alloc (malloc_sizes[i].cs_dmacachep, - flags); + cachep = malloc_sizes[i].cs_dmacachep; + else#endif -return kmem_cache_alloc (malloc_sizes[i].cs_cachep, flags); + cachep = malloc_sizes[i].cs_cachep; + + ret =kmem_cache_alloc_notrace (cachep, flags); + +kmemtrace_mark_alloc (KMEMTRACE_TYPE_KMALLOC , _THIS_IP_, ret, + size,slab_buffer_size (cachep), flags); + +return ret; }return __kmalloc (size, flags); }
@@ -62,8 +88,25 @@ found:extern void *__kmalloc_node (size_t size,gfp_t flags,int node);extern void *kmem_cache_alloc_node (struct kmem_cache *,gfp_t flags,int node); -static inline void *kmalloc_node (size_t size,gfp_t flags,int node) +#ifdef CONFIG_KMEMTRACE +extern void *kmem_cache_alloc_node_notrace (struct kmem_cache *cachep, +gfp_t flags, +int nodeid); +#else +static __always_inline void * +kmem_cache_alloc_node_notrace (struct kmem_cache *cachep, +gfp_t flags, +int nodeid) +{ +return kmem_cache_alloc_node (cachep, flags, nodeid); +} +#endif + +static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) { +struct kmem_cache *cachep; +void *ret; +if (__builtin_constant_p (size)) {int i =0 ;
@@ -84,11 +127,18 @@ static inline void *kmalloc_node(size_t size, gfp_t flags, int node) found:#ifdef CONFIG_ZONE_DMA if (flags &GFP_DMA ) -return kmem_cache_alloc_node (malloc_sizes[i].cs_dmacachep, - flags, node); + cachep = malloc_sizes[i].cs_dmacachep; + else#endif -return kmem_cache_alloc_node (malloc_sizes[i].cs_cachep, - flags, node); + cachep = malloc_sizes[i].cs_cachep; + + ret =kmem_cache_alloc_node_notrace (cachep, flags, node); + +kmemtrace_mark_alloc_node (KMEMTRACE_TYPE_KMALLOC , _THIS_IP_, + ret, size,slab_buffer_size (cachep), + flags, node); + +return ret; }return __kmalloc_node (size, flags, node); }
mm/slab.c +64 -7
138 lines not on this page · raw message
Signature · 7 lines
1.5.6.1 -- 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>
PATCH 4/5 kmemtrace: SLUB hooks.
This adds hooks for the SLUB allocator, to allow tracing with kmemtrace.
--- include/linux/slub_def.h | 53 ++++++++++++++++++++++++++++++++++-- mm/slub.c | 66 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 110 insertions(+), 9 deletions(-)
include/linux/slub_def.h +50 -3
@@ -10,6 +10,7 @@#include <linux/gfp.h> #include <linux/workqueue.h> #include <linux/kobject.h> +#include <linux/kmemtrace.h> enum stat_item {ALLOC_FASTPATH ,/* Allocation from cpu slab */
@@ -203,13 +204,31 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)void *kmem_cache_alloc (struct kmem_cache *,gfp_t );void *__kmalloc (size_t size,gfp_t flags); +#ifdef CONFIG_KMEMTRACE +extern void *kmem_cache_alloc_notrace (struct kmem_cache *s,gfp_t gfpflags); +#else +static __always_inline void * +kmem_cache_alloc_notrace (struct kmem_cache *s,gfp_t gfpflags) +{ +return kmem_cache_alloc (s, gfpflags); +} +#endif + static __always_inline void *kmalloc_large(size_t size, gfp_t flags) { -return (void *)__get_free_pages (flags | __GFP_COMP,get_order (size)); +unsigned int order =get_order (size); +void *ret = (void *)__get_free_pages (flags, order); + +kmemtrace_mark_alloc (KMEMTRACE_TYPE_KMALLOC , _THIS_IP_, ret, + size,PAGE_SIZE << order, flags); + +return ret; } static __always_inline void *kmalloc(size_t size, gfp_t flags) { +void *ret; +if (__builtin_constant_p (size)) {if (size >PAGE_SIZE )return kmalloc_large (size, flags);
@@ -220,7 +239,13 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)if (!s)return ZERO_SIZE_PTR ; -return kmem_cache_alloc (s, flags); + ret =kmem_cache_alloc_notrace (s, flags); + +kmemtrace_mark_alloc (KMEMTRACE_TYPE_KMALLOC , + _THIS_IP_, ret, + size, s->size, flags); + +return ret; } }return __kmalloc (size, flags);
@@ -230,8 +255,24 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)void *__kmalloc_node (size_t size,gfp_t flags,int node);void *kmem_cache_alloc_node (struct kmem_cache *,gfp_t flags,int node); +#ifdef CONFIG_KMEMTRACE +extern void *kmem_cache_alloc_node_notrace (struct kmem_cache *s, +gfp_t gfpflags, +int node); +#else +static __always_inline void * +kmem_cache_alloc_node_notrace (struct kmem_cache *s, +gfp_t gfpflags, +int node) +{ +return kmem_cache_alloc_node (s, gfpflags, node); +} +#endif + static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) { +void *ret; +if (__builtin_constant_p (size) && size <=PAGE_SIZE && !(flags &SLUB_DMA )) {struct kmem_cache *s =kmalloc_slab (size);
@@ -239,7 +280,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)if (!s)return ZERO_SIZE_PTR ; -return kmem_cache_alloc_node (s, flags, node); + ret =kmem_cache_alloc_node_notrace (s, flags, node); + +kmemtrace_mark_alloc_node (KMEMTRACE_TYPE_KMALLOC , + _THIS_IP_, ret, + size, s->size, flags, node); + +return ret; }return __kmalloc_node (size, flags, node); }
mm/slub.c +60 -6
125 lines not on this page · raw message
Signature · 7 lines
1.5.6.1 -- 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>
PATCH 5/5 kmemtrace: SLOB hooks.
This adds hooks for the SLOB allocator, to allow tracing with kmemtrace.
We also convert some inline functions to __always_inline to make sure _RET_IP_, which expands to __builtin_return_address(0), always works as expected.
--- include/linux/slob_def.h | 9 +++++---- mm/slob.c | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 10 deletions(-)
include/linux/slob_def.h +5 -4
@@ -3,14 +3,15 @@void *kmem_cache_alloc_node (struct kmem_cache *,gfp_t flags,int node); -static inline void *kmem_cache_alloc (struct kmem_cache *cachep,gfp_t flags) +static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep, +gfp_t flags) {return kmem_cache_alloc_node (cachep, flags,-1 ); }void *__kmalloc_node (size_t size,gfp_t flags,int node); -static inline void *kmalloc_node (size_t size,gfp_t flags,int node) +static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) {return __kmalloc_node (size, flags, node); }
@@ -23,12 +24,12 @@ static inline void *kmalloc_node(size_t size, gfp_t flags, int node)* kmalloc is the normal method of allocating memory * in the kernel. */ -static inline void *kmalloc (size_t size,gfp_t flags) +static __always_inline void *kmalloc(size_t size, gfp_t flags) {return __kmalloc_node (size, flags,-1 ); } -static inline void *__kmalloc (size_t size,gfp_t flags) +static __always_inline void *__kmalloc(size_t size, gfp_t flags) {return kmalloc (size, flags); }
mm/slob.c +31 -6
@@ -65,6 +65,7 @@#include <linux/module.h> #include <linux/rcupdate.h> #include <linux/list.h> +#include <linux/kmemtrace.h> #include <asm/atomic.h> /*
@@ -463,27 +464,38 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node) {unsigned int *m;int align =max (ARCH_KMALLOC_MINALIGN ,ARCH_SLAB_MINALIGN ); +void *ret;if (size <PAGE_SIZE - align) {if (!size)return ZERO_SIZE_PTR ; m =slob_alloc (size + align, gfp, align, node); +if (!m)return NULL ; *m = size; -return (void *)m + align; + ret = (void *)m + align; + +kmemtrace_mark_alloc_node (KMEMTRACE_TYPE_KMALLOC , + _RET_IP_, ret, + size, size + align, gfp, node); }else { -void *ret; +unsigned int order =get_order (size); - ret =slob_new_page (gfp | __GFP_COMP,get_order (size), node); + ret =slob_new_page (gfp | __GFP_COMP, order, node);if (ret) {struct page *page; page =virt_to_page (ret); page->private = size; } -return ret; + +kmemtrace_mark_alloc_node (KMEMTRACE_TYPE_KMALLOC , + _RET_IP_, ret, + size,PAGE_SIZE << order, gfp, node); } + +return ret; }EXPORT_SYMBOL (__kmalloc_node);
@@ -501,6 +513,8 @@ void kfree(const void *block)slob_free (m, *m + align); }else put_page (&sp->page); + +kmemtrace_mark_free (KMEMTRACE_TYPE_KMALLOC , _RET_IP_, block); }EXPORT_SYMBOL (kfree);
@@ -569,10 +583,19 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node) {void *b; -if (c->size <PAGE_SIZE ) +if (c->size <PAGE_SIZE ) { b =slob_alloc (c->size, flags, c->align, node); -else +kmemtrace_mark_alloc_node (KMEMTRACE_TYPE_CACHE , + _RET_IP_, b, c->size, +SLOB_UNITS (c->size) *SLOB_UNIT , + flags, node); + }else { b =slob_new_page (flags,get_order (c->size), node); +kmemtrace_mark_alloc_node (KMEMTRACE_TYPE_CACHE , + _RET_IP_, b, c->size, +PAGE_SIZE <<get_order (c->size), + flags, node); + }if (c->ctor) c->ctor (c, b);
@@ -608,6 +631,8 @@ void kmem_cache_free(struct kmem_cache *c, void *b) }else {__kmem_cache_free (b, c->size); } + +kmemtrace_mark_free (KMEMTRACE_TYPE_CACHE , _RET_IP_, b); }EXPORT_SYMBOL (kmem_cache_free);
Signature · 7 lines
1.5.6.1 -- 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>
Re: [PATCH 5/5] kmemtrace: SLOB hooks.
Quoted 7 lines · Eduard - Gabriel Munteanu
This adds hooks for the SLOB allocator, to allow tracing with kmemtrace.
We also convert some inline functions to
__always_inlineto make sure _RET_IP_, which expands to__builtin_return_address(0), always works as expected.Signed-off-by Eduard - Gabriel Munteanu <[email protected]>
I think Matt acked this already but as you dropped the tags, I'll ask once more before I merge this.
--
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>
Matt Mackall
Acked-byRe: [PATCH 5/5] kmemtrace: SLOB hooks.
Quoted 4 lines · Pekka Enberg
Quoted 2 lines · Eduard - Gabriel Munteanu
This adds hooks for the SLOB allocator, to allow tracing with kmemtrace.
Quoted 8 lines
Quoted 5 lines
We also convert some inline functions to
__always_inlineto make sure _RET_IP_, which expands to__builtin_return_address(0), always works as expected.Signed-off-by Eduard - Gabriel Munteanu <[email protected]>I think Matt acked this already but as you dropped the tags, I'll ask once more before I merge this.
Yeah, that's fine.
Signature · 7 lines
Mathematics is the supreme nostalgia of our time. -- 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>
Pekka Enberg
AppliedRe: [PATCH 5/5] kmemtrace: SLOB hooks.
Quoted 9 lines · Matt Mackall
Quoted 8 lines · Pekka Enberg
Quoted 6 lines · Eduard - Gabriel Munteanu
This adds hooks for the SLOB allocator, to allow tracing with kmemtrace.
We also convert some inline functions to
__always_inlineto make sure _RET_IP_, which expands to__builtin_return_address(0), always works as expected.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Eduard - Gabriel Munteanu <[email protected]>I think Matt acked this already but as you dropped the tags, I'll ask once more before I merge this.
Yeah, that's fine.
Acked-by Matt Mackall <[email protected]>
Applied, thanks!
--
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>
Re: [PATCH 4/5] kmemtrace: SLUB hooks.
In reply to Eduard - Gabriel MunteanuQuoted 9 lines · Eduard - Gabriel Munteanu
static
__always_inlinevoid *kmalloc_node(size_t size,gfp_tflags, int node) {include/linux/slub_def.h +2
-0+void *ret; +if (__builtin_constant_p (size) && size <=PAGE_SIZE && !(flags &SLUB_DMA )) {struct kmem_cache *s =kmalloc_slab (size);@@ -239,7 +280,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)if (!s)
include/linux/slub_def.h static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) · line 289
Quoted 10 lines
include/linux/slub_def.h +7
-1return ZERO_SIZE_PTR ; -return kmem_cache_alloc_node (s, flags, node); + ret =kmem_cache_alloc_node_notrace (s, flags, node); + +kmemtrace_mark_alloc_node (KMEMTRACE_TYPE_KMALLOC , + _THIS_IP_, ret, + size, s->size, flags, node); + +return ret;
You could simplify the stuff in slub.h if you would fall back to the uninlined functions in the case that kmemtrace is enabled. IMHO adding additional inline code here does grow these function to a size where inlining is not useful anymore.
Quoted 14 lines
mm/slub.c +1
-0@@ -23,6 +23,7 @@#include <linux/kallsyms.h> #include <linux/memory.h> #include <linux/math64.h> +#include <linux/kmemtrace.h> /* * Lock order: @@ -1652,18 +1653,47 @@ static __always_inline void *slab_alloc(struct kmem_cache *s,
mm/slub.c static __always_inline void *slab_alloc(struct kmem_cache *s, · line 1662
Quoted 10 lines
mm/slub.c +6
-1void *kmem_cache_alloc (struct kmem_cache *s,gfp_t gfpflags) { -return slab_alloc (s, gfpflags,-1 ,__builtin_return_address (0 )); +void *ret =slab_alloc (s, gfpflags,-1 ,__builtin_return_address (0 )); + +kmemtrace_mark_alloc (KMEMTRACE_TYPE_CACHE , _RET_IP_, ret, + s->objsize, s->size, gfpflags); + +return ret; }
_RET_IP == __builtin_return_address(0) right? Put that into a local variable? At least we need consistent usage within one function. Maybe convert __builtin_return_address(0) to _RET_IP_ within slub?
Quoted 11 lines
mm/slub.c +8
-0EXPORT_SYMBOL (kmem_cache_alloc); +#ifdef CONFIG_KMEMTRACE +void *kmem_cache_alloc_notrace (struct kmem_cache *s,gfp_t gfpflags) +{ +return slab_alloc (s, gfpflags,-1 ,__builtin_return_address (0 )); +} +EXPORT_SYMBOL (kmem_cache_alloc_notrace); +#endif +#ifdef CONFIG_NUMA
mm/slub.c static __always_inline void *slab_alloc(struct kmem_cache *s, · line 1682
Quoted 10 lines
mm/slub.c +7
-1void *kmem_cache_alloc_node (struct kmem_cache *s,gfp_t gfpflags,int node) { -return slab_alloc (s, gfpflags, node,__builtin_return_address (0 )); +void *ret =slab_alloc (s, gfpflags, node, +__builtin_return_address (0 )); + +kmemtrace_mark_alloc_node (KMEMTRACE_TYPE_CACHE , _RET_IP_, ret, + s->objsize, s->size, gfpflags, node); + +return ret;
Same here.
Quoted 18 lines
mm/slub.c +10
-0}EXPORT_SYMBOL (kmem_cache_alloc_node);#endif +#ifdef CONFIG_KMEMTRACE +void *kmem_cache_alloc_node_notrace (struct kmem_cache *s, +gfp_t gfpflags, +int node) +{ +return slab_alloc (s, gfpflags, node,__builtin_return_address (0 )); +} +EXPORT_SYMBOL (kmem_cache_alloc_node_notrace); +#endif +/* * Slow patch handling. This may still be called frequently since objects * have a longer lifetime than the cpu slabs in most processing loads.
mm/slub.c void kmem_cache_free(struct kmem_cache *s, void *x) · line 1807
Quoted 7 lines
mm/slub.c +2
-0@@ -1771,6 +1801,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x) page =virt_to_head_page (x);slab_free (s, page, x,__builtin_return_address (0 )); + +kmemtrace_mark_free (KMEMTRACE_TYPE_CACHE , _RET_IP_, x); }EXPORT_SYMBOL (kmem_cache_free);
And again.
Quoted 13 lines
mm/slub.c +1
-0@@ -2676,6 +2708,7 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)void *__kmalloc (size_t size,gfp_t flags) {struct kmem_cache *s; +void *ret;if (unlikely (size >PAGE_SIZE ))return kmalloc_large (size, flags);@@ -2685,7 +2718,12 @@ void *__kmalloc(size_t size, gfp_t flags)if (unlikely (ZERO_OR_NULL_PTR (s)))return s;
mm/slub.c void *__kmalloc(size_t size, gfp_t flags) · line 2729
Quoted 10 lines
mm/slub.c +6
-1-return slab_alloc (s, flags,-1 ,__builtin_return_address (0 )); + ret =slab_alloc (s, flags,-1 ,__builtin_return_address (0 )); + +kmemtrace_mark_alloc (KMEMTRACE_TYPE_KMALLOC , _RET_IP_, ret, + size, s->size, flags); + +return ret; }EXPORT_SYMBOL (__kmalloc);
And again.
;
mm/slub.c void kfree(const void *x) · line 2827
Quoted 7 lines
#endif
mm/slub.c +2
-0@@ -2771,6 +2823,8 @@ void kfree(const void *x)return ; }slab_free (page->slab, page, object,__builtin_return_address (0 )); + +kmemtrace_mark_free (KMEMTRACE_TYPE_KMALLOC , _RET_IP_, x);
And another one.
--
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>
Re: [PATCH 4/5] kmemtrace: SLUB hooks.
Quoted 15 lines · Christoph Lameter
Quoted 11 lines · Eduard - Gabriel Munteanu
static
__always_inlinevoid *kmalloc_node(size_t size,gfp_tflags, int node) {include/linux/slub_def.h +2
-0+void *ret; +if (__builtin_constant_p (size) && size <=PAGE_SIZE && !(flags &SLUB_DMA )) {struct kmem_cache *s =kmalloc_slab (size);@@ -239,7 +280,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)if (!s)return ZERO_SIZE_PTR ;
Quoted 12 lines
include/linux/slub_def.h static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) · line 289
Quoted 8 lines
include/linux/slub_def.h +7
-1-return kmem_cache_alloc_node (s, flags, node); + ret =kmem_cache_alloc_node_notrace (s, flags, node); + +kmemtrace_mark_alloc_node (KMEMTRACE_TYPE_KMALLOC , + _THIS_IP_, ret, + size, s->size, flags, node); + +return ret;You could simplify the stuff in
slub.hif you would fall back to the uninlined functions in the case that kmemtrace is enabled. IMHO adding additional inline code here does grow these function to a size where inlining is not useful anymore.
So, if CONFIG_KMEMTRACE is enabled, make the inlined version go away completely? I'm okay with that though I wonder if that means we now take a performance hit when CONFIG_KMEMTRACE is enabled but tracing is disabled at run-time...
Quoted 14 lines
Quoted 14 lines
mm/slub.c +1
-0@@ -23,6 +23,7 @@#include <linux/kallsyms.h> #include <linux/memory.h> #include <linux/math64.h> +#include <linux/kmemtrace.h> /* * Lock order: @@ -1652,18 +1653,47 @@ static __always_inline void *slab_alloc(struct kmem_cache *s,
Quoted 14 lines
mm/slub.c static __always_inline void *slab_alloc(struct kmem_cache *s, · line 1662
Quoted 10 lines
mm/slub.c +6
-1void *kmem_cache_alloc (struct kmem_cache *s,gfp_t gfpflags) { -return slab_alloc (s, gfpflags,-1 ,__builtin_return_address (0 )); +void *ret =slab_alloc (s, gfpflags,-1 ,__builtin_return_address (0 )); + +kmemtrace_mark_alloc (KMEMTRACE_TYPE_CACHE , _RET_IP_, ret, + s->objsize, s->size, gfpflags); + +return ret; }
_RET_IP==__builtin_return_address(0)right? Put that into a local variable? At least we need consistent usage within one function. Maybe convert__builtin_return_address(0)to _RET_IP_ within slub?
I think we should just convert SLUB to use _RET_IP_ everywhere. Eduard, care to make a patch and send it and rebase this on top of that?
--
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>
Re: [PATCH 4/5] kmemtrace: SLUB hooks.
Quoted 28 lines · Pekka Enberg
Quoted 15 lines · Christoph Lameter
Quoted 11 lines · Eduard - Gabriel Munteanu
static
__always_inlinevoid *kmalloc_node(size_t size,gfp_tflags, int node) {include/linux/slub_def.h +2
-0+void *ret; +if (__builtin_constant_p (size) && size <=PAGE_SIZE && !(flags &SLUB_DMA )) {struct kmem_cache *s =kmalloc_slab (size);@@ -239,7 +280,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)if (!s)return ZERO_SIZE_PTR ;Quoted 11 lines
include/linux/slub_def.h static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) · line 289
Quoted 8 lines
include/linux/slub_def.h +7
-1-return kmem_cache_alloc_node (s, flags, node); + ret =kmem_cache_alloc_node_notrace (s, flags, node); + +kmemtrace_mark_alloc_node (KMEMTRACE_TYPE_KMALLOC , + _THIS_IP_, ret, + size, s->size, flags, node); + +return ret;You could simplify the stuff in
slub.hif you would fall back to the uninlined functions in the case that kmemtrace is enabled. IMHO adding additional inline code here does grow these function to a size where inlining is not useful anymore.
Quoted 4 lines
So, if
CONFIG_KMEMTRACEis enabled, make the inlined version go away completely? I'm okay with that though I wonder if that means we now take a performance hit whenCONFIG_KMEMTRACEis enabled but tracing is disabled at run-time...
We already take a performance hit because of the additional function calls.
With the above approach the kernel binary will grow significantly because you are now inserting an additional function call at all call sites.
--
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>
Re: [PATCH 4/5] kmemtrace: SLUB hooks.
Quoted 34 lines · Christoph Lameter
Quoted 28 lines · Pekka Enberg
Quoted 15 lines · Christoph Lameter
Quoted 11 lines · Eduard - Gabriel Munteanu
static
__always_inlinevoid *kmalloc_node(size_t size,gfp_tflags, int node) {include/linux/slub_def.h +2
-0+void *ret; +if (__builtin_constant_p (size) && size <=PAGE_SIZE && !(flags &SLUB_DMA )) {struct kmem_cache *s =kmalloc_slab (size);@@ -239,7 +280,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)if (!s)return ZERO_SIZE_PTR ;Quoted 11 lines
include/linux/slub_def.h static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) · line 289
Quoted 8 lines
include/linux/slub_def.h +7
-1-return kmem_cache_alloc_node (s, flags, node); + ret =kmem_cache_alloc_node_notrace (s, flags, node); + +kmemtrace_mark_alloc_node (KMEMTRACE_TYPE_KMALLOC , + _THIS_IP_, ret, + size, s->size, flags, node); + +return ret;You could simplify the stuff in
slub.hif you would fall back to the uninlined functions in the case that kmemtrace is enabled. IMHO adding additional inline code here does grow these function to a size where inlining is not useful anymore.Quoted 4 lines
So, if
CONFIG_KMEMTRACEis enabled, make the inlined version go away completely? I'm okay with that though I wonder if that means we now take a performance hit whenCONFIG_KMEMTRACEis enabled but tracing is disabled at run-time...
Quoted 4 lines
We already take a performance hit because of the additional function calls.
With the above approach the kernel binary will grow significantly because you are now inserting an additional function call at all call sites.
The function call is supposed to go away when we convert kmemtrace to use Mathieu's markers but I suppose even then we have a problem with inlining?
--
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>
Re: [PATCH 4/5] kmemtrace: SLUB hooks.
Quoted 3 lines · Pekka Enberg
The function call is supposed to go away when we convert kmemtrace to use Mathieu's markers but I suppose even then we have a problem with inlining?
The function calls are overwritten with NOPs? Or how does that work?
--
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>
Re: [PATCH 4/5] kmemtrace: SLUB hooks.
Quoted 7 lines · Christoph Lameter
Quoted 3 lines · Pekka Enberg
The function call is supposed to go away when we convert kmemtrace to use Mathieu's markers but I suppose even then we have a problem with inlining?
The function calls are overwritten with NOPs? Or how does that work?
I have no idea. Mathieu, Eduard?
--
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>
Re: [PATCH 4/5] kmemtrace: SLUB hooks.
Quoted 10 lines · Pekka Enberg
Quoted 7 lines · Christoph Lameter
Quoted 3 lines · Pekka Enberg
The function call is supposed to go away when we convert kmemtrace to use Mathieu's markers but I suppose even then we have a problem with inlining?
The function calls are overwritten with NOPs? Or how does that work?
I have no idea. Mathieu, Eduard?
Yes, the code is patched at runtime. But AFAIK markers already provide this stuff (called "immediate values"). Mathieu's tracepoints also do it. But it's not available on all arches. x86 and x86-64 work as far as I remember.
--
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>
Re: [PATCH 4/5] kmemtrace: SLUB hooks.
Quoted 8 lines · * Eduard - Gabriel Munteanu ([email protected]) wrote:
Quoted 7 lines · Pekka Enberg
Quoted 6 lines · Christoph Lameter
Quoted 3 lines · Pekka Enberg
The function call is supposed to go away when we convert kmemtrace to use Mathieu's markers but I suppose even then we have a problem with inlining?
Quoted 9 lines
Quoted 3 lines
Quoted 1 line
The function calls are overwritten with NOPs? Or how does that work?
I have no idea. Mathieu, Eduard?
Yes, the code is patched at runtime. But AFAIK markers already provide this stuff (called "immediate values"). Mathieu's tracepoints also do it. But it's not available on all arches. x86 and x86-64 work as far as I remember.
The markers present in mainline kernel does not use immediate values. However, immediate values in tip does implement a load immediate/test/branch for x86, x86_64 and powerpc. I also have support for sparc64 in my lttng tree.
Mathieu
Signature · 8 lines
Mathieu Desnoyers OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68 -- 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>
Re: [PATCH 4/5] kmemtrace: SLUB hooks.
In reply to Eduard - Gabriel MunteanuQuoted 8 lines · Eduard - Gabriel Munteanu
Quoted 7 lines · Pekka Enberg
Quoted 6 lines · Christoph Lameter
Quoted 3 lines · Pekka Enberg
The function call is supposed to go away when we convert kmemtrace to use Mathieu's markers but I suppose even then we have a problem with inlining?
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
The function calls are overwritten with NOPs? Or how does that work?
I have no idea. Mathieu, Eduard?
Yes, the code is patched at runtime. But AFAIK markers already provide this stuff (called "immediate values"). Mathieu's tracepoints also do it. But it's not available on all arches. x86 and x86-64 work as far as I remember.
Did we ever see size(1) numbers for kernels with and without this support? I'm still a bit worried about adding branches to such a popular inline. Simply multiplying the branch test by the number of locations is pretty substantial, never mind the unlikely part of the branch.
Signature · 7 lines
Mathematics is the supreme nostalgia of our time. -- 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>
Re: [PATCH 4/5] kmemtrace: SLUB hooks.
In reply to Christoph LameterQuoted 7 lines · Christoph Lameter
Quoted 3 lines · Pekka Enberg
The function call is supposed to go away when we convert kmemtrace to use Mathieu's markers but I suppose even then we have a problem with inlining?
The function calls are overwritten with NOPs? Or how does that work?
I believe in the latest version they are just a variable test. But when Mathieu's immediate code makes it in (which it is in linux-tip), we will be overwriting the conditionals with nops (Mathieu, correct me if I'm wrong here).
But the calls themselves are done in the unlikely branch. This is important, as Mathieu stated in previous thread. The reason is that all the stack setup for the function call is also in the unlikely branch, and the normal fast path does not take a hit for the function call setup.
-- Steve
--
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>
Re: [PATCH 4/5] kmemtrace: SLUB hooks.
Quoted 9 lines · * Steven Rostedt ([email protected]) wrote:
Quoted 6 lines · Christoph Lameter
Quoted 3 lines · Pekka Enberg
The function call is supposed to go away when we convert kmemtrace to use Mathieu's markers but I suppose even then we have a problem with inlining?
Quoted 7 lines
Quoted 1 line
The function calls are overwritten with NOPs? Or how does that work?
I believe in the latest version they are just a variable test. But when Mathieu's immediate code makes it in (which it is in linux-tip), we will be overwriting the conditionals with nops (Mathieu, correct me if I'm wrong here).
The current immediate values in tip does a load immediate, test, branch, which removes the cost of the memory load. We will try to get gcc support to be able to declare patchable static jump sites, which could be patched with NOPs when disabled. But that will probably not happen "now".
Mathieu
Quoted 7 lines
But the calls themselves are done in the unlikely branch. This is important, as Mathieu stated in previous thread. The reason is that all the stack setup for the function call is also in the unlikely branch, and the normal fast path does not take a hit for the function call setup.
-- Steve
Signature · 2 lines
Mathieu Desnoyers OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68
Re: [PATCH 4/5] kmemtrace: SLUB hooks.
In reply to Christoph LameterQuoted 34 lines · Christoph Lameter
Quoted 28 lines · Pekka Enberg
Quoted 15 lines · Christoph Lameter
Quoted 11 lines · Eduard - Gabriel Munteanu
static
__always_inlinevoid *kmalloc_node(size_t size,gfp_tflags, int node) {include/linux/slub_def.h +2
-0+void *ret; +if (__builtin_constant_p (size) && size <=PAGE_SIZE && !(flags &SLUB_DMA )) {struct kmem_cache *s =kmalloc_slab (size);@@ -239,7 +280,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)if (!s)return ZERO_SIZE_PTR ;Quoted 11 lines
include/linux/slub_def.h static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) · line 289
Quoted 8 lines
include/linux/slub_def.h +7
-1-return kmem_cache_alloc_node (s, flags, node); + ret =kmem_cache_alloc_node_notrace (s, flags, node); + +kmemtrace_mark_alloc_node (KMEMTRACE_TYPE_KMALLOC , + _THIS_IP_, ret, + size, s->size, flags, node); + +return ret;You could simplify the stuff in
slub.hif you would fall back to the uninlined functions in the case that kmemtrace is enabled. IMHO adding additional inline code here does grow these function to a size where inlining is not useful anymore.Quoted 4 lines
So, if
CONFIG_KMEMTRACEis enabled, make the inlined version go away completely? I'm okay with that though I wonder if that means we now take a performance hit whenCONFIG_KMEMTRACEis enabled but tracing is disabled at run-time...
Quoted 5 lines
We already take a performance hit because of the additional function calls.
With the above approach the kernel binary will grow significantly because you are now inserting an additional function call at all call sites.
The kmemtrace_mark_alloc_node itself is an inline function, which calls another inline function "trace_mark" which is designed to test a read_mostly variable, and will do an "unlikely" jmp if the variable is set (which it is when tracing is enabled), to the actual function call.
There should be no extra function calls when this is configured on but tracing disabled. We try very hard to keep the speed of the tracer as close to a non tracing kernel as possible when tracing is disabled.
-- Steve
--
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>
Re: [PATCH 4/5] kmemtrace: SLUB hooks.
Quoted 8 lines · Steven Rostedt
The
kmemtrace_mark_alloc_nodeitself is an inline function, which calls another inline function "trace_mark" which is designed to test aread_mostlyvariable, and will do an "unlikely" jmp if the variable is set (which it is when tracing is enabled), to the actual function call.There should be no extra function calls when this is configured on but tracing disabled. We try very hard to keep the speed of the tracer as close to a non tracing kernel as possible when tracing is disabled.
Makes sense. But then we have even more code bloat because of the tests that are inserted in all call sites of kmalloc.
--
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>
Re: [PATCH 4/5] kmemtrace: SLUB hooks.
Quoted 7 lines · Christoph Lameter
[...]
Quoted 3 lines
There should be no extra function calls when this is configured on but tracing disabled. We try very hard to keep the speed of the tracer as close to a non tracing kernel as possible when tracing is disabled.
Makes sense. But then we have even more code bloat because of the tests that are inserted in all call sites of kmalloc.
Are you talking about the tests that implement checking whether a marker is active or not? Those checks are already efficient, and will get more so with the "immediate values" optimization in or near the tree.
- FChE
--
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>
Re: [PATCH 4/5] kmemtrace: SLUB hooks.
Quoted 6 lines · Frank Ch. Eigler
Quoted 4 lines · Christoph Lameter
[...]
Quoted 3 lines
There should be no extra function calls when this is configured on but tracing disabled. We try very hard to keep the speed of the tracer as close to a non tracing kernel as possible when tracing is disabled.
Quoted 7 lines
Quoted 2 lines
Makes sense. But then we have even more code bloat because of the tests that are inserted in all call sites of kmalloc.
Are you talking about the tests that implement checking whether a marker is active or not? Those checks are already efficient, and will get more so with the "immediate values" optimization in or near the tree.
AFAICT: Each test also adds an out of line call to the tracing facility.
--
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>
Re: [PATCH 4/5] kmemtrace: SLUB hooks.
Quoted 10 lines · Christoph Lameter
Quoted 9 lines · Frank Ch. Eigler
Quoted 6 lines · Christoph Lameter
[...]
Quoted 3 lines
There should be no extra function calls when this is configured on but tracing disabled. We try very hard to keep the speed of the tracer as close to a non tracing kernel as possible when tracing is disabled.
Makes sense. But then we have even more code bloat because of the tests that are inserted in all call sites of kmalloc.
Quoted 7 lines
Quoted 4 lines
Are you talking about the tests that implement checking whether a marker is active or not? Those checks are already efficient, and will get more so with the "immediate values" optimization in or near the tree.
AFAICT: Each test also adds an out of line call to the tracing facility.
Frank,
Christoph is correct. He's not bringing up the issue of efficiency, but the issue of bloat.
The marker code will be added to everyplace that calls kmalloc. Which can be quite a lot. I'd be interested in seeing the size of the .text section with and without this patch added and makers configure in.
-- Steve
--
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>
Re: [PATCH 4/5] kmemtrace: SLUB hooks.
In reply to Christoph LameterHi -
Quoted 2 lines · Christoph Lameter
[...]
AFAICT: Each test also adds an out of line call to the tracing facility.
Yes, but that call is normally placed out of the cache-hot path with unlikely().
- FChE
--
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>
Re: [PATCH 4/5] kmemtrace: SLUB hooks.
In reply to Christoph LameterQuoted 7 lines · * Christoph Lameter ([email protected]) wrote:
Quoted 5 lines · Steven Rostedt
The
kmemtrace_mark_alloc_nodeitself is an inline function, which calls another inline function "trace_mark" which is designed to test aread_mostlyvariable, and will do an "unlikely" jmp if the variable is set (which it is when tracing is enabled), to the actual function call.
Quoted 7 lines
Quoted 3 lines
There should be no extra function calls when this is configured on but tracing disabled. We try very hard to keep the speed of the tracer as close to a non tracing kernel as possible when tracing is disabled.
Makes sense. But then we have even more code bloat because of the tests that are inserted in all call sites of kmalloc.
The long-term goal is to turn the tests into NOPs, but only once we get gcc support.
Mathieu
Signature · 8 lines
Mathieu Desnoyers OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68 -- 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>
Re: [PATCH 4/5] kmemtrace: SLUB hooks.
In reply to Pekka EnbergQuoted 29 lines · Pekka Enberg
Quoted 15 lines · Christoph Lameter
Quoted 11 lines · Eduard - Gabriel Munteanu
static
__always_inlinevoid *kmalloc_node(size_t size,gfp_tflags, int node) {include/linux/slub_def.h +2
-0+void *ret; +if (__builtin_constant_p (size) && size <=PAGE_SIZE && !(flags &SLUB_DMA )) {struct kmem_cache *s =kmalloc_slab (size);@@ -239,7 +280,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)if (!s)return ZERO_SIZE_PTR ;Quoted 12 lines
include/linux/slub_def.h static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) · line 289
Quoted 8 lines
include/linux/slub_def.h +7
-1-return kmem_cache_alloc_node (s, flags, node); + ret =kmem_cache_alloc_node_notrace (s, flags, node); + +kmemtrace_mark_alloc_node (KMEMTRACE_TYPE_KMALLOC , + _THIS_IP_, ret, + size, s->size, flags, node); + +return ret;You could simplify the stuff in
slub.hif you would fall back to the uninlined functions in the case that kmemtrace is enabled. IMHO adding additional inline code here does grow these function to a size where inlining is not useful anymore.
Quoted 4 lines
So, if
CONFIG_KMEMTRACEis enabled, make the inlined version go away completely? I'm okay with that though I wonder if that means we now take a performance hit whenCONFIG_KMEMTRACEis enabled but tracing is disabled at run-time...
Oh, good. I'm also thinking to add a macro that expands to simple inline when CONFIG_KMEMTRACE is disabled and to __always_inline otherwise.
Quoted 10 lines
Quoted 9 lines
mm/slub.c static __always_inline void *slab_alloc(struct kmem_cache *s, · line 1662
Quoted 5 lines
mm/slub.c +4
-0+kmemtrace_mark_alloc (KMEMTRACE_TYPE_CACHE , _RET_IP_, ret, + s->objsize, s->size, gfpflags); + +return ret; }
_RET_IP==__builtin_return_address(0)right? Put that into a local variable? At least we need consistent usage within one function. Maybe convert__builtin_return_address(0)to _RET_IP_ within slub?
Quoted 2 lines
I think we should just convert SLUB to use _RET_IP_ everywhere. Eduard, care to make a patch and send it and rebase this on top of that?
Sure. Will get back soon.
--
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>
Pekka Enberg
AppliedRe: [PATCH 3/5] kmemtrace: SLAB hooks.
In reply to Eduard - Gabriel MunteanuQuoted 7 lines · Eduard - Gabriel Munteanu
This adds hooks for the SLAB allocator, to allow tracing with kmemtrace.
We also convert some inline functions to
__always_inlineto make sure _RET_IP_, which expands to__builtin_return_address(0), always works as expected.Signed-off-by Eduard - Gabriel Munteanu <[email protected]>
Applied, thanks!
--
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>
Pekka Enberg
AppliedRe: [PATCH 2/5] kmemtrace: Additional documentation.
In reply to Eduard - Gabriel MunteanuQuoted 5 lines · Eduard - Gabriel Munteanu
Documented kmemtrace's ABI, purpose and design. Also includes a short usage guide, FAQ, as well as a link to the userspace application's Git repository, which is currently hosted at repo.or.cz.
Signed-off-by Eduard - Gabriel Munteanu <[email protected]>
Applied, thanks!
--
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>
Re: [PATCH 2/5] kmemtrace: Additional documentation.
In reply to Eduard - Gabriel MunteanuQuoted 74 lines · On Sun, 10 Aug 2008 20:14:04 +0300 Eduard - Gabriel Munteanu wrote:
Documented kmemtrace's ABI, purpose and design. Also includes a short usage guide, FAQ, as well as a link to the userspace application's Git repository, which is currently hosted at repo.or.cz.
Signed-off-by Eduard - Gabriel Munteanu <[email protected]>--- Documentation/ABI/testing/debugfs-kmemtrace | 71 +++++++++++++++ Documentation/vm/kmemtrace.txt | 126 +++++++++++++++++++++++++++ 2 files changed, 197 insertions(+), 0 deletions(-) create mode 100644 Documentation/ABI/testing/debugfs-kmemtrace create mode 100644 Documentation/vm/kmemtrace.txtDocumentation/ABI/testing/debugfs-kmemtrace new file +56
-0@@ -0,0 +1,71 @@ +What: /sys/kernel/debug/kmemtrace/ +Date: July 2008 +Contact: Eduard - Gabriel Munteanu <[email protected]> +Description: + +In kmemtrace-enabled kernels, the following files are created: + +/sys/kernel/debug/kmemtrace/ + cpu<n> (0400) Per-CPU tracing data, see below. (binary) + total_overruns (0400) Total number of bytes which were dropped from + cpu<n> files because of full buffer condition, + non-binary. (text) + abi_version (0400) Kernel's kmemtrace ABI version. (text) + +Each per-CPU file should be read according to the relay interface. That is, +the reader should set affinity to that specific CPU and, as currently done by +the userspace application (though there are other methods), use poll() with +an infinite timeout before every read(). Otherwise, erroneous data may be +read. The binary data has the following _core_ format: + + Event ID (1 byte) Unsigned integer, one of: + 0 - represents an allocation (KMEMTRACE_EVENT_ALLOC) + 1 - represents a freeing of previously allocated memory + (KMEMTRACE_EVENT_FREE) + Type ID (1 byte) Unsigned integer, one of: + 0 - this is a kmalloc() / kfree() + 1 - this is a kmem_cache_alloc() / kmem_cache_free() + 2 - this is a __get_free_pages() et al. + Event size (2 bytes) Unsigned integer representing the + size of this event. Used to extend + kmemtrace. Discard the bytes you + don't know about. + Sequence number (4 bytes) Signed integer used to reorder data + logged on SMP machines. Wraparound + must be taken into account, although + it is unlikely. + Caller address (8 bytes) Return address to the caller. + Pointer to mem (8 bytes) Pointer to target memory area. Can be + NULL, but not all such calls might be + recorded. + +In case of KMEMTRACE_EVENT_ALLOC events, the next fields follow: + + Requested bytes (8 bytes) Total number of requested bytes, + unsigned, must not be zero. + Allocated bytes (8 bytes) Total number of actually allocated + bytes, unsigned, must not be lower + than requested bytes. + Requested flags (4 bytes) GFP flags supplied by the caller. + Target CPU (4 bytes) Signed integer, valid for event id 1. + If equal to -1, target CPU is the same + as origin CPU, but the reverse might + not be true. + +The data is made available in the same endianness the machine has. +
Documentation/ABI/testing/debugfs-kmemtrace line 66
Quoted 10 lines
Documentation/ABI/testing/debugfs-kmemtrace new file +10
-0+Other event ids and type ids may be defined and added. Other fields may be +added by increasing event size, but see below for details. +Every modification to the ABI, including new id definitions, are followed +by bumping the ABI version by one. + +Adding new data to the packet (features) is done at the end of the mandatory +data: + Feature size (2 byte) + Feature ID (1 byte) + Feature data (Feature size - 4 bytes)
Why is this "- 4 bytes"? Is there an implied alignment byte somewhere in the features "struct"? How about making it explicit?
Quoted 65 lines
Documentation/ABI/testing/debugfs-kmemtrace new file +5
-0+ + +Users: + kmemtrace-user - git://repo.or.cz/kmemtrace-user.git +Documentation/vm/kmemtrace.txt new file +54
-0@@ -0,0 +1,126 @@ + kmemtrace - Kernel Memory Tracer + + by Eduard - Gabriel Munteanu + <[email protected]> + +I. Introduction +=============== + +kmemtrace helps kernel developers figure out two things: +1) how different allocators (SLAB, SLUB etc.) perform +2) how kernel code allocates memory and how much + +To do this, we trace every allocation and export information to the userspace +through the relay interface. We export things such as the number of requested +bytes, the number of bytes actually allocated (i.e. including internal +fragmentation), whether this is a slab allocation or a plain kmalloc() and so +on. + +The actual analysis is performed by a userspace tool (see section III for +details on where to get it from). It logs the data exported by the kernel, +processes it and (as of writing this) can provide the following information: +- the total amount of memory allocated and fragmentation per call-site +- the amount of memory allocated and fragmentation per allocation +- total memory allocated and fragmentation in the collected dataset +- number of cross-CPU allocation and frees (makes sense in NUMA environments) + +Moreover, it can potentially find inconsistent and erroneous behavior in +kernel code, such as using slab free functions on kmalloc'ed memory or +allocating less memory than requested (but not truly failed allocations). + +kmemtrace also makes provisions for tracing on some arch and analysing the +data on another. + +II. Design and goals +==================== + +kmemtrace was designed to handle rather large amounts of data. Thus, it uses +the relay interface to export whatever is logged to userspace, which then +stores it. Analysis and reporting is done asynchronously, that is, after the +data is collected and stored. By design, it allows one to log and analyse +on different machines and different arches. + +As of writing this, the ABI is not considered stable, though it might not +change much. However, no guarantees are made about compatibility yet. When +deemed stable, the ABI should still allow easy extension while maintaining +backward compatibility. This is described further in Documentation/ABI. + +Summary of design goals: + - allow logging and analysis to be done across different machines + - be fast and anticipate usage in high-load environments (*) + - be reasonably extensible + - make it possible for GNU/Linux distributions to have kmemtrace + included in their repositories +
Documentation/vm/kmemtrace.txt line 64
Quoted 10 lines
Documentation/vm/kmemtrace.txt new file +10
-0+(*) - one of the reasons Pekka Enberg's original userspace data analysis + tool's code was rewritten from Perl to C (although this is more than a + simple conversion) + + +III. Quick usage guide +====================== + +1) Get a kernel that supports kmemtrace and build it accordingly (i.e. enable +CONFIG_KMEMTRACE and CONFIG_DEFAULT_ENABLED).
CONFIG_KMEMTRACE_DEFAULT_ENABLED
Documentation/vm/kmemtrace.txt line 66
Quoted 2 lines
Documentation/vm/kmemtrace.txt new file +2
-0+ +2) Get the userspace tool and build it:
...
---
~Randy
Linux Plumbers Conference, 17-19 September 2008, Portland, Oregon USA
http://linuxplumbersconf.org/
--
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>
Pekka Enberg
AppliedRe: [PATCH 1/5] kmemtrace: Core implementation.
In reply to Eduard - Gabriel MunteanuQuoted 7 lines · Eduard - Gabriel Munteanu
kmemtrace provides tracing for slab allocator functions, such as kmalloc, kfree,
kmem_cache_alloc,kmem_cache_freeetc.. Collected data is then fed to the userspace application in order to analyse allocation hotspots, internal fragmentation and so on, making it possible to see how well an allocator performs, as well as debug and profile kernel code.Signed-off-by Eduard - Gabriel Munteanu <[email protected]>
Applied, thanks!
--
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>