2 * Copyright (c) 2019 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #ifndef _SYS__MALLOC_H_
31 #define _SYS__MALLOC_H_
34 * Do not include this header outside _KERNEL or _KERNEL_STRUCTURES scopes.
35 * Used in <sys/user.h>.
38 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
39 #include <sys/cdefs.h> /* for __cache_align */
40 #include <machine/stdint.h> /* for __* types */
41 #include <machine/param.h> /* for SMP_MAXCPU */
44 * The malloc tracking structure. Note that per-cpu entries must be
45 * aggregated for accurate statistics, they do not actually break the
46 * stats down by cpu (e.g. the cpu freeing memory will subtract from
47 * its slot, not the originating cpu's slot).
49 * SMP_MAXCPU is used so modules which use malloc remain compatible
52 * Warning: __cachealign typically represents 64 byte alignment, so
53 * this structure may be larger than expected.
58 __int64_t calls; /* total packets of this type ever allocated */
61 * This value will be added to ks_loosememuse and resetted,
62 * once it goes above certain threshold (ZoneSize). This
63 * is intended to reduce frequency of ks_loosememuse (global)
70 struct malloc_type *ks_next; /* next in list */
71 __size_t ks_loosememuse; /* (inaccurate) aggregate memuse */
72 __size_t ks_limit; /* most that are allowed to exist */
73 __uint64_t ks_mtflags; /* MTF_x flags */
75 __uint32_t ks_unused1;
76 __uint32_t ks_magic; /* if it's not magic, don't touch it */
77 const char *ks_shortdesc; /* short description */
78 __uint64_t ks_unused2;
79 struct kmalloc_use *ks_use;
80 struct kmalloc_use ks_use0; /* dummy prior to SMP startup */
83 typedef struct malloc_type *malloc_type_t;
85 #define MALLOC_DECLARE(type) \
86 extern struct malloc_type type[1] /* ref as ptr */
90 #endif /* !_SYS__MALLOC_H_ */