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 * Query if this process is state-managed by RunningBoard. 44 */ 45 typedef struct proc * proc_t; 46 extern bool memorystatus_get_proc_is_managed(proc_t proc); 47 48 /* 49 * Return the minimum number of available pages jetsam requires before it 50 * begins killing non-idle processes. This is useful for some pageout 51 * mechanisms to avoid deadlock. 52 */ 53 extern uint32_t memorystatus_get_critical_page_shortage_threshold(void); 54 55 /* 56 * Return the minimum number of available pages jetsam requires before it 57 * begins killing idle processes. This is consumed by the vm pressure 58 * notification system in the absence of the compressor. 59 */ 60 extern uint32_t memorystatus_get_idle_exit_page_shortage_threshold(void); 61 62 /* 63 * Return the minimum number of available pages jetsam requires before it 64 * begins killing processes which have violated their soft memory limit. This 65 * is consumed by the vm pressure notification system in the absence of the 66 * compressor. 67 */ 68 extern uint32_t memorystatus_get_soft_memlimit_page_shortage_threshold(void); 69 70 /* 71 * Return the minumum number of available pages jetsam requires before it 72 * begins reaping long-idle processes. 73 */ 74 extern uint32_t memorystatus_get_reaper_page_shortage_threshold(void); 75 76 /* 77 * Return the current number of available pages in the system. 78 */ 79 extern uint32_t memorystatus_get_available_page_count(void); 80 81 /* 82 * Set the available page count and consider engaging response measures (e.g. 83 * waking jetsam thread/pressure-notification thread). 84 */ 85 extern void memorystatus_update_available_page_count(uint32_t available_pages); 86 87 /* 88 * Override fast-jetsam support. If override is enabled, fast-jetsam will be 89 * disabled. 90 */ 91 extern void memorystatus_fast_jetsam_override(bool enable_override); 92 93 /* 94 * Callout to jetsam. If pid is -1, we wake up the memorystatus thread to do asynchronous kills. 95 * For any other pid we try to kill that process synchronously. 96 */ 97 extern bool memorystatus_kill_on_zone_map_exhaustion(pid_t pid); 98 99 /* 100 * Kill a single process due to compressor space shortage. 101 */ 102 extern bool memorystatus_kill_on_VM_compressor_space_shortage(bool async); 103 104 /* 105 * Asynchronously kill a single process due to VM Pageout Starvation (i.e. 106 * a "stuck" external pageout thread). 107 */ 108 extern void memorystatus_kill_on_vps_starvation(void); 109 110 /* 111 * Synchronously kill a single process due to vnode exhaustion 112 */ 113 extern bool memorystatus_kill_on_vnode_exhaustion(void); 114 115 /* 116 * Wake up the memorystatus thread so it can do async kills. 117 * The memorystatus thread will keep killing until the system is 118 * considered healthy. 119 */ 120 extern void memorystatus_thread_wake(void); 121 122 /* 123 * Respond to compressor exhaustion by waking the jetsam thread or 124 * synchronously invoking a no-paging-space action. 125 */ 126 extern void memorystatus_respond_to_compressor_exhaustion(void); 127 128 /* 129 * Respond to swap exhaustion by waking the jetsam thread or 130 * synchronously invoking a no-paging-space action. 131 */ 132 extern void memorystatus_respond_to_swap_exhaustion(void); 133 134 __END_DECLS 135