Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b9ce08c0 authored by Eduard - Gabriel Munteanu's avatar Eduard - Gabriel Munteanu Committed by Pekka Enberg
Browse files

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.

Signed-off-by: default avatarEduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
Signed-off-by: default avatarPekka Enberg <penberg@cs.helsinki.fi>
parent 35995a4d
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -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.
@@ -1018,6 +1019,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.
+6 −0
Original line number Diff line number Diff line
@@ -2565,6 +2565,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
+85 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2008 Eduard - Gabriel Munteanu
 *
 * This file is released under GPL version 2.
 */

#ifndef _LINUX_KMEMTRACE_H
#define _LINUX_KMEMTRACE_H

#ifdef __KERNEL__

#include <linux/types.h>
#include <linux/marker.h>

enum kmemtrace_type_id {
	KMEMTRACE_TYPE_KMALLOC = 0,	/* kmalloc() or kfree(). */
	KMEMTRACE_TYPE_CACHE,		/* kmem_cache_*(). */
	KMEMTRACE_TYPE_PAGES,		/* __get_free_pages() and friends. */
};

#ifdef CONFIG_KMEMTRACE

extern void kmemtrace_init(void);

static inline void kmemtrace_mark_alloc_node(enum kmemtrace_type_id type_id,
					     unsigned long call_site,
					     const void *ptr,
					     size_t bytes_req,
					     size_t bytes_alloc,
					     gfp_t gfp_flags,
					     int node)
{
	trace_mark(kmemtrace_alloc, "type_id %d call_site %lu ptr %lu "
		   "bytes_req %lu bytes_alloc %lu gfp_flags %lu node %d",
		   type_id, call_site, (unsigned long) ptr,
		   bytes_req, bytes_alloc, (unsigned long) gfp_flags, node);
}

static inline void kmemtrace_mark_free(enum kmemtrace_type_id type_id,
				       unsigned long call_site,
				       const void *ptr)
{
	trace_mark(kmemtrace_free, "type_id %d call_site %lu ptr %lu",
		   type_id, call_site, (unsigned long) ptr);
}

#else /* CONFIG_KMEMTRACE */

static inline void kmemtrace_init(void)
{
}

static inline void kmemtrace_mark_alloc_node(enum kmemtrace_type_id type_id,
					     unsigned long call_site,
					     const void *ptr,
					     size_t bytes_req,
					     size_t bytes_alloc,
					     gfp_t gfp_flags,
					     int node)
{
}

static inline void kmemtrace_mark_free(enum kmemtrace_type_id type_id,
				       unsigned long call_site,
				       const void *ptr)
{
}

#endif /* CONFIG_KMEMTRACE */

static inline void kmemtrace_mark_alloc(enum kmemtrace_type_id type_id,
					unsigned long call_site,
					const void *ptr,
					size_t bytes_req,
					size_t bytes_alloc,
					gfp_t gfp_flags)
{
	kmemtrace_mark_alloc_node(type_id, call_site, ptr,
				  bytes_req, bytes_alloc, gfp_flags, -1);
}

#endif /* __KERNEL__ */

#endif /* _LINUX_KMEMTRACE_H */
+2 −0
Original line number Diff line number Diff line
@@ -69,6 +69,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>
@@ -653,6 +654,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();
+28 −0
Original line number Diff line number Diff line
@@ -803,6 +803,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.

menuconfig BUILD_DOCSRC
	bool "Build targets in Documentation/ tree"
	depends on HEADERS_CHECK
Loading