11eaf0ac3Slogwang /*- 2*22ce4affSfengbojiang * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3*22ce4affSfengbojiang * 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 #ifndef _MEMSTAT_INTERNAL_H_ 321eaf0ac3Slogwang #define _MEMSTAT_INTERNAL_H_ 331eaf0ac3Slogwang 341eaf0ac3Slogwang /* 351eaf0ac3Slogwang * memstat maintains its own internal notion of statistics on each memory 361eaf0ac3Slogwang * type, common across UMA and kernel malloc. Some fields are straight from 371eaf0ac3Slogwang * the allocator statistics, others are derived when extracted from the 381eaf0ac3Slogwang * kernel. A struct memory_type will describe each type supported by an 391eaf0ac3Slogwang * allocator. memory_type structures can be chained into lists. 401eaf0ac3Slogwang */ 411eaf0ac3Slogwang struct memory_type { 421eaf0ac3Slogwang /* 431eaf0ac3Slogwang * Static properties of type. 441eaf0ac3Slogwang */ 451eaf0ac3Slogwang int mt_allocator; /* malloc(9), uma(9), etc. */ 461eaf0ac3Slogwang char mt_name[MEMTYPE_MAXNAME]; /* name of memory type. */ 471eaf0ac3Slogwang 481eaf0ac3Slogwang /* 491eaf0ac3Slogwang * (Relatively) static zone settings, that don't uniquely identify 501eaf0ac3Slogwang * the zone, but also don't change much. 511eaf0ac3Slogwang */ 521eaf0ac3Slogwang uint64_t mt_countlimit; /* 0, or maximum allocations. */ 531eaf0ac3Slogwang uint64_t mt_byteslimit; /* 0, or maximum bytes. */ 541eaf0ac3Slogwang uint64_t mt_sizemask; /* malloc: allocated size bitmask. */ 551eaf0ac3Slogwang uint64_t mt_size; /* uma: size of objects. */ 561eaf0ac3Slogwang uint64_t mt_rsize; /* uma: real size of objects. */ 571eaf0ac3Slogwang 581eaf0ac3Slogwang /* 591eaf0ac3Slogwang * Zone or type information that includes all caches and any central 601eaf0ac3Slogwang * zone state. Depending on the allocator, this may be synthesized 611eaf0ac3Slogwang * from several sources, or directly measured. 621eaf0ac3Slogwang */ 631eaf0ac3Slogwang uint64_t mt_memalloced; /* Bytes allocated over life time. */ 641eaf0ac3Slogwang uint64_t mt_memfreed; /* Bytes freed over life time. */ 651eaf0ac3Slogwang uint64_t mt_numallocs; /* Allocations over life time. */ 661eaf0ac3Slogwang uint64_t mt_numfrees; /* Frees over life time. */ 671eaf0ac3Slogwang uint64_t mt_bytes; /* Bytes currently allocated. */ 681eaf0ac3Slogwang uint64_t mt_count; /* Number of current allocations. */ 691eaf0ac3Slogwang uint64_t mt_free; /* Number of cached free items. */ 701eaf0ac3Slogwang uint64_t mt_failures; /* Number of allocation failures. */ 711eaf0ac3Slogwang uint64_t mt_sleeps; /* Number of allocation sleeps. */ 72*22ce4affSfengbojiang uint64_t mt_xdomain; /* Number of cross domain sleeps. */ 731eaf0ac3Slogwang 741eaf0ac3Slogwang /* 751eaf0ac3Slogwang * Caller-owned memory. 761eaf0ac3Slogwang */ 771eaf0ac3Slogwang void *mt_caller_pointer[MEMSTAT_MAXCALLER]; /* Pointers. */ 781eaf0ac3Slogwang uint64_t mt_caller_uint64[MEMSTAT_MAXCALLER]; /* Integers. */ 791eaf0ac3Slogwang 801eaf0ac3Slogwang /* 811eaf0ac3Slogwang * For allocators making use of per-CPU caches, we also provide raw 821eaf0ac3Slogwang * statistics from the central allocator and each per-CPU cache, 831eaf0ac3Slogwang * which (combined) sometimes make up the above general statistics. 841eaf0ac3Slogwang * 851eaf0ac3Slogwang * First, central zone/type state, all numbers excluding any items 861eaf0ac3Slogwang * cached in per-CPU caches. 871eaf0ac3Slogwang * 881eaf0ac3Slogwang * XXXRW: Might be desirable to separately expose allocation stats 891eaf0ac3Slogwang * from zone, which should (combined with per-cpu) add up to the 901eaf0ac3Slogwang * global stats above. 911eaf0ac3Slogwang */ 921eaf0ac3Slogwang uint64_t mt_zonefree; /* Free items in zone. */ 931eaf0ac3Slogwang uint64_t mt_kegfree; /* Free items in keg. */ 941eaf0ac3Slogwang 951eaf0ac3Slogwang /* 961eaf0ac3Slogwang * Per-CPU measurements fall into two categories: per-CPU allocation, 971eaf0ac3Slogwang * and per-CPU cache state. 981eaf0ac3Slogwang */ 991eaf0ac3Slogwang struct mt_percpu_alloc_s { 1001eaf0ac3Slogwang uint64_t mtp_memalloced;/* Per-CPU mt_memalloced. */ 1011eaf0ac3Slogwang uint64_t mtp_memfreed; /* Per-CPU mt_memfreed. */ 1021eaf0ac3Slogwang uint64_t mtp_numallocs; /* Per-CPU mt_numallocs. */ 1031eaf0ac3Slogwang uint64_t mtp_numfrees; /* Per-CPU mt_numfrees. */ 1041eaf0ac3Slogwang uint64_t mtp_sizemask; /* Per-CPU mt_sizemask. */ 1051eaf0ac3Slogwang void *mtp_caller_pointer[MEMSTAT_MAXCALLER]; 1061eaf0ac3Slogwang uint64_t mtp_caller_uint64[MEMSTAT_MAXCALLER]; 1071eaf0ac3Slogwang } *mt_percpu_alloc; 1081eaf0ac3Slogwang 1091eaf0ac3Slogwang struct mt_percpu_cache_s { 1101eaf0ac3Slogwang uint64_t mtp_free; /* Per-CPU cache free items. */ 1111eaf0ac3Slogwang } *mt_percpu_cache; 1121eaf0ac3Slogwang 1131eaf0ac3Slogwang LIST_ENTRY(memory_type) mt_list; /* List of types. */ 1141eaf0ac3Slogwang }; 1151eaf0ac3Slogwang 1161eaf0ac3Slogwang /* 1171eaf0ac3Slogwang * Description of struct memory_type_list is in memstat.h. 1181eaf0ac3Slogwang */ 1191eaf0ac3Slogwang struct memory_type_list { 1201eaf0ac3Slogwang LIST_HEAD(, memory_type) mtl_list; 1211eaf0ac3Slogwang int mtl_error; 1221eaf0ac3Slogwang }; 1231eaf0ac3Slogwang 1241eaf0ac3Slogwang void _memstat_mtl_empty(struct memory_type_list *list); 1251eaf0ac3Slogwang struct memory_type *_memstat_mt_allocate(struct memory_type_list *list, 1261eaf0ac3Slogwang int allocator, const char *name, int maxcpus); 1271eaf0ac3Slogwang void _memstat_mt_reset_stats(struct memory_type *mtp, 1281eaf0ac3Slogwang int maxcpus); 1291eaf0ac3Slogwang 1301eaf0ac3Slogwang #endif /* !_MEMSTAT_INTERNAL_H_ */ 131