xref: /f-stack/tools/libmemstat/memstat.c (revision d4a07e70)
11eaf0ac3Slogwang /*-
222ce4affSfengbojiang  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
322ce4affSfengbojiang  *
41eaf0ac3Slogwang  * Copyright (c) 2005 Robert N. M. Watson
51eaf0ac3Slogwang  * All rights reserved.
61eaf0ac3Slogwang  *
71eaf0ac3Slogwang  * Redistribution and use in source and binary forms, with or without
81eaf0ac3Slogwang  * modification, are permitted provided that the following conditions
91eaf0ac3Slogwang  * are met:
101eaf0ac3Slogwang  * 1. Redistributions of source code must retain the above copyright
111eaf0ac3Slogwang  *    notice, this list of conditions and the following disclaimer.
121eaf0ac3Slogwang  * 2. Redistributions in binary form must reproduce the above copyright
131eaf0ac3Slogwang  *    notice, this list of conditions and the following disclaimer in the
141eaf0ac3Slogwang  *    documentation and/or other materials provided with the distribution.
151eaf0ac3Slogwang  *
161eaf0ac3Slogwang  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
171eaf0ac3Slogwang  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
181eaf0ac3Slogwang  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
191eaf0ac3Slogwang  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
201eaf0ac3Slogwang  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
211eaf0ac3Slogwang  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
221eaf0ac3Slogwang  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
231eaf0ac3Slogwang  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
241eaf0ac3Slogwang  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
251eaf0ac3Slogwang  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
261eaf0ac3Slogwang  * SUCH DAMAGE.
271eaf0ac3Slogwang  *
281eaf0ac3Slogwang  * $FreeBSD$
291eaf0ac3Slogwang  */
301eaf0ac3Slogwang 
311eaf0ac3Slogwang #include <sys/param.h>
3222ce4affSfengbojiang #include <sys/queue.h>
331eaf0ac3Slogwang #include <sys/sysctl.h>
341eaf0ac3Slogwang 
351eaf0ac3Slogwang #include <err.h>
361eaf0ac3Slogwang #include <errno.h>
371eaf0ac3Slogwang #include <stdio.h>
381eaf0ac3Slogwang #include <stdlib.h>
391eaf0ac3Slogwang #include <string.h>
401eaf0ac3Slogwang 
41*d4a07e70Sfengbojiang #ifdef FSTACK
42*d4a07e70Sfengbojiang #include <stdint.h>
43*d4a07e70Sfengbojiang #endif
44*d4a07e70Sfengbojiang 
451eaf0ac3Slogwang #include "memstat.h"
461eaf0ac3Slogwang #include "memstat_internal.h"
471eaf0ac3Slogwang 
481eaf0ac3Slogwang const char *
memstat_strerror(int error)491eaf0ac3Slogwang memstat_strerror(int error)
501eaf0ac3Slogwang {
511eaf0ac3Slogwang 
521eaf0ac3Slogwang 	switch (error) {
531eaf0ac3Slogwang 	case MEMSTAT_ERROR_NOMEMORY:
541eaf0ac3Slogwang 		return ("Cannot allocate memory");
551eaf0ac3Slogwang 	case MEMSTAT_ERROR_VERSION:
561eaf0ac3Slogwang 		return ("Version mismatch");
571eaf0ac3Slogwang 	case MEMSTAT_ERROR_PERMISSION:
581eaf0ac3Slogwang 		return ("Permission denied");
591eaf0ac3Slogwang 	case MEMSTAT_ERROR_DATAERROR:
601eaf0ac3Slogwang 		return ("Data format error");
611eaf0ac3Slogwang 	case MEMSTAT_ERROR_KVM:
621eaf0ac3Slogwang 		return ("KVM error");
631eaf0ac3Slogwang 	case MEMSTAT_ERROR_KVM_NOSYMBOL:
641eaf0ac3Slogwang 		return ("KVM unable to find symbol");
651eaf0ac3Slogwang 	case MEMSTAT_ERROR_KVM_SHORTREAD:
661eaf0ac3Slogwang 		return ("KVM short read");
671eaf0ac3Slogwang 	case MEMSTAT_ERROR_UNDEFINED:
681eaf0ac3Slogwang 	default:
691eaf0ac3Slogwang 		return ("Unknown error");
701eaf0ac3Slogwang 	}
711eaf0ac3Slogwang }
721eaf0ac3Slogwang 
731eaf0ac3Slogwang struct memory_type_list *
memstat_mtl_alloc(void)741eaf0ac3Slogwang memstat_mtl_alloc(void)
751eaf0ac3Slogwang {
761eaf0ac3Slogwang 	struct memory_type_list *mtlp;
771eaf0ac3Slogwang 
781eaf0ac3Slogwang 	mtlp = malloc(sizeof(*mtlp));
791eaf0ac3Slogwang 	if (mtlp == NULL)
801eaf0ac3Slogwang 		return (NULL);
811eaf0ac3Slogwang 
821eaf0ac3Slogwang 	LIST_INIT(&mtlp->mtl_list);
831eaf0ac3Slogwang 	mtlp->mtl_error = MEMSTAT_ERROR_UNDEFINED;
841eaf0ac3Slogwang 	return (mtlp);
851eaf0ac3Slogwang }
861eaf0ac3Slogwang 
871eaf0ac3Slogwang struct memory_type *
memstat_mtl_first(struct memory_type_list * list)881eaf0ac3Slogwang memstat_mtl_first(struct memory_type_list *list)
891eaf0ac3Slogwang {
901eaf0ac3Slogwang 
911eaf0ac3Slogwang 	return (LIST_FIRST(&list->mtl_list));
921eaf0ac3Slogwang }
931eaf0ac3Slogwang 
941eaf0ac3Slogwang struct memory_type *
memstat_mtl_next(struct memory_type * mtp)951eaf0ac3Slogwang memstat_mtl_next(struct memory_type *mtp)
961eaf0ac3Slogwang {
971eaf0ac3Slogwang 
981eaf0ac3Slogwang 	return (LIST_NEXT(mtp, mt_list));
991eaf0ac3Slogwang }
1001eaf0ac3Slogwang 
1011eaf0ac3Slogwang void
_memstat_mtl_empty(struct memory_type_list * list)1021eaf0ac3Slogwang _memstat_mtl_empty(struct memory_type_list *list)
1031eaf0ac3Slogwang {
1041eaf0ac3Slogwang 	struct memory_type *mtp;
1051eaf0ac3Slogwang 
1061eaf0ac3Slogwang 	while ((mtp = LIST_FIRST(&list->mtl_list))) {
1071eaf0ac3Slogwang 		free(mtp->mt_percpu_alloc);
1081eaf0ac3Slogwang 		free(mtp->mt_percpu_cache);
1091eaf0ac3Slogwang 		LIST_REMOVE(mtp, mt_list);
1101eaf0ac3Slogwang 		free(mtp);
1111eaf0ac3Slogwang 	}
1121eaf0ac3Slogwang }
1131eaf0ac3Slogwang 
1141eaf0ac3Slogwang void
memstat_mtl_free(struct memory_type_list * list)1151eaf0ac3Slogwang memstat_mtl_free(struct memory_type_list *list)
1161eaf0ac3Slogwang {
1171eaf0ac3Slogwang 
1181eaf0ac3Slogwang 	_memstat_mtl_empty(list);
1191eaf0ac3Slogwang 	free(list);
1201eaf0ac3Slogwang }
1211eaf0ac3Slogwang 
1221eaf0ac3Slogwang int
memstat_mtl_geterror(struct memory_type_list * list)1231eaf0ac3Slogwang memstat_mtl_geterror(struct memory_type_list *list)
1241eaf0ac3Slogwang {
1251eaf0ac3Slogwang 
1261eaf0ac3Slogwang 	return (list->mtl_error);
1271eaf0ac3Slogwang }
1281eaf0ac3Slogwang 
1291eaf0ac3Slogwang /*
1301eaf0ac3Slogwang  * Look for an existing memory_type entry in a memory_type list, based on the
1311eaf0ac3Slogwang  * allocator and name of the type.  If not found, return NULL.  No errno or
1321eaf0ac3Slogwang  * memstat error.
1331eaf0ac3Slogwang  */
1341eaf0ac3Slogwang struct memory_type *
memstat_mtl_find(struct memory_type_list * list,int allocator,const char * name)1351eaf0ac3Slogwang memstat_mtl_find(struct memory_type_list *list, int allocator,
1361eaf0ac3Slogwang     const char *name)
1371eaf0ac3Slogwang {
1381eaf0ac3Slogwang 	struct memory_type *mtp;
1391eaf0ac3Slogwang 
1401eaf0ac3Slogwang 	LIST_FOREACH(mtp, &list->mtl_list, mt_list) {
1411eaf0ac3Slogwang 		if ((mtp->mt_allocator == allocator ||
1421eaf0ac3Slogwang 		    allocator == ALLOCATOR_ANY) &&
1431eaf0ac3Slogwang 		    strcmp(mtp->mt_name, name) == 0)
1441eaf0ac3Slogwang 			return (mtp);
1451eaf0ac3Slogwang 	}
1461eaf0ac3Slogwang 	return (NULL);
1471eaf0ac3Slogwang }
1481eaf0ac3Slogwang 
1491eaf0ac3Slogwang /*
1501eaf0ac3Slogwang  * Allocate a new memory_type with the specificed allocator type and name,
1511eaf0ac3Slogwang  * then insert into the list.  The structure will be zero'd.
1521eaf0ac3Slogwang  *
1531eaf0ac3Slogwang  * libmemstat(3) internal function.
1541eaf0ac3Slogwang  */
1551eaf0ac3Slogwang struct memory_type *
_memstat_mt_allocate(struct memory_type_list * list,int allocator,const char * name,int maxcpus)1561eaf0ac3Slogwang _memstat_mt_allocate(struct memory_type_list *list, int allocator,
1571eaf0ac3Slogwang     const char *name, int maxcpus)
1581eaf0ac3Slogwang {
1591eaf0ac3Slogwang 	struct memory_type *mtp;
1601eaf0ac3Slogwang 
1611eaf0ac3Slogwang 	mtp = malloc(sizeof(*mtp));
1621eaf0ac3Slogwang 	if (mtp == NULL)
1631eaf0ac3Slogwang 		return (NULL);
1641eaf0ac3Slogwang 
1651eaf0ac3Slogwang 	bzero(mtp, sizeof(*mtp));
1661eaf0ac3Slogwang 
1671eaf0ac3Slogwang 	mtp->mt_allocator = allocator;
1681eaf0ac3Slogwang 	mtp->mt_percpu_alloc = malloc(sizeof(struct mt_percpu_alloc_s) *
1691eaf0ac3Slogwang 	    maxcpus);
1701eaf0ac3Slogwang 	mtp->mt_percpu_cache = malloc(sizeof(struct mt_percpu_cache_s) *
1711eaf0ac3Slogwang 	    maxcpus);
1721eaf0ac3Slogwang 	strlcpy(mtp->mt_name, name, MEMTYPE_MAXNAME);
1731eaf0ac3Slogwang 	LIST_INSERT_HEAD(&list->mtl_list, mtp, mt_list);
1741eaf0ac3Slogwang 	return (mtp);
1751eaf0ac3Slogwang }
1761eaf0ac3Slogwang 
1771eaf0ac3Slogwang /*
1781eaf0ac3Slogwang  * Reset any libmemstat(3)-owned statistics in a memory_type record so that
1791eaf0ac3Slogwang  * it can be reused without incremental addition problems.  Caller-owned
1801eaf0ac3Slogwang  * memory is left "as-is", and must be updated by the caller if desired.
1811eaf0ac3Slogwang  *
1821eaf0ac3Slogwang  * libmemstat(3) internal function.
1831eaf0ac3Slogwang  */
1841eaf0ac3Slogwang void
_memstat_mt_reset_stats(struct memory_type * mtp,int maxcpus)1851eaf0ac3Slogwang _memstat_mt_reset_stats(struct memory_type *mtp, int maxcpus)
1861eaf0ac3Slogwang {
1871eaf0ac3Slogwang 	int i;
1881eaf0ac3Slogwang 
1891eaf0ac3Slogwang 	mtp->mt_countlimit = 0;
1901eaf0ac3Slogwang 	mtp->mt_byteslimit = 0;
1911eaf0ac3Slogwang 	mtp->mt_sizemask = 0;
1921eaf0ac3Slogwang 	mtp->mt_size = 0;
1931eaf0ac3Slogwang 
1941eaf0ac3Slogwang 	mtp->mt_memalloced = 0;
1951eaf0ac3Slogwang 	mtp->mt_memfreed = 0;
1961eaf0ac3Slogwang 	mtp->mt_numallocs = 0;
1971eaf0ac3Slogwang 	mtp->mt_numfrees = 0;
1981eaf0ac3Slogwang 	mtp->mt_bytes = 0;
1991eaf0ac3Slogwang 	mtp->mt_count = 0;
2001eaf0ac3Slogwang 	mtp->mt_free = 0;
2011eaf0ac3Slogwang 	mtp->mt_failures = 0;
2021eaf0ac3Slogwang 	mtp->mt_sleeps = 0;
2031eaf0ac3Slogwang 
2041eaf0ac3Slogwang 	mtp->mt_zonefree = 0;
2051eaf0ac3Slogwang 	mtp->mt_kegfree = 0;
2061eaf0ac3Slogwang 
2071eaf0ac3Slogwang 	for (i = 0; i < maxcpus; i++) {
2081eaf0ac3Slogwang 		mtp->mt_percpu_alloc[i].mtp_memalloced = 0;
2091eaf0ac3Slogwang 		mtp->mt_percpu_alloc[i].mtp_memfreed = 0;
2101eaf0ac3Slogwang 		mtp->mt_percpu_alloc[i].mtp_numallocs = 0;
2111eaf0ac3Slogwang 		mtp->mt_percpu_alloc[i].mtp_numfrees = 0;
2121eaf0ac3Slogwang 		mtp->mt_percpu_alloc[i].mtp_sizemask = 0;
2131eaf0ac3Slogwang 		mtp->mt_percpu_cache[i].mtp_free = 0;
2141eaf0ac3Slogwang 	}
2151eaf0ac3Slogwang }
2161eaf0ac3Slogwang 
2171eaf0ac3Slogwang /*
2181eaf0ac3Slogwang  * Accessor methods for struct memory_type.  Avoids encoding the structure
2191eaf0ac3Slogwang  * ABI into the application.
2201eaf0ac3Slogwang  */
2211eaf0ac3Slogwang const char *
memstat_get_name(const struct memory_type * mtp)2221eaf0ac3Slogwang memstat_get_name(const struct memory_type *mtp)
2231eaf0ac3Slogwang {
2241eaf0ac3Slogwang 
2251eaf0ac3Slogwang 	return (mtp->mt_name);
2261eaf0ac3Slogwang }
2271eaf0ac3Slogwang 
2281eaf0ac3Slogwang int
memstat_get_allocator(const struct memory_type * mtp)2291eaf0ac3Slogwang memstat_get_allocator(const struct memory_type *mtp)
2301eaf0ac3Slogwang {
2311eaf0ac3Slogwang 
2321eaf0ac3Slogwang 	return (mtp->mt_allocator);
2331eaf0ac3Slogwang }
2341eaf0ac3Slogwang 
2351eaf0ac3Slogwang uint64_t
memstat_get_countlimit(const struct memory_type * mtp)2361eaf0ac3Slogwang memstat_get_countlimit(const struct memory_type *mtp)
2371eaf0ac3Slogwang {
2381eaf0ac3Slogwang 
2391eaf0ac3Slogwang 	return (mtp->mt_countlimit);
2401eaf0ac3Slogwang }
2411eaf0ac3Slogwang 
2421eaf0ac3Slogwang uint64_t
memstat_get_byteslimit(const struct memory_type * mtp)2431eaf0ac3Slogwang memstat_get_byteslimit(const struct memory_type *mtp)
2441eaf0ac3Slogwang {
2451eaf0ac3Slogwang 
2461eaf0ac3Slogwang 	return (mtp->mt_byteslimit);
2471eaf0ac3Slogwang }
2481eaf0ac3Slogwang 
2491eaf0ac3Slogwang uint64_t
memstat_get_sizemask(const struct memory_type * mtp)2501eaf0ac3Slogwang memstat_get_sizemask(const struct memory_type *mtp)
2511eaf0ac3Slogwang {
2521eaf0ac3Slogwang 
2531eaf0ac3Slogwang 	return (mtp->mt_sizemask);
2541eaf0ac3Slogwang }
2551eaf0ac3Slogwang 
2561eaf0ac3Slogwang uint64_t
memstat_get_size(const struct memory_type * mtp)2571eaf0ac3Slogwang memstat_get_size(const struct memory_type *mtp)
2581eaf0ac3Slogwang {
2591eaf0ac3Slogwang 
2601eaf0ac3Slogwang 	return (mtp->mt_size);
2611eaf0ac3Slogwang }
2621eaf0ac3Slogwang 
2631eaf0ac3Slogwang uint64_t
memstat_get_rsize(const struct memory_type * mtp)2641eaf0ac3Slogwang memstat_get_rsize(const struct memory_type *mtp)
2651eaf0ac3Slogwang {
2661eaf0ac3Slogwang 
2671eaf0ac3Slogwang 	return (mtp->mt_rsize);
2681eaf0ac3Slogwang }
2691eaf0ac3Slogwang 
2701eaf0ac3Slogwang uint64_t
memstat_get_memalloced(const struct memory_type * mtp)2711eaf0ac3Slogwang memstat_get_memalloced(const struct memory_type *mtp)
2721eaf0ac3Slogwang {
2731eaf0ac3Slogwang 
2741eaf0ac3Slogwang 	return (mtp->mt_memalloced);
2751eaf0ac3Slogwang }
2761eaf0ac3Slogwang 
2771eaf0ac3Slogwang uint64_t
memstat_get_memfreed(const struct memory_type * mtp)2781eaf0ac3Slogwang memstat_get_memfreed(const struct memory_type *mtp)
2791eaf0ac3Slogwang {
2801eaf0ac3Slogwang 
2811eaf0ac3Slogwang 	return (mtp->mt_memfreed);
2821eaf0ac3Slogwang }
2831eaf0ac3Slogwang 
2841eaf0ac3Slogwang uint64_t
memstat_get_numallocs(const struct memory_type * mtp)2851eaf0ac3Slogwang memstat_get_numallocs(const struct memory_type *mtp)
2861eaf0ac3Slogwang {
2871eaf0ac3Slogwang 
2881eaf0ac3Slogwang 	return (mtp->mt_numallocs);
2891eaf0ac3Slogwang }
2901eaf0ac3Slogwang 
2911eaf0ac3Slogwang uint64_t
memstat_get_numfrees(const struct memory_type * mtp)2921eaf0ac3Slogwang memstat_get_numfrees(const struct memory_type *mtp)
2931eaf0ac3Slogwang {
2941eaf0ac3Slogwang 
2951eaf0ac3Slogwang 	return (mtp->mt_numfrees);
2961eaf0ac3Slogwang }
2971eaf0ac3Slogwang 
2981eaf0ac3Slogwang uint64_t
memstat_get_bytes(const struct memory_type * mtp)2991eaf0ac3Slogwang memstat_get_bytes(const struct memory_type *mtp)
3001eaf0ac3Slogwang {
3011eaf0ac3Slogwang 
3021eaf0ac3Slogwang 	return (mtp->mt_bytes);
3031eaf0ac3Slogwang }
3041eaf0ac3Slogwang 
3051eaf0ac3Slogwang uint64_t
memstat_get_count(const struct memory_type * mtp)3061eaf0ac3Slogwang memstat_get_count(const struct memory_type *mtp)
3071eaf0ac3Slogwang {
3081eaf0ac3Slogwang 
3091eaf0ac3Slogwang 	return (mtp->mt_count);
3101eaf0ac3Slogwang }
3111eaf0ac3Slogwang 
3121eaf0ac3Slogwang uint64_t
memstat_get_free(const struct memory_type * mtp)3131eaf0ac3Slogwang memstat_get_free(const struct memory_type *mtp)
3141eaf0ac3Slogwang {
3151eaf0ac3Slogwang 
3161eaf0ac3Slogwang 	return (mtp->mt_free);
3171eaf0ac3Slogwang }
3181eaf0ac3Slogwang 
3191eaf0ac3Slogwang uint64_t
memstat_get_failures(const struct memory_type * mtp)3201eaf0ac3Slogwang memstat_get_failures(const struct memory_type *mtp)
3211eaf0ac3Slogwang {
3221eaf0ac3Slogwang 
3231eaf0ac3Slogwang 	return (mtp->mt_failures);
3241eaf0ac3Slogwang }
3251eaf0ac3Slogwang 
3261eaf0ac3Slogwang uint64_t
memstat_get_sleeps(const struct memory_type * mtp)3271eaf0ac3Slogwang memstat_get_sleeps(const struct memory_type *mtp)
3281eaf0ac3Slogwang {
3291eaf0ac3Slogwang 
3301eaf0ac3Slogwang 	return (mtp->mt_sleeps);
3311eaf0ac3Slogwang }
3321eaf0ac3Slogwang 
33322ce4affSfengbojiang uint64_t
memstat_get_xdomain(const struct memory_type * mtp)33422ce4affSfengbojiang memstat_get_xdomain(const struct memory_type *mtp)
33522ce4affSfengbojiang {
33622ce4affSfengbojiang 
33722ce4affSfengbojiang 	return (mtp->mt_xdomain);
33822ce4affSfengbojiang }
33922ce4affSfengbojiang 
3401eaf0ac3Slogwang void *
memstat_get_caller_pointer(const struct memory_type * mtp,int index)3411eaf0ac3Slogwang memstat_get_caller_pointer(const struct memory_type *mtp, int index)
3421eaf0ac3Slogwang {
3431eaf0ac3Slogwang 
3441eaf0ac3Slogwang 	return (mtp->mt_caller_pointer[index]);
3451eaf0ac3Slogwang }
3461eaf0ac3Slogwang 
3471eaf0ac3Slogwang void
memstat_set_caller_pointer(struct memory_type * mtp,int index,void * value)3481eaf0ac3Slogwang memstat_set_caller_pointer(struct memory_type *mtp, int index, void *value)
3491eaf0ac3Slogwang {
3501eaf0ac3Slogwang 
3511eaf0ac3Slogwang 	mtp->mt_caller_pointer[index] = value;
3521eaf0ac3Slogwang }
3531eaf0ac3Slogwang 
3541eaf0ac3Slogwang uint64_t
memstat_get_caller_uint64(const struct memory_type * mtp,int index)3551eaf0ac3Slogwang memstat_get_caller_uint64(const struct memory_type *mtp, int index)
3561eaf0ac3Slogwang {
3571eaf0ac3Slogwang 
3581eaf0ac3Slogwang 	return (mtp->mt_caller_uint64[index]);
3591eaf0ac3Slogwang }
3601eaf0ac3Slogwang 
3611eaf0ac3Slogwang void
memstat_set_caller_uint64(struct memory_type * mtp,int index,uint64_t value)3621eaf0ac3Slogwang memstat_set_caller_uint64(struct memory_type *mtp, int index, uint64_t value)
3631eaf0ac3Slogwang {
3641eaf0ac3Slogwang 
3651eaf0ac3Slogwang 	mtp->mt_caller_uint64[index] = value;
3661eaf0ac3Slogwang }
3671eaf0ac3Slogwang 
3681eaf0ac3Slogwang uint64_t
memstat_get_zonefree(const struct memory_type * mtp)3691eaf0ac3Slogwang memstat_get_zonefree(const struct memory_type *mtp)
3701eaf0ac3Slogwang {
3711eaf0ac3Slogwang 
3721eaf0ac3Slogwang 	return (mtp->mt_zonefree);
3731eaf0ac3Slogwang }
3741eaf0ac3Slogwang 
3751eaf0ac3Slogwang uint64_t
memstat_get_kegfree(const struct memory_type * mtp)3761eaf0ac3Slogwang memstat_get_kegfree(const struct memory_type *mtp)
3771eaf0ac3Slogwang {
3781eaf0ac3Slogwang 
3791eaf0ac3Slogwang 	return (mtp->mt_kegfree);
3801eaf0ac3Slogwang }
3811eaf0ac3Slogwang 
3821eaf0ac3Slogwang uint64_t
memstat_get_percpu_memalloced(const struct memory_type * mtp,int cpu)3831eaf0ac3Slogwang memstat_get_percpu_memalloced(const struct memory_type *mtp, int cpu)
3841eaf0ac3Slogwang {
3851eaf0ac3Slogwang 
3861eaf0ac3Slogwang 	return (mtp->mt_percpu_alloc[cpu].mtp_memalloced);
3871eaf0ac3Slogwang }
3881eaf0ac3Slogwang 
3891eaf0ac3Slogwang uint64_t
memstat_get_percpu_memfreed(const struct memory_type * mtp,int cpu)3901eaf0ac3Slogwang memstat_get_percpu_memfreed(const struct memory_type *mtp, int cpu)
3911eaf0ac3Slogwang {
3921eaf0ac3Slogwang 
3931eaf0ac3Slogwang 	return (mtp->mt_percpu_alloc[cpu].mtp_memfreed);
3941eaf0ac3Slogwang }
3951eaf0ac3Slogwang 
3961eaf0ac3Slogwang uint64_t
memstat_get_percpu_numallocs(const struct memory_type * mtp,int cpu)3971eaf0ac3Slogwang memstat_get_percpu_numallocs(const struct memory_type *mtp, int cpu)
3981eaf0ac3Slogwang {
3991eaf0ac3Slogwang 
4001eaf0ac3Slogwang 	return (mtp->mt_percpu_alloc[cpu].mtp_numallocs);
4011eaf0ac3Slogwang }
4021eaf0ac3Slogwang 
4031eaf0ac3Slogwang uint64_t
memstat_get_percpu_numfrees(const struct memory_type * mtp,int cpu)4041eaf0ac3Slogwang memstat_get_percpu_numfrees(const struct memory_type *mtp, int cpu)
4051eaf0ac3Slogwang {
4061eaf0ac3Slogwang 
4071eaf0ac3Slogwang 	return (mtp->mt_percpu_alloc[cpu].mtp_numfrees);
4081eaf0ac3Slogwang }
4091eaf0ac3Slogwang 
4101eaf0ac3Slogwang uint64_t
memstat_get_percpu_sizemask(const struct memory_type * mtp,int cpu)4111eaf0ac3Slogwang memstat_get_percpu_sizemask(const struct memory_type *mtp, int cpu)
4121eaf0ac3Slogwang {
4131eaf0ac3Slogwang 
4141eaf0ac3Slogwang 	return (mtp->mt_percpu_alloc[cpu].mtp_sizemask);
4151eaf0ac3Slogwang }
4161eaf0ac3Slogwang 
4171eaf0ac3Slogwang void *
memstat_get_percpu_caller_pointer(const struct memory_type * mtp,int cpu,int index)4181eaf0ac3Slogwang memstat_get_percpu_caller_pointer(const struct memory_type *mtp, int cpu,
4191eaf0ac3Slogwang     int index)
4201eaf0ac3Slogwang {
4211eaf0ac3Slogwang 
4221eaf0ac3Slogwang 	return (mtp->mt_percpu_alloc[cpu].mtp_caller_pointer[index]);
4231eaf0ac3Slogwang }
4241eaf0ac3Slogwang 
4251eaf0ac3Slogwang void
memstat_set_percpu_caller_pointer(struct memory_type * mtp,int cpu,int index,void * value)4261eaf0ac3Slogwang memstat_set_percpu_caller_pointer(struct memory_type *mtp, int cpu,
4271eaf0ac3Slogwang     int index, void *value)
4281eaf0ac3Slogwang {
4291eaf0ac3Slogwang 
4301eaf0ac3Slogwang 	mtp->mt_percpu_alloc[cpu].mtp_caller_pointer[index] = value;
4311eaf0ac3Slogwang }
4321eaf0ac3Slogwang 
4331eaf0ac3Slogwang uint64_t
memstat_get_percpu_caller_uint64(const struct memory_type * mtp,int cpu,int index)4341eaf0ac3Slogwang memstat_get_percpu_caller_uint64(const struct memory_type *mtp, int cpu,
4351eaf0ac3Slogwang     int index)
4361eaf0ac3Slogwang {
4371eaf0ac3Slogwang 
4381eaf0ac3Slogwang 	return (mtp->mt_percpu_alloc[cpu].mtp_caller_uint64[index]);
4391eaf0ac3Slogwang }
4401eaf0ac3Slogwang 
4411eaf0ac3Slogwang void
memstat_set_percpu_caller_uint64(struct memory_type * mtp,int cpu,int index,uint64_t value)4421eaf0ac3Slogwang memstat_set_percpu_caller_uint64(struct memory_type *mtp, int cpu, int index,
4431eaf0ac3Slogwang     uint64_t value)
4441eaf0ac3Slogwang {
4451eaf0ac3Slogwang 
4461eaf0ac3Slogwang 	mtp->mt_percpu_alloc[cpu].mtp_caller_uint64[index] = value;
4471eaf0ac3Slogwang }
4481eaf0ac3Slogwang 
4491eaf0ac3Slogwang uint64_t
memstat_get_percpu_free(const struct memory_type * mtp,int cpu)4501eaf0ac3Slogwang memstat_get_percpu_free(const struct memory_type *mtp, int cpu)
4511eaf0ac3Slogwang {
4521eaf0ac3Slogwang 
4531eaf0ac3Slogwang 	return (mtp->mt_percpu_cache[cpu].mtp_free);
4541eaf0ac3Slogwang }
455