xref: /freebsd/share/man/man4/dtrace_dtmalloc.4 (revision 03bc95b060a91ed9d410270d00d1dd4f8edcdcc7)
1.\"
2.\" Copyright (c) 2025-2026 Mateusz Piotrowski <0mp@FreeBSD.org>
3.\"
4.\" SPDX-License-Identifier: BSD-2-Clause
5.\"
6.Dd May 12, 2026
7.Dt DTRACE_DTMALLOC 4
8.Os
9.Sh NAME
10.Nm dtrace_dtmalloc
11.Nd a DTrace provider for tracing kernel memory allocations by type
12.Sh SYNOPSIS
13.Nm dtmalloc Ns Cm :: Ns Ar function Ns Cm :malloc
14.Nm dtmalloc Ns Cm :: Ns Ar function Ns Cm :free
15.Sh DESCRIPTION
16The
17.Nm dtmalloc
18provider instruments
19.Xr malloc 9
20and
21.Xr free 9
22kernel functions to trace memory allocations by type.
23Refer to
24.Xr malloc 9
25for more details about malloc types.
26.Pp
27The
28.Nm dtmalloc Ns Cm :: Ns Ar function Ns Cm :malloc
29probe fires upon a successful allocation.
30Its probe arguments are:
31.Bl -column -offset indent "malloc Probe Argument" "Definition"
32.It Sy Probe Argument Ta Sy Definition
33.It Fa args[0]  Ta Ft struct malloc_type *mtp
34.It Fa args[1]  Ta Ft struct malloc_type_internal *mtip
35.It Fa args[2]  Ta Ft struct malloc_type_stats *mtsp
36.It Fa args[3]  Ta Ft unsigned long size
37.It Fa args[4]  Ta Ft int zindx
38.El
39.Pp
40The
41.Nm dtmalloc Ns Cm :: Ns Ar function Ns Cm :free
42probe fires upon a free operation.
43Its probe arguments are:
44.Bl -column -offset indent "free Probe Argument" "Definition"
45.It Sy free Probe Argument Ta Sy Definition
46.It Fa args[0]  Ta Ft struct malloc_type *mtp
47.It Fa args[1]  Ta Ft struct malloc_type_internal *mtip
48.It Fa args[2]  Ta Ft struct malloc_type_stats *mtsp
49.It Fa args[3]  Ta Ft unsigned long size
50.It Fa args[4]  Ta Always 0
51.El
52.Pp
53The first three arguments for each probe
54.Po i.e.,
55.Fa mtp , mtip ,
56and
57.Fa mtsp Pc
58provide references to the
59.Xr malloc 9
60type internals;
61.Fa size
62is the size of the allocation;
63.Fa zindx
64is the index into the
65.Va kmemzones[]
66array used for the allocation.
67In practice,
68.Fa size
69is the most useful parameter to trace.
70.Sh IMPLEMENTATION NOTES
71The
72.Ar function
73part of the probe description in the
74.Nm dtmalloc
75provider is the
76.Xr malloc 9
77type short description with all whitespace characters replaced
78with underscores.
79For example, a malloc type defined by
80.Bd -literal -offset indent
81MALLOC_DEFINE(M_FOO_BAR, "foo bar", "FooBar subsystem");
82.Ed
83.Pp
84will have probes called
85.Bd -literal -offset indent
86dtmalloc::foo_bar:
87.Ed
88.Sh FILES
89.Bl -tag -width "<sys/malloc.h>"
90.It In sys/malloc.h
91The header where
92.Vt struct malloc_type
93is defined.
94.El
95.Sh EXAMPLES
96.Ss Example 1 : Counting Successful Memory Allocations by Type
97.Bd -literal -offset 2n
98# dtrace -n 'dtmalloc:::malloc {@[stringof args[0]->ks_shortdesc] = count()}'
99dtrace: description 'dtmalloc:::malloc ' matched 480 probes
100^C
101  80211node                                                         1
102  CAM CCB                                                           1
103  CAM periph                                                        1
104  ioctlops                                                          1
105  netlink                                                           1
106  soname                                                            4
107  sysctltmp                                                         4
108  solaris                                                           5
109  acpica                                                           16
110  temp                                                             36
111  lkpikmalloc                                                      44
112  iov                                                             100
113  selfd                                                           648
114.Ed
115.Sh SEE ALSO
116.Xr dtrace 1 ,
117.Xr tracing 7 ,
118.Xr malloc 9
119.Sh AUTHORS
120.An -nosplit
121.Nm
122was written by
123.An John Birrell Aq Mt jb@FreeBSD.org .
124.Pp
125This manual page was written by
126.An Mateusz Piotrowski Aq Mt 0mp@FreeBSD.org .
127.Sh CAVEATS
128The
129.Nm dtmalloc
130provider does not trace
131.Xr uma 9
132allocations.
133