memstat_internal.h revision 148619
1219019Sgabor/*- 2219019Sgabor * Copyright (c) 2005 Robert N. M. Watson 3219019Sgabor * All rights reserved. 4219019Sgabor * 5219019Sgabor * Redistribution and use in source and binary forms, with or without 6219019Sgabor * modification, are permitted provided that the following conditions 7219019Sgabor * are met: 8219019Sgabor * 1. Redistributions of source code must retain the above copyright 9219019Sgabor * notice, this list of conditions and the following disclaimer. 10219019Sgabor * 2. Redistributions in binary form must reproduce the above copyright 11219019Sgabor * notice, this list of conditions and the following disclaimer in the 12219019Sgabor * documentation and/or other materials provided with the distribution. 13219019Sgabor * 14219019Sgabor * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15219019Sgabor * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16219019Sgabor * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17219019Sgabor * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18219019Sgabor * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19219019Sgabor * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20219019Sgabor * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21219019Sgabor * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22219019Sgabor * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23219019Sgabor * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24219019Sgabor * SUCH DAMAGE. 25219019Sgabor * 26219019Sgabor * $FreeBSD: head/lib/libmemstat/memstat_internal.h 148619 2005-08-01 13:18:21Z rwatson $ 27219019Sgabor */ 28219019Sgabor 29219019Sgabor#ifndef _MEMSTAT_INTERNAL_H_ 30219019Sgabor#define _MEMSTAT_INTERNAL_H_ 31219019Sgabor 32219019Sgabor/* 33219019Sgabor * memstat maintains its own internal notion of statistics on each memory 34219019Sgabor * type, common across UMA and kernel malloc. Some fields are straight from 35219019Sgabor * the allocator statistics, others are derived when extracted from the 36219019Sgabor * kernel. A struct memory_type will describe each type supported by an 37219019Sgabor * allocator. memory_type structures can be chained into lists. 38219019Sgabor */ 39219019Sgaborstruct memory_type { 40219019Sgabor /* 41219019Sgabor * Static properties of type. 42219019Sgabor */ 43219019Sgabor int mt_allocator; /* malloc(9), uma(9), etc. */ 44219019Sgabor char mt_name[MEMTYPE_MAXNAME]; /* name of memory type. */ 45219019Sgabor 46219019Sgabor /* 47219019Sgabor * (Relatively) static zone settings, that don't uniquely identify 48219019Sgabor * the zone, but also don't change much. 49219019Sgabor */ 50219019Sgabor uint64_t mt_countlimit; /* 0, or maximum allocations. */ 51219019Sgabor uint64_t mt_byteslimit; /* 0, or maximum bytes. */ 52219019Sgabor uint64_t mt_sizemask; /* malloc: allocated size bitmask. */ 53219019Sgabor uint64_t mt_size; /* uma: size of objects. */ 54 55 /* 56 * Zone or type information that includes all caches and any central 57 * zone state. Depending on the allocator, this may be synthesized 58 * from several sources, or directly measured. 59 */ 60 uint64_t mt_memalloced; /* Bytes allocated over life time. */ 61 uint64_t mt_memfreed; /* Bytes freed over life time. */ 62 uint64_t mt_numallocs; /* Allocations over life time. */ 63 uint64_t mt_numfrees; /* Frees over life time. */ 64 uint64_t mt_bytes; /* Bytes currently allocated. */ 65 uint64_t mt_count; /* Number of current allocations. */ 66 uint64_t mt_free; /* Number of cached free items. */ 67 uint64_t mt_failures; /* Number of allocation failures. */ 68 69 /* 70 * Caller-owned memory. 71 */ 72 void *mt_caller_pointer[MEMSTAT_MAXCALLER]; /* Pointers. */ 73 uint64_t mt_caller_uint64[MEMSTAT_MAXCALLER]; /* Integers. */ 74 75 /* 76 * For allocators making use of per-CPU caches, we also provide raw 77 * statistics from the central allocator and each per-CPU cache, 78 * which (combined) sometimes make up the above general statistics. 79 * 80 * First, central zone/type state, all numbers excluding any items 81 * cached in per-CPU caches. 82 * 83 * XXXRW: Might be desirable to separately expose allocation stats 84 * from zone, which should (combined with per-cpu) add up to the 85 * global stats above. 86 */ 87 uint64_t mt_zonefree; /* Free items in zone. */ 88 uint64_t mt_kegfree; /* Free items in keg. */ 89 90 /* 91 * Per-CPU measurements fall into two categories: per-CPU allocation, 92 * and per-CPU cache state. 93 */ 94 struct { 95 uint64_t mtp_memalloced;/* Per-CPU mt_memalloced. */ 96 uint64_t mtp_memfreed; /* Per-CPU mt_memfreed. */ 97 uint64_t mtp_numallocs; /* Per-CPU mt_numallocs. */ 98 uint64_t mtp_numfrees; /* Per-CPU mt_numfrees. */ 99 uint64_t mtp_sizemask; /* Per-CPU mt_sizemask. */ 100 void *mtp_caller_pointer[MEMSTAT_MAXCALLER]; 101 uint64_t mtp_caller_uint64[MEMSTAT_MAXCALLER]; 102 } mt_percpu_alloc[MEMSTAT_MAXCPU]; 103 104 struct { 105 uint64_t mtp_free; /* Per-CPU cache free items. */ 106 } mt_percpu_cache[MEMSTAT_MAXCPU]; 107 108 LIST_ENTRY(memory_type) mt_list; /* List of types. */ 109}; 110 111/* 112 * Description of struct memory_type_list is in memstat.h. 113 */ 114struct memory_type_list { 115 LIST_HEAD(, memory_type) mtl_list; 116 int mtl_error; 117}; 118 119void _memstat_mtl_empty(struct memory_type_list *list); 120struct memory_type *_memstat_mt_allocate(struct memory_type_list *list, 121 int allocator, const char *name); 122void _memstat_mt_reset_stats(struct memory_type *mtp); 123 124#endif /* !_MEMSTAT_INTERNAL_H_ */ 125