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]
22 * Copyright (c) 1987, 2010, Oracle and/or its affiliates. All rights reserved.
25 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
26 /* All Rights Reserved */
29 * University Copyright- Copyright (c) 1982, 1986, 1988
30 * The Regents of the University of California
33 * University Acknowledgment- Portions of this document are derived from
34 * software developed by the University of California, Berkeley, and its
41 #include <sys/isa_defs.h>
42 #include <sys/feature_tests.h>
44 #include <sys/fs/swapnode.h>
50 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
51 #error "Cannot use swapctl in the large files compilation environment"
54 /* The following are for the swapctl system call */
56 #define SC_ADD 1 /* add a specified resource for swapping */
57 #define SC_LIST 2 /* list all the swapping resources */
58 #define SC_REMOVE 3 /* remove the specified swapping resource */
59 #define SC_GETNSWP 4 /* get number of swap resources configured */
60 #define SC_AINFO 5 /* get anonymous memory resource information */
62 typedef struct swapres
{
63 char *sr_name
; /* pathname of the resource specified */
64 off_t sr_start
; /* starting offset of the swapping resource */
65 off_t sr_length
; /* length of the swap area */
68 typedef struct swapent
{
69 char *ste_path
; /* get the name of the swap file */
70 off_t ste_start
; /* starting block for swapping */
71 off_t ste_length
; /* length of swap area */
72 long ste_pages
; /* numbers of pages for swapping */
73 long ste_free
; /* numbers of ste_pages free */
74 int ste_flags
; /* see below */
77 typedef struct swaptable
{
78 int swt_n
; /* number of swapents following */
79 struct swapent swt_ent
[1]; /* array of swt_n swapents */
83 #if defined(_SYSCALL32)
85 /* Kernel's view of user ILP32 swapres and swapent structures */
87 typedef struct swapres32
{
88 caddr32_t sr_name
; /* pathname of the resource specified */
89 off32_t sr_start
; /* starting offset of the swapping resource */
90 off32_t sr_length
; /* length of the swap area */
93 typedef struct swapent32
{
94 caddr32_t ste_path
; /* get the name of the swap file */
95 off32_t ste_start
; /* starting block for swapping */
96 off32_t ste_length
; /* length of swap area */
97 int32_t ste_pages
; /* numbers of pages for swapping */
98 int32_t ste_free
; /* numbers of ste_pages free */
99 int32_t ste_flags
; /* see below */
102 typedef struct swaptable32
{
103 int32_t swt_n
; /* number of swapents following */
104 struct swapent32 swt_ent
[1]; /* array of swt_n swapents */
107 #endif /* _SYSCALL32 */
110 extern int swapctl(int, void *, int *);
111 #if defined(_LP64) && defined(_SYSCALL32)
112 extern int swapctl32(int, void *, int *);
113 #endif /* _LP64 && _SYSCALL32 */
115 #if defined(__STDC__)
116 extern int swapctl(int, void *);
118 extern int swapctl();
123 /* ste_flags values */
125 #define ST_INDEL 0x01 /* Deletion of file is in progress. */
126 /* Prevents others from deleting or */
127 /* allocating from it */
128 #define ST_DOINGDEL 0x02 /* Set during deletion of file */
129 /* Clearing during deletion signals */
130 /* that you want to add the file back */
131 /* again, and will eventually cause */
132 /* it to be added back */
135 * VM - virtual swap device.
138 ulong_t si_soff
; /* starting offset (bytes) of file */
139 ulong_t si_eoff
; /* ending offset (bytes) of file */
140 struct vnode
*si_vp
; /* vnode (commonvp if device) */
141 struct swapinfo
*si_next
; /* next swap area */
142 int si_allocs
; /* # of conseq. allocs from this area */
143 short si_flags
; /* flags defined below */
144 pgcnt_t si_npgs
; /* number of pages of swap space */
145 pgcnt_t si_nfpgs
; /* number of free pages of swap space */
146 int si_pnamelen
; /* swap file name length + 1 */
147 char *si_pname
; /* swap file name */
148 ssize_t si_mapsize
; /* # bytes allocated for bitmap */
149 uint_t
*si_swapslots
; /* bitmap of slots, unset == free */
150 pgcnt_t si_hint
; /* first page to check if free */
151 ssize_t si_checkcnt
; /* # of checks to find freeslot */
152 ssize_t si_alloccnt
; /* used to find ave checks */
156 * Stuff to convert an anon slot pointer to a page name.
157 * Because the address of the slot (ap) is a unique identifier, we
158 * use it to generate a unique (vp,off), as shown in the comment for
161 * The off bits are shifted PAGESHIFT to directly form a page aligned
162 * offset; the vp index bits map 1-1 to a vnode.
165 #define MAX_SWAP_VNODES_LOG2 11 /* log2(MAX_SWAP_VNODES) */
166 #define MAX_SWAP_VNODES (1U << MAX_SWAP_VNODES_LOG2) /* max # swap vnodes */
167 #define AN_VPMASK (MAX_SWAP_VNODES - 1) /* vp index mask */
168 #define AN_VPSHIFT MAX_SWAP_VNODES_LOG2
170 * Convert from an anon slot to associated vnode and offset.
172 #define swap_xlate(AP, VPP, OFFP) \
174 *(VPP) = (AP)->an_vp; \
175 *(OFFP) = (AP)->an_off; \
177 #define swap_xlate_nopanic swap_xlate
180 * Get a vnode name for an anon slot.
181 * The vnum, offset are derived from anon struct address which is
182 * 16 bytes aligned. anon structs may be kmem_cache_alloc'd concurrently by
183 * multiple threads and come from a small range of addresses (same slab), in
184 * which case high order AP bits do not vary much, so choose vnum from low
185 * order bits which vary the most. Different threads will thus get different
186 * vnums and vnodes, which avoids vph_mutex_contention on the subsequent
189 * +-----------...-------------------+-----------------------+----+
190 * | swap offset | vnum |0000|
191 * +-----------...-------------------+-----------------------+----+
194 #define swap_alloc(AP) \
196 (AP)->an_vp = swapfs_getvp(((uintptr_t)(AP) >> AN_CACHE_ALIGN_LOG2) \
198 (AP)->an_off = (anoff_t)((((uintptr_t)(AP)) >> \
199 AN_VPSHIFT + AN_CACHE_ALIGN_LOG2) << PAGESHIFT); \
203 * Free the page name for the specified anon slot.
204 * For now there's nothing to do.
206 #define swap_free(AP)
208 /* Flags for swap_phys_alloc */
209 #define SA_NOT 0x01 /* Must have slot from swap dev other than input one */
211 /* Special error codes for swap_newphysname() */
212 #define SE_NOSWAP -1 /* No physical swap slots available */
213 #define SE_NOANON -2 /* No anon slot for swap slot */
216 extern struct anon
*swap_anon(struct vnode
*vp
, u_offset_t off
);
217 extern int swap_phys_alloc(struct vnode
**vpp
, u_offset_t
*offp
, size_t *lenp
,
219 extern void swap_phys_free(struct vnode
*vp
, u_offset_t off
, size_t len
);
220 extern int swap_getphysname(struct vnode
*vp
, u_offset_t off
,
221 struct vnode
**pvpp
, u_offset_t
*poffp
);
222 extern int swap_newphysname(struct vnode
*vp
, u_offset_t offset
,
223 u_offset_t
*offp
, size_t *lenp
, struct vnode
**pvpp
, u_offset_t
*poffp
);
225 extern struct swapinfo
*swapinfo
;
226 extern int swap_debug
;
230 #define SW_RENAME 0x01
232 #define SW_ALLOC 0x04
234 #define SWAP_PRINT(f, s, x1, x2, x3, x4, x5) \
235 if (swap_debug & f) \
236 printf(s, x1, x2, x3, x4, x5);
237 #else /* SWAP_DEBUG */
238 #define SWAP_PRINT(f, s, x1, x2, x3, x4, x5)
239 #endif /* SWAP_DEBUG */
245 #endif /* _SYS_SWAP_H */