xref: /xnu-10002.81.5/bsd/skywalk/mem/skmem_var.h (revision 5e3eaea39dcf651e66cb99ba7d70e32cc4a99587)
1 /*
2  * Copyright (c) 2016-2021 Apple Inc. All rights reserved.
3  *
4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5  *
6  * This file contains Original Code and/or Modifications of Original Code
7  * as defined in and that are subject to the Apple Public Source License
8  * Version 2.0 (the 'License'). You may not use this file except in
9  * compliance with the License. The rights granted to you under the License
10  * may not be used to create, or enable the creation or redistribution of,
11  * unlawful or unlicensed copies of an Apple operating system, or to
12  * circumvent, violate, or enable the circumvention or violation of, any
13  * terms of an Apple operating system software license agreement.
14  *
15  * Please obtain a copy of the License at
16  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17  *
18  * The Original Code and all software distributed under the License are
19  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23  * Please see the License for the specific language governing rights and
24  * limitations under the License.
25  *
26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27  */
28 
29 #ifndef _SKYWALK_MEM_SKMEMVAR_H
30 #define _SKYWALK_MEM_SKMEMVAR_H
31 
32 #ifdef BSD_KERNEL_PRIVATE
33 #include <skywalk/mem/skmem_region_var.h>
34 #include <skywalk/mem/skmem_cache_var.h>
35 #include <skywalk/mem/skmem_arena_var.h>
36 
37 #if defined(__arm64__)
38 #define SKMEM_PAGE_SIZE PAGE_MAX_SIZE
39 #else /* __i386__, __x86_64__ */
40 #define SKMEM_PAGE_SIZE PAGE_SIZE
41 #endif /* __i386__, __x86_64__ */
42 
43 /*
44  * Initial segment sizes for non-monolithic regions.  Smaller size allows more
45  * finer-grained control over the memory, at the expense of overheads.  The
46  * effective region segment size is computed by skmem_region_params_config(),
47  * depending on the number and size of objects.  This may be overridden by
48  * the "skmem_seg_size" and "skmem_buf_seg_size" boot-arg.
49  *
50  * The sizes are always multiples of SKMEM_PAGE_SIZE.
51  */
52 #define SKMEM_MIN_SEG_SIZE      (16 * 1024)
53 #define SKMEM_SEG_SIZE          SKMEM_MIN_SEG_SIZE /* default for all */
54 #define SKMEM_MD_SEG_SIZE       (16 * 1024)     /* default for metadata */
55 #define SKMEM_DRV_BUF_SEG_SIZE  (64 * 1024)     /* default for device buffer */
56 #define SKMEM_USR_BUF_SEG_SIZE  (16 * 1024)     /* default for user buffer */
57 
58 #define SKMEM_DRV_BUF_SEG_MULTIPLIER    2
59 
60 #define SKMEM_ARENA_PREFIX      "ska"
61 #define SKMEM_REGION_PREFIX     "skr"
62 #define SKMEM_CACHE_PREFIX      "skc"
63 #define SKMEM_ZONE_PREFIX       "skywalk"
64 #if DEBUG || DEVELOPMENT
65 #define SMKEM_KT_DEFAULT        KT_PRIV_ACCT
66 #else
67 #define SMKEM_KT_DEFAULT        KT_DEFAULT
68 #endif
69 #define SKMEM_TYPE_DEFINE(var, type) \
70 	KALLOC_TYPE_DEFINE(var, type, SMKEM_KT_DEFAULT)
71 
72 extern lck_attr_t skmem_lock_attr;
73 extern lck_grp_t skmem_lock_grp;
74 extern uint32_t skmem_usr_buf_seg_size;
75 
76 #if (DEVELOPMENT || DEBUG)
77 SYSCTL_DECL(_kern_skywalk_mem);
78 #endif /* (DEVELOPMENT || DEBUG) */
79 
80 #define SKMEM_MEM_CONSTRAINED_DEVICE()    \
81     (max_mem_actual <= (2ULL * 1024ULL * 1024ULL * 1024ULL))
82 
83 __BEGIN_DECLS
84 extern void skmem_init(void);
85 extern void skmem_fini(void);
86 extern const struct skmem_region_params *skmem_get_default(skmem_region_id_t);
87 extern uint32_t skmem_cpu_cache_line_size(void);
88 extern void skmem_dispatch(thread_call_t, void (*func)(void), uint64_t);
89 extern struct skmem_region *skmem_get_sysctls_region(void);
90 extern char *skmem_dump(struct skmem_region *);
91 extern boolean_t skmem_lowmem_check(void);
92 #if (DEVELOPMENT || DEBUG)
93 extern void skmem_test_init(void);
94 extern void skmem_test_fini(void);
95 extern bool skmem_test_enabled(void);
96 #endif /* (DEVELOPMENT || DEBUG) */
97 __END_DECLS
98 #endif /* BSD_KERNEL_PRIVATE */
99 #endif /* _SKYWALK_MEM_SKMEMVAR_H */
100