memstat.h revision 147997
1187770Sluigi/*-
2187770Sluigi * Copyright (c) 2005 Robert N. M. Watson
3187770Sluigi * All rights reserved.
4187770Sluigi *
5187770Sluigi * Redistribution and use in source and binary forms, with or without
6187770Sluigi * modification, are permitted provided that the following conditions
7187770Sluigi * are met:
8187770Sluigi * 1. Redistributions of source code must retain the above copyright
9187770Sluigi *    notice, this list of conditions and the following disclaimer.
10187770Sluigi * 2. Redistributions in binary form must reproduce the above copyright
11187770Sluigi *    notice, this list of conditions and the following disclaimer in the
12187770Sluigi *    documentation and/or other materials provided with the distribution.
13187770Sluigi *
14187770Sluigi * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15187770Sluigi * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16187770Sluigi * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17187770Sluigi * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18187770Sluigi * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19187770Sluigi * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20187770Sluigi * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21187770Sluigi * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22187770Sluigi * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23187770Sluigi * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24187770Sluigi * SUCH DAMAGE.
25187770Sluigi *
26187770Sluigi * $FreeBSD: head/lib/libmemstat/memstat.h 147997 2005-07-14 17:40:02Z rwatson $
27187770Sluigi */
28187770Sluigi
29187770Sluigi#ifndef _MEMSTAT_H_
30187770Sluigi#define	_MEMSTAT_H_
31187770Sluigi
32187770Sluigi/*
33187770Sluigi * Number of CPU slots in library-internal data structures.  This should be
34187770Sluigi * at least the value of MAXCPU from param.h.
35187770Sluigi */
36187770Sluigi#define	MEMSTAT_MAXCPU	16
37187770Sluigi
38187770Sluigi/*
39187770Sluigi * libmemstat(3) is able to extract memory data from different allocators;
40187770Sluigi * when it does so, it tags which allocator it got the data from so that
41187770Sluigi * consumers can determine which fields are usable, as data returned varies
42187770Sluigi * some.
43187770Sluigi */
44187770Sluigi#define	ALLOCATOR_UNKNOWN	0
45187770Sluigi#define	ALLOCATOR_MALLOC	1
46187770Sluigi#define	ALLOCATOR_UMA		2
47187770Sluigi#define	ALLOCATOR_ANY		255
48187770Sluigi
49187770Sluigi/*
50220802Sglebius * Library maximum type name.  Should be max(set of name maximums over
51220802Sglebius * various allocators).
52220802Sglebius */
53220802Sglebius#define	MEMTYPE_MAXNAME		32
54220802Sglebius
55220802Sglebius/*
56220802Sglebius * Forward declare struct memory_type, which holds per-type properties and
57220804Sglebius * statistics.  This is an opaque type, to be frobbed only from within the
58220802Sglebius * library, in order to avoid building ABI assumptions into the application.
59187770Sluigi * Accessor methods should be used to get and sometimes set the fields from
60187770Sluigi * consumers of the library.
61187770Sluigi */
62187770Sluigistruct memory_type;
63187770Sluigi
64187770Sluigi/*
65187770Sluigi * struct memory_type_list is the head of a list of memory types and
66220802Sglebius * statistics.
67187770Sluigi */
68187770Sluigistruct memory_type_list;
69220802Sglebius
70187770Sluigi/*
71187770Sluigi * Functions for managing memory type and statistics data.
72187770Sluigi */
73187770Sluigistruct memory_type_list	*memstat_mtl_alloc(void);
74187770Sluigistruct memory_type	*memstat_mtl_first(struct memory_type_list *list);
75187770Sluigistruct memory_type	*memstat_mtl_next(struct memory_type *mtp);
76187770Sluigistruct memory_type	*memstat_mtl_find(struct memory_type_list *list,
77187770Sluigi			    int allocator, const char *name);
78187770Sluigivoid	memstat_mtl_free(struct memory_type_list *list);
79187770Sluigi
80187770Sluigi/*
81187770Sluigi * Functions to retrieve data from a live kernel using sysctl.
82187770Sluigi */
83187770Sluigiint	memstat_sysctl_all(struct memory_type_list *list, int flags);
84187770Sluigiint	memstat_sysctl_malloc(struct memory_type_list *list, int flags);
85187770Sluigiint	memstat_sysctl_uma(struct memory_type_list *list, int flags);
86187770Sluigi
87220804Sglebius/*
88187770Sluigi * Accessor methods for struct memory_type_list.
89220804Sglebius */
90187770Sluigiconst char	*memstat_get_name(const struct memory_type *mtp);
91187770Sluigiint		 memstat_get_allocator(const struct memory_type *mtp);
92187770Sluigiuint64_t	 memstat_get_countlimit(const struct memory_type *mtp);
93187770Sluigiuint64_t	 memstat_get_byteslimit(const struct memory_type *mtp);
94187770Sluigiuint64_t	 memstat_get_sizemask(const struct memory_type *mtp);
95187770Sluigiuint64_t	 memstat_get_size(const struct memory_type *mtp);
96187770Sluigiuint64_t	 memstat_get_memalloced(const struct memory_type *mtp);
97187770Sluigiuint64_t	 memstat_get_memfreed(const struct memory_type *mtp);
98187770Sluigiuint64_t	 memstat_get_numallocs(const struct memory_type *mtp);
99187770Sluigiuint64_t	 memstat_get_numfrees(const struct memory_type *mtp);
100187770Sluigiuint64_t	 memstat_get_bytes(const struct memory_type *mtp);
101187770Sluigiuint64_t	 memstat_get_count(const struct memory_type *mtp);
102187770Sluigiuint64_t	 memstat_get_free(const struct memory_type *mtp);
103187770Sluigiuint64_t	 memstat_get_failures(const struct memory_type *mtp);
104187770Sluigivoid		*memstat_get_caller_pointer(const struct memory_type *mtp,
105187770Sluigi		    int index);
106187770Sluigivoid		 memstat_set_caller_pointer(struct memory_type *mtp,
107187770Sluigi		    int index, void *value);
108187770Sluigiuint64_t	 memstat_get_caller_uint64(const struct memory_type *mtp,
109187770Sluigi		    int index);
110187770Sluigivoid		 memstat_set_caller_uint64(struct memory_type *mtp, int index,
111187770Sluigi		    uint64_t value);
112187770Sluigiuint64_t	 memstat_get_zonefree(const struct memory_type *mtp);
113187770Sluigiuint64_t	 memstat_get_percpu_memalloced(const struct memory_type *mtp,
114187770Sluigi		    int cpu);
115187770Sluigiuint64_t	 memstat_get_percpu_memfreed(const struct memory_type *mtp,
116187770Sluigi		    int cpu);
117187770Sluigiuint64_t	 memstat_get_percpu_numallocs(const struct memory_type *mtp,
118187770Sluigi		    int cpu);
119187770Sluigiuint64_t	 memstat_get_percpu_numfrees(const struct memory_type *mtp,
120187770Sluigi		    int cpu);
121187770Sluigiuint64_t	 memstat_get_percpu_sizemask(const struct memory_type *mtp,
122187770Sluigi		    int cpu);
123187770Sluigivoid		*memstat_get_percpu_caller_pointer(
124187770Sluigi		    const struct memory_type *mtp, int cpu, int index);
125187770Sluigivoid		 memstat_set_percpu_caller_pointer(struct memory_type *mtp,
126187770Sluigi		    int cpu, int index, void *value);
127187770Sluigiuint64_t	 memstat_get_percpu_caller_uint64(
128187770Sluigi		    const struct memory_type *mtp, int cpu, int index);
129187770Sluigivoid		 memstat_set_percpu_caller_uint64(struct memory_type *mtp,
130187770Sluigi		    int cpu, int index, uint64_t value);
131187770Sluigiuint64_t	 memstat_get_percpu_free(const struct memory_type *mtp,
132187770Sluigi		    int cpu);
133187770Sluigi
134187770Sluigi#endif /* !_MEMSTAT_H_ */
135187770Sluigi