xref: /xnu-11417.140.69/bsd/sys/kern_memorystatus_xnu.h (revision 43a90889846e00bfb5cf1d255cdc0a701a1e05a4)
1 /*
2  * Copyright (c) 2024 Apple Computer, 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 #include <stdbool.h>
29 #include <stdint.h>
30 #include <sys/_types/_pid_t.h>
31 
32 #pragma once
33 
34 #if !XNU_KERNEL_PRIVATE
35 #error "Including xnu-private header in unexpected target"
36 #endif /* !XNU_KERNEL_PRIVATE */
37 
38 __BEGIN_DECLS
39 
40 /* TODO: migrate other xnu-private interfaces from kern_memorystatus.h */
41 
42 /*
43  * Return the minimum number of available pages jetsam requires before it
44  * begins killing non-idle processes. This is useful for some pageout
45  * mechanisms to avoid deadlock.
46  */
47 extern uint32_t memorystatus_get_critical_page_shortage_threshold(void);
48 
49 /*
50  * Return the minimum number of available pages jetsam requires before it
51  * begins killing idle processes. This is consumed by the vm pressure
52  * notification system in the absence of the compressor.
53  */
54 extern uint32_t memorystatus_get_idle_exit_page_shortage_threshold(void);
55 
56 /*
57  * Return the minimum number of available pages jetsam requires before it
58  * begins killing processes which have violated their soft memory limit. This
59  * is consumed by the vm pressure notification system in the absence of the
60  * compressor.
61  */
62 extern uint32_t memorystatus_get_soft_memlimit_page_shortage_threshold(void);
63 
64 /*
65  * Return the minumum number of available pages jetsam requires before it
66  * begins reaping long-idle processes.
67  */
68 extern uint32_t memorystatus_get_reaper_page_shortage_threshold(void);
69 
70 /*
71  * Return the current number of available pages in the system.
72  */
73 extern uint32_t memorystatus_get_available_page_count(void);
74 
75 /*
76  * Set the available page count and consider engaging response measures (e.g.
77  * waking jetsam thread/pressure-notification thread).
78  */
79 extern void memorystatus_update_available_page_count(uint32_t available_pages);
80 
81 /*
82  * Override fast-jetsam support. If override is enabled, fast-jetsam will be
83  * disabled.
84  */
85 extern void memorystatus_fast_jetsam_override(bool enable_override);
86 
87 /*
88  * Callout to jetsam. If pid is -1, we wake up the memorystatus thread to do asynchronous kills.
89  * For any other pid we try to kill that process synchronously.
90  */
91 extern bool memorystatus_kill_on_zone_map_exhaustion(pid_t pid);
92 
93 /*
94  * Kill a single process due to compressor space shortage.
95  */
96 extern bool memorystatus_kill_on_VM_compressor_space_shortage(bool async);
97 
98 /*
99  * Asynchronously kill a single process due to VM Pageout Starvation (i.e.
100  * a "stuck" external pageout thread).
101  */
102 extern void memorystatus_kill_on_vps_starvation(void);
103 
104 /*
105  * Synchronously kill a single process due to vnode exhaustion
106  */
107 extern bool memorystatus_kill_on_vnode_exhaustion(void);
108 
109 /*
110  * Wake up the memorystatus thread so it can do async kills.
111  * The memorystatus thread will keep killing until the system is
112  * considered healthy.
113  */
114 extern void memorystatus_thread_wake(void);
115 
116 /*
117  * Respond to compressor exhaustion by waking the jetsam thread or
118  * synchronously invoking a no-paging-space action.
119  */
120 extern void memorystatus_respond_to_compressor_exhaustion(void);
121 
122 /*
123  * Respond to swap exhaustion by waking the jetsam thread or
124  * synchronously invoking a no-paging-space action.
125  */
126 extern void memorystatus_respond_to_swap_exhaustion(void);
127 
128 __END_DECLS
129