xref: /xnu-12377.1.9/osfmk/vm/vm_compressor_internal.h (revision f6217f891ac0bb64f3d375211650a4c1ff8ca1ea)
1 /*
2  * Copyright (c) 2023 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_VM_COMPRESSOR_INTERNAL_H_
30 #define _VM_VM_COMPRESSOR_INTERNAL_H_
31 
32 #include <sys/cdefs.h>
33 #include <vm/vm_compressor_xnu.h>
34 
35 __BEGIN_DECLS
36 #ifdef XNU_KERNEL_PRIVATE
37 
38 
39 void vm_consider_waking_compactor_swapper(void);
40 void vm_consider_swapping(void);
41 void vm_compressor_flush(void);
42 void c_seg_free(c_segment_t);
43 void c_seg_free_locked(c_segment_t);
44 void c_seg_need_delayed_compaction(c_segment_t, boolean_t);
45 void c_seg_update_task_owner(c_segment_t, task_t);
46 void vm_compressor_record_warmup_start(void);
47 void vm_compressor_record_warmup_end(void);
48 
49 int                     vm_wants_task_throttled(task_t);
50 
51 extern void             vm_compaction_swapper_do_init(void);
52 extern void             vm_compressor_swap_init(void);
53 extern lck_rw_t         c_master_lock;
54 
55 #define PAGE_REPLACEMENT_DISALLOWED(enable)     (enable == TRUE ? lck_rw_lock_shared(&c_master_lock) : lck_rw_done(&c_master_lock))
56 #define PAGE_REPLACEMENT_ALLOWED(enable)        (enable == TRUE ? lck_rw_lock_exclusive(&c_master_lock) : lck_rw_done(&c_master_lock))
57 
58 #if ENCRYPTED_SWAP
59 extern void             vm_swap_decrypt(c_segment_t, bool);
60 #endif /* ENCRYPTED_SWAP */
61 
62 extern void             vm_swap_free(uint64_t);
63 
64 extern void             c_seg_swapin_requeue(c_segment_t, boolean_t, boolean_t, boolean_t);
65 extern int              c_seg_swapin(c_segment_t, boolean_t, boolean_t);
66 extern void             c_seg_wait_on_busy(c_segment_t);
67 extern void             c_seg_trim_tail(c_segment_t);
68 extern void             c_seg_switch_state(c_segment_t, int, boolean_t);
69 
70 
71 extern boolean_t        fastwake_recording_in_progress;
72 extern int              compaction_swapper_inited;
73 extern int              compaction_swapper_running;
74 extern uint64_t         vm_swap_put_failures;
75 
76 extern int              c_overage_swapped_count;
77 extern int              c_overage_swapped_limit;
78 
79 extern queue_head_t     c_minor_list_head;
80 extern queue_head_t     c_age_list_head;
81 extern queue_head_t     c_major_list_head;
82 extern queue_head_t     c_early_swapout_list_head;
83 extern queue_head_t     c_regular_swapout_list_head;
84 extern queue_head_t     c_late_swapout_list_head;
85 extern queue_head_t     c_swappedout_list_head;
86 extern queue_head_t     c_swappedout_sparse_list_head;
87 
88 extern uint64_t         first_c_segment_to_warm_generation_id;
89 extern uint64_t         last_c_segment_to_warm_generation_id;
90 extern boolean_t        hibernate_flushing;
91 extern boolean_t        hibernate_no_swapspace;
92 extern boolean_t        hibernate_in_progress_with_pinned_swap;
93 extern boolean_t        hibernate_flush_timed_out;
94 
95 extern void c_seg_insert_into_q(queue_head_t *, c_segment_t);
96 
97 extern uint64_t vm_compressor_compute_elapsed_msecs(clock_sec_t, clock_nsec_t, clock_sec_t, clock_nsec_t);
98 
99 uint32_t vm_compressor_get_encode_scratch_size(void) __pure2;
100 uint32_t vm_compressor_get_decode_scratch_size(void) __pure2;
101 
102 #if RECORD_THE_COMPRESSED_DATA
103 extern void      c_compressed_record_init(void);
104 extern void      c_compressed_record_write(char *, int);
105 #endif
106 
107 #endif /* XNU_KERNEL_PRIVATE */
108 __END_DECLS
109 #endif /* _VM_VM_COMPRESSOR_INTERNAL_H_ */
110