xref: /freebsd/sys/contrib/openzfs/config/kernel-kmem.m4 (revision 7a7741af18d6c8a804cc643cb7ecda9d730c6aa6)
1*eda14cbcSMatt Macydnl #
2*eda14cbcSMatt Macydnl # Enabled by default it provides a minimal level of memory tracking.
3*eda14cbcSMatt Macydnl # A total count of bytes allocated is kept for each alloc and free.
4*eda14cbcSMatt Macydnl # Then at module unload time a report to the console will be printed
5*eda14cbcSMatt Macydnl # if memory was leaked.
6*eda14cbcSMatt Macydnl #
7*eda14cbcSMatt MacyAC_DEFUN([SPL_AC_DEBUG_KMEM], [
8*eda14cbcSMatt Macy	AC_ARG_ENABLE([debug-kmem],
9*eda14cbcSMatt Macy		[AS_HELP_STRING([--enable-debug-kmem],
10*eda14cbcSMatt Macy		[Enable basic kmem accounting @<:@default=no@:>@])],
11*eda14cbcSMatt Macy		[],
12*eda14cbcSMatt Macy		[enable_debug_kmem=no])
13*eda14cbcSMatt Macy
14*eda14cbcSMatt Macy	AS_IF([test "x$enable_debug_kmem" = xyes],
15*eda14cbcSMatt Macy	[
16*eda14cbcSMatt Macy		KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM"
17*eda14cbcSMatt Macy		DEBUG_KMEM="_with_debug_kmem"
18*eda14cbcSMatt Macy		AC_DEFINE([DEBUG_KMEM], [1],
19*eda14cbcSMatt Macy		[Define to 1 to enable basic kmem accounting])
20*eda14cbcSMatt Macy	], [
21*eda14cbcSMatt Macy		DEBUG_KMEM="_without_debug_kmem"
22*eda14cbcSMatt Macy	])
23*eda14cbcSMatt Macy
24*eda14cbcSMatt Macy	AC_SUBST(DEBUG_KMEM)
25*eda14cbcSMatt Macy	AC_MSG_CHECKING([whether basic kmem accounting is enabled])
26*eda14cbcSMatt Macy	AC_MSG_RESULT([$enable_debug_kmem])
27*eda14cbcSMatt Macy])
28*eda14cbcSMatt Macy
29*eda14cbcSMatt Macydnl #
30*eda14cbcSMatt Macydnl # Disabled by default it provides detailed memory tracking.  This
31*eda14cbcSMatt Macydnl # feature also requires --enable-debug-kmem to be set.  When enabled
32*eda14cbcSMatt Macydnl # not only will total bytes be tracked but also the location of every
33*eda14cbcSMatt Macydnl # alloc and free.  When the SPL module is unloaded a list of all leaked
34*eda14cbcSMatt Macydnl # addresses and where they were allocated will be dumped to the console.
35*eda14cbcSMatt Macydnl # Enabling this feature has a significant impact on performance but it
36*eda14cbcSMatt Macydnl # makes finding memory leaks pretty straight forward.
37*eda14cbcSMatt Macydnl #
38*eda14cbcSMatt MacyAC_DEFUN([SPL_AC_DEBUG_KMEM_TRACKING], [
39*eda14cbcSMatt Macy	AC_ARG_ENABLE([debug-kmem-tracking],
40*eda14cbcSMatt Macy		[AS_HELP_STRING([--enable-debug-kmem-tracking],
41*eda14cbcSMatt Macy		[Enable detailed kmem tracking  @<:@default=no@:>@])],
42*eda14cbcSMatt Macy		[],
43*eda14cbcSMatt Macy		[enable_debug_kmem_tracking=no])
44*eda14cbcSMatt Macy
45*eda14cbcSMatt Macy	AS_IF([test "x$enable_debug_kmem_tracking" = xyes],
46*eda14cbcSMatt Macy	[
47*eda14cbcSMatt Macy		KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM_TRACKING"
48*eda14cbcSMatt Macy		DEBUG_KMEM_TRACKING="_with_debug_kmem_tracking"
49*eda14cbcSMatt Macy		AC_DEFINE([DEBUG_KMEM_TRACKING], [1],
50*eda14cbcSMatt Macy		[Define to 1 to enable detailed kmem tracking])
51*eda14cbcSMatt Macy	], [
52*eda14cbcSMatt Macy		DEBUG_KMEM_TRACKING="_without_debug_kmem_tracking"
53*eda14cbcSMatt Macy	])
54*eda14cbcSMatt Macy
55*eda14cbcSMatt Macy	AC_SUBST(DEBUG_KMEM_TRACKING)
56*eda14cbcSMatt Macy	AC_MSG_CHECKING([whether detailed kmem tracking is enabled])
57*eda14cbcSMatt Macy	AC_MSG_RESULT([$enable_debug_kmem_tracking])
58*eda14cbcSMatt Macy])
59*eda14cbcSMatt Macy
60*eda14cbcSMatt Macydnl #
61*eda14cbcSMatt Macydnl # 5.8 API,
62*eda14cbcSMatt Macydnl # __vmalloc PAGE_KERNEL removal
63*eda14cbcSMatt Macydnl #
64*eda14cbcSMatt MacyAC_DEFUN([ZFS_AC_KERNEL_SRC_VMALLOC_PAGE_KERNEL], [
65*eda14cbcSMatt Macy	ZFS_LINUX_TEST_SRC([__vmalloc], [
66*eda14cbcSMatt Macy		#include <linux/mm.h>
67*eda14cbcSMatt Macy		#include <linux/vmalloc.h>
68*eda14cbcSMatt Macy	],[
69*eda14cbcSMatt Macy		void *p __attribute__ ((unused));
70*eda14cbcSMatt Macy
71*eda14cbcSMatt Macy		p = __vmalloc(0, GFP_KERNEL, PAGE_KERNEL);
72*eda14cbcSMatt Macy	])
73*eda14cbcSMatt Macy])
74*eda14cbcSMatt Macy
75*eda14cbcSMatt MacyAC_DEFUN([ZFS_AC_KERNEL_VMALLOC_PAGE_KERNEL], [
76*eda14cbcSMatt Macy	AC_MSG_CHECKING([whether __vmalloc(ptr, flags, pageflags) is available])
77*eda14cbcSMatt Macy	ZFS_LINUX_TEST_RESULT([__vmalloc], [
78*eda14cbcSMatt Macy		AC_MSG_RESULT(yes)
79*eda14cbcSMatt Macy		AC_DEFINE(HAVE_VMALLOC_PAGE_KERNEL, 1, [__vmalloc page flags exists])
80*eda14cbcSMatt Macy	],[
81*eda14cbcSMatt Macy		AC_MSG_RESULT(no)
82*eda14cbcSMatt Macy	])
83*eda14cbcSMatt Macy])
84*eda14cbcSMatt Macy-
85