]> git.saurik.com Git - apple/xnu.git/blame - osfmk/vm/vm_compressor_backing_store.h
xnu-2422.100.13.tar.gz
[apple/xnu.git] / osfmk / vm / vm_compressor_backing_store.h
CommitLineData
39236c6e
A
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 <kern/kalloc.h>
32#include <vm/vm_kern.h>
33#include <mach/kern_return.h>
34#include <kern/queue.h>
35#include <vm/vm_pageout.h>
36#include <vm/vm_protos.h>
37#include <vm/vm_compressor.h>
38#include <libkern/crypto/aes.h>
39#include <kern/host_statistics.h>
40
41
42#define SANITY_CHECK_SWAP_ROUTINES 0
43
44#if SANITY_CHECK_SWAP_ROUTINES
45
46#define MIN_SWAP_FILE_SIZE (4 * 1024)
47
48#define MAX_SWAP_FILE_SIZE (4 * 1024)
49
50#define COMPRESSED_SWAP_CHUNK_SIZE (4 * 1024)
51
52#define VM_SWAPFILE_HIWATER_SEGS (MIN_SWAP_FILE_SIZE / COMPRESSED_SWAP_CHUNK_SIZE)
53
54#define SWAPFILE_RECLAIM_THRESHOLD_SEGS (MIN_SWAP_FILE_SIZE / COMPRESSED_SWAP_CHUNK_SIZE)
55
56#else /* SANITY_CHECK_SWAP_ROUTINES */
57
58
59#define MIN_SWAP_FILE_SIZE (256 * 1024 * 1024)
60
61#define MAX_SWAP_FILE_SIZE (1 * 1024 * 1024 * 1024)
62
63
64#define COMPRESSED_SWAP_CHUNK_SIZE (C_SEG_BUFSIZE)
65
66#define VM_SWAPFILE_HIWATER_SEGS (MIN_SWAP_FILE_SIZE / COMPRESSED_SWAP_CHUNK_SIZE)
67
68#define SWAPFILE_RECLAIM_THRESHOLD_SEGS ((15 * (MAX_SWAP_FILE_SIZE / COMPRESSED_SWAP_CHUNK_SIZE)) / 10)
69
70#endif /* SANITY_CHECK_SWAP_ROUTINES */
71
72#define SWAP_FILE_NAME "/var/vm/swapfile"
73#define SWAPFILENAME_LEN (int)(strlen(SWAP_FILE_NAME))
74#define SWAPFILENAME_INDEX_LEN 2 /* Doesn't include the terminating NULL character */
75
76#define SWAP_SLOT_MASK 0x1FFFFFFFF
77#define SWAP_DEVICE_SHIFT 33
78
79extern int vm_num_swap_files;
80extern boolean_t vm_swap_up;
81
82struct swapfile;
83lck_grp_attr_t vm_swap_data_lock_grp_attr;
84lck_grp_t vm_swap_data_lock_grp;
85lck_attr_t vm_swap_data_lock_attr;
86lck_mtx_ext_t vm_swap_data_lock_ext;
87lck_mtx_t vm_swap_data_lock;
88
89void vm_swap_init(void);
90boolean_t vm_swap_create_file(void);
91kern_return_t vm_swap_put(vm_offset_t, uint64_t*, uint64_t, c_segment_t);
92void vm_swap_flush(void);
93void vm_swap_reclaim(void);
94void vm_swap_encrypt(c_segment_t);
95uint64_t vm_swap_get_total_space(void);
96uint64_t vm_swap_get_used_space(void);
97uint64_t vm_swap_get_free_space(void);
98
99struct vnode;
100extern void vm_swapfile_open(const char *path, struct vnode **vp);
101extern void vm_swapfile_close(uint64_t path, struct vnode *vp);
102extern int vm_swapfile_preallocate(struct vnode *vp, uint64_t *size);
103extern uint64_t vm_swapfile_get_blksize(struct vnode *vp);
104extern uint64_t vm_swapfile_get_transfer_size(struct vnode *vp);
105extern int vm_swapfile_io(struct vnode *vp, uint64_t offset, uint64_t start, int npages, int flags);
106
107