* [RFC PATCH 1/5] kmemtrace: Core implementation. [not found] <1215712946-23572-1-git-send-email-eduard.munteanu@linux360.ro> @ 2008-07-10 18:05 ` Eduard - Gabriel Munteanu 2008-07-11 8:41 ` Pekka Enberg [not found] ` <1215712946-23572-2-git-send-email-eduard.munteanu@linux360.ro> 1 sibling, 1 reply; 30+ messages in thread From: Eduard - Gabriel Munteanu @ 2008-07-10 18:05 UTC (permalink / raw) To: penberg; +Cc: linux-kernel, linux-mm 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. Signed-off-by: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> --- MAINTAINERS | 6 ++ include/linux/kmemtrace.h | 110 +++++++++++++++++++++++ init/main.c | 2 + lib/Kconfig.debug | 4 + mm/Makefile | 2 +- mm/kmemtrace.c | 213 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 336 insertions(+), 1 deletions(-) create mode 100644 include/linux/kmemtrace.h create mode 100644 mm/kmemtrace.c diff --git a/MAINTAINERS b/MAINTAINERS index 6476125..87a743a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2425,6 +2425,12 @@ M: jason.wessel@windriver.com L: kgdb-bugreport@lists.sourceforge.net S: Maintained +KMEMTRACE +P: Eduard - Gabriel Munteanu +M: eduard.munteanu@linux360.ro +L: linux-kernel@vger.kernel.org +S: Maintained + KPROBES P: Ananth N Mavinakayanahalli M: ananth@in.ibm.com diff --git a/include/linux/kmemtrace.h b/include/linux/kmemtrace.h new file mode 100644 index 0000000..11cd8e2 --- /dev/null +++ b/include/linux/kmemtrace.h @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2008 Eduard - Gabriel Munteanu + * + * This file is released under GPL version 2. + */ + +#ifndef _LINUX_KMEMTRACE_H +#define _LINUX_KMEMTRACE_H + +#include <linux/types.h> + +/* ABI definition starts here. */ + +#define KMEMTRACE_ABI_VERSION 1 + +enum kmemtrace_event_id { + KMEMTRACE_EVENT_NULL = 0, /* Erroneous event. */ + KMEMTRACE_EVENT_ALLOC, + KMEMTRACE_EVENT_FREE, +}; + +enum kmemtrace_kind_id { + KMEMTRACE_KIND_KERNEL = 0, /* kmalloc() / kfree(). */ + KMEMTRACE_KIND_CACHE, /* kmem_cache_*(). */ + KMEMTRACE_KIND_PAGES, /* __get_free_pages() and friends. */ +}; + +struct kmemtrace_event { + __u16 event_id; /* Allocate or free? */ + __u16 kind_id; /* Kind of allocation/free. */ + __s32 node; /* Target CPU. */ + __u64 call_site; /* Caller address. */ + __u64 ptr; /* Pointer to allocation. */ + __u64 bytes_req; /* Number of bytes requested. */ + __u64 bytes_alloc; /* Number of bytes allocated. */ + __u64 gfp_flags; /* Requested flags. */ + __s64 timestamp; /* When the operation occured in ns. */ +} __attribute__ ((__packed__)); + +/* End of ABI definition. */ + +#ifdef __KERNEL__ + +#include <linux/marker.h> + +#ifdef CONFIG_KMEMTRACE + +extern void kmemtrace_init(void); + +static inline void kmemtrace_mark_alloc_node(enum kmemtrace_kind_id kind_id, + unsigned long call_site, + const void *ptr, + size_t bytes_req, + size_t bytes_alloc, + unsigned long gfp_flags, + int node) +{ + trace_mark(kmemtrace_alloc, "kind_id %d call_site %lu ptr %lu " + "bytes_req %lu bytes_alloc %lu gfp_flags %lu node %d", + kind_id, call_site, (unsigned long) ptr, + bytes_req, bytes_alloc, gfp_flags, node); +} + +static inline void kmemtrace_mark_free(enum kmemtrace_kind_id kind_id, + unsigned long call_site, + const void *ptr) +{ + trace_mark(kmemtrace_free, "kind_id %d call_site %lu ptr %lu", + kind_id, call_site, (unsigned long) ptr); +} + +#else /* CONFIG_KMEMTRACE */ + +static inline void kmemtrace_init(void) +{ +} + +static inline void kmemtrace_mark_alloc_node(enum kmemtrace_kind_id kind_id, + unsigned long call_site, + const void *ptr, + size_t bytes_req, + size_t bytes_alloc, + unsigned long gfp_flags, + int node) +{ +} + +static inline void kmemtrace_mark_free(enum kmemtrace_kind_id kind_id, + unsigned long call_site, + const void *ptr) +{ +} + +#endif /* CONFIG_KMEMTRACE */ + +static inline void kmemtrace_mark_alloc(enum kmemtrace_kind_id kind_id, + unsigned long call_site, + const void *ptr, + size_t bytes_req, + size_t bytes_alloc, + unsigned long gfp_flags) +{ + kmemtrace_mark_alloc_node(kind_id, call_site, ptr, + bytes_req, bytes_alloc, gfp_flags, -1); +} + +#endif /* __KERNEL__ */ + +#endif /* _LINUX_KMEMTRACE_H */ + diff --git a/init/main.c b/init/main.c index 057f364..c00659c 100644 --- a/init/main.c +++ b/init/main.c @@ -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(); diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index d2099f4..6bacab5 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -674,6 +674,10 @@ config FIREWIRE_OHCI_REMOTE_DMA If unsure, say N. +config KMEMTRACE + bool "Kernel memory tracer" + depends on RELAY && DEBUG_FS && MARKERS + source "samples/Kconfig" source "lib/Kconfig.kgdb" diff --git a/mm/Makefile b/mm/Makefile index 18c143b..d88a3bc 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -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 diff --git a/mm/kmemtrace.c b/mm/kmemtrace.c new file mode 100644 index 0000000..13d37b3 --- /dev/null +++ b/mm/kmemtrace.c @@ -0,0 +1,213 @@ +/* + * Copyright (C) 2008 Pekka Enberg, Eduard - Gabriel Munteanu + * + * This file is released under GPL version 2. + */ + +#include <linux/string.h> +#include <linux/debugfs.h> +#include <linux/relay.h> +#include <linux/module.h> +#include <linux/marker.h> +#include <linux/gfp.h> +#include <linux/kmemtrace.h> + +#define KMEMTRACE_SUBBUF_SIZE 8192 * sizeof(struct kmemtrace_event) +#define KMEMTRACE_N_SUBBUFS 20 + +static struct rchan *kmemtrace_chan; +static u32 kmemtrace_buf_overruns; +static unsigned int kmemtrace_n_subbufs; + +static inline void kmemtrace_log_event(struct kmemtrace_event *event) +{ + relay_write(kmemtrace_chan, event, sizeof(struct kmemtrace_event)); +} + +static void kmemtrace_probe_alloc(void *probe_data, void *call_data, + const char *format, va_list *args) +{ + unsigned long flags; + struct kmemtrace_event ev; + + /* + * Don't convert this to use structure initializers, + * C99 does not guarantee the rvalues evaluation order. + */ + ev.event_id = KMEMTRACE_EVENT_ALLOC; + ev.kind_id = va_arg(*args, int); + ev.call_site = va_arg(*args, unsigned long); + ev.ptr = va_arg(*args, unsigned long); + /* Don't trace ignored allocations. */ + if (!ev.ptr) + return; + ev.bytes_req = va_arg(*args, unsigned long); + ev.bytes_alloc = va_arg(*args, unsigned long); + /* ev.timestamp set below, to preserve event ordering. */ + ev.gfp_flags = va_arg(*args, unsigned long); + /* Don't trace ignored allocations. */ + if (ev.gfp_flags & __GFP_NOTRACE) + return; + ev.node = va_arg(*args, int); + + local_irq_save(flags); + ev.timestamp = ktime_to_ns(ktime_get()); + kmemtrace_log_event(&ev); + local_irq_restore(flags); +} + +static void kmemtrace_probe_free(void *probe_data, void *call_data, + const char *format, va_list *args) +{ + unsigned long flags; + struct kmemtrace_event ev; + + /* + * Don't convert this to use structure initializers, + * C99 does not guarantee the rvalues evaluation order. + */ + ev.event_id = KMEMTRACE_EVENT_FREE; + ev.kind_id = va_arg(*args, int); + ev.call_site = va_arg(*args, unsigned long); + ev.ptr = va_arg(*args, unsigned long); + /* Don't trace ignored allocations. */ + if (!ev.ptr) + return; + /* ev.timestamp set below, to preserve event ordering. */ + + local_irq_save(flags); + ev.timestamp = ktime_to_ns(ktime_get()); + kmemtrace_log_event(&ev); + local_irq_restore(flags); +} + +static struct dentry * +kmemtrace_create_buf_file(const char *filename, struct dentry *parent, + int mode, struct rchan_buf *buf, int *is_global) +{ + return debugfs_create_file(filename, mode, parent, buf, + &relay_file_operations); +} + +static int kmemtrace_remove_buf_file(struct dentry *dentry) +{ + debugfs_remove(dentry); + + return 0; +} + +static int kmemtrace_count_overruns(struct rchan_buf *buf, + void *subbuf, void *prev_subbuf, + size_t prev_padding) +{ + if (relay_buf_full(buf)) { + kmemtrace_buf_overruns++; + return 0; + } + + return 1; +} + +static struct rchan_callbacks relay_callbacks = { + .create_buf_file = kmemtrace_create_buf_file, + .remove_buf_file = kmemtrace_remove_buf_file, + .subbuf_start = kmemtrace_count_overruns, +}; + +static struct dentry *kmemtrace_dir; +static struct dentry *kmemtrace_overruns_dentry; + +static void kmemtrace_cleanup(void) +{ + relay_close(kmemtrace_chan); + marker_probe_unregister("kmemtrace_alloc", + kmemtrace_probe_alloc, NULL); + marker_probe_unregister("kmemtrace_free", + kmemtrace_probe_free, NULL); + if (kmemtrace_overruns_dentry) + debugfs_remove(kmemtrace_overruns_dentry); +} + +static int __init kmemtrace_setup_late(void) +{ + if (!kmemtrace_chan) + goto failed; + + kmemtrace_dir = debugfs_create_dir("kmemtrace", NULL); + if (!kmemtrace_dir) + goto cleanup; + + kmemtrace_overruns_dentry = + debugfs_create_u32("total_overruns", S_IRUSR, + kmemtrace_dir, &kmemtrace_buf_overruns); + if (!kmemtrace_overruns_dentry) + goto dir_cleanup; + + if (relay_late_setup_files(kmemtrace_chan, "cpu", kmemtrace_dir)) + goto overrun_cleanup; + + printk(KERN_INFO "kmemtrace: fully up.\n"); + + return 0; + +overrun_cleanup: + debugfs_remove(kmemtrace_overruns_dentry); + kmemtrace_overruns_dentry = NULL; +dir_cleanup: + debugfs_remove(kmemtrace_dir); +cleanup: + kmemtrace_cleanup(); +failed: + return 1; +} + +late_initcall(kmemtrace_setup_late); + +static int __init kmemtrace_set_subbuf_size(char *str) +{ + get_option(&str, &kmemtrace_n_subbufs); + return 0; +} + +early_param("kmemtrace.subbufs", kmemtrace_set_subbuf_size); + +void kmemtrace_init(void) +{ + int err; + + if (!kmemtrace_n_subbufs) + kmemtrace_n_subbufs = KMEMTRACE_N_SUBBUFS; + + kmemtrace_chan = relay_open(NULL, NULL, KMEMTRACE_SUBBUF_SIZE, + kmemtrace_n_subbufs, &relay_callbacks, + NULL); + if (!kmemtrace_chan) { + printk(KERN_INFO "kmemtrace: could not open relay channel\n"); + return; + } + + err = marker_probe_register("kmemtrace_alloc", "kind_id %d " + "call_site %lu ptr %lu " + "bytes_req %lu bytes_alloc %lu " + "gfp_flags %lu node %d", + kmemtrace_probe_alloc, NULL); + if (err) + goto probe_alloc_fail; + err = marker_probe_register("kmemtrace_free", "kind_id %d " + "call_site %lu ptr %lu", + kmemtrace_probe_free, NULL); + if (err) + goto probe_free_fail; + + printk(KERN_INFO "kmemtrace: early init successful.\n"); + return; + +probe_free_fail: + err = marker_probe_unregister("kmemtrace_alloc", + kmemtrace_probe_alloc, NULL); + printk(KERN_INFO "kmemtrace: could not register marker probes!\n"); +probe_alloc_fail: + relay_close(kmemtrace_chan); + kmemtrace_chan = NULL; +} + -- 1.5.6.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [RFC PATCH 1/5] kmemtrace: Core implementation. 2008-07-10 18:05 ` [RFC PATCH 1/5] kmemtrace: Core implementation Eduard - Gabriel Munteanu @ 2008-07-11 8:41 ` Pekka Enberg 2008-07-11 20:02 ` Eduard - Gabriel Munteanu 0 siblings, 1 reply; 30+ messages in thread From: Pekka Enberg @ 2008-07-11 8:41 UTC (permalink / raw) To: Eduard - Gabriel Munteanu; +Cc: linux-kernel, linux-mm, Christoph Lameter Hi Eduard-Gabriel, On Thu, Jul 10, 2008 at 9:05 PM, Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> wrote: > 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. > > Signed-off-by: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> > new file mode 100644 > index 0000000..11cd8e2 > --- /dev/null > +++ b/include/linux/kmemtrace.h > @@ -0,0 +1,110 @@ > +/* > + * Copyright (C) 2008 Eduard - Gabriel Munteanu > + * > + * This file is released under GPL version 2. > + */ > + > +#ifndef _LINUX_KMEMTRACE_H > +#define _LINUX_KMEMTRACE_H > + > +#include <linux/types.h> > + > +/* ABI definition starts here. */ > + > +#define KMEMTRACE_ABI_VERSION 1 > + > +enum kmemtrace_event_id { > + KMEMTRACE_EVENT_NULL = 0, /* Erroneous event. */ > + KMEMTRACE_EVENT_ALLOC, > + KMEMTRACE_EVENT_FREE, > +}; > + > +enum kmemtrace_kind_id { > + KMEMTRACE_KIND_KERNEL = 0, /* kmalloc() / kfree(). */ > + KMEMTRACE_KIND_CACHE, /* kmem_cache_*(). */ > + KMEMTRACE_KIND_PAGES, /* __get_free_pages() and friends. */ > +}; Can we do s/kind/type/, please? Also, the names "kernel" and "cache" are confusing. Can we just call them "kmalloc" and "kmem_cache" instead? > + > +struct kmemtrace_event { > + __u16 event_id; /* Allocate or free? */ > + __u16 kind_id; /* Kind of allocation/free. */ > + __s32 node; /* Target CPU. */ > + __u64 call_site; /* Caller address. */ > + __u64 ptr; /* Pointer to allocation. */ > + __u64 bytes_req; /* Number of bytes requested. */ > + __u64 bytes_alloc; /* Number of bytes allocated. */ > + __u64 gfp_flags; /* Requested flags. */ > + __s64 timestamp; /* When the operation occured in ns. */ > +} __attribute__ ((__packed__)); Why do you need to use the __packed__ attribute here? Looks like the struct is already laid out properly. > + > +/* End of ABI definition. */ -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [RFC PATCH 1/5] kmemtrace: Core implementation. 2008-07-11 8:41 ` Pekka Enberg @ 2008-07-11 20:02 ` Eduard - Gabriel Munteanu 0 siblings, 0 replies; 30+ messages in thread From: Eduard - Gabriel Munteanu @ 2008-07-11 20:02 UTC (permalink / raw) To: Pekka Enberg; +Cc: linux-kernel, linux-mm, Christoph Lameter On Fri, 11 Jul 2008 11:41:20 +0300 "Pekka Enberg" <penberg@cs.helsinki.fi> wrote: > Hi Eduard-Gabriel, > > On Thu, Jul 10, 2008 at 9:05 PM, Eduard - Gabriel Munteanu > <eduard.munteanu@linux360.ro> wrote: > > 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. > > > > Signed-off-by: Eduard - Gabriel Munteanu > > <eduard.munteanu@linux360.ro> > > > new file mode 100644 > > index 0000000..11cd8e2 > > --- /dev/null > > +++ b/include/linux/kmemtrace.h > > @@ -0,0 +1,110 @@ > > +/* > > + * Copyright (C) 2008 Eduard - Gabriel Munteanu > > + * > > + * This file is released under GPL version 2. > > + */ > > + > > +#ifndef _LINUX_KMEMTRACE_H > > +#define _LINUX_KMEMTRACE_H > > + > > +#include <linux/types.h> > > + > > +/* ABI definition starts here. */ > > + > > +#define KMEMTRACE_ABI_VERSION 1 > > + > > +enum kmemtrace_event_id { > > + KMEMTRACE_EVENT_NULL = 0, /* Erroneous event. */ > > + KMEMTRACE_EVENT_ALLOC, > > + KMEMTRACE_EVENT_FREE, > > +}; > > + > > +enum kmemtrace_kind_id { > > + KMEMTRACE_KIND_KERNEL = 0, /* kmalloc() / kfree(). */ > > + KMEMTRACE_KIND_CACHE, /* kmem_cache_*(). */ > > + KMEMTRACE_KIND_PAGES, /* __get_free_pages() and > > friends. */ +}; > > Can we do s/kind/type/, please? Also, the names "kernel" and "cache" > are confusing. Can we just call them "kmalloc" and "kmem_cache" > instead? Sure. I thought "type" would be too confusing. Regarding the use of "kmalloc" and "kmem_cache", I'd have a few objections: 1. "kmalloc" is ambiguous and may mislead some people into thinking that such a type is inappropriate for kfree(). 2. "kmem_cache" seemed way too long. The tracing function calls are already kinda long. > > + > > +struct kmemtrace_event { > > + __u16 event_id; /* Allocate or free? */ > > + __u16 kind_id; /* Kind of allocation/free. > > */ > > + __s32 node; /* Target CPU. */ > > + __u64 call_site; /* Caller address. */ > > + __u64 ptr; /* Pointer to allocation. */ > > + __u64 bytes_req; /* Number of bytes > > requested. */ > > + __u64 bytes_alloc; /* Number of bytes > > allocated. */ > > + __u64 gfp_flags; /* Requested flags. */ > > + __s64 timestamp; /* When the operation > > occured in ns. */ +} __attribute__ ((__packed__)); > > Why do you need to use the __packed__ attribute here? Looks like the > struct is already laid out properly. __packed__ doesn't hurt and will keep us from getting fried when doing cross-platform tracing (e.g. trace on ARM, analyze on x86) in case the ABI changes. It's also a reminder that it's best to keep the structure packed tight and avoid alignment. > > + > > +/* End of ABI definition. */ -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
[parent not found: <1215712946-23572-2-git-send-email-eduard.munteanu@linux360.ro>]
* [RFC PATCH 2/5] Add new GFP flag __GFP_NOTRACE. [not found] ` <1215712946-23572-2-git-send-email-eduard.munteanu@linux360.ro> @ 2008-07-10 18:06 ` Eduard - Gabriel Munteanu 2008-07-11 8:33 ` Pekka Enberg 2008-07-11 14:41 ` Christoph Lameter [not found] ` <1215712946-23572-3-git-send-email-eduard.munteanu@linux360.ro> 1 sibling, 2 replies; 30+ messages in thread From: Eduard - Gabriel Munteanu @ 2008-07-10 18:06 UTC (permalink / raw) To: penberg; +Cc: linux-kernel, linux-mm __GFP_NOTRACE turns off allocator tracing for that particular allocation. This is used by kmemtrace to correctly classify different kinds of allocations, without recording one event multiple times. Example: SLAB's kmalloc() calls kmem_cache_alloc(), but we want to record this only as a kmalloc. Signed-off-by: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> --- include/linux/gfp.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index b414be3..693a5a9 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -43,6 +43,7 @@ struct vm_area_struct; #define __GFP_REPEAT ((__force gfp_t)0x400u) /* See above */ #define __GFP_NOFAIL ((__force gfp_t)0x800u) /* See above */ #define __GFP_NORETRY ((__force gfp_t)0x1000u)/* See above */ +#define __GFP_NOTRACE ((__force gfp_t)0x2000u) /* Inhibit tracing this. */ #define __GFP_COMP ((__force gfp_t)0x4000u)/* Add compound page metadata */ #define __GFP_ZERO ((__force gfp_t)0x8000u)/* Return zeroed page on success */ #define __GFP_NOMEMALLOC ((__force gfp_t)0x10000u) /* Don't use emergency reserves */ -- 1.5.6.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [RFC PATCH 2/5] Add new GFP flag __GFP_NOTRACE. 2008-07-10 18:06 ` [RFC PATCH 2/5] Add new GFP flag __GFP_NOTRACE Eduard - Gabriel Munteanu @ 2008-07-11 8:33 ` Pekka Enberg 2008-07-11 14:41 ` Christoph Lameter 1 sibling, 0 replies; 30+ messages in thread From: Pekka Enberg @ 2008-07-11 8:33 UTC (permalink / raw) To: Eduard - Gabriel Munteanu; +Cc: linux-kernel, linux-mm, Christoph Lameter Hi Eduard-Gabriel, On Thu, Jul 10, 2008 at 9:06 PM, Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> wrote: > __GFP_NOTRACE turns off allocator tracing for that particular allocation. > > This is used by kmemtrace to correctly classify different kinds of > allocations, without recording one event multiple times. Example: SLAB's > kmalloc() calls kmem_cache_alloc(), but we want to record this only as a > kmalloc. > > Signed-off-by: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> I don't like this approach. I think you can just place the hooks in the proper place in SLAB to avoid this? -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [RFC PATCH 2/5] Add new GFP flag __GFP_NOTRACE. 2008-07-10 18:06 ` [RFC PATCH 2/5] Add new GFP flag __GFP_NOTRACE Eduard - Gabriel Munteanu 2008-07-11 8:33 ` Pekka Enberg @ 2008-07-11 14:41 ` Christoph Lameter 2008-07-11 19:56 ` Eduard - Gabriel Munteanu 1 sibling, 1 reply; 30+ messages in thread From: Christoph Lameter @ 2008-07-11 14:41 UTC (permalink / raw) To: Eduard - Gabriel Munteanu; +Cc: penberg, linux-kernel, linux-mm Eduard - Gabriel Munteanu wrote: > This is used by kmemtrace to correctly classify different kinds of > allocations, without recording one event multiple times. Example: SLAB's > kmalloc() calls kmem_cache_alloc(), but we want to record this only as a > kmalloc. Well then I guess we need to put the recording logic into kmem_cache_alloc? -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [RFC PATCH 2/5] Add new GFP flag __GFP_NOTRACE. 2008-07-11 14:41 ` Christoph Lameter @ 2008-07-11 19:56 ` Eduard - Gabriel Munteanu 0 siblings, 0 replies; 30+ messages in thread From: Eduard - Gabriel Munteanu @ 2008-07-11 19:56 UTC (permalink / raw) To: Christoph Lameter; +Cc: penberg, linux-kernel, linux-mm On Fri, 11 Jul 2008 09:41:20 -0500 Christoph Lameter <cl@linux-foundation.org> wrote: > Eduard - Gabriel Munteanu wrote: > > > This is used by kmemtrace to correctly classify different kinds of > > allocations, without recording one event multiple times. Example: > > SLAB's kmalloc() calls kmem_cache_alloc(), but we want to record > > this only as a kmalloc. > > Well then I guess we need to put the recording logic into > kmem_cache_alloc? Okay, will do it another way. I thought there may be other legitimate uses of something like __GFP_NOTRACE. Eduard -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
[parent not found: <1215712946-23572-3-git-send-email-eduard.munteanu@linux360.ro>]
* [RFC PATCH 3/5] kmemtrace: SLAB hooks. [not found] ` <1215712946-23572-3-git-send-email-eduard.munteanu@linux360.ro> @ 2008-07-10 18:06 ` Eduard - Gabriel Munteanu 2008-07-11 8:49 ` Pekka Enberg [not found] ` <1215712946-23572-4-git-send-email-eduard.munteanu@linux360.ro> 1 sibling, 1 reply; 30+ messages in thread From: Eduard - Gabriel Munteanu @ 2008-07-10 18:06 UTC (permalink / raw) To: penberg; +Cc: linux-kernel, linux-mm This adds hooks for the SLAB allocator, to allow tracing with kmemtrace. Signed-off-by: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> --- include/linux/slab_def.h | 16 +++++++++++++--- mm/slab.c | 35 +++++++++++++++++++++++++++++------ 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h index 39c3a5e..89d0cca 100644 --- a/include/linux/slab_def.h +++ b/include/linux/slab_def.h @@ -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 { @@ -30,6 +31,8 @@ void *__kmalloc(size_t size, gfp_t flags); static inline void *kmalloc(size_t size, gfp_t flags) { + void *ret; + if (__builtin_constant_p(size)) { int i = 0; @@ -50,10 +53,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); + ret = kmem_cache_alloc(malloc_sizes[i].cs_dmacachep, + flags | __GFP_NOTRACE); + else #endif - return kmem_cache_alloc(malloc_sizes[i].cs_cachep, flags); + ret = kmem_cache_alloc(malloc_sizes[i].cs_cachep, + flags | __GFP_NOTRACE); + + kmemtrace_mark_alloc(KMEMTRACE_KIND_KERNEL, _THIS_IP_, ret, + size, malloc_sizes[i].cs_size, flags); + + return ret; } return __kmalloc(size, flags); } diff --git a/mm/slab.c b/mm/slab.c index 046607f..29f0599 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -111,6 +111,7 @@ #include <linux/rtmutex.h> #include <linux/reciprocal_div.h> #include <linux/debugobjects.h> +#include <linux/kmemtrace.h> #include <asm/cacheflush.h> #include <asm/tlbflush.h> @@ -3621,7 +3622,12 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp) */ void *kmem_cache_alloc(struct kmem_cache *cachep, gfp_t flags) { - return __cache_alloc(cachep, flags, __builtin_return_address(0)); + void *ret = __cache_alloc(cachep, flags, __builtin_return_address(0)); + + kmemtrace_mark_alloc(KMEMTRACE_KIND_CACHE, _RET_IP_, ret, + obj_size(cachep), obj_size(cachep), flags); + + return ret; } EXPORT_SYMBOL(kmem_cache_alloc); @@ -3669,8 +3675,14 @@ out: #ifdef CONFIG_NUMA void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid) { - return __cache_alloc_node(cachep, flags, nodeid, - __builtin_return_address(0)); + void *ret = __cache_alloc_node(cachep, flags, nodeid, + __builtin_return_address(0)); + + kmemtrace_mark_alloc_node(KMEMTRACE_KIND_CACHE, _RET_IP_, ret, + obj_size(cachep), obj_size(cachep), + flags, nodeid); + + return ret; } EXPORT_SYMBOL(kmem_cache_alloc_node); @@ -3718,6 +3730,7 @@ static __always_inline void *__do_kmalloc(size_t size, gfp_t flags, void *caller) { struct kmem_cache *cachep; + void *ret; /* If you want to save a few bytes .text space: replace * __ with kmem_. @@ -3726,12 +3739,18 @@ static __always_inline void *__do_kmalloc(size_t size, gfp_t flags, */ cachep = __find_general_cachep(size, flags); if (unlikely(ZERO_OR_NULL_PTR(cachep))) - return cachep; - return __cache_alloc(cachep, flags, caller); + ret = cachep; + else { + ret = __cache_alloc(cachep, flags, caller); + kmemtrace_mark_alloc(KMEMTRACE_KIND_KERNEL, caller, ret, + size, cachep->buffer_size, flags); + } + + return ret; } -#ifdef CONFIG_DEBUG_SLAB +#if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_KMEMTRACE) void *__kmalloc(size_t size, gfp_t flags) { return __do_kmalloc(size, flags, __builtin_return_address(0)); @@ -3770,6 +3789,8 @@ void kmem_cache_free(struct kmem_cache *cachep, void *objp) debug_check_no_obj_freed(objp, obj_size(cachep)); __cache_free(cachep, objp); local_irq_restore(flags); + + kmemtrace_mark_free(KMEMTRACE_KIND_CACHE, _RET_IP_, objp); } EXPORT_SYMBOL(kmem_cache_free); @@ -3796,6 +3817,8 @@ void kfree(const void *objp) debug_check_no_obj_freed(objp, obj_size(c)); __cache_free(c, (void *)objp); local_irq_restore(flags); + + kmemtrace_mark_free(KMEMTRACE_KIND_KERNEL, _RET_IP_, objp); } EXPORT_SYMBOL(kfree); -- 1.5.6.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [RFC PATCH 3/5] kmemtrace: SLAB hooks. 2008-07-10 18:06 ` [RFC PATCH 3/5] kmemtrace: SLAB hooks Eduard - Gabriel Munteanu @ 2008-07-11 8:49 ` Pekka Enberg 2008-07-12 19:04 ` [PATCH] " Eduard - Gabriel Munteanu 0 siblings, 1 reply; 30+ messages in thread From: Pekka Enberg @ 2008-07-11 8:49 UTC (permalink / raw) To: Eduard - Gabriel Munteanu; +Cc: linux-kernel, linux-mm, Christoph Lameter Hi Eduard-Gabriel, On Thu, Jul 10, 2008 at 9:06 PM, Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> wrote: > This adds hooks for the SLAB allocator, to allow tracing with kmemtrace. > > Signed-off-by: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> > static inline void *kmalloc(size_t size, gfp_t flags) > { > + void *ret; > + > if (__builtin_constant_p(size)) { > int i = 0; > > @@ -50,10 +53,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); > + ret = kmem_cache_alloc(malloc_sizes[i].cs_dmacachep, > + flags | __GFP_NOTRACE); > + else > #endif > - return kmem_cache_alloc(malloc_sizes[i].cs_cachep, flags); > + ret = kmem_cache_alloc(malloc_sizes[i].cs_cachep, > + flags | __GFP_NOTRACE); > + > + kmemtrace_mark_alloc(KMEMTRACE_KIND_KERNEL, _THIS_IP_, ret, > + size, malloc_sizes[i].cs_size, flags); > + > + return ret; I think this would be cleaner if you'd simply add a new __kmem_cache_alloc() entry point in SLAB that takes the "kind" as an argument. That way you wouldn't have to play tricks with GFP flags. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH] kmemtrace: SLAB hooks. 2008-07-11 8:49 ` Pekka Enberg @ 2008-07-12 19:04 ` Eduard - Gabriel Munteanu 2008-07-14 16:28 ` Pekka Enberg 0 siblings, 1 reply; 30+ messages in thread From: Eduard - Gabriel Munteanu @ 2008-07-12 19:04 UTC (permalink / raw) To: penberg; +Cc: linux-kernel, linux-mm, cl This adds hooks for the SLAB allocator, to allow tracing with kmemtrace. Signed-off-by: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> --- Dropped the __GFP_NOTRACE thing. Also fixed NUMA tracing and some whitespace errors. What do you think? include/linux/slab_def.h | 56 +++++++++++++++++++++++++++++++++++++----- mm/slab.c | 61 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 104 insertions(+), 13 deletions(-) diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h index 39c3a5e..040fe72 100644 --- a/include/linux/slab_def.h +++ b/include/linux/slab_def.h @@ -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,20 @@ extern struct cache_sizes malloc_sizes[]; 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(struct kmem_cache *cachep, gfp_t flags); +#else +static inline void *__kmem_cache_alloc(struct kmem_cache *cachep, + gfp_t flags) +{ + return __kmem_cache_alloc(cachep, flags); +} +#endif + static inline void *kmalloc(size_t size, gfp_t flags) { + void *ret; + if (__builtin_constant_p(size)) { int i = 0; @@ -50,10 +63,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); + ret = __kmem_cache_alloc(malloc_sizes[i].cs_dmacachep, + flags); + else #endif - return kmem_cache_alloc(malloc_sizes[i].cs_cachep, flags); + ret = __kmem_cache_alloc(malloc_sizes[i].cs_cachep, + flags); + + kmemtrace_mark_alloc(KMEMTRACE_KIND_KERNEL, _THIS_IP_, ret, + size, malloc_sizes[i].cs_size, flags); + + return ret; } return __kmalloc(size, flags); } @@ -62,8 +82,23 @@ 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); +#ifdef CONFIG_KMEMTRACE +extern void *__kmem_cache_alloc_node(struct kmem_cache *cachep, + gfp_t flags, + int nodeid); +#else +static inline void *__kmem_cache_alloc_node(struct kmem_cache *cachep, + gfp_t flags, + int nodeid) +{ + return kmem_cache_alloc_node(cachep, flags, nodeid); +} +#endif + static inline void *kmalloc_node(size_t size, gfp_t flags, int node) { + void *ret; + if (__builtin_constant_p(size)) { int i = 0; @@ -84,11 +119,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); + ret = __kmem_cache_alloc_node(malloc_sizes[i].cs_dmacachep, + flags, node); + else #endif - return kmem_cache_alloc_node(malloc_sizes[i].cs_cachep, - flags, node); + ret = __kmem_cache_alloc_node(malloc_sizes[i].cs_cachep, + flags, node); + + kmemtrace_mark_alloc_node(KMEMTRACE_KIND_KERNEL, _THIS_IP_, + ret, size, malloc_sizes[i].cs_size, + flags, node); + + return ret; } return __kmalloc_node(size, flags, node); } diff --git a/mm/slab.c b/mm/slab.c index 046607f..f07e022 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -111,6 +111,7 @@ #include <linux/rtmutex.h> #include <linux/reciprocal_div.h> #include <linux/debugobjects.h> +#include <linux/kmemtrace.h> #include <asm/cacheflush.h> #include <asm/tlbflush.h> @@ -3621,10 +3622,23 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp) */ void *kmem_cache_alloc(struct kmem_cache *cachep, gfp_t flags) { - return __cache_alloc(cachep, flags, __builtin_return_address(0)); + void *ret = __cache_alloc(cachep, flags, __builtin_return_address(0)); + + kmemtrace_mark_alloc(KMEMTRACE_KIND_CACHE, _RET_IP_, ret, + obj_size(cachep), obj_size(cachep), flags); + + return ret; } EXPORT_SYMBOL(kmem_cache_alloc); +#ifdef CONFIG_KMEMTRACE +void *__kmem_cache_alloc(struct kmem_cache *cachep, gfp_t flags) +{ + return __cache_alloc(cachep, flags, __builtin_return_address(0)); +} +EXPORT_SYMBOL(__kmem_cache_alloc); +#endif + /** * kmem_ptr_validate - check if an untrusted pointer might be a slab entry. * @cachep: the cache we're checking against @@ -3669,20 +3683,44 @@ out: #ifdef CONFIG_NUMA void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid) { - return __cache_alloc_node(cachep, flags, nodeid, - __builtin_return_address(0)); + void *ret = __cache_alloc_node(cachep, flags, nodeid, + __builtin_return_address(0)); + + kmemtrace_mark_alloc_node(KMEMTRACE_KIND_CACHE, _RET_IP_, ret, + obj_size(cachep), obj_size(cachep), + flags, nodeid); + + return ret; } EXPORT_SYMBOL(kmem_cache_alloc_node); +#ifdef CONFIG_KMEMTRACE +void *__kmem_cache_alloc_node(struct kmem_cache *cachep, + gfp_t flags, + int nodeid) +{ + return __cache_alloc_node(cachep, flags, nodeid, + __builtin_return_address(0)); +} +EXPORT_SYMBOL(__kmem_cache_alloc_node); +#endif + static __always_inline void * __do_kmalloc_node(size_t size, gfp_t flags, int node, void *caller) { struct kmem_cache *cachep; + void *ret; cachep = kmem_find_general_cachep(size, flags); if (unlikely(ZERO_OR_NULL_PTR(cachep))) return cachep; - return kmem_cache_alloc_node(cachep, flags, node); + ret = __kmem_cache_alloc_node(cachep, flags, node); + + kmemtrace_mark_alloc_node(KMEMTRACE_KIND_KERNEL, + (unsigned long) caller, ret, + size, cachep->buffer_size, flags, node); + + return ret; } #ifdef CONFIG_DEBUG_SLAB @@ -3718,6 +3756,7 @@ static __always_inline void *__do_kmalloc(size_t size, gfp_t flags, void *caller) { struct kmem_cache *cachep; + void *ret; /* If you want to save a few bytes .text space: replace * __ with kmem_. @@ -3727,11 +3766,17 @@ static __always_inline void *__do_kmalloc(size_t size, gfp_t flags, cachep = __find_general_cachep(size, flags); if (unlikely(ZERO_OR_NULL_PTR(cachep))) return cachep; - return __cache_alloc(cachep, flags, caller); + ret = __cache_alloc(cachep, flags, caller); + + kmemtrace_mark_alloc(KMEMTRACE_KIND_KERNEL, + (unsigned long) caller, ret, + size, cachep->buffer_size, flags); + + return ret; } -#ifdef CONFIG_DEBUG_SLAB +#if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_KMEMTRACE) void *__kmalloc(size_t size, gfp_t flags) { return __do_kmalloc(size, flags, __builtin_return_address(0)); @@ -3770,6 +3815,8 @@ void kmem_cache_free(struct kmem_cache *cachep, void *objp) debug_check_no_obj_freed(objp, obj_size(cachep)); __cache_free(cachep, objp); local_irq_restore(flags); + + kmemtrace_mark_free(KMEMTRACE_KIND_CACHE, _RET_IP_, objp); } EXPORT_SYMBOL(kmem_cache_free); @@ -3796,6 +3843,8 @@ void kfree(const void *objp) debug_check_no_obj_freed(objp, obj_size(c)); __cache_free(c, (void *)objp); local_irq_restore(flags); + + kmemtrace_mark_free(KMEMTRACE_KIND_KERNEL, _RET_IP_, objp); } EXPORT_SYMBOL(kfree); -- 1.5.6.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH] kmemtrace: SLAB hooks. 2008-07-12 19:04 ` [PATCH] " Eduard - Gabriel Munteanu @ 2008-07-14 16:28 ` Pekka Enberg 2008-07-14 16:32 ` Christoph Lameter 0 siblings, 1 reply; 30+ messages in thread From: Pekka Enberg @ 2008-07-14 16:28 UTC (permalink / raw) To: Eduard - Gabriel Munteanu; +Cc: linux-kernel, linux-mm, cl Hi Eduard-Gabriel, On Sat, 2008-07-12 at 22:04 +0300, Eduard - Gabriel Munteanu wrote: > This adds hooks for the SLAB allocator, to allow tracing with kmemtrace. > > Signed-off-by: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> > @@ -28,8 +29,20 @@ extern struct cache_sizes malloc_sizes[]; > 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(struct kmem_cache *cachep, gfp_t flags); > +#else > +static inline void *__kmem_cache_alloc(struct kmem_cache *cachep, > + gfp_t flags) > +{ > + return __kmem_cache_alloc(cachep, flags); Looks as if the function calls itself i>>?recursively? -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH] kmemtrace: SLAB hooks. 2008-07-14 16:28 ` Pekka Enberg @ 2008-07-14 16:32 ` Christoph Lameter 2008-07-14 17:21 ` Eduard - Gabriel Munteanu 2008-07-14 17:42 ` [RESEND PATCH] " Eduard - Gabriel Munteanu 0 siblings, 2 replies; 30+ messages in thread From: Christoph Lameter @ 2008-07-14 16:32 UTC (permalink / raw) To: Pekka Enberg; +Cc: Eduard - Gabriel Munteanu, linux-kernel, linux-mm Pekka Enberg wrote: > Hi Eduard-Gabriel, > > On Sat, 2008-07-12 at 22:04 +0300, Eduard - Gabriel Munteanu wrote: >> This adds hooks for the SLAB allocator, to allow tracing with kmemtrace. >> >> Signed-off-by: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> >> @@ -28,8 +29,20 @@ extern struct cache_sizes malloc_sizes[]; >> 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(struct kmem_cache *cachep, gfp_t flags); >> +#else >> +static inline void *__kmem_cache_alloc(struct kmem_cache *cachep, >> + gfp_t flags) >> +{ >> + return __kmem_cache_alloc(cachep, flags); > > Looks as if the function calls itself i>>?recursively? > Code not tested? Are you sure you configured for slab? -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH] kmemtrace: SLAB hooks. 2008-07-14 16:32 ` Christoph Lameter @ 2008-07-14 17:21 ` Eduard - Gabriel Munteanu 2008-07-14 17:42 ` [RESEND PATCH] " Eduard - Gabriel Munteanu 1 sibling, 0 replies; 30+ messages in thread From: Eduard - Gabriel Munteanu @ 2008-07-14 17:21 UTC (permalink / raw) To: Christoph Lameter; +Cc: Pekka Enberg, linux-kernel, linux-mm On Mon, 14 Jul 2008 11:32:25 -0500 Christoph Lameter <cl@linux-foundation.org> wrote: > > Looks as if the function calls itself i>>?recursively? > > > > Code not tested? Are you sure you configured for slab? This was a stupid typo on my part. I tested, but only with CONFIG_KMEMTRACE, which took the 'extern' ifdef branch. I'll resubmit in a few minutes. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
* [RESEND PATCH] kmemtrace: SLAB hooks. 2008-07-14 16:32 ` Christoph Lameter 2008-07-14 17:21 ` Eduard - Gabriel Munteanu @ 2008-07-14 17:42 ` Eduard - Gabriel Munteanu 2008-07-14 18:19 ` Pekka Enberg 1 sibling, 1 reply; 30+ messages in thread From: Eduard - Gabriel Munteanu @ 2008-07-14 17:42 UTC (permalink / raw) To: cl; +Cc: penberg, linux-kernel, linux-mm This adds hooks for the SLAB allocator, to allow tracing with kmemtrace. Signed-off-by: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> --- Okay, the rationale is this: 1. When CONFIG_KMEMTRACE is set, __kmem_cache_alloc is defined in mm/slab.c, where it does not call tracers. 2. When CONFIG_KMEMTRACE is _not_ set, __kmem_cache_alloc goes through the usual kmem_cache_alloc, which contains tracers, but are no-ops because CONFIG_KMEMTRACE is not set. Therefore, in any case, __kmem_cache_alloc does not do tracing. Hope this makes sense. include/linux/slab_def.h | 56 +++++++++++++++++++++++++++++++++++++----- mm/slab.c | 61 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 104 insertions(+), 13 deletions(-) diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h index 39c3a5e..758803f 100644 --- a/include/linux/slab_def.h +++ b/include/linux/slab_def.h @@ -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,20 @@ extern struct cache_sizes malloc_sizes[]; 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(struct kmem_cache *cachep, gfp_t flags); +#else +static inline void *__kmem_cache_alloc(struct kmem_cache *cachep, + gfp_t flags) +{ + return kmem_cache_alloc(cachep, flags); +} +#endif + static inline void *kmalloc(size_t size, gfp_t flags) { + void *ret; + if (__builtin_constant_p(size)) { int i = 0; @@ -50,10 +63,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); + ret = __kmem_cache_alloc(malloc_sizes[i].cs_dmacachep, + flags); + else #endif - return kmem_cache_alloc(malloc_sizes[i].cs_cachep, flags); + ret = __kmem_cache_alloc(malloc_sizes[i].cs_cachep, + flags); + + kmemtrace_mark_alloc(KMEMTRACE_KIND_KERNEL, _THIS_IP_, ret, + size, malloc_sizes[i].cs_size, flags); + + return ret; } return __kmalloc(size, flags); } @@ -62,8 +82,23 @@ 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); +#ifdef CONFIG_KMEMTRACE +extern void *__kmem_cache_alloc_node(struct kmem_cache *cachep, + gfp_t flags, + int nodeid); +#else +static inline void *__kmem_cache_alloc_node(struct kmem_cache *cachep, + gfp_t flags, + int nodeid) +{ + return kmem_cache_alloc_node(cachep, flags, nodeid); +} +#endif + static inline void *kmalloc_node(size_t size, gfp_t flags, int node) { + void *ret; + if (__builtin_constant_p(size)) { int i = 0; @@ -84,11 +119,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); + ret = __kmem_cache_alloc_node(malloc_sizes[i].cs_dmacachep, + flags, node); + else #endif - return kmem_cache_alloc_node(malloc_sizes[i].cs_cachep, - flags, node); + ret = __kmem_cache_alloc_node(malloc_sizes[i].cs_cachep, + flags, node); + + kmemtrace_mark_alloc_node(KMEMTRACE_KIND_KERNEL, _THIS_IP_, + ret, size, malloc_sizes[i].cs_size, + flags, node); + + return ret; } return __kmalloc_node(size, flags, node); } diff --git a/mm/slab.c b/mm/slab.c index 046607f..f07e022 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -111,6 +111,7 @@ #include <linux/rtmutex.h> #include <linux/reciprocal_div.h> #include <linux/debugobjects.h> +#include <linux/kmemtrace.h> #include <asm/cacheflush.h> #include <asm/tlbflush.h> @@ -3621,10 +3622,23 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp) */ void *kmem_cache_alloc(struct kmem_cache *cachep, gfp_t flags) { - return __cache_alloc(cachep, flags, __builtin_return_address(0)); + void *ret = __cache_alloc(cachep, flags, __builtin_return_address(0)); + + kmemtrace_mark_alloc(KMEMTRACE_KIND_CACHE, _RET_IP_, ret, + obj_size(cachep), obj_size(cachep), flags); + + return ret; } EXPORT_SYMBOL(kmem_cache_alloc); +#ifdef CONFIG_KMEMTRACE +void *__kmem_cache_alloc(struct kmem_cache *cachep, gfp_t flags) +{ + return __cache_alloc(cachep, flags, __builtin_return_address(0)); +} +EXPORT_SYMBOL(__kmem_cache_alloc); +#endif + /** * kmem_ptr_validate - check if an untrusted pointer might be a slab entry. * @cachep: the cache we're checking against @@ -3669,20 +3683,44 @@ out: #ifdef CONFIG_NUMA void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid) { - return __cache_alloc_node(cachep, flags, nodeid, - __builtin_return_address(0)); + void *ret = __cache_alloc_node(cachep, flags, nodeid, + __builtin_return_address(0)); + + kmemtrace_mark_alloc_node(KMEMTRACE_KIND_CACHE, _RET_IP_, ret, + obj_size(cachep), obj_size(cachep), + flags, nodeid); + + return ret; } EXPORT_SYMBOL(kmem_cache_alloc_node); +#ifdef CONFIG_KMEMTRACE +void *__kmem_cache_alloc_node(struct kmem_cache *cachep, + gfp_t flags, + int nodeid) +{ + return __cache_alloc_node(cachep, flags, nodeid, + __builtin_return_address(0)); +} +EXPORT_SYMBOL(__kmem_cache_alloc_node); +#endif + static __always_inline void * __do_kmalloc_node(size_t size, gfp_t flags, int node, void *caller) { struct kmem_cache *cachep; + void *ret; cachep = kmem_find_general_cachep(size, flags); if (unlikely(ZERO_OR_NULL_PTR(cachep))) return cachep; - return kmem_cache_alloc_node(cachep, flags, node); + ret = __kmem_cache_alloc_node(cachep, flags, node); + + kmemtrace_mark_alloc_node(KMEMTRACE_KIND_KERNEL, + (unsigned long) caller, ret, + size, cachep->buffer_size, flags, node); + + return ret; } #ifdef CONFIG_DEBUG_SLAB @@ -3718,6 +3756,7 @@ static __always_inline void *__do_kmalloc(size_t size, gfp_t flags, void *caller) { struct kmem_cache *cachep; + void *ret; /* If you want to save a few bytes .text space: replace * __ with kmem_. @@ -3727,11 +3766,17 @@ static __always_inline void *__do_kmalloc(size_t size, gfp_t flags, cachep = __find_general_cachep(size, flags); if (unlikely(ZERO_OR_NULL_PTR(cachep))) return cachep; - return __cache_alloc(cachep, flags, caller); + ret = __cache_alloc(cachep, flags, caller); + + kmemtrace_mark_alloc(KMEMTRACE_KIND_KERNEL, + (unsigned long) caller, ret, + size, cachep->buffer_size, flags); + + return ret; } -#ifdef CONFIG_DEBUG_SLAB +#if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_KMEMTRACE) void *__kmalloc(size_t size, gfp_t flags) { return __do_kmalloc(size, flags, __builtin_return_address(0)); @@ -3770,6 +3815,8 @@ void kmem_cache_free(struct kmem_cache *cachep, void *objp) debug_check_no_obj_freed(objp, obj_size(cachep)); __cache_free(cachep, objp); local_irq_restore(flags); + + kmemtrace_mark_free(KMEMTRACE_KIND_CACHE, _RET_IP_, objp); } EXPORT_SYMBOL(kmem_cache_free); @@ -3796,6 +3843,8 @@ void kfree(const void *objp) debug_check_no_obj_freed(objp, obj_size(c)); __cache_free(c, (void *)objp); local_irq_restore(flags); + + kmemtrace_mark_free(KMEMTRACE_KIND_KERNEL, _RET_IP_, objp); } EXPORT_SYMBOL(kfree); -- 1.5.6.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [RESEND PATCH] kmemtrace: SLAB hooks. 2008-07-14 17:42 ` [RESEND PATCH] " Eduard - Gabriel Munteanu @ 2008-07-14 18:19 ` Pekka Enberg 2008-07-14 18:37 ` eduard.munteanu 0 siblings, 1 reply; 30+ messages in thread From: Pekka Enberg @ 2008-07-14 18:19 UTC (permalink / raw) To: Eduard - Gabriel Munteanu; +Cc: cl, linux-kernel, linux-mm Hi Eduard-Gabriel, On Mon, 2008-07-14 at 20:42 +0300, Eduard - Gabriel Munteanu wrote: > This adds hooks for the SLAB allocator, to allow tracing with > kmemtrace. > > Signed-off-by: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> > @@ -28,8 +29,20 @@ extern struct cache_sizes malloc_sizes[]; > 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(struct kmem_cache *cachep, gfp_t flags); > +#else > +static inline void *__kmem_cache_alloc(struct kmem_cache *cachep, > + gfp_t flags) > +{ > + return kmem_cache_alloc(cachep, flags); > +} > +#endif > + I'm okay with this approach but then you need to do s/__kmem_cache_alloc/kmem_cache_alloc_trace/ or similar. In the kernel, it's always the *upper* level function that doesn't have the underscores. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [RESEND PATCH] kmemtrace: SLAB hooks. 2008-07-14 18:19 ` Pekka Enberg @ 2008-07-14 18:37 ` eduard.munteanu 2008-07-15 7:17 ` Pekka Enberg 0 siblings, 1 reply; 30+ messages in thread From: eduard.munteanu @ 2008-07-14 18:37 UTC (permalink / raw) To: Pekka Enberg; +Cc: cl, linux-kernel, linux-mm On Mon, Jul 14, 2008 at 09:19:48PM +0300, Pekka Enberg wrote: > Hi Eduard-Gabriel, > > On Mon, 2008-07-14 at 20:42 +0300, Eduard - Gabriel Munteanu wrote: > > This adds hooks for the SLAB allocator, to allow tracing with > > kmemtrace. > > > > Signed-off-by: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> > > @@ -28,8 +29,20 @@ extern struct cache_sizes malloc_sizes[]; > > 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(struct kmem_cache *cachep, gfp_t flags); > > +#else > > +static inline void *__kmem_cache_alloc(struct kmem_cache *cachep, > > + gfp_t flags) > > +{ > > + return kmem_cache_alloc(cachep, flags); > > +} > > +#endif > > + > > I'm okay with this approach but then you need to do > s/__kmem_cache_alloc/kmem_cache_alloc_trace/ or similar. In the kernel, > it's always the *upper* level function that doesn't have the > underscores. Hmm, doesn't really make sense: 1. This should be called kmem_cache_alloc_notrace, not *_trace. __kmem_cache_alloc() _disables_ tracing. 2. __kmem_cache_alloc is not really upper level now, since it's called only in kmalloc. So it's an internal function which is not supposed to be used by other kernel code. Are you sure I should do this? Eduard -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [RESEND PATCH] kmemtrace: SLAB hooks. 2008-07-14 18:37 ` eduard.munteanu @ 2008-07-15 7:17 ` Pekka Enberg 0 siblings, 0 replies; 30+ messages in thread From: Pekka Enberg @ 2008-07-15 7:17 UTC (permalink / raw) To: eduard.munteanu; +Cc: cl, linux-kernel, linux-mm On Mon, 2008-07-14 at 21:37 +0300, eduard.munteanu@linux360.ro wrote: > > I'm okay with this approach but then you need to do > > s/__kmem_cache_alloc/kmem_cache_alloc_trace/ or similar. In the kernel, > > it's always the *upper* level function that doesn't have the > > underscores. > > Hmm, doesn't really make sense: > 1. This should be called kmem_cache_alloc_notrace, not *_trace. > __kmem_cache_alloc() _disables_ tracing. kmem_cache_alloc_notrace() sounds good to me. > 2. __kmem_cache_alloc is not really upper level now, since it's called > only in kmalloc. So it's an internal function which is not supposed to > be used by other kernel code. > > Are you sure I should do this? Yes. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
[parent not found: <1215712946-23572-4-git-send-email-eduard.munteanu@linux360.ro>]
* [RFC PATCH 4/5] kmemtrace: SLUB hooks. [not found] ` <1215712946-23572-4-git-send-email-eduard.munteanu@linux360.ro> @ 2008-07-10 18:06 ` Eduard - Gabriel Munteanu 2008-07-11 8:35 ` Pekka Enberg 2008-07-11 8:45 ` Pekka Enberg [not found] ` <1215712946-23572-5-git-send-email-eduard.munteanu@linux360.ro> 1 sibling, 2 replies; 30+ messages in thread From: Eduard - Gabriel Munteanu @ 2008-07-10 18:06 UTC (permalink / raw) To: penberg; +Cc: linux-kernel, linux-mm This adds hooks for the SLUB allocator, to allow tracing with kmemtrace. Signed-off-by: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> --- include/linux/slub_def.h | 9 +++++++- mm/slub.c | 49 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h index d117ea2..d60ab10 100644 --- a/include/linux/slub_def.h +++ b/include/linux/slub_def.h @@ -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 */ @@ -205,7 +206,13 @@ void *__kmalloc(size_t size, gfp_t flags); 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_KIND_KERNEL, _THIS_IP_, ret, + size, PAGE_SIZE << order, flags); + + return ret; } static __always_inline void *kmalloc(size_t size, gfp_t flags) diff --git a/mm/slub.c b/mm/slub.c index 1a427c0..6841dfa 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -23,6 +23,7 @@ #include <linux/kallsyms.h> #include <linux/memory.h> #include <linux/math64.h> +#include <linux/kmemtrace.h> /* * Lock order: @@ -1650,14 +1651,25 @@ static __always_inline void *slab_alloc(struct kmem_cache *s, void *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_KIND_CACHE, _RET_IP_, ret, + s->objsize, s->size, gfpflags); + + return ret; } EXPORT_SYMBOL(kmem_cache_alloc); #ifdef CONFIG_NUMA void *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_KIND_CACHE, _RET_IP_, ret, + s->objsize, s->size, gfpflags, node); + + return ret; } EXPORT_SYMBOL(kmem_cache_alloc_node); #endif @@ -1769,6 +1781,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_KIND_CACHE, _RET_IP_, x); } EXPORT_SYMBOL(kmem_cache_free); @@ -2674,6 +2688,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); @@ -2683,7 +2698,12 @@ void *__kmalloc(size_t size, gfp_t flags) if (unlikely(ZERO_OR_NULL_PTR(s))) return s; - return slab_alloc(s, flags, -1, __builtin_return_address(0)); + ret = slab_alloc(s, flags, -1, __builtin_return_address(0)); + + kmemtrace_mark_alloc(KMEMTRACE_KIND_KERNEL, _RET_IP_, ret, + size, (size_t) s->size, (unsigned long) flags); + + return ret; } EXPORT_SYMBOL(__kmalloc); @@ -2702,16 +2722,29 @@ static void *kmalloc_large_node(size_t size, gfp_t flags, int node) void *__kmalloc_node(size_t size, gfp_t flags, int node) { struct kmem_cache *s; - - if (unlikely(size > PAGE_SIZE)) - return kmalloc_large_node(size, flags, node); + void *ret; + + if (unlikely(size > PAGE_SIZE)) { + ret = kmalloc_large_node(size, flags, node); + + kmemtrace_mark_alloc_node(KMEMTRACE_KIND_KERNEL, _RET_IP_, ret, + size, PAGE_SIZE << get_order(size), + (unsigned long) flags, node); + + return ret; + } s = get_slab(size, flags); if (unlikely(ZERO_OR_NULL_PTR(s))) return s; - return slab_alloc(s, flags, node, __builtin_return_address(0)); + ret = slab_alloc(s, flags, node, __builtin_return_address(0)); + + kmemtrace_mark_alloc_node(KMEMTRACE_KIND_KERNEL, _RET_IP_, ret, + size, s->size, (unsigned long) flags, node); + + return ret; } EXPORT_SYMBOL(__kmalloc_node); #endif @@ -2769,6 +2802,8 @@ void kfree(const void *x) return; } slab_free(page->slab, page, object, __builtin_return_address(0)); + + kmemtrace_mark_free(KMEMTRACE_KIND_KERNEL, _RET_IP_, x); } EXPORT_SYMBOL(kfree); -- 1.5.6.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [RFC PATCH 4/5] kmemtrace: SLUB hooks. 2008-07-10 18:06 ` [RFC PATCH 4/5] kmemtrace: SLUB hooks Eduard - Gabriel Munteanu @ 2008-07-11 8:35 ` Pekka Enberg 2008-07-11 14:48 ` Christoph Lameter 2008-07-11 8:45 ` Pekka Enberg 1 sibling, 1 reply; 30+ messages in thread From: Pekka Enberg @ 2008-07-11 8:35 UTC (permalink / raw) To: Eduard - Gabriel Munteanu; +Cc: linux-kernel, linux-mm, Christoph Lameter Hi, Christoph, can you please take a look at this? On Thu, Jul 10, 2008 at 9:06 PM, Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> wrote: > This adds hooks for the SLUB allocator, to allow tracing with kmemtrace. > > Signed-off-by: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> Reviewed-by: Pekka Enberg <penberg@cs.helsinki.fi> > --- > include/linux/slub_def.h | 9 +++++++- > mm/slub.c | 49 +++++++++++++++++++++++++++++++++++++++------ > 2 files changed, 50 insertions(+), 8 deletions(-) > > diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h > index d117ea2..d60ab10 100644 > --- a/include/linux/slub_def.h > +++ b/include/linux/slub_def.h > @@ -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 */ > @@ -205,7 +206,13 @@ void *__kmalloc(size_t size, gfp_t flags); > > 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_KIND_KERNEL, _THIS_IP_, ret, > + size, PAGE_SIZE << order, flags); > + > + return ret; > } > > static __always_inline void *kmalloc(size_t size, gfp_t flags) > diff --git a/mm/slub.c b/mm/slub.c > index 1a427c0..6841dfa 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -23,6 +23,7 @@ > #include <linux/kallsyms.h> > #include <linux/memory.h> > #include <linux/math64.h> > +#include <linux/kmemtrace.h> > > /* > * Lock order: > @@ -1650,14 +1651,25 @@ static __always_inline void *slab_alloc(struct kmem_cache *s, > > void *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_KIND_CACHE, _RET_IP_, ret, > + s->objsize, s->size, gfpflags); > + > + return ret; > } > EXPORT_SYMBOL(kmem_cache_alloc); > > #ifdef CONFIG_NUMA > void *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_KIND_CACHE, _RET_IP_, ret, > + s->objsize, s->size, gfpflags, node); > + > + return ret; > } > EXPORT_SYMBOL(kmem_cache_alloc_node); > #endif > @@ -1769,6 +1781,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_KIND_CACHE, _RET_IP_, x); > } > EXPORT_SYMBOL(kmem_cache_free); > > @@ -2674,6 +2688,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); > @@ -2683,7 +2698,12 @@ void *__kmalloc(size_t size, gfp_t flags) > if (unlikely(ZERO_OR_NULL_PTR(s))) > return s; > > - return slab_alloc(s, flags, -1, __builtin_return_address(0)); > + ret = slab_alloc(s, flags, -1, __builtin_return_address(0)); > + > + kmemtrace_mark_alloc(KMEMTRACE_KIND_KERNEL, _RET_IP_, ret, > + size, (size_t) s->size, (unsigned long) flags); > + > + return ret; > } > EXPORT_SYMBOL(__kmalloc); > > @@ -2702,16 +2722,29 @@ static void *kmalloc_large_node(size_t size, gfp_t flags, int node) > void *__kmalloc_node(size_t size, gfp_t flags, int node) > { > struct kmem_cache *s; > - > - if (unlikely(size > PAGE_SIZE)) > - return kmalloc_large_node(size, flags, node); > + void *ret; > + > + if (unlikely(size > PAGE_SIZE)) { > + ret = kmalloc_large_node(size, flags, node); > + > + kmemtrace_mark_alloc_node(KMEMTRACE_KIND_KERNEL, _RET_IP_, ret, > + size, PAGE_SIZE << get_order(size), > + (unsigned long) flags, node); > + > + return ret; > + } > > s = get_slab(size, flags); > > if (unlikely(ZERO_OR_NULL_PTR(s))) > return s; > > - return slab_alloc(s, flags, node, __builtin_return_address(0)); > + ret = slab_alloc(s, flags, node, __builtin_return_address(0)); > + > + kmemtrace_mark_alloc_node(KMEMTRACE_KIND_KERNEL, _RET_IP_, ret, > + size, s->size, (unsigned long) flags, node); > + > + return ret; > } > EXPORT_SYMBOL(__kmalloc_node); > #endif > @@ -2769,6 +2802,8 @@ void kfree(const void *x) > return; > } > slab_free(page->slab, page, object, __builtin_return_address(0)); > + > + kmemtrace_mark_free(KMEMTRACE_KIND_KERNEL, _RET_IP_, x); > } > EXPORT_SYMBOL(kfree); > > -- > 1.5.6.1 > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [RFC PATCH 4/5] kmemtrace: SLUB hooks. 2008-07-11 8:35 ` Pekka Enberg @ 2008-07-11 14:48 ` Christoph Lameter 2008-07-11 20:21 ` Eduard - Gabriel Munteanu 2008-07-12 13:28 ` Eduard - Gabriel Munteanu 0 siblings, 2 replies; 30+ messages in thread From: Christoph Lameter @ 2008-07-11 14:48 UTC (permalink / raw) To: Pekka Enberg; +Cc: Eduard - Gabriel Munteanu, linux-kernel, linux-mm Pekka Enberg wrote: > Christoph, can you please take a look at this? Yeah. I saw it. Is there some high level description as to how this is going to be used? -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [RFC PATCH 4/5] kmemtrace: SLUB hooks. 2008-07-11 14:48 ` Christoph Lameter @ 2008-07-11 20:21 ` Eduard - Gabriel Munteanu 2008-07-12 13:28 ` Eduard - Gabriel Munteanu 1 sibling, 0 replies; 30+ messages in thread From: Eduard - Gabriel Munteanu @ 2008-07-11 20:21 UTC (permalink / raw) To: Christoph Lameter; +Cc: Pekka Enberg, linux-kernel, linux-mm On Fri, 11 Jul 2008 09:48:03 -0500 Christoph Lameter <cl@linux-foundation.org> wrote: > Pekka Enberg wrote: > > > Christoph, can you please take a look at this? > > Yeah. I saw it. Is there some high level description as to how this > is going to be used? I'll soon post a link to a repo that holds the userspace tool. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [RFC PATCH 4/5] kmemtrace: SLUB hooks. 2008-07-11 14:48 ` Christoph Lameter 2008-07-11 20:21 ` Eduard - Gabriel Munteanu @ 2008-07-12 13:28 ` Eduard - Gabriel Munteanu 2008-07-12 13:36 ` Eduard - Gabriel Munteanu 1 sibling, 1 reply; 30+ messages in thread From: Eduard - Gabriel Munteanu @ 2008-07-12 13:28 UTC (permalink / raw) To: Christoph Lameter; +Cc: Pekka Enberg, linux-kernel, linux-mm On Fri, 11 Jul 2008 09:48:03 -0500 Christoph Lameter <cl@linux-foundation.org> wrote: > Pekka Enberg wrote: > > > Christoph, can you please take a look at this? > > Yeah. I saw it. Is there some high level description as to how this > is going to be used? Here is the userspace application's git tree: http://repo.or.cz/w/kmemtrace-user.git -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [RFC PATCH 4/5] kmemtrace: SLUB hooks. 2008-07-12 13:28 ` Eduard - Gabriel Munteanu @ 2008-07-12 13:36 ` Eduard - Gabriel Munteanu 0 siblings, 0 replies; 30+ messages in thread From: Eduard - Gabriel Munteanu @ 2008-07-12 13:36 UTC (permalink / raw) To: Eduard - Gabriel Munteanu Cc: Christoph Lameter, Pekka Enberg, linux-kernel, linux-mm On Sat, 12 Jul 2008 16:28:36 +0300 Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> wrote: > On Fri, 11 Jul 2008 09:48:03 -0500 > Christoph Lameter <cl@linux-foundation.org> wrote: > > > Pekka Enberg wrote: > > > > > Christoph, can you please take a look at this? > > > > Yeah. I saw it. Is there some high level description as to how this > > is going to be used? > > Here is the userspace application's git tree: > http://repo.or.cz/w/kmemtrace-user.git Basically, you go like this: 1. Boot the kernel, preferably into 'single' runlevel. 2. Mount debugfs and whatever other filesystems. 3. Run kmemtraced, wait a few seconds and stop it. 4*. Check /debug/kmemtrace/total_overruns (debugfs is mounted on /debug) to see if there were any buffer overruns. 5*. Run kmemtrace-check on all CPU cpu*.out to see if there are any erroneous events. 6. Run kmemtrace-report with no parameters to get a short summary of how the allocator performs. * - you can optionally skip these steps. To build the userspace app, launch './configure' when running on that particular kmemtrace-enabled kernel. It should correctly detect the headers directory. Otherwise, add KERNEL_SOURCES variable as an argument to configure. Then run 'make'. BTW, that repo may change, so don't rely on those commits to be consistent for a long time. I could delete them all and restructure the project. Eduard -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [RFC PATCH 4/5] kmemtrace: SLUB hooks. 2008-07-10 18:06 ` [RFC PATCH 4/5] kmemtrace: SLUB hooks Eduard - Gabriel Munteanu 2008-07-11 8:35 ` Pekka Enberg @ 2008-07-11 8:45 ` Pekka Enberg 2008-07-11 20:19 ` Eduard - Gabriel Munteanu 1 sibling, 1 reply; 30+ messages in thread From: Pekka Enberg @ 2008-07-11 8:45 UTC (permalink / raw) To: Eduard - Gabriel Munteanu; +Cc: linux-kernel, linux-mm, Christoph Lameter Hi Eduard-Gabriel, On Thu, Jul 10, 2008 at 9:06 PM, Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> wrote: > This adds hooks for the SLUB allocator, to allow tracing with kmemtrace. > > Signed-off-by: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> > @@ -205,7 +206,13 @@ void *__kmalloc(size_t size, gfp_t flags); > > 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_KIND_KERNEL, _THIS_IP_, ret, > + size, PAGE_SIZE << order, flags); Oh, I missed this on the first review. Here we have, like in SLOB, page allocator pass-through, so wouldn't KIND_PAGES be more appropriate? -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [RFC PATCH 4/5] kmemtrace: SLUB hooks. 2008-07-11 8:45 ` Pekka Enberg @ 2008-07-11 20:19 ` Eduard - Gabriel Munteanu 2008-07-14 16:30 ` Pekka Enberg 0 siblings, 1 reply; 30+ messages in thread From: Eduard - Gabriel Munteanu @ 2008-07-11 20:19 UTC (permalink / raw) To: Pekka Enberg; +Cc: linux-kernel, linux-mm, Christoph Lameter On Fri, 11 Jul 2008 11:45:59 +0300 "Pekka Enberg" <penberg@cs.helsinki.fi> wrote: > Hi Eduard-Gabriel, > > On Thu, Jul 10, 2008 at 9:06 PM, Eduard - Gabriel Munteanu > <eduard.munteanu@linux360.ro> wrote: > > This adds hooks for the SLUB allocator, to allow tracing with > > kmemtrace. > > > > Signed-off-by: Eduard - Gabriel Munteanu > > <eduard.munteanu@linux360.ro> > > > @@ -205,7 +206,13 @@ void *__kmalloc(size_t size, gfp_t flags); > > > > 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_KIND_KERNEL, _THIS_IP_, ret, > > + size, PAGE_SIZE << order, flags); > > Oh, I missed this on the first review. Here we have, like in SLOB, > page allocator pass-through, so wouldn't KIND_PAGES be more > appropriate? The rationale was to be able to trace how kmalloc()s perform, no matter what the allocator does behind the scenes. Presumably, the developer would know what kmalloc() really does with an allocation request. Does this sound okay? Eduard -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [RFC PATCH 4/5] kmemtrace: SLUB hooks. 2008-07-11 20:19 ` Eduard - Gabriel Munteanu @ 2008-07-14 16:30 ` Pekka Enberg 0 siblings, 0 replies; 30+ messages in thread From: Pekka Enberg @ 2008-07-14 16:30 UTC (permalink / raw) To: Eduard - Gabriel Munteanu; +Cc: linux-kernel, linux-mm, Christoph Lameter Hi Eduard-Gabriel, On Fri, 11 Jul 2008 11:45:59 +0300 > > Oh, I missed this on the first review. Here we have, like in SLOB, > > page allocator pass-through, so wouldn't KIND_PAGES be more > > appropriate? i>>?On Fri, 2008-07-11 at 23:19 +0300, Eduard - Gabriel Munteanu wrote: > The rationale was to be able to trace how kmalloc()s perform, no matter > what the allocator does behind the scenes. Presumably, the developer > would know what kmalloc() really does with an allocation request. > > Does this sound okay? Fine with me. Pekka -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
[parent not found: <1215712946-23572-5-git-send-email-eduard.munteanu@linux360.ro>]
* [RFC PATCH 5/5] kmemtrace: SLOB hooks. [not found] ` <1215712946-23572-5-git-send-email-eduard.munteanu@linux360.ro> @ 2008-07-10 18:06 ` Eduard - Gabriel Munteanu 2008-07-11 8:44 ` Pekka Enberg 0 siblings, 1 reply; 30+ messages in thread From: Eduard - Gabriel Munteanu @ 2008-07-10 18:06 UTC (permalink / raw) To: penberg; +Cc: linux-kernel, linux-mm This adds hooks for the SLOB allocator, to allow tracing with kmemtrace. Signed-off-by: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> --- mm/slob.c | 37 +++++++++++++++++++++++++++++++------ 1 files changed, 31 insertions(+), 6 deletions(-) diff --git a/mm/slob.c b/mm/slob.c index a3ad667..44f395a 100644 --- a/mm/slob.c +++ b/mm/slob.c @@ -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_KIND_KERNEL, + _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_KIND_KERNEL, + _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_KIND_KERNEL, _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_KIND_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_KIND_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_KIND_CACHE, _RET_IP_, b); } EXPORT_SYMBOL(kmem_cache_free); -- 1.5.6.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [RFC PATCH 5/5] kmemtrace: SLOB hooks. 2008-07-10 18:06 ` [RFC PATCH 5/5] kmemtrace: SLOB hooks Eduard - Gabriel Munteanu @ 2008-07-11 8:44 ` Pekka Enberg 2008-07-11 15:36 ` Matt Mackall 0 siblings, 1 reply; 30+ messages in thread From: Pekka Enberg @ 2008-07-11 8:44 UTC (permalink / raw) To: Eduard - Gabriel Munteanu Cc: linux-kernel, linux-mm, Christoph Lameter, Matt Mackall Hi, Matt, can you take a look at this? I know you don't want *debugging* code in SLOB but this is for instrumentation. On Thu, Jul 10, 2008 at 9:06 PM, Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> wrote: > This adds hooks for the SLOB allocator, to allow tracing with kmemtrace. > > Signed-off-by: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> > --- > mm/slob.c | 37 +++++++++++++++++++++++++++++++------ > 1 files changed, 31 insertions(+), 6 deletions(-) > > diff --git a/mm/slob.c b/mm/slob.c > index a3ad667..44f395a 100644 > --- a/mm/slob.c > +++ b/mm/slob.c > @@ -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_KIND_KERNEL, > + _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_KIND_KERNEL, The latter case is actually page allocator pass-through so I wonder if we want to use KIND_PAGES here instead? > + _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_KIND_KERNEL, _RET_IP_, block); Same comment here. > } > 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_KIND_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_KIND_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_KIND_CACHE, _RET_IP_, b); > } > EXPORT_SYMBOL(kmem_cache_free); > > -- > 1.5.6.1 > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [RFC PATCH 5/5] kmemtrace: SLOB hooks. 2008-07-11 8:44 ` Pekka Enberg @ 2008-07-11 15:36 ` Matt Mackall 2008-07-11 20:14 ` Eduard - Gabriel Munteanu 0 siblings, 1 reply; 30+ messages in thread From: Matt Mackall @ 2008-07-11 15:36 UTC (permalink / raw) To: Pekka Enberg Cc: Eduard - Gabriel Munteanu, linux-kernel, linux-mm, Christoph Lameter On Fri, 2008-07-11 at 11:44 +0300, Pekka Enberg wrote: > Hi, > > Matt, can you take a look at this? I know you don't want *debugging* > code in SLOB but this is for instrumentation. I presume this code all disappears in a default SLOB build? > On Thu, Jul 10, 2008 at 9:06 PM, Eduard - Gabriel Munteanu > <eduard.munteanu@linux360.ro> wrote: > > This adds hooks for the SLOB allocator, to allow tracing with kmemtrace. > > > > Signed-off-by: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> > > --- > > mm/slob.c | 37 +++++++++++++++++++++++++++++++------ > > 1 files changed, 31 insertions(+), 6 deletions(-) > > > > diff --git a/mm/slob.c b/mm/slob.c > > index a3ad667..44f395a 100644 > > --- a/mm/slob.c > > +++ b/mm/slob.c > > @@ -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; There's tons of tab damage in this patch. Or perhaps it's just been mangled by someone's mailer? > > 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_KIND_KERNEL, > > + _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_KIND_KERNEL, > > The latter case is actually page allocator pass-through so I wonder if > we want to use KIND_PAGES here instead? > > > + _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_KIND_KERNEL, _RET_IP_, block); > > Same comment here. > > > } > > 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_KIND_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_KIND_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_KIND_CACHE, _RET_IP_, b); > > } > > EXPORT_SYMBOL(kmem_cache_free); > > > > -- > > 1.5.6.1 > > > > -- > > To unsubscribe, send a message with 'unsubscribe linux-mm' in > > the body to majordomo@kvack.org. For more info on Linux MM, > > see: http://www.linux-mm.org/ . > > Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> > > -- Mathematics is the supreme nostalgia of our time. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [RFC PATCH 5/5] kmemtrace: SLOB hooks. 2008-07-11 15:36 ` Matt Mackall @ 2008-07-11 20:14 ` Eduard - Gabriel Munteanu 0 siblings, 0 replies; 30+ messages in thread From: Eduard - Gabriel Munteanu @ 2008-07-11 20:14 UTC (permalink / raw) To: Matt Mackall; +Cc: Pekka Enberg, linux-kernel, linux-mm, Christoph Lameter On Fri, 11 Jul 2008 10:36:37 -0500 Matt Mackall <mpm@selenic.com> wrote: > > On Fri, 2008-07-11 at 11:44 +0300, Pekka Enberg wrote: > > Hi, > > > > Matt, can you take a look at this? I know you don't want *debugging* > > code in SLOB but this is for instrumentation. > > I presume this code all disappears in a default SLOB build? Yes, of course. If CONFIG_KMEMTRACE is disabled, those calls go into empty static inlines. > > On Thu, Jul 10, 2008 at 9:06 PM, Eduard - Gabriel Munteanu > > <eduard.munteanu@linux360.ro> wrote: > > > This adds hooks for the SLOB allocator, to allow tracing with > > > kmemtrace. > > > > > > Signed-off-by: Eduard - Gabriel Munteanu > > > <eduard.munteanu@linux360.ro> --- > > > mm/slob.c | 37 +++++++++++++++++++++++++++++++------ > > > 1 files changed, 31 insertions(+), 6 deletions(-) > > > > > > diff --git a/mm/slob.c b/mm/slob.c > > > index a3ad667..44f395a 100644 > > > --- a/mm/slob.c > > > +++ b/mm/slob.c > > > @@ -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; > > There's tons of tab damage in this patch. Or perhaps it's just been > mangled by someone's mailer? I know :-(. This was intended as a simple RFC, things will change on subsequent submissions. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 30+ messages in thread
end of thread, other threads:[~2008-07-15 7:17 UTC | newest]
Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <1215712946-23572-1-git-send-email-eduard.munteanu@linux360.ro>
2008-07-10 18:05 ` [RFC PATCH 1/5] kmemtrace: Core implementation Eduard - Gabriel Munteanu
2008-07-11 8:41 ` Pekka Enberg
2008-07-11 20:02 ` Eduard - Gabriel Munteanu
[not found] ` <1215712946-23572-2-git-send-email-eduard.munteanu@linux360.ro>
2008-07-10 18:06 ` [RFC PATCH 2/5] Add new GFP flag __GFP_NOTRACE Eduard - Gabriel Munteanu
2008-07-11 8:33 ` Pekka Enberg
2008-07-11 14:41 ` Christoph Lameter
2008-07-11 19:56 ` Eduard - Gabriel Munteanu
[not found] ` <1215712946-23572-3-git-send-email-eduard.munteanu@linux360.ro>
2008-07-10 18:06 ` [RFC PATCH 3/5] kmemtrace: SLAB hooks Eduard - Gabriel Munteanu
2008-07-11 8:49 ` Pekka Enberg
2008-07-12 19:04 ` [PATCH] " Eduard - Gabriel Munteanu
2008-07-14 16:28 ` Pekka Enberg
2008-07-14 16:32 ` Christoph Lameter
2008-07-14 17:21 ` Eduard - Gabriel Munteanu
2008-07-14 17:42 ` [RESEND PATCH] " Eduard - Gabriel Munteanu
2008-07-14 18:19 ` Pekka Enberg
2008-07-14 18:37 ` eduard.munteanu
2008-07-15 7:17 ` Pekka Enberg
[not found] ` <1215712946-23572-4-git-send-email-eduard.munteanu@linux360.ro>
2008-07-10 18:06 ` [RFC PATCH 4/5] kmemtrace: SLUB hooks Eduard - Gabriel Munteanu
2008-07-11 8:35 ` Pekka Enberg
2008-07-11 14:48 ` Christoph Lameter
2008-07-11 20:21 ` Eduard - Gabriel Munteanu
2008-07-12 13:28 ` Eduard - Gabriel Munteanu
2008-07-12 13:36 ` Eduard - Gabriel Munteanu
2008-07-11 8:45 ` Pekka Enberg
2008-07-11 20:19 ` Eduard - Gabriel Munteanu
2008-07-14 16:30 ` Pekka Enberg
[not found] ` <1215712946-23572-5-git-send-email-eduard.munteanu@linux360.ro>
2008-07-10 18:06 ` [RFC PATCH 5/5] kmemtrace: SLOB hooks Eduard - Gabriel Munteanu
2008-07-11 8:44 ` Pekka Enberg
2008-07-11 15:36 ` Matt Mackall
2008-07-11 20:14 ` Eduard - Gabriel Munteanu
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox