xref: /freebsd/usr.bin/netstat/mbuf.c (revision ade9ccfe211ac8b27c58a4dc11a6cd1d33767ce0)
165475bc8SDavid E. O'Brien /*-
29b50d902SRodney W. Grimes  * Copyright (c) 1983, 1988, 1993
3c8e6b689SRobert Watson  *	The Regents of the University of California.
4c8e6b689SRobert Watson  * Copyright (c) 2005 Robert N. M. Watson
5c8e6b689SRobert Watson  * All rights reserved.
69b50d902SRodney W. Grimes  *
79b50d902SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
89b50d902SRodney W. Grimes  * modification, are permitted provided that the following conditions
99b50d902SRodney W. Grimes  * are met:
109b50d902SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
119b50d902SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
129b50d902SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
139b50d902SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
149b50d902SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
159b50d902SRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
169b50d902SRodney W. Grimes  *    must display the following acknowledgement:
179b50d902SRodney W. Grimes  *	This product includes software developed by the University of
189b50d902SRodney W. Grimes  *	California, Berkeley and its contributors.
199b50d902SRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
209b50d902SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
219b50d902SRodney W. Grimes  *    without specific prior written permission.
229b50d902SRodney W. Grimes  *
239b50d902SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
249b50d902SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
259b50d902SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
269b50d902SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
279b50d902SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
289b50d902SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
299b50d902SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
309b50d902SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
319b50d902SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
329b50d902SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
339b50d902SRodney W. Grimes  * SUCH DAMAGE.
349b50d902SRodney W. Grimes  */
359b50d902SRodney W. Grimes 
365d422d6aSPhilippe Charnier #if 0
376cc6f122SPhilippe Charnier #ifndef lint
389b50d902SRodney W. Grimes static char sccsid[] = "@(#)mbuf.c	8.1 (Berkeley) 6/6/93";
399b50d902SRodney W. Grimes #endif /* not lint */
406cc6f122SPhilippe Charnier #endif
416cc6f122SPhilippe Charnier 
426cc6f122SPhilippe Charnier #include <sys/cdefs.h>
436cc6f122SPhilippe Charnier __FBSDID("$FreeBSD$");
449b50d902SRodney W. Grimes 
459b50d902SRodney W. Grimes #include <sys/param.h>
4613ae2e2dSGarrett Wollman #include <sys/mbuf.h>
479b50d902SRodney W. Grimes #include <sys/protosw.h>
4805d1f5bcSAndrey V. Elsukov #include <sys/sf_buf.h>
499b50d902SRodney W. Grimes #include <sys/socket.h>
50feda1a43SJohn Baldwin #include <sys/socketvar.h>
5113ae2e2dSGarrett Wollman #include <sys/sysctl.h>
529b50d902SRodney W. Grimes 
535d422d6aSPhilippe Charnier #include <err.h>
54d4426f28SRobert Watson #include <kvm.h>
55c8e6b689SRobert Watson #include <memstat.h>
567b95a1ebSYaroslav Tykhiy #include <stdint.h>
579b50d902SRodney W. Grimes #include <stdio.h>
58821df508SXin LI #include <stdlib.h>
59*ade9ccfeSMarcel Moolenaar #include <stdbool.h>
60821df508SXin LI #include <string.h>
61*ade9ccfeSMarcel Moolenaar #include <libxo/xo.h>
629b50d902SRodney W. Grimes #include "netstat.h"
639b50d902SRodney W. Grimes 
649b50d902SRodney W. Grimes /*
65d4426f28SRobert Watson  * Print mbuf statistics.
669b50d902SRodney W. Grimes  */
679b50d902SRodney W. Grimes void
68d4426f28SRobert Watson mbpr(void *kvmd, u_long mbaddr)
69c8e6b689SRobert Watson {
70c8e6b689SRobert Watson 	struct memory_type_list *mtlp;
71c8e6b689SRobert Watson 	struct memory_type *mtp;
727b95a1ebSYaroslav Tykhiy 	uintmax_t mbuf_count, mbuf_bytes, mbuf_free, mbuf_failures, mbuf_size;
73504a74faSAlfred Perlstein 	uintmax_t mbuf_sleeps;
74d35acb50SGleb Smirnoff 	uintmax_t cluster_count, cluster_limit, cluster_free;
75504a74faSAlfred Perlstein 	uintmax_t cluster_failures, cluster_size, cluster_sleeps;
767b95a1ebSYaroslav Tykhiy 	uintmax_t packet_count, packet_bytes, packet_free, packet_failures;
77504a74faSAlfred Perlstein 	uintmax_t packet_sleeps;
78d35acb50SGleb Smirnoff 	uintmax_t tag_bytes;
79d35acb50SGleb Smirnoff 	uintmax_t jumbop_count, jumbop_limit, jumbop_free;
80504a74faSAlfred Perlstein 	uintmax_t jumbop_failures, jumbop_sleeps, jumbop_size;
81d35acb50SGleb Smirnoff 	uintmax_t jumbo9_count, jumbo9_limit, jumbo9_free;
82504a74faSAlfred Perlstein 	uintmax_t jumbo9_failures, jumbo9_sleeps, jumbo9_size;
83d35acb50SGleb Smirnoff 	uintmax_t jumbo16_count, jumbo16_limit, jumbo16_free;
84504a74faSAlfred Perlstein 	uintmax_t jumbo16_failures, jumbo16_sleeps, jumbo16_size;
857b95a1ebSYaroslav Tykhiy 	uintmax_t bytes_inuse, bytes_incache, bytes_total;
86c8e6b689SRobert Watson 	int nsfbufs, nsfbufspeak, nsfbufsused;
8705d1f5bcSAndrey V. Elsukov 	struct sfstat sfstat;
88c8e6b689SRobert Watson 	size_t mlen;
89feda1a43SJohn Baldwin 	int error;
90c8e6b689SRobert Watson 
91c8e6b689SRobert Watson 	mtlp = memstat_mtl_alloc();
92c8e6b689SRobert Watson 	if (mtlp == NULL) {
93*ade9ccfeSMarcel Moolenaar 		xo_warn("memstat_mtl_alloc");
94c8e6b689SRobert Watson 		return;
95c8e6b689SRobert Watson 	}
96c8e6b689SRobert Watson 
97c8e6b689SRobert Watson 	/*
98d4426f28SRobert Watson 	 * Use memstat_*_all() because some mbuf-related memory is in uma(9),
99d4426f28SRobert Watson 	 * and some malloc(9).
100c8e6b689SRobert Watson 	 */
101d4426f28SRobert Watson 	if (live) {
102c8e6b689SRobert Watson 		if (memstat_sysctl_all(mtlp, 0) < 0) {
103*ade9ccfeSMarcel Moolenaar 			xo_warnx("memstat_sysctl_all: %s",
1044f7ac59bSRobert Watson 			    memstat_strerror(memstat_mtl_geterror(mtlp)));
105c8e6b689SRobert Watson 			goto out;
106c8e6b689SRobert Watson 		}
107d4426f28SRobert Watson 	} else {
108d4426f28SRobert Watson 		if (memstat_kvm_all(mtlp, kvmd) < 0) {
109d4426f28SRobert Watson 			error = memstat_mtl_geterror(mtlp);
110d4426f28SRobert Watson 			if (error == MEMSTAT_ERROR_KVM)
111*ade9ccfeSMarcel Moolenaar 				xo_warnx("memstat_kvm_all: %s",
112d4426f28SRobert Watson 				    kvm_geterr(kvmd));
113d4426f28SRobert Watson 			else
114*ade9ccfeSMarcel Moolenaar 				xo_warnx("memstat_kvm_all: %s",
115d4426f28SRobert Watson 				    memstat_strerror(error));
116d4426f28SRobert Watson 			goto out;
117d4426f28SRobert Watson 		}
118d4426f28SRobert Watson 	}
119c8e6b689SRobert Watson 
120c8e6b689SRobert Watson 	mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_MEM_NAME);
121c8e6b689SRobert Watson 	if (mtp == NULL) {
122*ade9ccfeSMarcel Moolenaar 		xo_warnx("memstat_mtl_find: zone %s not found", MBUF_MEM_NAME);
123c8e6b689SRobert Watson 		goto out;
124c8e6b689SRobert Watson 	}
125c8e6b689SRobert Watson 	mbuf_count = memstat_get_count(mtp);
126c8e6b689SRobert Watson 	mbuf_bytes = memstat_get_bytes(mtp);
127c8e6b689SRobert Watson 	mbuf_free = memstat_get_free(mtp);
128c8e6b689SRobert Watson 	mbuf_failures = memstat_get_failures(mtp);
129504a74faSAlfred Perlstein 	mbuf_sleeps = memstat_get_sleeps(mtp);
130c8e6b689SRobert Watson 	mbuf_size = memstat_get_size(mtp);
131c8e6b689SRobert Watson 
132c8e6b689SRobert Watson 	mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_PACKET_MEM_NAME);
133c8e6b689SRobert Watson 	if (mtp == NULL) {
134*ade9ccfeSMarcel Moolenaar 		xo_warnx("memstat_mtl_find: zone %s not found",
135c8e6b689SRobert Watson 		    MBUF_PACKET_MEM_NAME);
136c8e6b689SRobert Watson 		goto out;
137c8e6b689SRobert Watson 	}
138c8e6b689SRobert Watson 	packet_count = memstat_get_count(mtp);
139c8e6b689SRobert Watson 	packet_bytes = memstat_get_bytes(mtp);
140c8e6b689SRobert Watson 	packet_free = memstat_get_free(mtp);
141504a74faSAlfred Perlstein 	packet_sleeps = memstat_get_sleeps(mtp);
142c8e6b689SRobert Watson 	packet_failures = memstat_get_failures(mtp);
143c8e6b689SRobert Watson 
144c8e6b689SRobert Watson 	mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_CLUSTER_MEM_NAME);
145c8e6b689SRobert Watson 	if (mtp == NULL) {
146*ade9ccfeSMarcel Moolenaar 		xo_warnx("memstat_mtl_find: zone %s not found",
147c8e6b689SRobert Watson 		    MBUF_CLUSTER_MEM_NAME);
148c8e6b689SRobert Watson 		goto out;
149c8e6b689SRobert Watson 	}
150c8e6b689SRobert Watson 	cluster_count = memstat_get_count(mtp);
151c8e6b689SRobert Watson 	cluster_limit = memstat_get_countlimit(mtp);
152c8e6b689SRobert Watson 	cluster_free = memstat_get_free(mtp);
153c8e6b689SRobert Watson 	cluster_failures = memstat_get_failures(mtp);
154504a74faSAlfred Perlstein 	cluster_sleeps = memstat_get_sleeps(mtp);
155c8e6b689SRobert Watson 	cluster_size = memstat_get_size(mtp);
156c8e6b689SRobert Watson 
157c8e6b689SRobert Watson 	mtp = memstat_mtl_find(mtlp, ALLOCATOR_MALLOC, MBUF_TAG_MEM_NAME);
158c8e6b689SRobert Watson 	if (mtp == NULL) {
159*ade9ccfeSMarcel Moolenaar 		xo_warnx("memstat_mtl_find: malloc type %s not found",
160c8e6b689SRobert Watson 		    MBUF_TAG_MEM_NAME);
161c8e6b689SRobert Watson 		goto out;
162c8e6b689SRobert Watson 	}
163c8e6b689SRobert Watson 	tag_bytes = memstat_get_bytes(mtp);
164c8e6b689SRobert Watson 
1652b22cf9cSAndre Oppermann 	mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_JUMBOP_MEM_NAME);
1662b22cf9cSAndre Oppermann 	if (mtp == NULL) {
167*ade9ccfeSMarcel Moolenaar 		xo_warnx("memstat_mtl_find: zone %s not found",
1682b22cf9cSAndre Oppermann 		    MBUF_JUMBOP_MEM_NAME);
1692b22cf9cSAndre Oppermann 		goto out;
1702b22cf9cSAndre Oppermann 	}
1712b22cf9cSAndre Oppermann 	jumbop_count = memstat_get_count(mtp);
1722b22cf9cSAndre Oppermann 	jumbop_limit = memstat_get_countlimit(mtp);
1732b22cf9cSAndre Oppermann 	jumbop_free = memstat_get_free(mtp);
1742b22cf9cSAndre Oppermann 	jumbop_failures = memstat_get_failures(mtp);
175504a74faSAlfred Perlstein 	jumbop_sleeps = memstat_get_sleeps(mtp);
1762b22cf9cSAndre Oppermann 	jumbop_size = memstat_get_size(mtp);
1772b22cf9cSAndre Oppermann 
1782b22cf9cSAndre Oppermann 	mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_JUMBO9_MEM_NAME);
1792b22cf9cSAndre Oppermann 	if (mtp == NULL) {
180*ade9ccfeSMarcel Moolenaar 		xo_warnx("memstat_mtl_find: zone %s not found",
1812b22cf9cSAndre Oppermann 		    MBUF_JUMBO9_MEM_NAME);
1822b22cf9cSAndre Oppermann 		goto out;
1832b22cf9cSAndre Oppermann 	}
1842b22cf9cSAndre Oppermann 	jumbo9_count = memstat_get_count(mtp);
1852b22cf9cSAndre Oppermann 	jumbo9_limit = memstat_get_countlimit(mtp);
1862b22cf9cSAndre Oppermann 	jumbo9_free = memstat_get_free(mtp);
1872b22cf9cSAndre Oppermann 	jumbo9_failures = memstat_get_failures(mtp);
188504a74faSAlfred Perlstein 	jumbo9_sleeps = memstat_get_sleeps(mtp);
1892b22cf9cSAndre Oppermann 	jumbo9_size = memstat_get_size(mtp);
1902b22cf9cSAndre Oppermann 
1912b22cf9cSAndre Oppermann 	mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_JUMBO16_MEM_NAME);
1922b22cf9cSAndre Oppermann 	if (mtp == NULL) {
193*ade9ccfeSMarcel Moolenaar 		xo_warnx("memstat_mtl_find: zone %s not found",
1942b22cf9cSAndre Oppermann 		    MBUF_JUMBO16_MEM_NAME);
1952b22cf9cSAndre Oppermann 		goto out;
1962b22cf9cSAndre Oppermann 	}
1972b22cf9cSAndre Oppermann 	jumbo16_count = memstat_get_count(mtp);
1982b22cf9cSAndre Oppermann 	jumbo16_limit = memstat_get_countlimit(mtp);
1992b22cf9cSAndre Oppermann 	jumbo16_free = memstat_get_free(mtp);
2002b22cf9cSAndre Oppermann 	jumbo16_failures = memstat_get_failures(mtp);
201504a74faSAlfred Perlstein 	jumbo16_sleeps = memstat_get_sleeps(mtp);
2022b22cf9cSAndre Oppermann 	jumbo16_size = memstat_get_size(mtp);
2032b22cf9cSAndre Oppermann 
204*ade9ccfeSMarcel Moolenaar 	xo_open_container("mbuf-statistics");
205*ade9ccfeSMarcel Moolenaar 
206*ade9ccfeSMarcel Moolenaar 	xo_emit("{:mbuf-current/%ju}/{:mbuf-cache/%ju}/{:mbuf-total/%ju} "
207*ade9ccfeSMarcel Moolenaar 	    "{N:mbufs in use (current\\/cache\\/total)}\n",
208c8e6b689SRobert Watson 	    mbuf_count + packet_count, mbuf_free + packet_free,
209c8e6b689SRobert Watson 	    mbuf_count + packet_count + mbuf_free + packet_free);
210c8e6b689SRobert Watson 
211*ade9ccfeSMarcel Moolenaar 	xo_emit("{:cluster-current/%ju}/{:cluster-cache/%ju}/"
212*ade9ccfeSMarcel Moolenaar 	    "{:cluster-total/%ju}/{:cluster-max/%ju} "
213*ade9ccfeSMarcel Moolenaar 	    "{N:mbuf clusters in use (current\\/cache\\/total\\/max)}\n",
214c8e6b689SRobert Watson 	    cluster_count - packet_free, cluster_free + packet_free,
215c8e6b689SRobert Watson 	    cluster_count + cluster_free, cluster_limit);
216c8e6b689SRobert Watson 
217*ade9ccfeSMarcel Moolenaar 	xo_emit("{:packet-count/%ju}/{:packet-free/%ju} "
218*ade9ccfeSMarcel Moolenaar 	    "{N:mbuf+clusters out of packet secondary zone in use "
219*ade9ccfeSMarcel Moolenaar 	    "(current\\/cache)}\n",
2201434cbd6SAndre Oppermann 	    packet_count, packet_free);
2211434cbd6SAndre Oppermann 
222*ade9ccfeSMarcel Moolenaar 	xo_emit("{:jumbo-count/%ju}/{:jumbo-cache/%ju}/{:jumbo-total/%ju}/"
223*ade9ccfeSMarcel Moolenaar 	    "{:jumbo-max/%ju} {:jumbo-page-size/%ju}{U:k} {N:(page size)} "
224*ade9ccfeSMarcel Moolenaar 	    "{N:jumbo clusters in use (current\\/cache\\/total\\/max)}\n",
2252b22cf9cSAndre Oppermann 	    jumbop_count, jumbop_free, jumbop_count + jumbop_free,
2262b22cf9cSAndre Oppermann 	    jumbop_limit, jumbop_size / 1024);
2272b22cf9cSAndre Oppermann 
228*ade9ccfeSMarcel Moolenaar 	xo_emit("{:jumbo9-count/%ju}/{:jumbo9-cache/%ju}/"
229*ade9ccfeSMarcel Moolenaar 	    "{:jumbo9-total/%ju}/{:jumbo9-max/%ju} "
230*ade9ccfeSMarcel Moolenaar 	    "{N:9k jumbo clusters in use (current\\/cache\\/total\\/max)}\n",
2312b22cf9cSAndre Oppermann 	    jumbo9_count, jumbo9_free, jumbo9_count + jumbo9_free,
2322b22cf9cSAndre Oppermann 	    jumbo9_limit);
2332b22cf9cSAndre Oppermann 
234*ade9ccfeSMarcel Moolenaar 	xo_emit("{:jumbo16-count/%ju}/{:jumbo16-cache/%ju}/"
235*ade9ccfeSMarcel Moolenaar 	    "{:jumbo16-total/%ju}/{:jumbo16-limit/%ju} "
236*ade9ccfeSMarcel Moolenaar 	    "{N:16k jumbo clusters in use (current\\/cache\\/total\\/max)}\n",
2372b22cf9cSAndre Oppermann 	    jumbo16_count, jumbo16_free, jumbo16_count + jumbo16_free,
2382b22cf9cSAndre Oppermann 	    jumbo16_limit);
2392b22cf9cSAndre Oppermann 
240c8e6b689SRobert Watson #if 0
241*ade9ccfeSMarcel Moolenaar 	xo_emit("{:tag-count/%ju} {N:mbuf tags in use}\n", tag_count);
242c8e6b689SRobert Watson #endif
243c8e6b689SRobert Watson 
244c8e6b689SRobert Watson 	/*-
245c8e6b689SRobert Watson 	 * Calculate in-use bytes as:
246c8e6b689SRobert Watson 	 * - straight mbuf memory
247c8e6b689SRobert Watson 	 * - mbuf memory in packets
248c8e6b689SRobert Watson 	 * - the clusters attached to packets
249c8e6b689SRobert Watson 	 * - and the rest of the non-packet-attached clusters.
250c8e6b689SRobert Watson 	 * - m_tag memory
251c8e6b689SRobert Watson 	 * This avoids counting the clusters attached to packets in the cache.
252c8e6b689SRobert Watson 	 * This currently excludes sf_buf space.
253c8e6b689SRobert Watson 	 */
254c8e6b689SRobert Watson 	bytes_inuse =
255c8e6b689SRobert Watson 	    mbuf_bytes +			/* straight mbuf memory */
256c8e6b689SRobert Watson 	    packet_bytes +			/* mbufs in packets */
257c8e6b689SRobert Watson 	    (packet_count * cluster_size) +	/* clusters in packets */
258c8e6b689SRobert Watson 	    /* other clusters */
259c8e6b689SRobert Watson 	    ((cluster_count - packet_count - packet_free) * cluster_size) +
2602b22cf9cSAndre Oppermann 	    tag_bytes +
2612b22cf9cSAndre Oppermann 	    (jumbop_count * jumbop_size) +	/* jumbo clusters */
2622b22cf9cSAndre Oppermann 	    (jumbo9_count * jumbo9_size) +
2632b22cf9cSAndre Oppermann 	    (jumbo16_count * jumbo16_size);
264c8e6b689SRobert Watson 
265c8e6b689SRobert Watson 	/*
266c8e6b689SRobert Watson 	 * Calculate in-cache bytes as:
267c8e6b689SRobert Watson 	 * - cached straught mbufs
268c8e6b689SRobert Watson 	 * - cached packet mbufs
269c8e6b689SRobert Watson 	 * - cached packet clusters
270c8e6b689SRobert Watson 	 * - cached straight clusters
271c8e6b689SRobert Watson 	 * This currently excludes sf_buf space.
272c8e6b689SRobert Watson 	 */
273c8e6b689SRobert Watson 	bytes_incache =
274c8e6b689SRobert Watson 	    (mbuf_free * mbuf_size) +		/* straight free mbufs */
275c8e6b689SRobert Watson 	    (packet_free * mbuf_size) +		/* mbufs in free packets */
276c8e6b689SRobert Watson 	    (packet_free * cluster_size) +	/* clusters in free packets */
2772b22cf9cSAndre Oppermann 	    (cluster_free * cluster_size) +	/* free clusters */
2782b22cf9cSAndre Oppermann 	    (jumbop_free * jumbop_size) +	/* jumbo clusters */
2792b22cf9cSAndre Oppermann 	    (jumbo9_free * jumbo9_size) +
2802b22cf9cSAndre Oppermann 	    (jumbo16_free * jumbo16_size);
281c8e6b689SRobert Watson 
282c8e6b689SRobert Watson 	/*
283c8e6b689SRobert Watson 	 * Total is bytes in use + bytes in cache.  This doesn't take into
284c8e6b689SRobert Watson 	 * account various other misc data structures, overhead, etc, but
285c8e6b689SRobert Watson 	 * gives the user something useful despite that.
286c8e6b689SRobert Watson 	 */
287c8e6b689SRobert Watson 	bytes_total = bytes_inuse + bytes_incache;
288c8e6b689SRobert Watson 
289*ade9ccfeSMarcel Moolenaar 	xo_emit("{:bytes-in-use/%ju}{U:K}/{:bytes-in-cache/%ju}{U:K}/"
290*ade9ccfeSMarcel Moolenaar 	    "{:bytes-total/%ju}{U:K} "
291*ade9ccfeSMarcel Moolenaar 	    "{N:bytes allocated to network (current\\/cache\\/total)}\n",
292*ade9ccfeSMarcel Moolenaar 	    bytes_inuse / 1024, bytes_incache / 1024, bytes_total / 1024);
293c8e6b689SRobert Watson 
294*ade9ccfeSMarcel Moolenaar 	xo_emit("{:mbuf-failures/%ju}/{:cluster-failures/%ju}/"
295*ade9ccfeSMarcel Moolenaar 	    "{:packet-failures/%ju} {N:requests for mbufs denied "
296*ade9ccfeSMarcel Moolenaar 	    "(mbufs\\/clusters\\/mbuf+clusters)}\n",
297*ade9ccfeSMarcel Moolenaar 	    mbuf_failures, cluster_failures, packet_failures);
298*ade9ccfeSMarcel Moolenaar 	xo_emit("{:mbuf-sleeps/%ju}/{:cluster-sleeps/%ju}/{:packet-sleeps/%ju} "
299*ade9ccfeSMarcel Moolenaar 	    "{N:requests for mbufs delayed "
300*ade9ccfeSMarcel Moolenaar 	    "(mbufs\\/clusters\\/mbuf+clusters)}\n",
301*ade9ccfeSMarcel Moolenaar 	    mbuf_sleeps, cluster_sleeps, packet_sleeps);
302c8e6b689SRobert Watson 
303*ade9ccfeSMarcel Moolenaar 	xo_emit("{:jumbop-sleeps/%ju}/{:jumbo9-sleeps/%ju}/"
304*ade9ccfeSMarcel Moolenaar 	    "{:jumbo16-sleeps/%ju} {N:/requests for jumbo clusters delayed "
305*ade9ccfeSMarcel Moolenaar 	    "(%juk\\/9k\\/16k)}\n",
306*ade9ccfeSMarcel Moolenaar 	    jumbop_sleeps, jumbo9_sleeps, jumbo16_sleeps, jumbop_size / 1024);
307*ade9ccfeSMarcel Moolenaar 	xo_emit("{:jumbop-failures/%ju}/{:jumbo9-failures/%ju}/"
308*ade9ccfeSMarcel Moolenaar 	    "{:jumbo16-failures/%ju} {N:/requests for jumbo clusters denied "
309*ade9ccfeSMarcel Moolenaar 	    "(%juk\\/9k\\/16k)}\n",
310*ade9ccfeSMarcel Moolenaar 	    jumbop_failures, jumbo9_failures, jumbo16_failures,
311*ade9ccfeSMarcel Moolenaar 	    jumbop_size / 1024);
3122b22cf9cSAndre Oppermann 
313d4426f28SRobert Watson 	if (live) {
314dd8dfa82SRobert Watson 		mlen = sizeof(nsfbufs);
315dd8dfa82SRobert Watson 		if (!sysctlbyname("kern.ipc.nsfbufs", &nsfbufs, &mlen, NULL,
316dd8dfa82SRobert Watson 		    0) &&
317dd8dfa82SRobert Watson 		    !sysctlbyname("kern.ipc.nsfbufsused", &nsfbufsused,
318dd8dfa82SRobert Watson 		    &mlen, NULL, 0) &&
319dd8dfa82SRobert Watson 		    !sysctlbyname("kern.ipc.nsfbufspeak", &nsfbufspeak,
320dd8dfa82SRobert Watson 		    &mlen, NULL, 0))
321*ade9ccfeSMarcel Moolenaar 			xo_emit("{:nsfbufs-current/%d}/{:nsfbufs-peak/%d}/"
322*ade9ccfeSMarcel Moolenaar 			    "{:nsfbufs/%d} "
323*ade9ccfeSMarcel Moolenaar 			    "{N:sfbufs in use (current\\/peak\\/max)}\n",
324dd8dfa82SRobert Watson 			    nsfbufsused, nsfbufspeak, nsfbufs);
32505d1f5bcSAndrey V. Elsukov 		mlen = sizeof(sfstat);
32605d1f5bcSAndrey V. Elsukov 		if (sysctlbyname("kern.ipc.sfstat", &sfstat, &mlen, NULL, 0)) {
327*ade9ccfeSMarcel Moolenaar 			xo_warn("kern.ipc.sfstat");
328d4426f28SRobert Watson 			goto out;
329d4426f28SRobert Watson 		}
330d4426f28SRobert Watson 	} else {
33105d1f5bcSAndrey V. Elsukov 		if (kread_counters(mbaddr, (char *)&sfstat, sizeof sfstat) != 0)
332d4426f28SRobert Watson 			goto out;
333d4426f28SRobert Watson 	}
334*ade9ccfeSMarcel Moolenaar 	xo_emit("{:sfbufs-alloc-failed/%ju} {N:requests for sfbufs denied}\n",
33505d1f5bcSAndrey V. Elsukov 	    (uintmax_t)sfstat.sf_allocfail);
336*ade9ccfeSMarcel Moolenaar 	xo_emit("{:sfbufs-alloc-wait/%ju} {N:requests for sfbufs delayed}\n",
33705d1f5bcSAndrey V. Elsukov 	    (uintmax_t)sfstat.sf_allocwait);
338*ade9ccfeSMarcel Moolenaar 	xo_emit("{:sfbufs-io-count/%ju} "
339*ade9ccfeSMarcel Moolenaar 	    "{N:requests for I\\/O initiated by sendfile}\n",
34005d1f5bcSAndrey V. Elsukov 	    (uintmax_t)sfstat.sf_iocnt);
341c8e6b689SRobert Watson out:
342*ade9ccfeSMarcel Moolenaar 	xo_close_container("mbuf-statistics");
343c8e6b689SRobert Watson 	memstat_mtl_free(mtlp);
344c8e6b689SRobert Watson }
345