1 /* 2 * Copyright (c) 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 __VM_RECLAIM_INTERNAL__ 30 #define __VM_RECLAIM_INTERNAL__ 31 32 #if CONFIG_DEFERRED_RECLAIM 33 34 #include <vm/vm_reclaim_xnu.h> 35 36 #if MACH_KERNEL_PRIVATE 37 38 __enum_closed_decl(vm_deferred_reclamation_action_t, uint32_t, { 39 RECLAIM_TRIM, // Reclaim a bit of memory from everyone 40 RECLAIM_FULL, // Fully drain every reclaim buffer 41 RECLAIM_ASYNC, // Drain the async reclaim queue 42 }); 43 44 kern_return_t vm_deferred_reclamation_buffer_init_internal( 45 task_t task, 46 mach_vm_address_ut *address, 47 mach_vm_size_ut size); 48 49 kern_return_t vm_deferred_reclamation_buffer_synchronize_internal(task_t task, size_t max_entries_to_reclaim); 50 51 /* 52 * Ask the deferred reclamation subsystem to reclaim memory. 53 * See the documentation for vm_deferred_reclamation_action above. 54 */ 55 void vm_deferred_reclamation_reclaim_memory( 56 vm_deferred_reclamation_action_t action, 57 vm_deferred_reclamation_options_t options); 58 59 kern_return_t vm_deferred_reclamation_buffer_update_reclaimable_bytes_internal( 60 task_t task, size_t reclaimable_bytes); 61 62 /* 63 * Create a fork of the given reclamation buffer for a new task. 64 * Parent buffer must be locked and will be unlocked on return. 65 * 66 * This must be called when forking a task that has a reclamation buffer 67 * to ensure that the kernel knows about the child's reclamation buffer. 68 * The caller must lock the parent's reclamation buffer BEFORE forking 69 * the parent's vm_map. Otherwise the parent's buffer could get reclaimed 70 * in between the map fork and the buffer fork causing the child's 71 * data structures to be out of sync. 72 */ 73 vm_deferred_reclamation_metadata_t vm_deferred_reclamation_buffer_fork( 74 task_t task, 75 vm_deferred_reclamation_metadata_t parent); 76 77 void vm_deferred_reclamation_buffer_lock(vm_deferred_reclamation_metadata_t metadata); 78 void vm_deferred_reclamation_buffer_unlock(vm_deferred_reclamation_metadata_t metadata); 79 80 #if DEVELOPMENT || DEBUG 81 /* 82 * Testing helpers 83 */ 84 bool vm_deferred_reclamation_block_until_pid_has_been_reclaimed(int pid); 85 #endif /* DEVELOPMENT || DEBUG */ 86 87 #endif /* MACH_KERNEL_PRIVATE */ 88 #endif /* CONFIG_DEFERRED_RECLAIM */ 89 #endif /*__VM_RECLAIM_INTERNAL__ */ 90