xref: /xnu-11215.41.3/osfmk/vm/vm_compressor_backing_store_internal.h (revision 33de042d024d46de5ff4e89f2471de6608e37fa4)
1 /*
2  * Copyright (c) 2000-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 #ifndef _VM_VM_COMPRESSOR_BACKING_STORE_H_
29 #define _VM_VM_COMPRESSOR_BACKING_STORE_H_
30 
31 #ifdef MACH_KERNEL_PRIVATE
32 
33 #include <kern/kern_types.h>
34 #include <kern/locks.h>
35 #include <vm/vm_kern.h>
36 #include <mach/kern_return.h>
37 #include <kern/queue.h>
38 #include <vm/vm_pageout.h>
39 #include <vm/vm_protos.h>
40 #include <vm/vm_compressor_xnu.h>
41 #include <libkern/crypto/aes.h>
42 #include <kern/host_statistics.h>
43 #include <vm/vm_pageout_xnu.h>
44 #include <vm/vm_compressor_backing_store_xnu.h>
45 
46 #if !XNU_TARGET_OS_OSX
47 
48 #define MIN_SWAP_FILE_SIZE              (64 * 1024 * 1024ULL)
49 
50 #define MAX_SWAP_FILE_SIZE              (128 * 1024 * 1024ULL)
51 
52 #else /* !XNU_TARGET_OS_OSX */
53 
54 #define MIN_SWAP_FILE_SIZE              (256 * 1024 * 1024ULL)
55 
56 #define MAX_SWAP_FILE_SIZE              (1 * 1024 * 1024 * 1024ULL)
57 
58 #endif /* !XNU_TARGET_OS_OSX */
59 
60 #if defined(XNU_TARGET_OS_OSX)
61 #define SWAP_VOLUME_NAME        "/System/Volumes"
62 #define SWAP_FILE_NAME          SWAP_VOLUME_NAME "/VM/swapfile"
63 #else
64 #define SWAP_VOLUME_NAME        "/private/var"
65 #define SWAP_FILE_NAME          SWAP_VOLUME_NAME "/vm/swapfile"
66 #endif
67 
68 #define SWAPFILENAME_LEN        (int)(strlen(SWAP_FILE_NAME))
69 
70 
71 #define SWAP_SLOT_MASK          0x1FFFFFFFF
72 #define SWAP_DEVICE_SHIFT       33
73 
74 extern int              vm_num_swap_files;
75 extern uint64_t         vm_swap_volume_capacity;
76 
77 struct swapfile;
78 
79 boolean_t vm_swap_create_file(void);
80 
81 
82 struct swapout_io_completion {
83 	int          swp_io_busy;
84 	int          swp_io_done;
85 	int          swp_io_error;
86 
87 	uint32_t     swp_c_size;
88 	c_segment_t  swp_c_seg;
89 
90 	struct swapfile *swp_swf;
91 	uint64_t        swp_f_offset;
92 
93 	struct upl_io_completion swp_upl_ctx;
94 };
95 void vm_swapout_iodone(void *, int);
96 
97 
98 kern_return_t vm_swap_put_finish(struct swapfile *, uint64_t *, int, boolean_t);
99 kern_return_t vm_swap_put(vm_offset_t, uint64_t*, uint32_t, c_segment_t, struct swapout_io_completion *);
100 
101 void vm_swap_flush(void);
102 void vm_swap_reclaim(void);
103 void vm_swap_encrypt(c_segment_t);
104 
105 uint64_t vm_swap_get_used_space(void);
106 uint64_t vm_swap_get_max_configured_space(void);
107 void vm_swap_reset_max_segs_tracking(uint64_t *alloced_max, uint64_t *used_max);
108 
109 extern __startup_func void vm_compressor_swap_init_swap_file_limit(void);
110 
111 
112 
113 
114 #endif /* MACH_KERNEL_PRIVATE */
115 
116 struct vnode;
117 
118 extern void vm_swapfile_open(const char *path, struct vnode **vp);
119 extern void vm_swapfile_close(uint64_t path, struct vnode *vp);
120 extern int vm_swapfile_preallocate(struct vnode *vp, uint64_t *size, boolean_t *pin);
121 extern uint64_t vm_swapfile_get_blksize(struct vnode *vp);
122 extern uint64_t vm_swapfile_get_transfer_size(struct vnode *vp);
123 extern int vm_swapfile_io(struct vnode *vp, uint64_t offset, uint64_t start, int npages, int flags, void *upl_ctx);
124 extern int vm_record_file_write(struct vnode *vp, uint64_t offset, char *buf, int size);
125 int vm_swap_vol_get_capacity(const char *volume_name, uint64_t *capacity);
126 #if CONFIG_FREEZE
127 int vm_swap_vol_get_budget(struct vnode* vp, uint64_t *freeze_daily_budget);
128 #endif /* CONFIG_FREEZE */
129 
130 
131 #endif /* _VM_VM_COMPRESSOR_BACKING_STORE_H_ */
132