]>
Commit | Line | Data |
---|---|---|
2d21ac55 A |
1 | /* |
2 | * Copyright (c) 2006 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 | */ | |
2d21ac55 | 28 | |
316670eb A |
29 | #ifndef SYS_MEMORYSTATUS_H |
30 | #define SYS_MEMORYSTATUS_H | |
b0d623f7 A |
31 | |
32 | #include <stdint.h> | |
33 | #include <sys/time.h> | |
34 | #include <sys/proc.h> | |
316670eb A |
35 | #include <sys/param.h> |
36 | ||
39037602 A |
37 | #define MEMORYSTATUS_ENTITLEMENT "com.apple.private.memorystatus" |
38 | ||
39236c6e | 39 | #define JETSAM_PRIORITY_REVISION 2 |
316670eb | 40 | |
fe8ab488 A |
41 | #define JETSAM_PRIORITY_IDLE_HEAD -2 |
42 | /* The value -1 is an alias to JETSAM_PRIORITY_DEFAULT */ | |
39236c6e | 43 | #define JETSAM_PRIORITY_IDLE 0 |
39037602 A |
44 | #define JETSAM_PRIORITY_IDLE_DEFERRED 1 /* Keeping this around till all xnu_quick_tests can be moved away from it.*/ |
45 | #define JETSAM_PRIORITY_AGING_BAND1 JETSAM_PRIORITY_IDLE_DEFERRED | |
39236c6e | 46 | #define JETSAM_PRIORITY_BACKGROUND_OPPORTUNISTIC 2 |
39037602 | 47 | #define JETSAM_PRIORITY_AGING_BAND2 JETSAM_PRIORITY_BACKGROUND_OPPORTUNISTIC |
39236c6e | 48 | #define JETSAM_PRIORITY_BACKGROUND 3 |
39037602 | 49 | #define JETSAM_PRIORITY_ELEVATED_INACTIVE JETSAM_PRIORITY_BACKGROUND |
39236c6e A |
50 | #define JETSAM_PRIORITY_MAIL 4 |
51 | #define JETSAM_PRIORITY_PHONE 5 | |
52 | #define JETSAM_PRIORITY_UI_SUPPORT 8 | |
53 | #define JETSAM_PRIORITY_FOREGROUND_SUPPORT 9 | |
54 | #define JETSAM_PRIORITY_FOREGROUND 10 | |
55 | #define JETSAM_PRIORITY_AUDIO_AND_ACCESSORY 12 | |
56 | #define JETSAM_PRIORITY_CONDUCTOR 13 | |
57 | #define JETSAM_PRIORITY_HOME 16 | |
58 | #define JETSAM_PRIORITY_EXECUTIVE 17 | |
59 | #define JETSAM_PRIORITY_IMPORTANT 18 | |
60 | #define JETSAM_PRIORITY_CRITICAL 19 | |
316670eb | 61 | |
39236c6e | 62 | #define JETSAM_PRIORITY_MAX 21 |
b0d623f7 | 63 | |
39236c6e A |
64 | /* TODO - tune. This should probably be lower priority */ |
65 | #define JETSAM_PRIORITY_DEFAULT 18 | |
66 | #define JETSAM_PRIORITY_TELEPHONY 19 | |
2d21ac55 | 67 | |
39236c6e A |
68 | /* Compatibility */ |
69 | #define DEFAULT_JETSAM_PRIORITY 18 | |
70 | ||
71 | #define DEFERRED_IDLE_EXIT_TIME_SECS 10 | |
72 | ||
73 | #define KEV_MEMORYSTATUS_SUBCLASS 3 | |
2d21ac55 | 74 | |
b0d623f7 | 75 | enum { |
316670eb A |
76 | kMemorystatusLevelNote = 1, |
77 | kMemorystatusSnapshotNote = 2, | |
78 | kMemorystatusFreezeNote = 3, | |
79 | kMemorystatusPressureNote = 4 | |
b0d623f7 A |
80 | }; |
81 | ||
2d21ac55 | 82 | enum { |
316670eb A |
83 | kMemorystatusLevelAny = -1, |
84 | kMemorystatusLevelNormal = 0, | |
85 | kMemorystatusLevelWarning = 1, | |
86 | kMemorystatusLevelUrgent = 2, | |
87 | kMemorystatusLevelCritical = 3 | |
2d21ac55 A |
88 | }; |
89 | ||
316670eb | 90 | typedef struct memorystatus_priority_entry { |
b0d623f7 | 91 | pid_t pid; |
316670eb | 92 | int32_t priority; |
39236c6e | 93 | uint64_t user_data; |
39037602 | 94 | int32_t limit; /* MB */ |
39236c6e | 95 | uint32_t state; |
316670eb | 96 | } memorystatus_priority_entry_t; |
b0d623f7 | 97 | |
316670eb | 98 | typedef struct memorystatus_kernel_stats { |
b0d623f7 A |
99 | uint32_t free_pages; |
100 | uint32_t active_pages; | |
101 | uint32_t inactive_pages; | |
316670eb | 102 | uint32_t throttled_pages; |
b0d623f7 A |
103 | uint32_t purgeable_pages; |
104 | uint32_t wired_pages; | |
39236c6e A |
105 | uint32_t speculative_pages; |
106 | uint32_t filebacked_pages; | |
107 | uint32_t anonymous_pages; | |
108 | uint32_t compressor_pages; | |
109 | uint64_t compressions; | |
110 | uint64_t decompressions; | |
111 | uint64_t total_uncompressed_pages_in_compressor; | |
316670eb | 112 | } memorystatus_kernel_stats_t; |
b0d623f7 A |
113 | |
114 | /* | |
115 | ** This is a variable-length struct. | |
316670eb | 116 | ** Allocate a buffer of the size returned by the sysctl, cast to a memorystatus_snapshot_t * |
b0d623f7 A |
117 | */ |
118 | ||
316670eb | 119 | typedef struct jetsam_snapshot_entry { |
39236c6e | 120 | pid_t pid; |
39037602 | 121 | char name[(2*MAXCOMLEN)+1]; |
39236c6e | 122 | int32_t priority; |
39236c6e | 123 | uint32_t state; |
39236c6e | 124 | uint32_t fds; |
39037602 A |
125 | uint8_t uuid[16]; |
126 | uint64_t user_data; | |
127 | uint64_t killed; | |
128 | uint64_t pages; | |
129 | uint64_t max_pages; | |
130 | uint64_t max_pages_lifetime; | |
131 | uint64_t purgeable_pages; | |
132 | uint64_t jse_internal_pages; | |
133 | uint64_t jse_internal_compressed_pages; | |
134 | uint64_t jse_purgeable_nonvolatile_pages; | |
135 | uint64_t jse_purgeable_nonvolatile_compressed_pages; | |
136 | uint64_t jse_alternate_accounting_pages; | |
137 | uint64_t jse_alternate_accounting_compressed_pages; | |
138 | uint64_t jse_iokit_mapped_pages; | |
139 | uint64_t jse_page_table_pages; | |
140 | uint64_t jse_memory_region_count; | |
141 | uint64_t jse_gencount; /* memorystatus_thread generation counter */ | |
142 | uint64_t jse_starttime; /* absolute time when process starts */ | |
143 | uint64_t jse_killtime; /* absolute time when jetsam chooses to kill a process */ | |
144 | uint64_t jse_idle_delta; /* time spent in idle band */ | |
145 | uint64_t jse_coalition_jetsam_id; /* we only expose coalition id for COALITION_TYPE_JETSAM */ | |
fe8ab488 | 146 | struct timeval cpu_time; |
316670eb A |
147 | } memorystatus_jetsam_snapshot_entry_t; |
148 | ||
b0d623f7 | 149 | typedef struct jetsam_snapshot { |
39037602 A |
150 | uint64_t snapshot_time; /* absolute time snapshot was initialized */ |
151 | uint64_t notification_time; /* absolute time snapshot was consumed */ | |
152 | uint64_t js_gencount; /* memorystatus_thread generation counter */ | |
153 | memorystatus_kernel_stats_t stats; /* system stat when snapshot is initialized */ | |
b0d623f7 | 154 | size_t entry_count; |
39236c6e | 155 | memorystatus_jetsam_snapshot_entry_t entries[]; |
316670eb A |
156 | } memorystatus_jetsam_snapshot_t; |
157 | ||
316670eb A |
158 | typedef struct memorystatus_freeze_entry { |
159 | int32_t pid; | |
6d2010ae A |
160 | uint32_t flags; |
161 | uint32_t pages; | |
316670eb A |
162 | } memorystatus_freeze_entry_t; |
163 | ||
39236c6e A |
164 | /* TODO - deprecate; see <rdar://problem/12969599> */ |
165 | #define kMaxSnapshotEntries 192 | |
316670eb | 166 | |
39236c6e A |
167 | /* State */ |
168 | #define kMemorystatusSuspended 0x01 | |
169 | #define kMemorystatusFrozen 0x02 | |
170 | #define kMemorystatusWasThawed 0x04 | |
171 | #define kMemorystatusTracked 0x08 | |
172 | #define kMemorystatusSupportsIdleExit 0x10 | |
173 | #define kMemorystatusDirty 0x20 | |
6d2010ae | 174 | |
39236c6e A |
175 | /* Cause */ |
176 | enum { | |
177 | kMemorystatusKilled = 1, | |
178 | kMemorystatusKilledHiwat, | |
179 | kMemorystatusKilledVnodes, | |
180 | kMemorystatusKilledVMPageShortage, | |
181 | kMemorystatusKilledVMThrashing, | |
fe8ab488 | 182 | kMemorystatusKilledFCThrashing, |
39236c6e A |
183 | kMemorystatusKilledPerProcessLimit, |
184 | kMemorystatusKilledDiagnostic, | |
185 | kMemorystatusKilledIdleExit | |
186 | }; | |
6d2010ae | 187 | |
39037602 A |
188 | /* Jetsam exit reason definitions */ |
189 | #define JETSAM_REASON_INVALID 0 | |
190 | #define JETSAM_REASON_GENERIC 1 | |
191 | #define JETSAM_REASON_MEMORY_HIGHWATER 2 | |
192 | #define JETSAM_REASON_VNODE 3 | |
193 | #define JETSAM_REASON_MEMORY_VMPAGESHORTAGE 4 | |
194 | #define JETSAM_REASON_MEMORY_VMTHRASHING 5 | |
195 | #define JETSAM_REASON_MEMORY_FCTHRASHING 6 | |
196 | #define JETSAM_REASON_MEMORY_PERPROCESSLIMIT 7 | |
197 | #define JETSAM_REASON_MEMORY_DIAGNOSTIC 8 | |
198 | #define JETSAM_REASON_MEMORY_IDLE_EXIT 9 | |
199 | #define JETSAM_REASON_CPULIMIT 10 | |
200 | ||
39236c6e A |
201 | /* Temporary, to prevent the need for a linked submission of ReportCrash */ |
202 | /* Remove when <rdar://problem/13210532> has been integrated */ | |
b0d623f7 | 203 | enum { |
39236c6e | 204 | kMemorystatusKilledVM = kMemorystatusKilledVMPageShortage |
b0d623f7 | 205 | }; |
b0d623f7 | 206 | |
39236c6e A |
207 | /* Memorystatus control */ |
208 | #define MEMORYSTATUS_BUFFERSIZE_MAX 65536 | |
209 | ||
210 | #ifndef KERNEL | |
211 | int memorystatus_get_level(user_addr_t level); | |
212 | int memorystatus_control(uint32_t command, int32_t pid, uint32_t flags, void *buffer, size_t buffersize); | |
316670eb | 213 | #endif |
316670eb | 214 | |
39236c6e A |
215 | /* Commands */ |
216 | #define MEMORYSTATUS_CMD_GET_PRIORITY_LIST 1 | |
217 | #define MEMORYSTATUS_CMD_SET_PRIORITY_PROPERTIES 2 | |
218 | #define MEMORYSTATUS_CMD_GET_JETSAM_SNAPSHOT 3 | |
219 | #define MEMORYSTATUS_CMD_GET_PRESSURE_STATUS 4 | |
3e170ce0 A |
220 | #define MEMORYSTATUS_CMD_SET_JETSAM_HIGH_WATER_MARK 5 /* Set active memory limit = inactive memory limit, both non-fatal */ |
221 | #define MEMORYSTATUS_CMD_SET_JETSAM_TASK_LIMIT 6 /* Set active memory limit = inactive memory limit, both fatal */ | |
222 | #define MEMORYSTATUS_CMD_SET_MEMLIMIT_PROPERTIES 7 /* Set memory limits plus attributes independently */ | |
223 | #define MEMORYSTATUS_CMD_GET_MEMLIMIT_PROPERTIES 8 /* Get memory limits plus attributes */ | |
224 | #define MEMORYSTATUS_CMD_PRIVILEGED_LISTENER_ENABLE 9 /* Set the task's status as a privileged listener w.r.t memory notifications */ | |
225 | #define MEMORYSTATUS_CMD_PRIVILEGED_LISTENER_DISABLE 10 /* Reset the task's status as a privileged listener w.r.t memory notifications */ | |
490019cf A |
226 | #define MEMORYSTATUS_CMD_AGGRESSIVE_JETSAM_LENIENT_MODE_ENABLE 11 /* Enable the 'lenient' mode for aggressive jetsam. See comments in kern_memorystatus.c near the top. */ |
227 | #define MEMORYSTATUS_CMD_AGGRESSIVE_JETSAM_LENIENT_MODE_DISABLE 12 /* Disable the 'lenient' mode for aggressive jetsam. */ | |
39037602 A |
228 | #define MEMORYSTATUS_CMD_GET_MEMLIMIT_EXCESS 13 /* Compute how much a process's phys_footprint exceeds inactive memory limit */ |
229 | #define MEMORYSTATUS_CMD_ELEVATED_INACTIVEJETSAMPRIORITY_ENABLE 14 | |
230 | #define MEMORYSTATUS_CMD_ELEVATED_INACTIVEJETSAMPRIORITY_DISABLE 15 | |
231 | ||
3e170ce0 A |
232 | /* Commands that act on a group of processes */ |
233 | #define MEMORYSTATUS_CMD_GRP_SET_PROPERTIES 100 | |
39236c6e A |
234 | |
235 | #if PRIVATE | |
236 | /* Test commands */ | |
237 | ||
238 | /* Trigger forced jetsam */ | |
3e170ce0 A |
239 | #define MEMORYSTATUS_CMD_TEST_JETSAM 1000 |
240 | #define MEMORYSTATUS_CMD_TEST_JETSAM_SORT 1001 | |
39236c6e A |
241 | |
242 | /* Panic on jetsam options */ | |
243 | typedef struct memorystatus_jetsam_panic_options { | |
244 | uint32_t data; | |
245 | uint32_t mask; | |
246 | } memorystatus_jetsam_panic_options_t; | |
316670eb | 247 | |
3e170ce0 A |
248 | #define MEMORYSTATUS_CMD_SET_JETSAM_PANIC_BITS 1002 |
249 | ||
250 | /* Select priority band sort order */ | |
251 | #define JETSAM_SORT_NOSORT 0 | |
252 | #define JETSAM_SORT_DEFAULT 1 | |
253 | ||
39236c6e A |
254 | #endif /* PRIVATE */ |
255 | ||
3e170ce0 A |
256 | /* |
257 | * For use with memorystatus_control: | |
258 | * MEMORYSTATUS_CMD_GET_JETSAM_SNAPSHOT | |
259 | * | |
260 | * A jetsam snapshot is initialized when a non-idle | |
261 | * jetsam event occurs. The data is held in the | |
262 | * buffer until it is reaped. This is the default | |
263 | * behavior. | |
264 | * | |
265 | * Flags change the default behavior: | |
266 | * Demand mode - this is an on_demand snapshot, | |
267 | * meaning data is populated upon request. | |
268 | * | |
269 | * Boot mode - this is a snapshot of | |
270 | * memstats collected before loading the | |
271 | * init program. Once collected, these | |
272 | * stats do not change. In this mode, | |
273 | * the snapshot entry_count is always 0. | |
274 | * | |
275 | * Snapshots are inherently racey between request | |
276 | * for buffer size and actual data compilation. | |
277 | */ | |
278 | ||
279 | /* Flags */ | |
280 | #define MEMORYSTATUS_SNAPSHOT_ON_DEMAND 0x1 /* A populated snapshot buffer is returned on demand */ | |
281 | #define MEMORYSTATUS_SNAPSHOT_AT_BOOT 0x2 /* Returns a snapshot with memstats collected at boot */ | |
282 | ||
283 | ||
284 | /* | |
285 | * For use with memorystatus_control: | |
286 | * MEMORYSTATUS_CMD_SET_PRIORITY_PROPERTIES | |
287 | */ | |
39236c6e A |
288 | typedef struct memorystatus_priority_properties { |
289 | int32_t priority; | |
290 | uint64_t user_data; | |
291 | } memorystatus_priority_properties_t; | |
292 | ||
3e170ce0 A |
293 | /* |
294 | * For use with memorystatus_control: | |
295 | * MEMORYSTATUS_CMD_SET_MEMLIMIT_PROPERTIES | |
296 | * MEMORYSTATUS_CMD_GET_MEMLIMIT_PROPERTIES | |
297 | */ | |
298 | typedef struct memorystatus_memlimit_properties { | |
299 | int32_t memlimit_active; /* jetsam memory limit (in MB) when process is active */ | |
300 | uint32_t memlimit_active_attr; | |
301 | int32_t memlimit_inactive; /* jetsam memory limit (in MB) when process is inactive */ | |
302 | uint32_t memlimit_inactive_attr; | |
303 | } memorystatus_memlimit_properties_t; | |
304 | ||
305 | #define MEMORYSTATUS_MEMLIMIT_ATTR_FATAL 0x1 /* if set, exceeding the memlimit is fatal */ | |
306 | ||
39236c6e A |
307 | #ifdef XNU_KERNEL_PRIVATE |
308 | ||
3e170ce0 A |
309 | /* |
310 | * A process will be killed immediately if it crosses a memory limit marked as fatal. | |
311 | * Fatal limit types are the | |
312 | * - default system-wide task limit | |
313 | * - per-task custom memory limit | |
314 | * | |
315 | * A process with a non-fatal memory limit can exceed that limit, but becomes an early | |
316 | * candidate for jetsam when the device is under memory pressure. | |
317 | * Non-fatal limit types are the | |
318 | * - high-water-mark limit | |
319 | * | |
320 | * P_MEMSTAT_MEMLIMIT_BACKGROUND is translated in posix_spawn as | |
321 | * the fatal system_wide task limit when active | |
322 | * non-fatal inactive limit based on limit provided. | |
323 | * This is necessary for backward compatibility until the | |
324 | * the flag can be considered obsolete. | |
325 | * | |
326 | * Processes that opt into dirty tracking are evaluated | |
327 | * based on clean vs dirty state. | |
328 | * dirty ==> active | |
329 | * clean ==> inactive | |
330 | * | |
331 | * Processes that do not opt into dirty tracking are | |
332 | * evalulated based on priority level. | |
333 | * Foreground or above ==> active | |
334 | * Below Foreground ==> inactive | |
335 | */ | |
336 | ||
337 | /* | |
338 | * p_memstat_state flag holds | |
339 | * - in kernel process state and memlimit state | |
340 | */ | |
39236c6e A |
341 | |
342 | #define P_MEMSTAT_SUSPENDED 0x00000001 | |
343 | #define P_MEMSTAT_FROZEN 0x00000002 | |
344 | #define P_MEMSTAT_NORECLAIM 0x00000004 | |
345 | #define P_MEMSTAT_ERROR 0x00000008 | |
346 | #define P_MEMSTAT_LOCKED 0x00000010 | |
347 | #define P_MEMSTAT_TERMINATED 0x00000020 | |
348 | #define P_MEMSTAT_NOTFIED 0x00000040 | |
349 | #define P_MEMSTAT_PRIORITYUPDATED 0x00000080 | |
350 | #define P_MEMSTAT_FOREGROUND 0x00000100 | |
351 | #define P_MEMSTAT_DIAG_SUSPENDED 0x00000200 | |
352 | #define P_MEMSTAT_PRIOR_THAW 0x00000400 | |
fe8ab488 | 353 | #define P_MEMSTAT_MEMLIMIT_BACKGROUND 0x00000800 /* Task has a memory limit for when it's in the background. Used for a process' "high water mark".*/ |
39236c6e | 354 | #define P_MEMSTAT_INTERNAL 0x00001000 |
3e170ce0 A |
355 | #define P_MEMSTAT_FATAL_MEMLIMIT 0x00002000 /* current fatal state of the process's memlimit */ |
356 | #define P_MEMSTAT_MEMLIMIT_ACTIVE_FATAL 0x00004000 /* if set, exceeding limit is fatal when the process is active */ | |
357 | #define P_MEMSTAT_MEMLIMIT_ACTIVE_EXC_TRIGGERED 0x00008000 /* if set, supresses high-water-mark EXC_RESOURCE, allows one hit per active limit */ | |
358 | #define P_MEMSTAT_MEMLIMIT_INACTIVE_FATAL 0x00010000 /* if set, exceeding limit is fatal when the process is inactive */ | |
359 | #define P_MEMSTAT_MEMLIMIT_INACTIVE_EXC_TRIGGERED 0x00020000 /* if set, supresses high-water-mark EXC_RESOURCE, allows one hit per inactive limit */ | |
39037602 A |
360 | #define P_MEMSTAT_USE_ELEVATED_INACTIVE_BAND 0x00040000 /* if set, the process will go into this band & stay there when in the background instead |
361 | of the aging bands and/or the IDLE band. */ | |
316670eb A |
362 | |
363 | extern void memorystatus_init(void) __attribute__((section("__TEXT, initcode"))); | |
364 | ||
3e170ce0 A |
365 | extern void memorystatus_init_at_boot_snapshot(void); |
366 | ||
39236c6e | 367 | extern int memorystatus_add(proc_t p, boolean_t locked); |
3e170ce0 A |
368 | extern int memorystatus_update(proc_t p, int priority, uint64_t user_data, boolean_t effective, |
369 | boolean_t update_memlimit, int32_t memlimit_active, boolean_t memlimit_active_is_fatal, | |
370 | int32_t memlimit_inactive, boolean_t memlimit_inactive_is_fatal, boolean_t memlimit_background); | |
371 | ||
39236c6e A |
372 | extern int memorystatus_remove(proc_t p, boolean_t locked); |
373 | ||
39037602 A |
374 | int memorystatus_update_inactive_jetsam_priority_band(pid_t pid, uint32_t opflags, boolean_t effective_now); |
375 | ||
376 | ||
39236c6e A |
377 | extern int memorystatus_dirty_track(proc_t p, uint32_t pcontrol); |
378 | extern int memorystatus_dirty_set(proc_t p, boolean_t self, uint32_t pcontrol); | |
379 | extern int memorystatus_dirty_get(proc_t p); | |
fe8ab488 | 380 | extern int memorystatus_dirty_clear(proc_t p, uint32_t pcontrol); |
39236c6e A |
381 | |
382 | extern int memorystatus_on_terminate(proc_t p); | |
383 | ||
384 | extern void memorystatus_on_suspend(proc_t p); | |
385 | extern void memorystatus_on_resume(proc_t p); | |
386 | extern void memorystatus_on_inactivity(proc_t p); | |
387 | ||
388 | extern void memorystatus_on_pageout_scan_end(void); | |
389 | ||
390 | /* Memorystatus kevent */ | |
316670eb | 391 | |
39236c6e | 392 | void memorystatus_kevent_init(lck_grp_t *grp, lck_attr_t *attr); |
316670eb | 393 | |
39236c6e A |
394 | int memorystatus_knote_register(struct knote *kn); |
395 | void memorystatus_knote_unregister(struct knote *kn); | |
316670eb | 396 | |
39037602 A |
397 | #if CONFIG_MEMORYSTATUS |
398 | boolean_t memorystatus_turnoff_exception_and_get_fatalness(boolean_t warning, const int max_footprint_mb); | |
399 | void memorystatus_on_ledger_footprint_exceeded(int warning, boolean_t is_fatal); | |
400 | void proc_memstat_terminated(proc_t p, boolean_t set); | |
401 | boolean_t memorystatus_proc_is_dirty_unsafe(void *v); | |
402 | #endif /* CONFIG_MEMORYSTATUS */ | |
403 | ||
316670eb A |
404 | #if CONFIG_JETSAM |
405 | ||
3e170ce0 A |
406 | int memorystatus_get_pressure_status_kdp(void); |
407 | ||
39236c6e | 408 | typedef enum memorystatus_policy { |
316670eb A |
409 | kPolicyDefault = 0x0, |
410 | kPolicyMoreFree = 0x1, | |
411 | kPolicyDiagnoseAll = 0x2, | |
412 | kPolicyDiagnoseFirst = 0x4, | |
413 | kPolicyDiagnoseActive = (kPolicyDiagnoseAll | kPolicyDiagnoseFirst), | |
414 | } memorystatus_policy_t; | |
415 | ||
416 | extern int memorystatus_jetsam_wakeup; | |
417 | extern unsigned int memorystatus_jetsam_running; | |
2d21ac55 | 418 | |
39236c6e A |
419 | boolean_t memorystatus_kill_on_VM_page_shortage(boolean_t async); |
420 | boolean_t memorystatus_kill_on_VM_thrashing(boolean_t async); | |
fe8ab488 | 421 | boolean_t memorystatus_kill_on_FC_thrashing(boolean_t async); |
39236c6e | 422 | boolean_t memorystatus_kill_on_vnode_limit(void); |
316670eb | 423 | |
fe8ab488 | 424 | void jetsam_on_ledger_cpulimit_exceeded(void); |
316670eb | 425 | |
39236c6e | 426 | void memorystatus_pages_update(unsigned int pages_avail); |
316670eb | 427 | |
39236c6e | 428 | #else /* CONFIG_JETSAM */ |
316670eb | 429 | |
39236c6e | 430 | boolean_t memorystatus_idle_exit_from_VM(void); |
316670eb | 431 | |
39236c6e | 432 | #endif /* !CONFIG_JETSAM */ |
6d2010ae A |
433 | |
434 | #ifdef CONFIG_FREEZE | |
6d2010ae | 435 | |
316670eb A |
436 | #define FREEZE_PAGES_MIN ( 1 * 1024 * 1024 / PAGE_SIZE) |
437 | #define FREEZE_PAGES_MAX (16 * 1024 * 1024 / PAGE_SIZE) | |
6d2010ae | 438 | |
316670eb A |
439 | #define FREEZE_SUSPENDED_THRESHOLD_LOW 2 |
440 | #define FREEZE_SUSPENDED_THRESHOLD_DEFAULT 4 | |
441 | ||
3e170ce0 | 442 | #define FREEZE_DAILY_MB_MAX_DEFAULT 1024 |
316670eb A |
443 | |
444 | typedef struct throttle_interval_t { | |
445 | uint32_t mins; | |
446 | uint32_t burst_multiple; | |
447 | uint32_t pageouts; | |
448 | uint32_t max_pageouts; | |
449 | mach_timespec_t ts; | |
450 | boolean_t throttle; | |
451 | } throttle_interval_t; | |
452 | ||
453 | extern boolean_t memorystatus_freeze_enabled; | |
454 | extern int memorystatus_freeze_wakeup; | |
455 | ||
456 | extern void memorystatus_freeze_init(void) __attribute__((section("__TEXT, initcode"))); | |
3e170ce0 | 457 | extern int memorystatus_freeze_process_sync(proc_t p); |
316670eb A |
458 | #endif /* CONFIG_FREEZE */ |
459 | ||
39236c6e A |
460 | #if VM_PRESSURE_EVENTS |
461 | ||
39236c6e A |
462 | extern kern_return_t memorystatus_update_vm_pressure(boolean_t); |
463 | ||
fe8ab488 | 464 | #if CONFIG_MEMORYSTATUS |
3e170ce0 A |
465 | /* Flags */ |
466 | extern int memorystatus_low_mem_privileged_listener(uint32_t op_flags); | |
39236c6e | 467 | extern int memorystatus_send_pressure_note(int pid); |
fe8ab488 | 468 | extern boolean_t memorystatus_is_foreground_locked(proc_t p); |
39236c6e | 469 | extern boolean_t memorystatus_bg_pressure_eligible(proc_t p); |
fe8ab488 | 470 | #endif /* CONFIG_MEMORYSTATUS */ |
39236c6e A |
471 | |
472 | #endif /* VM_PRESSURE_EVENTS */ | |
473 | ||
316670eb | 474 | #endif /* XNU_KERNEL_PRIVATE */ |
2d21ac55 | 475 | |
316670eb | 476 | #endif /* SYS_MEMORYSTATUS_H */ |