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