Unleashed v1.4
[unleashed.git] / include / sys / swap.h
bloba9f354b9025144f781136664e4885834ed1a2afe
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
23 * Copyright (c) 1987, 2010, Oracle and/or its affiliates. All rights reserved.
26 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
30 * University Copyright- Copyright (c) 1982, 1986, 1988
31 * The Regents of the University of California
32 * All Rights Reserved
34 * University Acknowledgment- Portions of this document are derived from
35 * software developed by the University of California, Berkeley, and its
36 * contributors.
39 #ifndef _SYS_SWAP_H
40 #define _SYS_SWAP_H
42 #include <sys/isa_defs.h>
43 #include <sys/feature_tests.h>
44 #include <vm/anon.h>
45 #include <sys/fs/swapnode.h>
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
51 /* The following are for the swapctl system call */
53 #define SC_ADD 1 /* add a specified resource for swapping */
54 #define SC_LIST 2 /* list all the swapping resources */
55 #define SC_REMOVE 3 /* remove the specified swapping resource */
56 #define SC_GETNSWP 4 /* get number of swap resources configured */
57 #define SC_AINFO 5 /* get anonymous memory resource information */
59 typedef struct swapres {
60 char *sr_name; /* pathname of the resource specified */
61 off_t sr_start; /* starting offset of the swapping resource */
62 off_t sr_length; /* length of the swap area */
63 } swapres_t;
65 typedef struct swapent {
66 char *ste_path; /* get the name of the swap file */
67 off_t ste_start; /* starting block for swapping */
68 off_t ste_length; /* length of swap area */
69 long ste_pages; /* numbers of pages for swapping */
70 long ste_free; /* numbers of ste_pages free */
71 int ste_flags; /* see below */
72 } swapent_t;
74 typedef struct swaptable {
75 int swt_n; /* number of swapents following */
76 struct swapent swt_ent[1]; /* array of swt_n swapents */
77 } swaptbl_t;
80 #if defined(_SYSCALL32)
82 /* Kernel's view of user ILP32 swapres and swapent structures */
84 typedef struct swapres32 {
85 caddr32_t sr_name; /* pathname of the resource specified */
86 off_t sr_start; /* starting offset of the swapping resource */
87 off_t sr_length; /* length of the swap area */
88 } swapres32_t;
90 typedef struct swapent32 {
91 caddr32_t ste_path; /* get the name of the swap file */
92 off_t ste_start; /* starting block for swapping */
93 off_t ste_length; /* length of swap area */
94 int32_t ste_pages; /* numbers of pages for swapping */
95 int32_t ste_free; /* numbers of ste_pages free */
96 int32_t ste_flags; /* see below */
97 } swapent32_t;
99 typedef struct swaptable32 {
100 int32_t swt_n; /* number of swapents following */
101 struct swapent32 swt_ent[1]; /* array of swt_n swapents */
102 } swaptbl32_t;
104 #endif /* _SYSCALL32 */
106 #if defined(_KERNEL)
107 extern int swapctl(int, void *, int *);
108 #if defined(_LP64) && defined(_SYSCALL32)
109 extern int swapctl32(int, void *, int *);
110 #endif /* _LP64 && _SYSCALL32 */
111 #else /* !_KERNEL */
112 extern int swapctl(int, void *);
113 #endif /* _KERNEL */
116 /* ste_flags values */
118 #define ST_INDEL 0x01 /* Deletion of file is in progress. */
119 /* Prevents others from deleting or */
120 /* allocating from it */
121 #define ST_DOINGDEL 0x02 /* Set during deletion of file */
122 /* Clearing during deletion signals */
123 /* that you want to add the file back */
124 /* again, and will eventually cause */
125 /* it to be added back */
128 * VM - virtual swap device.
130 struct swapinfo {
131 ulong_t si_soff; /* starting offset (bytes) of file */
132 ulong_t si_eoff; /* ending offset (bytes) of file */
133 struct vnode *si_vp; /* vnode (commonvp if device) */
134 struct swapinfo *si_next; /* next swap area */
135 int si_allocs; /* # of conseq. allocs from this area */
136 short si_flags; /* flags defined below */
137 pgcnt_t si_npgs; /* number of pages of swap space */
138 pgcnt_t si_nfpgs; /* number of free pages of swap space */
139 int si_pnamelen; /* swap file name length + 1 */
140 char *si_pname; /* swap file name */
141 ssize_t si_mapsize; /* # bytes allocated for bitmap */
142 uint_t *si_swapslots; /* bitmap of slots, unset == free */
143 pgcnt_t si_hint; /* first page to check if free */
144 ssize_t si_checkcnt; /* # of checks to find freeslot */
145 ssize_t si_alloccnt; /* used to find ave checks */
149 * Stuff to convert an anon slot pointer to a page name.
150 * Because the address of the slot (ap) is a unique identifier, we
151 * use it to generate a unique (vp,off), as shown in the comment for
152 * swap_alloc().
154 * The off bits are shifted PAGESHIFT to directly form a page aligned
155 * offset; the vp index bits map 1-1 to a vnode.
158 #define MAX_SWAP_VNODES_LOG2 11 /* log2(MAX_SWAP_VNODES) */
159 #define MAX_SWAP_VNODES (1U << MAX_SWAP_VNODES_LOG2) /* max # swap vnodes */
160 #define AN_VPMASK (MAX_SWAP_VNODES - 1) /* vp index mask */
161 #define AN_VPSHIFT MAX_SWAP_VNODES_LOG2
163 * Convert from an anon slot to associated vnode and offset.
165 #define swap_xlate(AP, VPP, OFFP) \
167 *(VPP) = (AP)->an_vp; \
168 *(OFFP) = (AP)->an_off; \
170 #define swap_xlate_nopanic swap_xlate
173 * Get a vnode name for an anon slot.
174 * The vnum, offset are derived from anon struct address which is
175 * 16 bytes aligned. anon structs may be kmem_cache_alloc'd concurrently by
176 * multiple threads and come from a small range of addresses (same slab), in
177 * which case high order AP bits do not vary much, so choose vnum from low
178 * order bits which vary the most. Different threads will thus get different
179 * vnums and vnodes, which avoids contention on the subsequent
180 * page_hashin().
182 * +-----------...-------------------+-----------------------+----+
183 * | swap offset | vnum |0000|
184 * +-----------...-------------------+-----------------------+----+
185 * 63 15 14 4 3 0
187 #define swap_alloc(AP) \
189 (AP)->an_vp = swapfs_getvp(((uintptr_t)(AP) >> AN_CACHE_ALIGN_LOG2) \
190 & AN_VPMASK); \
191 (AP)->an_off = (anoff_t)((((uintptr_t)(AP)) >> \
192 AN_VPSHIFT + AN_CACHE_ALIGN_LOG2) << PAGESHIFT); \
196 * Free the page name for the specified anon slot.
197 * For now there's nothing to do.
199 #define swap_free(AP)
201 /* Flags for swap_phys_alloc */
202 #define SA_NOT 0x01 /* Must have slot from swap dev other than input one */
204 /* Special error codes for swap_newphysname() */
205 #define SE_NOSWAP -1 /* No physical swap slots available */
206 #define SE_NOANON -2 /* No anon slot for swap slot */
208 #ifdef _KERNEL
209 extern struct anon *swap_anon(struct vnode *vp, uoff_t off);
210 extern int swap_phys_alloc(struct vnode **vpp, uoff_t *offp, size_t *lenp,
211 uint_t flags);
212 extern void swap_phys_free(struct vnode *vp, uoff_t off, size_t len);
213 extern int swap_getphysname(struct vnode *vp, uoff_t off,
214 struct vnode **pvpp, uoff_t *poffp);
215 extern int swap_newphysname(struct vnode *vp, uoff_t offset,
216 uoff_t *offp, size_t *lenp, struct vnode **pvpp, uoff_t *poffp);
218 extern struct swapinfo *swapinfo;
219 extern int swap_debug;
220 #endif /* _KERNEL */
222 #ifdef SWAP_DEBUG
223 #define SW_RENAME 0x01
224 #define SW_RESV 0x02
225 #define SW_ALLOC 0x04
226 #define SW_CTL 0x08
227 #define SWAP_PRINT(f, s, x1, x2, x3, x4, x5) \
228 if (swap_debug & f) \
229 printf(s, x1, x2, x3, x4, x5);
230 #else /* SWAP_DEBUG */
231 #define SWAP_PRINT(f, s, x1, x2, x3, x4, x5)
232 #endif /* SWAP_DEBUG */
234 #ifdef __cplusplus
236 #endif
238 #endif /* _SYS_SWAP_H */