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