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 #ifndef _MEMSTAT_INTERNAL_H_ 300cddce49SRobert Watson #define _MEMSTAT_INTERNAL_H_ 310cddce49SRobert Watson 320cddce49SRobert Watson /* 330cddce49SRobert Watson * memstat maintains its own internal notion of statistics on each memory 340cddce49SRobert Watson * type, common across UMA and kernel malloc. Some fields are straight from 350cddce49SRobert Watson * the allocator statistics, others are derived when extracted from the 360cddce49SRobert Watson * kernel. A struct memory_type will describe each type supported by an 370cddce49SRobert Watson * allocator. memory_type structures can be chained into lists. 380cddce49SRobert Watson */ 390cddce49SRobert Watson struct memory_type { 400cddce49SRobert Watson /* 410cddce49SRobert Watson * Static properties of type. 420cddce49SRobert Watson */ 430cddce49SRobert Watson int mt_allocator; /* malloc(9), uma(9), etc. */ 440cddce49SRobert Watson char mt_name[MEMTYPE_MAXNAME]; /* name of memory type. */ 450cddce49SRobert Watson 460cddce49SRobert Watson /* 470cddce49SRobert Watson * (Relatively) static zone settings, that don't uniquely identify 480cddce49SRobert Watson * the zone, but also don't change much. 490cddce49SRobert Watson */ 500cddce49SRobert Watson uint64_t mt_countlimit; /* 0, or maximum allocations. */ 510cddce49SRobert Watson uint64_t mt_byteslimit; /* 0, or maximum bytes. */ 520cddce49SRobert Watson uint64_t mt_sizemask; /* malloc: allocated size bitmask. */ 530cddce49SRobert Watson uint64_t mt_size; /* uma: size of objects. */ 54345e3f4dSGleb Smirnoff uint64_t mt_rsize; /* uma: real size of objects. */ 550cddce49SRobert Watson 560cddce49SRobert Watson /* 570cddce49SRobert Watson * Zone or type information that includes all caches and any central 580cddce49SRobert Watson * zone state. Depending on the allocator, this may be synthesized 590cddce49SRobert Watson * from several sources, or directly measured. 600cddce49SRobert Watson */ 610cddce49SRobert Watson uint64_t mt_memalloced; /* Bytes allocated over life time. */ 620cddce49SRobert Watson uint64_t mt_memfreed; /* Bytes freed over life time. */ 630cddce49SRobert Watson uint64_t mt_numallocs; /* Allocations over life time. */ 640cddce49SRobert Watson uint64_t mt_numfrees; /* Frees over life time. */ 650cddce49SRobert Watson uint64_t mt_bytes; /* Bytes currently allocated. */ 660cddce49SRobert Watson uint64_t mt_count; /* Number of current allocations. */ 670cddce49SRobert Watson uint64_t mt_free; /* Number of cached free items. */ 680cddce49SRobert Watson uint64_t mt_failures; /* Number of allocation failures. */ 69bf965959SSean Bruno uint64_t mt_sleeps; /* Number of allocation sleeps. */ 70c1685086SJeff Roberson uint64_t mt_xdomain; /* Number of cross domain sleeps. */ 710cddce49SRobert Watson 720cddce49SRobert Watson /* 730cddce49SRobert Watson * Caller-owned memory. 740cddce49SRobert Watson */ 75ccf4e07eSRobert Watson void *mt_caller_pointer[MEMSTAT_MAXCALLER]; /* Pointers. */ 76ccf4e07eSRobert Watson uint64_t mt_caller_uint64[MEMSTAT_MAXCALLER]; /* Integers. */ 770cddce49SRobert Watson 780cddce49SRobert Watson /* 790cddce49SRobert Watson * For allocators making use of per-CPU caches, we also provide raw 800cddce49SRobert Watson * statistics from the central allocator and each per-CPU cache, 810cddce49SRobert Watson * which (combined) sometimes make up the above general statistics. 820cddce49SRobert Watson * 830cddce49SRobert Watson * First, central zone/type state, all numbers excluding any items 840cddce49SRobert Watson * cached in per-CPU caches. 850cddce49SRobert Watson * 860cddce49SRobert Watson * XXXRW: Might be desirable to separately expose allocation stats 870cddce49SRobert Watson * from zone, which should (combined with per-cpu) add up to the 880cddce49SRobert Watson * global stats above. 890cddce49SRobert Watson */ 900cddce49SRobert Watson uint64_t mt_zonefree; /* Free items in zone. */ 91ca108fe2SRobert Watson uint64_t mt_kegfree; /* Free items in keg. */ 920cddce49SRobert Watson 930cddce49SRobert Watson /* 940cddce49SRobert Watson * Per-CPU measurements fall into two categories: per-CPU allocation, 950cddce49SRobert Watson * and per-CPU cache state. 960cddce49SRobert Watson */ 971882360bSSergey Kandaurov struct mt_percpu_alloc_s { 980cddce49SRobert Watson uint64_t mtp_memalloced;/* Per-CPU mt_memalloced. */ 990cddce49SRobert Watson uint64_t mtp_memfreed; /* Per-CPU mt_memfreed. */ 1000cddce49SRobert Watson uint64_t mtp_numallocs; /* Per-CPU mt_numallocs. */ 1010cddce49SRobert Watson uint64_t mtp_numfrees; /* Per-CPU mt_numfrees. */ 1020cddce49SRobert Watson uint64_t mtp_sizemask; /* Per-CPU mt_sizemask. */ 103ccf4e07eSRobert Watson void *mtp_caller_pointer[MEMSTAT_MAXCALLER]; 104ccf4e07eSRobert Watson uint64_t mtp_caller_uint64[MEMSTAT_MAXCALLER]; 1051882360bSSergey Kandaurov } *mt_percpu_alloc; 1060cddce49SRobert Watson 1071882360bSSergey Kandaurov struct mt_percpu_cache_s { 1080cddce49SRobert Watson uint64_t mtp_free; /* Per-CPU cache free items. */ 1091882360bSSergey Kandaurov } *mt_percpu_cache; 1100cddce49SRobert Watson 1110cddce49SRobert Watson LIST_ENTRY(memory_type) mt_list; /* List of types. */ 1120cddce49SRobert Watson }; 1130cddce49SRobert Watson 1140cddce49SRobert Watson /* 1150cddce49SRobert Watson * Description of struct memory_type_list is in memstat.h. 1160cddce49SRobert Watson */ 11734562808SRobert Watson struct memory_type_list { 11834562808SRobert Watson LIST_HEAD(, memory_type) mtl_list; 11934562808SRobert Watson int mtl_error; 12034562808SRobert Watson }; 1210cddce49SRobert Watson 12222247a2aSRobert Watson void _memstat_mtl_empty(struct memory_type_list *list); 123ddefbc89SRobert Watson struct memory_type *_memstat_mt_allocate(struct memory_type_list *list, 1241882360bSSergey Kandaurov int allocator, const char *name, int maxcpus); 1251882360bSSergey Kandaurov void _memstat_mt_reset_stats(struct memory_type *mtp, 1261882360bSSergey Kandaurov int maxcpus); 1270cddce49SRobert Watson 1280cddce49SRobert Watson #endif /* !_MEMSTAT_INTERNAL_H_ */ 129