Page MenuHomeFreeBSD

D51396.diff
No OneTemporary

D51396.diff

diff --git a/cddl/contrib/opensolaris/cmd/dtrace/dtrace.1 b/cddl/contrib/opensolaris/cmd/dtrace/dtrace.1
--- a/cddl/contrib/opensolaris/cmd/dtrace/dtrace.1
+++ b/cddl/contrib/opensolaris/cmd/dtrace/dtrace.1
@@ -20,7 +20,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd July 30, 2025
+.Dd October 24, 2025
.Dt DTRACE 1
.Os
.Sh NAME
@@ -1292,6 +1292,7 @@
.Xr cpp 1 ,
.Xr dwatch 1 ,
.Xr dtrace_audit 4 ,
+.Xr dtrace_dtmalloc 4 ,
.Xr dtrace_dtrace 4 ,
.Xr dtrace_fbt 4 ,
.Xr dtrace_io 4 ,
diff --git a/share/man/man4/Makefile b/share/man/man4/Makefile
--- a/share/man/man4/Makefile
+++ b/share/man/man4/Makefile
@@ -1003,6 +1003,7 @@
.if ${MK_CDDL} != "no"
_dtrace_provs= dtrace_audit.4 \
+ dtrace_dtmalloc.4 \
dtrace_dtrace.4 \
dtrace_fbt.4 \
dtrace_io.4 \
diff --git a/share/man/man4/dtrace_dtmalloc.4 b/share/man/man4/dtrace_dtmalloc.4
new file mode 100644
--- /dev/null
+++ b/share/man/man4/dtrace_dtmalloc.4
@@ -0,0 +1,129 @@
+.\"
+.\" Copyright (c) 2025 Mateusz Piotrowski <0mp@FreeBSD.org>
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.Dd October 24, 2025
+.Dt DTRACE_DTMALLOC 4
+.Os
+.Sh NAME
+.Nm dtrace_dtmalloc
+.Nd a DTrace provider for tracing kernel memory allocations by type
+.Sh SYNOPSIS
+.Nm dtmalloc Ns Cm :: Ns Ar function Ns Cm :malloc
+.Nm dtmalloc Ns Cm :: Ns Ar function Ns Cm :free
+.Sh DESCRIPTION
+The
+.Nm dtmalloc
+provider allows for tracing
+memory allocations by type by instrumenting
+.Xr malloc 9
+and
+.Xr free 9
+kernel functions.
+.Pp
+The
+.Nm dtmalloc Ns Cm :: Ns Ar function Ns Cm :malloc
+probe fires upon a successful allocation.
+Its probe arguments are:
+.Bl -column -offset indent "malloc Probe Argument" "Definition"
+.It Sy Probe Argument Ta Sy Definition
+.It Fa args[0] Ta Ft struct malloc_type *mtp
+.It Fa args[1] Ta Ft struct malloc_type_internal *mtip
+.It Fa args[2] Ta Ft struct malloc_type_stats *mtsp
+.It Fa args[3] Ta Ft unsigned long size
+.It Fa args[4] Ta Ft int zindx
+.El
+.Pp
+The
+.Nm dtmalloc Ns Cm :: Ns Ar function Ns Cm :free
+probe fires upon a free operation.
+Its probe arguments are:
+.Bl -column -offset indent "free Probe Argument" "Definition"
+.It Sy free Probe Argument Ta Sy Definition
+.It Fa args[0] Ta Ft struct malloc_type *mtp
+.It Fa args[1] Ta Ft struct malloc_type_internal *mtip
+.It Fa args[2] Ta Ft struct malloc_type_stats *mtsp
+.It Fa args[3] Ta Ft unsigned long size
+.It Fa args[4] Ta Always 0
+.El
+.Pp
+The first three arguments for each probe
+.Po i.e.,
+.Fa mtp , mtip ,
+and
+.Fa mtsp Pc
+provide references to the
+.Xr malloc 9
+type internals;
+.Fa size
+is the size of the allocation;
+.Fa zindx
+is the index into the
+.Va kmemzones[]
+array used for the allocation.
+In practice,
+.Fa size
+is the most useful parameter to trace.
+.Sh IMPLEMENTATION NOTES
+The
+.Ar function
+part of the probe description in the
+.Nm dtmalloc
+provider is the
+.Xr malloc 9
+type short description with all whitespace characters replaced
+with underscores.
+For example, a malloc type defined by
+.Bd -literal -offset indent
+MALLOC_DEFINE(M_FOO_BAR, "foo bar", "FooBar subsystem");
+.Ed
+.Pp
+will have probes called
+.Bd -literal -offset indent
+dtmalloc::foo_bar:
+.Ed
+.Sh FILES
+.Bl -tag -width "<sys/malloc.h>"
+.It In sys/malloc.h
+The header where
+.Vt struct malloc_type
+is defined.
+.El
+.Sh EXAMPLES
+.Ss Example 1 : Counting Successful Memory Allocations by Type
+.Bd -literal -offset 2n
+# dtrace -n 'dtmalloc:::malloc {@[stringof args[0]->ks_shortdesc] = count()}'
+dtrace: description 'dtmalloc:::malloc ' matched 480 probes
+^C
+ 80211node 1
+ CAM CCB 1
+ CAM periph 1
+ ioctlops 1
+ netlink 1
+ soname 4
+ sysctltmp 4
+ solaris 5
+ acpica 16
+ temp 36
+ lkpikmalloc 44
+ iov 100
+ selfd 648
+.Ed
+.Sh SEE ALSO
+.Xr dtrace 1 ,
+.Xr tracing 7 ,
+.Xr malloc 9
+.Sh AUTHORS
+.An -nosplit
+.Nm
+was written by
+.An John Birrell Aq Mt jb@FreeBSD.org .
+This manual page was written by
+.An Mateusz Piotrowski Aq Mt 0mp@FreeBSD.org .
+.Sh CAVEATS
+The
+.Nm dtmalloc
+provider does not trace
+.Xr uma 9
+allocations.
diff --git a/share/man/man9/malloc.9 b/share/man/man9/malloc.9
--- a/share/man/man9/malloc.9
+++ b/share/man/man9/malloc.9
@@ -28,7 +28,7 @@
.\"
.\" $NetBSD: malloc.9,v 1.3 1996/11/11 00:05:11 lukem Exp $
.\"
-.Dd August 4, 2024
+.Dd October 24, 2025
.Dt MALLOC 9
.Os
.Sh NAME
@@ -394,6 +394,7 @@
Failing consistency checks will cause a panic or a system console
message.
.Sh SEE ALSO
+.Xr dtrace_dtmalloc 4 ,
.Xr numa 4 ,
.Xr vmstat 8 ,
.Xr contigmalloc 9 ,

File Metadata

Mime Type
text/plain
Expires
Wed, Jan 21, 10:06 PM (1 h, 24 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27821766
Default Alt Text
D51396.diff (5 KB)

Event Timeline