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
55 __int64_t calls; /* total packets of this type ever allocated */
58 * This value will be added to ks_loosememuse and resetted,
59 * once it goes above certain threshold (ZoneSize). This
60 * is intended to reduce frequency of ks_loosememuse (global)
67 struct malloc_type *ks_next; /* next in list */
68 __size_t ks_loosememuse; /* (inaccurate) aggregate memuse */
69 __size_t ks_limit; /* most that are allowed to exist */
70 struct kmalloc_use ks_use[SMP_MAXCPU];
71 __uint32_t ks_magic; /* if it's not magic, don't touch it */
72 const char *ks_shortdesc; /* short description */
73 __ssize_t ks_reserved[4]; /* future use (module compatibility) */
76 typedef struct malloc_type *malloc_type_t;
78 #define MALLOC_DECLARE(type) \
79 extern struct malloc_type type[1] /* placed here for portability */
83 #endif /* !_SYS__MALLOC_H_ */