10cddce49SRobert Watson /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
35e53a4f9SPedro F. Giffuni *
40cddce49SRobert Watson * Copyright (c) 2005 Robert N. M. Watson
50cddce49SRobert Watson * All rights reserved.
60cddce49SRobert Watson *
70cddce49SRobert Watson * Redistribution and use in source and binary forms, with or without
80cddce49SRobert Watson * modification, are permitted provided that the following conditions
90cddce49SRobert Watson * are met:
100cddce49SRobert Watson * 1. Redistributions of source code must retain the above copyright
110cddce49SRobert Watson * notice, this list of conditions and the following disclaimer.
120cddce49SRobert Watson * 2. Redistributions in binary form must reproduce the above copyright
130cddce49SRobert Watson * notice, this list of conditions and the following disclaimer in the
140cddce49SRobert Watson * documentation and/or other materials provided with the distribution.
150cddce49SRobert Watson *
160cddce49SRobert Watson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
170cddce49SRobert Watson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
180cddce49SRobert Watson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
190cddce49SRobert Watson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
200cddce49SRobert Watson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
210cddce49SRobert Watson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
220cddce49SRobert Watson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
230cddce49SRobert Watson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
240cddce49SRobert Watson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
250cddce49SRobert Watson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
260cddce49SRobert Watson * SUCH DAMAGE.
270cddce49SRobert Watson */
280cddce49SRobert Watson
290cddce49SRobert Watson #include <sys/param.h>
306bff85ffSDag-Erling Smørgrav #include <sys/queue.h>
310cddce49SRobert Watson #include <sys/sysctl.h>
320cddce49SRobert Watson
330cddce49SRobert Watson #include <err.h>
340cddce49SRobert Watson #include <errno.h>
350cddce49SRobert Watson #include <stdio.h>
360cddce49SRobert Watson #include <stdlib.h>
370cddce49SRobert Watson #include <string.h>
380cddce49SRobert Watson
390cddce49SRobert Watson #include "memstat.h"
400cddce49SRobert Watson #include "memstat_internal.h"
410cddce49SRobert Watson
42e754c6bbSRobert Watson const char *
memstat_strerror(int error)43e754c6bbSRobert Watson memstat_strerror(int error)
44e754c6bbSRobert Watson {
45e754c6bbSRobert Watson
46e754c6bbSRobert Watson switch (error) {
47e754c6bbSRobert Watson case MEMSTAT_ERROR_NOMEMORY:
48e754c6bbSRobert Watson return ("Cannot allocate memory");
49e754c6bbSRobert Watson case MEMSTAT_ERROR_VERSION:
50e754c6bbSRobert Watson return ("Version mismatch");
51e754c6bbSRobert Watson case MEMSTAT_ERROR_PERMISSION:
52e754c6bbSRobert Watson return ("Permission denied");
53e754c6bbSRobert Watson case MEMSTAT_ERROR_DATAERROR:
54e754c6bbSRobert Watson return ("Data format error");
5533c20d18SRobert Watson case MEMSTAT_ERROR_KVM:
5633c20d18SRobert Watson return ("KVM error");
5733c20d18SRobert Watson case MEMSTAT_ERROR_KVM_NOSYMBOL:
5833c20d18SRobert Watson return ("KVM unable to find symbol");
5933c20d18SRobert Watson case MEMSTAT_ERROR_KVM_SHORTREAD:
6033c20d18SRobert Watson return ("KVM short read");
61e754c6bbSRobert Watson case MEMSTAT_ERROR_UNDEFINED:
62e754c6bbSRobert Watson default:
63e754c6bbSRobert Watson return ("Unknown error");
64e754c6bbSRobert Watson }
65e754c6bbSRobert Watson }
66e754c6bbSRobert Watson
670cddce49SRobert Watson struct memory_type_list *
memstat_mtl_alloc(void)680cddce49SRobert Watson memstat_mtl_alloc(void)
690cddce49SRobert Watson {
700cddce49SRobert Watson struct memory_type_list *mtlp;
710cddce49SRobert Watson
720cddce49SRobert Watson mtlp = malloc(sizeof(*mtlp));
730cddce49SRobert Watson if (mtlp == NULL)
740cddce49SRobert Watson return (NULL);
750cddce49SRobert Watson
7634562808SRobert Watson LIST_INIT(&mtlp->mtl_list);
7734562808SRobert Watson mtlp->mtl_error = MEMSTAT_ERROR_UNDEFINED;
780cddce49SRobert Watson return (mtlp);
790cddce49SRobert Watson }
800cddce49SRobert Watson
810cddce49SRobert Watson struct memory_type *
memstat_mtl_first(struct memory_type_list * list)820cddce49SRobert Watson memstat_mtl_first(struct memory_type_list *list)
830cddce49SRobert Watson {
840cddce49SRobert Watson
8534562808SRobert Watson return (LIST_FIRST(&list->mtl_list));
860cddce49SRobert Watson }
870cddce49SRobert Watson
880cddce49SRobert Watson struct memory_type *
memstat_mtl_next(struct memory_type * mtp)890cddce49SRobert Watson memstat_mtl_next(struct memory_type *mtp)
900cddce49SRobert Watson {
910cddce49SRobert Watson
920cddce49SRobert Watson return (LIST_NEXT(mtp, mt_list));
930cddce49SRobert Watson }
940cddce49SRobert Watson
950cddce49SRobert Watson void
_memstat_mtl_empty(struct memory_type_list * list)9622247a2aSRobert Watson _memstat_mtl_empty(struct memory_type_list *list)
970cddce49SRobert Watson {
980cddce49SRobert Watson struct memory_type *mtp;
990cddce49SRobert Watson
10034562808SRobert Watson while ((mtp = LIST_FIRST(&list->mtl_list))) {
1011882360bSSergey Kandaurov free(mtp->mt_percpu_alloc);
1021882360bSSergey Kandaurov free(mtp->mt_percpu_cache);
1030cddce49SRobert Watson LIST_REMOVE(mtp, mt_list);
1040cddce49SRobert Watson free(mtp);
1050cddce49SRobert Watson }
10622247a2aSRobert Watson }
10722247a2aSRobert Watson
10822247a2aSRobert Watson void
memstat_mtl_free(struct memory_type_list * list)10922247a2aSRobert Watson memstat_mtl_free(struct memory_type_list *list)
11022247a2aSRobert Watson {
11122247a2aSRobert Watson
11222247a2aSRobert Watson _memstat_mtl_empty(list);
1130cddce49SRobert Watson free(list);
1140cddce49SRobert Watson }
1150cddce49SRobert Watson
11634562808SRobert Watson int
memstat_mtl_geterror(struct memory_type_list * list)11734562808SRobert Watson memstat_mtl_geterror(struct memory_type_list *list)
11834562808SRobert Watson {
11934562808SRobert Watson
12034562808SRobert Watson return (list->mtl_error);
12134562808SRobert Watson }
12234562808SRobert Watson
1230cddce49SRobert Watson /*
1240cddce49SRobert Watson * Look for an existing memory_type entry in a memory_type list, based on the
12534562808SRobert Watson * allocator and name of the type. If not found, return NULL. No errno or
12634562808SRobert Watson * memstat error.
1270cddce49SRobert Watson */
1280cddce49SRobert Watson struct memory_type *
memstat_mtl_find(struct memory_type_list * list,int allocator,const char * name)1290cddce49SRobert Watson memstat_mtl_find(struct memory_type_list *list, int allocator,
1300cddce49SRobert Watson const char *name)
1310cddce49SRobert Watson {
1320cddce49SRobert Watson struct memory_type *mtp;
1330cddce49SRobert Watson
13434562808SRobert Watson LIST_FOREACH(mtp, &list->mtl_list, mt_list) {
1350cddce49SRobert Watson if ((mtp->mt_allocator == allocator ||
1360cddce49SRobert Watson allocator == ALLOCATOR_ANY) &&
1370cddce49SRobert Watson strcmp(mtp->mt_name, name) == 0)
1380cddce49SRobert Watson return (mtp);
1390cddce49SRobert Watson }
1400cddce49SRobert Watson return (NULL);
1410cddce49SRobert Watson }
1420cddce49SRobert Watson
1430cddce49SRobert Watson /*
1440cddce49SRobert Watson * Allocate a new memory_type with the specificed allocator type and name,
1450cddce49SRobert Watson * then insert into the list. The structure will be zero'd.
146ddefbc89SRobert Watson *
147ddefbc89SRobert Watson * libmemstat(3) internal function.
1480cddce49SRobert Watson */
1490cddce49SRobert Watson struct memory_type *
_memstat_mt_allocate(struct memory_type_list * list,int allocator,const char * name,int maxcpus)150ddefbc89SRobert Watson _memstat_mt_allocate(struct memory_type_list *list, int allocator,
1511882360bSSergey Kandaurov const char *name, int maxcpus)
1520cddce49SRobert Watson {
1530cddce49SRobert Watson struct memory_type *mtp;
1540cddce49SRobert Watson
1550cddce49SRobert Watson mtp = malloc(sizeof(*mtp));
1560cddce49SRobert Watson if (mtp == NULL)
1570cddce49SRobert Watson return (NULL);
1580cddce49SRobert Watson
1590cddce49SRobert Watson bzero(mtp, sizeof(*mtp));
1600cddce49SRobert Watson
1610cddce49SRobert Watson mtp->mt_allocator = allocator;
1621882360bSSergey Kandaurov mtp->mt_percpu_alloc = malloc(sizeof(struct mt_percpu_alloc_s) *
1631882360bSSergey Kandaurov maxcpus);
1641882360bSSergey Kandaurov mtp->mt_percpu_cache = malloc(sizeof(struct mt_percpu_cache_s) *
1651882360bSSergey Kandaurov maxcpus);
1660cddce49SRobert Watson strlcpy(mtp->mt_name, name, MEMTYPE_MAXNAME);
16734562808SRobert Watson LIST_INSERT_HEAD(&list->mtl_list, mtp, mt_list);
1680cddce49SRobert Watson return (mtp);
1690cddce49SRobert Watson }
1700cddce49SRobert Watson
1710cddce49SRobert Watson /*
1720cddce49SRobert Watson * Reset any libmemstat(3)-owned statistics in a memory_type record so that
1730cddce49SRobert Watson * it can be reused without incremental addition problems. Caller-owned
1740cddce49SRobert Watson * memory is left "as-is", and must be updated by the caller if desired.
175ddefbc89SRobert Watson *
176ddefbc89SRobert Watson * libmemstat(3) internal function.
1770cddce49SRobert Watson */
1780cddce49SRobert Watson void
_memstat_mt_reset_stats(struct memory_type * mtp,int maxcpus)1791882360bSSergey Kandaurov _memstat_mt_reset_stats(struct memory_type *mtp, int maxcpus)
1800cddce49SRobert Watson {
1810cddce49SRobert Watson int i;
1820cddce49SRobert Watson
1830cddce49SRobert Watson mtp->mt_countlimit = 0;
1840cddce49SRobert Watson mtp->mt_byteslimit = 0;
1850cddce49SRobert Watson mtp->mt_sizemask = 0;
1860cddce49SRobert Watson mtp->mt_size = 0;
1870cddce49SRobert Watson
1880cddce49SRobert Watson mtp->mt_memalloced = 0;
1890cddce49SRobert Watson mtp->mt_memfreed = 0;
1900cddce49SRobert Watson mtp->mt_numallocs = 0;
1910cddce49SRobert Watson mtp->mt_numfrees = 0;
1920cddce49SRobert Watson mtp->mt_bytes = 0;
1930cddce49SRobert Watson mtp->mt_count = 0;
1940cddce49SRobert Watson mtp->mt_free = 0;
1950cddce49SRobert Watson mtp->mt_failures = 0;
196bf965959SSean Bruno mtp->mt_sleeps = 0;
1970cddce49SRobert Watson
1980cddce49SRobert Watson mtp->mt_zonefree = 0;
199ca108fe2SRobert Watson mtp->mt_kegfree = 0;
2000cddce49SRobert Watson
2011882360bSSergey Kandaurov for (i = 0; i < maxcpus; i++) {
2020cddce49SRobert Watson mtp->mt_percpu_alloc[i].mtp_memalloced = 0;
2030cddce49SRobert Watson mtp->mt_percpu_alloc[i].mtp_memfreed = 0;
2040cddce49SRobert Watson mtp->mt_percpu_alloc[i].mtp_numallocs = 0;
2050cddce49SRobert Watson mtp->mt_percpu_alloc[i].mtp_numfrees = 0;
2060cddce49SRobert Watson mtp->mt_percpu_alloc[i].mtp_sizemask = 0;
2070cddce49SRobert Watson mtp->mt_percpu_cache[i].mtp_free = 0;
2080cddce49SRobert Watson }
2090cddce49SRobert Watson }
2100cddce49SRobert Watson
2110cddce49SRobert Watson /*
2120cddce49SRobert Watson * Accessor methods for struct memory_type. Avoids encoding the structure
2130cddce49SRobert Watson * ABI into the application.
2140cddce49SRobert Watson */
2150cddce49SRobert Watson const char *
memstat_get_name(const struct memory_type * mtp)2160cddce49SRobert Watson memstat_get_name(const struct memory_type *mtp)
2170cddce49SRobert Watson {
2180cddce49SRobert Watson
2190cddce49SRobert Watson return (mtp->mt_name);
2200cddce49SRobert Watson }
2210cddce49SRobert Watson
2220cddce49SRobert Watson int
memstat_get_allocator(const struct memory_type * mtp)2230cddce49SRobert Watson memstat_get_allocator(const struct memory_type *mtp)
2240cddce49SRobert Watson {
2250cddce49SRobert Watson
2260cddce49SRobert Watson return (mtp->mt_allocator);
2270cddce49SRobert Watson }
2280cddce49SRobert Watson
2290cddce49SRobert Watson uint64_t
memstat_get_countlimit(const struct memory_type * mtp)2300cddce49SRobert Watson memstat_get_countlimit(const struct memory_type *mtp)
2310cddce49SRobert Watson {
2320cddce49SRobert Watson
2330cddce49SRobert Watson return (mtp->mt_countlimit);
2340cddce49SRobert Watson }
2350cddce49SRobert Watson
2360cddce49SRobert Watson uint64_t
memstat_get_byteslimit(const struct memory_type * mtp)2370cddce49SRobert Watson memstat_get_byteslimit(const struct memory_type *mtp)
2380cddce49SRobert Watson {
2390cddce49SRobert Watson
2400cddce49SRobert Watson return (mtp->mt_byteslimit);
2410cddce49SRobert Watson }
2420cddce49SRobert Watson
2430cddce49SRobert Watson uint64_t
memstat_get_sizemask(const struct memory_type * mtp)2440cddce49SRobert Watson memstat_get_sizemask(const struct memory_type *mtp)
2450cddce49SRobert Watson {
2460cddce49SRobert Watson
2470cddce49SRobert Watson return (mtp->mt_sizemask);
2480cddce49SRobert Watson }
2490cddce49SRobert Watson
2500cddce49SRobert Watson uint64_t
memstat_get_size(const struct memory_type * mtp)2510cddce49SRobert Watson memstat_get_size(const struct memory_type *mtp)
2520cddce49SRobert Watson {
2530cddce49SRobert Watson
2540cddce49SRobert Watson return (mtp->mt_size);
2550cddce49SRobert Watson }
2560cddce49SRobert Watson
2570cddce49SRobert Watson uint64_t
memstat_get_rsize(const struct memory_type * mtp)258345e3f4dSGleb Smirnoff memstat_get_rsize(const struct memory_type *mtp)
259345e3f4dSGleb Smirnoff {
260345e3f4dSGleb Smirnoff
261345e3f4dSGleb Smirnoff return (mtp->mt_rsize);
262345e3f4dSGleb Smirnoff }
263345e3f4dSGleb Smirnoff
264345e3f4dSGleb Smirnoff uint64_t
memstat_get_memalloced(const struct memory_type * mtp)2650cddce49SRobert Watson memstat_get_memalloced(const struct memory_type *mtp)
2660cddce49SRobert Watson {
2670cddce49SRobert Watson
2680cddce49SRobert Watson return (mtp->mt_memalloced);
2690cddce49SRobert Watson }
2700cddce49SRobert Watson
2710cddce49SRobert Watson uint64_t
memstat_get_memfreed(const struct memory_type * mtp)2720cddce49SRobert Watson memstat_get_memfreed(const struct memory_type *mtp)
2730cddce49SRobert Watson {
2740cddce49SRobert Watson
2750cddce49SRobert Watson return (mtp->mt_memfreed);
2760cddce49SRobert Watson }
2770cddce49SRobert Watson
2780cddce49SRobert Watson uint64_t
memstat_get_numallocs(const struct memory_type * mtp)2790cddce49SRobert Watson memstat_get_numallocs(const struct memory_type *mtp)
2800cddce49SRobert Watson {
2810cddce49SRobert Watson
2820cddce49SRobert Watson return (mtp->mt_numallocs);
2830cddce49SRobert Watson }
2840cddce49SRobert Watson
2850cddce49SRobert Watson uint64_t
memstat_get_numfrees(const struct memory_type * mtp)2860cddce49SRobert Watson memstat_get_numfrees(const struct memory_type *mtp)
2870cddce49SRobert Watson {
2880cddce49SRobert Watson
2890cddce49SRobert Watson return (mtp->mt_numfrees);
2900cddce49SRobert Watson }
2910cddce49SRobert Watson
2920cddce49SRobert Watson uint64_t
memstat_get_bytes(const struct memory_type * mtp)2930cddce49SRobert Watson memstat_get_bytes(const struct memory_type *mtp)
2940cddce49SRobert Watson {
2950cddce49SRobert Watson
2960cddce49SRobert Watson return (mtp->mt_bytes);
2970cddce49SRobert Watson }
2980cddce49SRobert Watson
2990cddce49SRobert Watson uint64_t
memstat_get_count(const struct memory_type * mtp)3000cddce49SRobert Watson memstat_get_count(const struct memory_type *mtp)
3010cddce49SRobert Watson {
3020cddce49SRobert Watson
3030cddce49SRobert Watson return (mtp->mt_count);
3040cddce49SRobert Watson }
3050cddce49SRobert Watson
3060cddce49SRobert Watson uint64_t
memstat_get_free(const struct memory_type * mtp)3070cddce49SRobert Watson memstat_get_free(const struct memory_type *mtp)
3080cddce49SRobert Watson {
3090cddce49SRobert Watson
3100cddce49SRobert Watson return (mtp->mt_free);
3110cddce49SRobert Watson }
3120cddce49SRobert Watson
3130cddce49SRobert Watson uint64_t
memstat_get_failures(const struct memory_type * mtp)3140cddce49SRobert Watson memstat_get_failures(const struct memory_type *mtp)
3150cddce49SRobert Watson {
3160cddce49SRobert Watson
3170cddce49SRobert Watson return (mtp->mt_failures);
3180cddce49SRobert Watson }
3190cddce49SRobert Watson
320bf965959SSean Bruno uint64_t
memstat_get_sleeps(const struct memory_type * mtp)321bf965959SSean Bruno memstat_get_sleeps(const struct memory_type *mtp)
322bf965959SSean Bruno {
323bf965959SSean Bruno
324bf965959SSean Bruno return (mtp->mt_sleeps);
325bf965959SSean Bruno }
326bf965959SSean Bruno
327c1685086SJeff Roberson uint64_t
memstat_get_xdomain(const struct memory_type * mtp)328c1685086SJeff Roberson memstat_get_xdomain(const struct memory_type *mtp)
329c1685086SJeff Roberson {
330c1685086SJeff Roberson
331c1685086SJeff Roberson return (mtp->mt_xdomain);
332c1685086SJeff Roberson }
333c1685086SJeff Roberson
3340cddce49SRobert Watson void *
memstat_get_caller_pointer(const struct memory_type * mtp,int index)3350cddce49SRobert Watson memstat_get_caller_pointer(const struct memory_type *mtp, int index)
3360cddce49SRobert Watson {
3370cddce49SRobert Watson
3380cddce49SRobert Watson return (mtp->mt_caller_pointer[index]);
3390cddce49SRobert Watson }
3400cddce49SRobert Watson
3410cddce49SRobert Watson void
memstat_set_caller_pointer(struct memory_type * mtp,int index,void * value)3420cddce49SRobert Watson memstat_set_caller_pointer(struct memory_type *mtp, int index, void *value)
3430cddce49SRobert Watson {
3440cddce49SRobert Watson
3450cddce49SRobert Watson mtp->mt_caller_pointer[index] = value;
3460cddce49SRobert Watson }
3470cddce49SRobert Watson
3480cddce49SRobert Watson uint64_t
memstat_get_caller_uint64(const struct memory_type * mtp,int index)3490cddce49SRobert Watson memstat_get_caller_uint64(const struct memory_type *mtp, int index)
3500cddce49SRobert Watson {
3510cddce49SRobert Watson
3520cddce49SRobert Watson return (mtp->mt_caller_uint64[index]);
3530cddce49SRobert Watson }
3540cddce49SRobert Watson
3550cddce49SRobert Watson void
memstat_set_caller_uint64(struct memory_type * mtp,int index,uint64_t value)3560cddce49SRobert Watson memstat_set_caller_uint64(struct memory_type *mtp, int index, uint64_t value)
3570cddce49SRobert Watson {
3580cddce49SRobert Watson
3590cddce49SRobert Watson mtp->mt_caller_uint64[index] = value;
3600cddce49SRobert Watson }
3610cddce49SRobert Watson
3620cddce49SRobert Watson uint64_t
memstat_get_zonefree(const struct memory_type * mtp)3630cddce49SRobert Watson memstat_get_zonefree(const struct memory_type *mtp)
3640cddce49SRobert Watson {
3650cddce49SRobert Watson
3660cddce49SRobert Watson return (mtp->mt_zonefree);
3670cddce49SRobert Watson }
3680cddce49SRobert Watson
3690cddce49SRobert Watson uint64_t
memstat_get_kegfree(const struct memory_type * mtp)370ca108fe2SRobert Watson memstat_get_kegfree(const struct memory_type *mtp)
371ca108fe2SRobert Watson {
372ca108fe2SRobert Watson
373ca108fe2SRobert Watson return (mtp->mt_kegfree);
374ca108fe2SRobert Watson }
375ca108fe2SRobert Watson
376ca108fe2SRobert Watson uint64_t
memstat_get_percpu_memalloced(const struct memory_type * mtp,int cpu)3770cddce49SRobert Watson memstat_get_percpu_memalloced(const struct memory_type *mtp, int cpu)
3780cddce49SRobert Watson {
3790cddce49SRobert Watson
3800cddce49SRobert Watson return (mtp->mt_percpu_alloc[cpu].mtp_memalloced);
3810cddce49SRobert Watson }
3820cddce49SRobert Watson
3830cddce49SRobert Watson uint64_t
memstat_get_percpu_memfreed(const struct memory_type * mtp,int cpu)3840cddce49SRobert Watson memstat_get_percpu_memfreed(const struct memory_type *mtp, int cpu)
3850cddce49SRobert Watson {
3860cddce49SRobert Watson
3870cddce49SRobert Watson return (mtp->mt_percpu_alloc[cpu].mtp_memfreed);
3880cddce49SRobert Watson }
3890cddce49SRobert Watson
3900cddce49SRobert Watson uint64_t
memstat_get_percpu_numallocs(const struct memory_type * mtp,int cpu)3910cddce49SRobert Watson memstat_get_percpu_numallocs(const struct memory_type *mtp, int cpu)
3920cddce49SRobert Watson {
3930cddce49SRobert Watson
3940cddce49SRobert Watson return (mtp->mt_percpu_alloc[cpu].mtp_numallocs);
3950cddce49SRobert Watson }
3960cddce49SRobert Watson
3970cddce49SRobert Watson uint64_t
memstat_get_percpu_numfrees(const struct memory_type * mtp,int cpu)3980cddce49SRobert Watson memstat_get_percpu_numfrees(const struct memory_type *mtp, int cpu)
3990cddce49SRobert Watson {
4000cddce49SRobert Watson
4010cddce49SRobert Watson return (mtp->mt_percpu_alloc[cpu].mtp_numfrees);
4020cddce49SRobert Watson }
4030cddce49SRobert Watson
4040cddce49SRobert Watson uint64_t
memstat_get_percpu_sizemask(const struct memory_type * mtp,int cpu)4050cddce49SRobert Watson memstat_get_percpu_sizemask(const struct memory_type *mtp, int cpu)
4060cddce49SRobert Watson {
4070cddce49SRobert Watson
4080cddce49SRobert Watson return (mtp->mt_percpu_alloc[cpu].mtp_sizemask);
4090cddce49SRobert Watson }
4100cddce49SRobert Watson
4110cddce49SRobert Watson void *
memstat_get_percpu_caller_pointer(const struct memory_type * mtp,int cpu,int index)4120cddce49SRobert Watson memstat_get_percpu_caller_pointer(const struct memory_type *mtp, int cpu,
4130cddce49SRobert Watson int index)
4140cddce49SRobert Watson {
4150cddce49SRobert Watson
4160cddce49SRobert Watson return (mtp->mt_percpu_alloc[cpu].mtp_caller_pointer[index]);
4170cddce49SRobert Watson }
4180cddce49SRobert Watson
4190cddce49SRobert Watson void
memstat_set_percpu_caller_pointer(struct memory_type * mtp,int cpu,int index,void * value)4200cddce49SRobert Watson memstat_set_percpu_caller_pointer(struct memory_type *mtp, int cpu,
4210cddce49SRobert Watson int index, void *value)
4220cddce49SRobert Watson {
4230cddce49SRobert Watson
4240cddce49SRobert Watson mtp->mt_percpu_alloc[cpu].mtp_caller_pointer[index] = value;
4250cddce49SRobert Watson }
4260cddce49SRobert Watson
4270cddce49SRobert Watson uint64_t
memstat_get_percpu_caller_uint64(const struct memory_type * mtp,int cpu,int index)4280cddce49SRobert Watson memstat_get_percpu_caller_uint64(const struct memory_type *mtp, int cpu,
4290cddce49SRobert Watson int index)
4300cddce49SRobert Watson {
4310cddce49SRobert Watson
4320cddce49SRobert Watson return (mtp->mt_percpu_alloc[cpu].mtp_caller_uint64[index]);
4330cddce49SRobert Watson }
4340cddce49SRobert Watson
4350cddce49SRobert Watson void
memstat_set_percpu_caller_uint64(struct memory_type * mtp,int cpu,int index,uint64_t value)4360cddce49SRobert Watson memstat_set_percpu_caller_uint64(struct memory_type *mtp, int cpu, int index,
4370cddce49SRobert Watson uint64_t value)
4380cddce49SRobert Watson {
4390cddce49SRobert Watson
4400cddce49SRobert Watson mtp->mt_percpu_alloc[cpu].mtp_caller_uint64[index] = value;
4410cddce49SRobert Watson }
4420cddce49SRobert Watson
4430cddce49SRobert Watson uint64_t
memstat_get_percpu_free(const struct memory_type * mtp,int cpu)4440cddce49SRobert Watson memstat_get_percpu_free(const struct memory_type *mtp, int cpu)
4450cddce49SRobert Watson {
4460cddce49SRobert Watson
4470cddce49SRobert Watson return (mtp->mt_percpu_cache[cpu].mtp_free);
4480cddce49SRobert Watson }
449