1*0f4c859eSApple OSS Distributions /* 2*0f4c859eSApple OSS Distributions * Copyright (c) 2013 Apple Inc. All rights reserved. 3*0f4c859eSApple OSS Distributions * 4*0f4c859eSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*0f4c859eSApple OSS Distributions * 6*0f4c859eSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*0f4c859eSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*0f4c859eSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*0f4c859eSApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*0f4c859eSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*0f4c859eSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*0f4c859eSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*0f4c859eSApple OSS Distributions * terms of an Apple operating system software license agreement. 14*0f4c859eSApple OSS Distributions * 15*0f4c859eSApple OSS Distributions * Please obtain a copy of the License at 16*0f4c859eSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*0f4c859eSApple OSS Distributions * 18*0f4c859eSApple OSS Distributions * The Original Code and all software distributed under the License are 19*0f4c859eSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*0f4c859eSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*0f4c859eSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*0f4c859eSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*0f4c859eSApple OSS Distributions * Please see the License for the specific language governing rights and 24*0f4c859eSApple OSS Distributions * limitations under the License. 25*0f4c859eSApple OSS Distributions * 26*0f4c859eSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*0f4c859eSApple OSS Distributions */ 28*0f4c859eSApple OSS Distributions 29*0f4c859eSApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE 30*0f4c859eSApple OSS Distributions 31*0f4c859eSApple OSS Distributions #ifndef _VM_VM_COMPRESSOR_PAGER_H_ 32*0f4c859eSApple OSS Distributions #define _VM_VM_COMPRESSOR_PAGER_H_ 33*0f4c859eSApple OSS Distributions 34*0f4c859eSApple OSS Distributions #include <mach/mach_types.h> 35*0f4c859eSApple OSS Distributions #include <kern/kern_types.h> 36*0f4c859eSApple OSS Distributions #include <vm/vm_external.h> 37*0f4c859eSApple OSS Distributions 38*0f4c859eSApple OSS Distributions extern kern_return_t vm_compressor_pager_put( 39*0f4c859eSApple OSS Distributions memory_object_t mem_obj, 40*0f4c859eSApple OSS Distributions memory_object_offset_t offset, 41*0f4c859eSApple OSS Distributions ppnum_t ppnum, 42*0f4c859eSApple OSS Distributions bool unmodified, 43*0f4c859eSApple OSS Distributions void **current_chead, 44*0f4c859eSApple OSS Distributions char *scratch_buf, 45*0f4c859eSApple OSS Distributions int *compressed_count_delta_p); 46*0f4c859eSApple OSS Distributions extern kern_return_t vm_compressor_pager_get( 47*0f4c859eSApple OSS Distributions memory_object_t mem_obj, 48*0f4c859eSApple OSS Distributions memory_object_offset_t offset, 49*0f4c859eSApple OSS Distributions ppnum_t ppnum, 50*0f4c859eSApple OSS Distributions int *my_fault_type, 51*0f4c859eSApple OSS Distributions int flags, 52*0f4c859eSApple OSS Distributions int *compressed_count_delta_p); 53*0f4c859eSApple OSS Distributions 54*0f4c859eSApple OSS Distributions __options_decl(vm_compressor_options_t, uint32_t, { 55*0f4c859eSApple OSS Distributions C_DONT_BLOCK = 0x00000001, 56*0f4c859eSApple OSS Distributions C_KEEP = 0x00000002, 57*0f4c859eSApple OSS Distributions C_KDP = 0x00000004, 58*0f4c859eSApple OSS Distributions C_PAGE_UNMODIFIED = 0x00000008, 59*0f4c859eSApple OSS Distributions }); 60*0f4c859eSApple OSS Distributions 61*0f4c859eSApple OSS Distributions extern unsigned int vm_compressor_pager_state_clr( 62*0f4c859eSApple OSS Distributions memory_object_t mem_obj, 63*0f4c859eSApple OSS Distributions memory_object_offset_t offset); 64*0f4c859eSApple OSS Distributions extern vm_external_state_t vm_compressor_pager_state_get( 65*0f4c859eSApple OSS Distributions memory_object_t mem_obj, 66*0f4c859eSApple OSS Distributions memory_object_offset_t offset); 67*0f4c859eSApple OSS Distributions 68*0f4c859eSApple OSS Distributions #define VM_COMPRESSOR_PAGER_STATE_GET(object, offset) \ 69*0f4c859eSApple OSS Distributions (((object)->internal && \ 70*0f4c859eSApple OSS Distributions (object)->pager != NULL && \ 71*0f4c859eSApple OSS Distributions !(object)->terminating && \ 72*0f4c859eSApple OSS Distributions (object)->alive) \ 73*0f4c859eSApple OSS Distributions ? vm_compressor_pager_state_get((object)->pager, \ 74*0f4c859eSApple OSS Distributions (offset) + (object)->paging_offset) \ 75*0f4c859eSApple OSS Distributions : VM_EXTERNAL_STATE_UNKNOWN) 76*0f4c859eSApple OSS Distributions 77*0f4c859eSApple OSS Distributions #define VM_COMPRESSOR_PAGER_STATE_CLR(object, offset) \ 78*0f4c859eSApple OSS Distributions MACRO_BEGIN \ 79*0f4c859eSApple OSS Distributions if ((object)->internal && \ 80*0f4c859eSApple OSS Distributions (object)->pager != NULL && \ 81*0f4c859eSApple OSS Distributions !(object)->terminating && \ 82*0f4c859eSApple OSS Distributions (object)->alive) { \ 83*0f4c859eSApple OSS Distributions int _num_pages_cleared; \ 84*0f4c859eSApple OSS Distributions _num_pages_cleared = \ 85*0f4c859eSApple OSS Distributions vm_compressor_pager_state_clr( \ 86*0f4c859eSApple OSS Distributions (object)->pager, \ 87*0f4c859eSApple OSS Distributions (offset) + (object)->paging_offset); \ 88*0f4c859eSApple OSS Distributions if (_num_pages_cleared) { \ 89*0f4c859eSApple OSS Distributions vm_compressor_pager_count((object)->pager, \ 90*0f4c859eSApple OSS Distributions -_num_pages_cleared, \ 91*0f4c859eSApple OSS Distributions FALSE, /* shared */ \ 92*0f4c859eSApple OSS Distributions (object)); \ 93*0f4c859eSApple OSS Distributions } \ 94*0f4c859eSApple OSS Distributions if (_num_pages_cleared && \ 95*0f4c859eSApple OSS Distributions ((object)->purgable != VM_PURGABLE_DENY || \ 96*0f4c859eSApple OSS Distributions (object)->vo_ledger_tag)) { \ 97*0f4c859eSApple OSS Distributions /* less compressed purgeable/tagged pages */ \ 98*0f4c859eSApple OSS Distributions assert(_num_pages_cleared == 1); \ 99*0f4c859eSApple OSS Distributions vm_object_owner_compressed_update( \ 100*0f4c859eSApple OSS Distributions (object), \ 101*0f4c859eSApple OSS Distributions -_num_pages_cleared); \ 102*0f4c859eSApple OSS Distributions } \ 103*0f4c859eSApple OSS Distributions } \ 104*0f4c859eSApple OSS Distributions MACRO_END 105*0f4c859eSApple OSS Distributions 106*0f4c859eSApple OSS Distributions extern void vm_compressor_pager_transfer( 107*0f4c859eSApple OSS Distributions memory_object_t dst_mem_obj, 108*0f4c859eSApple OSS Distributions memory_object_offset_t dst_offset, 109*0f4c859eSApple OSS Distributions memory_object_t src_mem_obj, 110*0f4c859eSApple OSS Distributions memory_object_offset_t src_offset); 111*0f4c859eSApple OSS Distributions extern memory_object_offset_t vm_compressor_pager_next_compressed( 112*0f4c859eSApple OSS Distributions memory_object_t mem_obj, 113*0f4c859eSApple OSS Distributions memory_object_offset_t offset); 114*0f4c859eSApple OSS Distributions 115*0f4c859eSApple OSS Distributions extern bool osenvironment_is_diagnostics(void); 116*0f4c859eSApple OSS Distributions extern void vm_compressor_init(void); 117*0f4c859eSApple OSS Distributions extern bool vm_compressor_is_slot_compressed(int *slot); 118*0f4c859eSApple OSS Distributions extern int vm_compressor_put(ppnum_t pn, int *slot, void **current_chead, char *scratch_buf, bool unmodified); 119*0f4c859eSApple OSS Distributions extern int vm_compressor_get(ppnum_t pn, int *slot, vm_compressor_options_t flags); 120*0f4c859eSApple OSS Distributions extern int vm_compressor_free(int *slot, vm_compressor_options_t flags); 121*0f4c859eSApple OSS Distributions 122*0f4c859eSApple OSS Distributions #if CONFIG_TRACK_UNMODIFIED_ANON_PAGES 123*0f4c859eSApple OSS Distributions extern uint64_t compressor_ro_uncompressed; 124*0f4c859eSApple OSS Distributions extern uint64_t compressor_ro_uncompressed_total_returned; 125*0f4c859eSApple OSS Distributions extern uint64_t compressor_ro_uncompressed_skip_returned; 126*0f4c859eSApple OSS Distributions extern uint64_t compressor_ro_uncompressed_get; 127*0f4c859eSApple OSS Distributions extern uint64_t compressor_ro_uncompressed_put; 128*0f4c859eSApple OSS Distributions extern uint64_t compressor_ro_uncompressed_swap_usage; 129*0f4c859eSApple OSS Distributions 130*0f4c859eSApple OSS Distributions extern int vm_uncompressed_put(ppnum_t pn, int *slot); 131*0f4c859eSApple OSS Distributions extern int vm_uncompressed_get(ppnum_t pn, int *slot, vm_compressor_options_t flags); 132*0f4c859eSApple OSS Distributions extern int vm_uncompressed_free(int *slot, vm_compressor_options_t flags); 133*0f4c859eSApple OSS Distributions #endif /* CONFIG_TRACK_UNMODIFIED_ANON_PAGES */ 134*0f4c859eSApple OSS Distributions 135*0f4c859eSApple OSS Distributions extern unsigned int vm_compressor_pager_reap_pages(memory_object_t mem_obj, int flags); 136*0f4c859eSApple OSS Distributions extern unsigned int vm_compressor_pager_get_count(memory_object_t mem_obj); 137*0f4c859eSApple OSS Distributions extern void vm_compressor_pager_count(memory_object_t mem_obj, 138*0f4c859eSApple OSS Distributions int compressed_count_delta, 139*0f4c859eSApple OSS Distributions boolean_t shared_lock, 140*0f4c859eSApple OSS Distributions vm_object_t object); 141*0f4c859eSApple OSS Distributions 142*0f4c859eSApple OSS Distributions extern void vm_compressor_transfer(int *dst_slot_p, int *src_slot_p); 143*0f4c859eSApple OSS Distributions 144*0f4c859eSApple OSS Distributions #if CONFIG_FREEZE 145*0f4c859eSApple OSS Distributions extern kern_return_t vm_compressor_pager_relocate(memory_object_t mem_obj, memory_object_offset_t mem_offset, void **current_chead); 146*0f4c859eSApple OSS Distributions extern kern_return_t vm_compressor_relocate(void **current_chead, int *src_slot_p); 147*0f4c859eSApple OSS Distributions extern void vm_compressor_finished_filling(void **current_chead); 148*0f4c859eSApple OSS Distributions #endif /* CONFIG_FREEZE */ 149*0f4c859eSApple OSS Distributions 150*0f4c859eSApple OSS Distributions #if DEVELOPMENT || DEBUG 151*0f4c859eSApple OSS Distributions extern kern_return_t vm_compressor_pager_inject_error(memory_object_t pager, 152*0f4c859eSApple OSS Distributions memory_object_offset_t offset); 153*0f4c859eSApple OSS Distributions extern void vm_compressor_inject_error(int *slot); 154*0f4c859eSApple OSS Distributions #endif /* DEVELOPMENT || DEBUG */ 155*0f4c859eSApple OSS Distributions 156*0f4c859eSApple OSS Distributions #endif /* _VM_VM_COMPRESSOR_PAGER_H_ */ 157*0f4c859eSApple OSS Distributions 158*0f4c859eSApple OSS Distributions #endif /* XNU_KERNEL_PRIVATE */ 159