1/*
2 * Copyright (c) 2013 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#ifdef XNU_KERNEL_PRIVATE
30
31#ifndef _VM_VM_COMPRESSOR_PAGER_H_
32#define _VM_VM_COMPRESSOR_PAGER_H_
33
34#include <mach/mach_types.h>
35#include <kern/kern_types.h>
36#include <vm/vm_external.h>
37
38extern kern_return_t vm_compressor_pager_put(
39 memory_object_t mem_obj,
40 memory_object_offset_t offset,
41 ppnum_t ppnum,
42 bool unmodified,
43 void **current_chead,
44 char *scratch_buf,
45 int *compressed_count_delta_p);
46extern kern_return_t vm_compressor_pager_get(
47 memory_object_t mem_obj,
48 memory_object_offset_t offset,
49 ppnum_t ppnum,
50 int *my_fault_type,
51 int flags,
52 int *compressed_count_delta_p);
53
54__options_decl(vm_compressor_options_t, uint32_t, {
55 C_DONT_BLOCK = 0x00000001,
56 C_KEEP = 0x00000002,
57 C_KDP = 0x00000004,
58 C_PAGE_UNMODIFIED = 0x00000008,
59});
60
61extern unsigned int vm_compressor_pager_state_clr(
62 memory_object_t mem_obj,
63 memory_object_offset_t offset);
64extern vm_external_state_t vm_compressor_pager_state_get(
65 memory_object_t mem_obj,
66 memory_object_offset_t offset);
67
68#define VM_COMPRESSOR_PAGER_STATE_GET(object, offset) \
69 (((object)->internal && \
70 (object)->pager != NULL && \
71 !(object)->terminating && \
72 (object)->alive) \
73 ? vm_compressor_pager_state_get((object)->pager, \
74 (offset) + (object)->paging_offset) \
75 : VM_EXTERNAL_STATE_UNKNOWN)
76
77#define VM_COMPRESSOR_PAGER_STATE_CLR(object, offset) \
78 MACRO_BEGIN \
79 if ((object)->internal && \
80 (object)->pager != NULL && \
81 !(object)->terminating && \
82 (object)->alive) { \
83 int _num_pages_cleared; \
84 _num_pages_cleared = \
85 vm_compressor_pager_state_clr( \
86 (object)->pager, \
87 (offset) + (object)->paging_offset); \
88 if (_num_pages_cleared) { \
89 vm_compressor_pager_count((object)->pager, \
90 -_num_pages_cleared, \
91 FALSE, /* shared */ \
92 (object)); \
93 } \
94 if (_num_pages_cleared && \
95 ((object)->purgable != VM_PURGABLE_DENY || \
96 (object)->vo_ledger_tag)) { \
97 /* less compressed purgeable/tagged pages */ \
98 assert(_num_pages_cleared == 1); \
99 vm_object_owner_compressed_update( \
100 (object), \
101 -_num_pages_cleared); \
102 } \
103 } \
104 MACRO_END
105
106extern void vm_compressor_pager_transfer(
107 memory_object_t dst_mem_obj,
108 memory_object_offset_t dst_offset,
109 memory_object_t src_mem_obj,
110 memory_object_offset_t src_offset);
111extern memory_object_offset_t vm_compressor_pager_next_compressed(
112 memory_object_t mem_obj,
113 memory_object_offset_t offset);
114
115extern bool osenvironment_is_diagnostics(void);
116extern void vm_compressor_init(void);
117extern bool vm_compressor_is_slot_compressed(int *slot);
118extern int vm_compressor_put(ppnum_t pn, int *slot, void **current_chead, char *scratch_buf, bool unmodified);
119extern int vm_compressor_get(ppnum_t pn, int *slot, vm_compressor_options_t flags);
120extern int vm_compressor_free(int *slot, vm_compressor_options_t flags);
121
122#if CONFIG_TRACK_UNMODIFIED_ANON_PAGES
123extern uint64_t compressor_ro_uncompressed;
124extern uint64_t compressor_ro_uncompressed_total_returned;
125extern uint64_t compressor_ro_uncompressed_skip_returned;
126extern uint64_t compressor_ro_uncompressed_get;
127extern uint64_t compressor_ro_uncompressed_put;
128extern uint64_t compressor_ro_uncompressed_swap_usage;
129
130extern int vm_uncompressed_put(ppnum_t pn, int *slot);
131extern int vm_uncompressed_get(ppnum_t pn, int *slot, vm_compressor_options_t flags);
132extern int vm_uncompressed_free(int *slot, vm_compressor_options_t flags);
133#endif /* CONFIG_TRACK_UNMODIFIED_ANON_PAGES */
134
135extern unsigned int vm_compressor_pager_reap_pages(memory_object_t mem_obj, int flags);
136extern unsigned int vm_compressor_pager_get_count(memory_object_t mem_obj);
137extern void vm_compressor_pager_count(memory_object_t mem_obj,
138 int compressed_count_delta,
139 boolean_t shared_lock,
140 vm_object_t object);
141
142extern void vm_compressor_transfer(int *dst_slot_p, int *src_slot_p);
143
144#if CONFIG_FREEZE
145extern kern_return_t vm_compressor_pager_relocate(memory_object_t mem_obj, memory_object_offset_t mem_offset, void **current_chead);
146extern kern_return_t vm_compressor_relocate(void **current_chead, int *src_slot_p);
147extern void vm_compressor_finished_filling(void **current_chead);
148#endif /* CONFIG_FREEZE */
149
150#if DEVELOPMENT || DEBUG
151extern kern_return_t vm_compressor_pager_inject_error(memory_object_t pager,
152 memory_object_offset_t offset);
153extern void vm_compressor_inject_error(int *slot);
154#endif /* DEVELOPMENT || DEBUG */
155
156#endif /* _VM_VM_COMPRESSOR_PAGER_H_ */
157
158#endif /* XNU_KERNEL_PRIVATE */
159