xref: /titanic_53/usr/src/uts/common/sys/swap.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
28*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate /*
31*7c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
32*7c478bd9Sstevel@tonic-gate  * The Regents of the University of California
33*7c478bd9Sstevel@tonic-gate  * All Rights Reserved
34*7c478bd9Sstevel@tonic-gate  *
35*7c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
36*7c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
37*7c478bd9Sstevel@tonic-gate  * contributors.
38*7c478bd9Sstevel@tonic-gate  */
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate #ifndef	_SYS_SWAP_H
41*7c478bd9Sstevel@tonic-gate #define	_SYS_SWAP_H
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
46*7c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
47*7c478bd9Sstevel@tonic-gate #include <vm/anon.h>
48*7c478bd9Sstevel@tonic-gate #include <sys/fs/swapnode.h>
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
51*7c478bd9Sstevel@tonic-gate extern "C" {
52*7c478bd9Sstevel@tonic-gate #endif
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
55*7c478bd9Sstevel@tonic-gate #error  "Cannot use swapctl in the large files compilation environment"
56*7c478bd9Sstevel@tonic-gate #endif
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate /* The following are for the swapctl system call */
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate #define	SC_ADD		1	/* add a specified resource for swapping */
61*7c478bd9Sstevel@tonic-gate #define	SC_LIST		2	/* list all the swapping resources */
62*7c478bd9Sstevel@tonic-gate #define	SC_REMOVE	3	/* remove the specified swapping resource */
63*7c478bd9Sstevel@tonic-gate #define	SC_GETNSWP	4	/* get number of swap resources configured */
64*7c478bd9Sstevel@tonic-gate #define	SC_AINFO	5	/* get anonymous memory resource information */
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate typedef struct swapres {
67*7c478bd9Sstevel@tonic-gate 	char	*sr_name;	/* pathname of the resource specified */
68*7c478bd9Sstevel@tonic-gate 	off_t	sr_start;	/* starting offset of the swapping resource */
69*7c478bd9Sstevel@tonic-gate 	off_t 	sr_length;	/* length of the swap area */
70*7c478bd9Sstevel@tonic-gate } swapres_t;
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate typedef struct swapent {
73*7c478bd9Sstevel@tonic-gate 	char 	*ste_path;	/* get the name of the swap file */
74*7c478bd9Sstevel@tonic-gate 	off_t	ste_start;	/* starting block for swapping */
75*7c478bd9Sstevel@tonic-gate 	off_t	ste_length;	/* length of swap area */
76*7c478bd9Sstevel@tonic-gate 	long	ste_pages;	/* numbers of pages for swapping */
77*7c478bd9Sstevel@tonic-gate 	long	ste_free;	/* numbers of ste_pages free */
78*7c478bd9Sstevel@tonic-gate 	int	ste_flags;	/* see below */
79*7c478bd9Sstevel@tonic-gate } swapent_t;
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate typedef struct swaptable {
82*7c478bd9Sstevel@tonic-gate 	int	swt_n;			/* number of swapents following */
83*7c478bd9Sstevel@tonic-gate 	struct	swapent	swt_ent[1];	/* array of swt_n swapents */
84*7c478bd9Sstevel@tonic-gate } swaptbl_t;
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32)
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate /* Kernel's view of user ILP32 swapres and swapent structures */
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate typedef struct swapres32 {
92*7c478bd9Sstevel@tonic-gate 	caddr32_t sr_name;	/* pathname of the resource specified */
93*7c478bd9Sstevel@tonic-gate 	off32_t	sr_start;	/* starting offset of the swapping resource */
94*7c478bd9Sstevel@tonic-gate 	off32_t	sr_length;	/* length of the swap area */
95*7c478bd9Sstevel@tonic-gate } swapres32_t;
96*7c478bd9Sstevel@tonic-gate 
97*7c478bd9Sstevel@tonic-gate typedef struct swapent32 {
98*7c478bd9Sstevel@tonic-gate 	caddr32_t ste_path;	/* get the name of the swap file */
99*7c478bd9Sstevel@tonic-gate 	off32_t	ste_start;	/* starting block for swapping */
100*7c478bd9Sstevel@tonic-gate 	off32_t	ste_length;	/* length of swap area */
101*7c478bd9Sstevel@tonic-gate 	int32_t	ste_pages;	/* numbers of pages for swapping */
102*7c478bd9Sstevel@tonic-gate 	int32_t	ste_free;	/* numbers of ste_pages free */
103*7c478bd9Sstevel@tonic-gate 	int32_t	ste_flags;	/* see below */
104*7c478bd9Sstevel@tonic-gate } swapent32_t;
105*7c478bd9Sstevel@tonic-gate 
106*7c478bd9Sstevel@tonic-gate typedef struct	swaptable32 {
107*7c478bd9Sstevel@tonic-gate 	int32_t	swt_n;			/* number of swapents following */
108*7c478bd9Sstevel@tonic-gate 	struct	swapent32 swt_ent[1];	/* array of swt_n swapents */
109*7c478bd9Sstevel@tonic-gate } swaptbl32_t;
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
114*7c478bd9Sstevel@tonic-gate extern int swapctl(int, void *, int *);
115*7c478bd9Sstevel@tonic-gate #if defined(_LP64) && defined(_SYSCALL32)
116*7c478bd9Sstevel@tonic-gate extern int swapctl32(int, void *, int *);
117*7c478bd9Sstevel@tonic-gate #endif /* _LP64 && _SYSCALL32 */
118*7c478bd9Sstevel@tonic-gate #else /* !_KERNEL */
119*7c478bd9Sstevel@tonic-gate #if defined(__STDC__)
120*7c478bd9Sstevel@tonic-gate extern int swapctl(int, void *);
121*7c478bd9Sstevel@tonic-gate #else
122*7c478bd9Sstevel@tonic-gate extern int swapctl();
123*7c478bd9Sstevel@tonic-gate #endif
124*7c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate /* ste_flags values */
128*7c478bd9Sstevel@tonic-gate 
129*7c478bd9Sstevel@tonic-gate #define	ST_INDEL	0x01		/* Deletion of file is in progress. */
130*7c478bd9Sstevel@tonic-gate 					/* Prevents others from deleting or */
131*7c478bd9Sstevel@tonic-gate 					/* allocating from it */
132*7c478bd9Sstevel@tonic-gate #define	ST_DOINGDEL	0x02		/* Set during deletion of file */
133*7c478bd9Sstevel@tonic-gate 					/* Clearing during deletion signals */
134*7c478bd9Sstevel@tonic-gate 					/* that you want to add the file back */
135*7c478bd9Sstevel@tonic-gate 					/* again, and will eventually cause */
136*7c478bd9Sstevel@tonic-gate 					/* it to be added back */
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate /*
139*7c478bd9Sstevel@tonic-gate  * VM - virtual swap device.
140*7c478bd9Sstevel@tonic-gate  */
141*7c478bd9Sstevel@tonic-gate struct	swapinfo {
142*7c478bd9Sstevel@tonic-gate 	ulong_t si_soff;		/* starting offset (bytes) of file */
143*7c478bd9Sstevel@tonic-gate 	ulong_t si_eoff;		/* ending offset (bytes) of file */
144*7c478bd9Sstevel@tonic-gate 	struct	vnode *si_vp;		/* vnode (commonvp if device) */
145*7c478bd9Sstevel@tonic-gate 	struct	swapinfo *si_next;	/* next swap area */
146*7c478bd9Sstevel@tonic-gate 	int	si_allocs;		/* # of conseq. allocs from this area */
147*7c478bd9Sstevel@tonic-gate 	short	si_flags;		/* flags defined below */
148*7c478bd9Sstevel@tonic-gate 	pgcnt_t	si_npgs;		/* number of pages of swap space */
149*7c478bd9Sstevel@tonic-gate 	pgcnt_t	si_nfpgs;		/* number of free pages of swap space */
150*7c478bd9Sstevel@tonic-gate 	int 	si_pnamelen;		/* swap file name length + 1 */
151*7c478bd9Sstevel@tonic-gate 	char 	*si_pname;		/* swap file name */
152*7c478bd9Sstevel@tonic-gate 	ssize_t	si_mapsize;		/* # bytes allocated for bitmap */
153*7c478bd9Sstevel@tonic-gate 	uint_t 	*si_swapslots;		/* bitmap of slots, unset == free */
154*7c478bd9Sstevel@tonic-gate 	pgcnt_t	si_hint;		/* first page to check if free */
155*7c478bd9Sstevel@tonic-gate 	ssize_t	si_checkcnt;		/* # of checks to find freeslot */
156*7c478bd9Sstevel@tonic-gate 	ssize_t	si_alloccnt;		/* used to find ave checks */
157*7c478bd9Sstevel@tonic-gate };
158*7c478bd9Sstevel@tonic-gate 
159*7c478bd9Sstevel@tonic-gate /*
160*7c478bd9Sstevel@tonic-gate  * Stuff to convert an anon slot pointer to a page name.
161*7c478bd9Sstevel@tonic-gate  * Because the address of the slot (ap) is a unique identifier, we
162*7c478bd9Sstevel@tonic-gate  * use it to generate a unique (vp,off), as shown below.
163*7c478bd9Sstevel@tonic-gate  *
164*7c478bd9Sstevel@tonic-gate  *  	|<-- 11 bits -->|<------32 - 11 --------->|
165*7c478bd9Sstevel@tonic-gate  *	   vp index bits	off bits
166*7c478bd9Sstevel@tonic-gate  *
167*7c478bd9Sstevel@tonic-gate  * The off bits are shifted PAGESHIFT to directly form a page aligned
168*7c478bd9Sstevel@tonic-gate  * offset; the vp index bits map 1-1 to a vnode.
169*7c478bd9Sstevel@tonic-gate  *
170*7c478bd9Sstevel@tonic-gate  * Note: if we go to 64 bit offsets, we could use all the bits as the
171*7c478bd9Sstevel@tonic-gate  * unique offset and just have one vnode.
172*7c478bd9Sstevel@tonic-gate  */
173*7c478bd9Sstevel@tonic-gate #define	AN_OFFSHIFT	11			/* vnum # bits */
174*7c478bd9Sstevel@tonic-gate #define	AN_VPSHIFT	21 			/* 32 - 11 */
175*7c478bd9Sstevel@tonic-gate #define	AN_VPSIZEMASK	0x7FF			/* vp index mask */
176*7c478bd9Sstevel@tonic-gate #define	MAX_SWAP_VNODES	2048			/* 1 << AN_OFFSHIFT */
177*7c478bd9Sstevel@tonic-gate #define	AN_CACHE_ALIGN	16			/* anon address aligned */
178*7c478bd9Sstevel@tonic-gate 						/* 16 bytes */
179*7c478bd9Sstevel@tonic-gate /*
180*7c478bd9Sstevel@tonic-gate  * Convert from an anon slot to associated vnode and offset.
181*7c478bd9Sstevel@tonic-gate  */
182*7c478bd9Sstevel@tonic-gate #define	swap_xlate(AP, VPP, OFFP)					\
183*7c478bd9Sstevel@tonic-gate {									\
184*7c478bd9Sstevel@tonic-gate 	*(VPP) = (AP)->an_vp;						\
185*7c478bd9Sstevel@tonic-gate 	*(OFFP) = (AP)->an_off;						\
186*7c478bd9Sstevel@tonic-gate }
187*7c478bd9Sstevel@tonic-gate #define	swap_xlate_nopanic	swap_xlate
188*7c478bd9Sstevel@tonic-gate 
189*7c478bd9Sstevel@tonic-gate /*
190*7c478bd9Sstevel@tonic-gate  * Get a vnode name for an anon slot.
191*7c478bd9Sstevel@tonic-gate  * The vnum, offset are derived from anon struct address which is
192*7c478bd9Sstevel@tonic-gate  * 16 bytes aligned. To get swap offset the anon address is shifted
193*7c478bd9Sstevel@tonic-gate  * by additional 11 bits which yields 32K aligned swap offset
194*7c478bd9Sstevel@tonic-gate  * (11 bits plus 4 bits alignment).
195*7c478bd9Sstevel@tonic-gate  * The vnum (vnode index) is created from bits 31-21.
196*7c478bd9Sstevel@tonic-gate  * The 64 bit swap offset is created from bits 63-32 and 20-4.
197*7c478bd9Sstevel@tonic-gate  * The 32 bit offset is created from bits 20-4.
198*7c478bd9Sstevel@tonic-gate  *
199*7c478bd9Sstevel@tonic-gate  * +-----------...----------+--------+-----------------------+----+
200*7c478bd9Sstevel@tonic-gate  * |        swap offset     |  vnum  |       swap offset     |0000|
201*7c478bd9Sstevel@tonic-gate  * +-----------...----------+--------+-----------------------+----+
202*7c478bd9Sstevel@tonic-gate  *  63	                  32 31    21 20	            4 3  0
203*7c478bd9Sstevel@tonic-gate  */
204*7c478bd9Sstevel@tonic-gate #define	swap_alloc(AP)							\
205*7c478bd9Sstevel@tonic-gate {									\
206*7c478bd9Sstevel@tonic-gate 	(AP)->an_vp = swapfs_getvp(((uintptr_t)(AP) >> AN_VPSHIFT)	\
207*7c478bd9Sstevel@tonic-gate 	    & AN_VPSIZEMASK); 						\
208*7c478bd9Sstevel@tonic-gate 	(AP)->an_off = (anoff_t)(((uintptr_t)(AP) & ~(uintptr_t)0xFFFFFFFF) \
209*7c478bd9Sstevel@tonic-gate 	    | (((uintptr_t)(AP) << AN_OFFSHIFT) & (uintptr_t)0xFFFFFFFF)); \
210*7c478bd9Sstevel@tonic-gate }
211*7c478bd9Sstevel@tonic-gate 
212*7c478bd9Sstevel@tonic-gate /*
213*7c478bd9Sstevel@tonic-gate  * Free the page name for the specified anon slot.
214*7c478bd9Sstevel@tonic-gate  * For now there's nothing to do.
215*7c478bd9Sstevel@tonic-gate  */
216*7c478bd9Sstevel@tonic-gate #define	swap_free(AP)
217*7c478bd9Sstevel@tonic-gate 
218*7c478bd9Sstevel@tonic-gate /* Flags for swap_phys_alloc */
219*7c478bd9Sstevel@tonic-gate #define	SA_NOT 	0x01 	/* Must have slot from swap dev other than input one */
220*7c478bd9Sstevel@tonic-gate 
221*7c478bd9Sstevel@tonic-gate /* Special error codes for swap_newphysname() */
222*7c478bd9Sstevel@tonic-gate #define	SE_NOSWAP	-1	/* No physical swap slots available */
223*7c478bd9Sstevel@tonic-gate #define	SE_NOANON	-2	/* No anon slot for swap slot */
224*7c478bd9Sstevel@tonic-gate 
225*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL
226*7c478bd9Sstevel@tonic-gate extern struct anon *swap_anon(struct vnode *vp, u_offset_t off);
227*7c478bd9Sstevel@tonic-gate extern int swap_phys_alloc(struct vnode **vpp, u_offset_t *offp, size_t *lenp,
228*7c478bd9Sstevel@tonic-gate     uint_t flags);
229*7c478bd9Sstevel@tonic-gate extern void swap_phys_free(struct vnode *vp, u_offset_t off, size_t len);
230*7c478bd9Sstevel@tonic-gate extern int swap_getphysname(struct vnode *vp, u_offset_t off,
231*7c478bd9Sstevel@tonic-gate     struct vnode **pvpp, u_offset_t *poffp);
232*7c478bd9Sstevel@tonic-gate extern int swap_newphysname(struct vnode *vp, u_offset_t offset,
233*7c478bd9Sstevel@tonic-gate     u_offset_t *offp, size_t *lenp, struct vnode **pvpp, u_offset_t *poffp);
234*7c478bd9Sstevel@tonic-gate 
235*7c478bd9Sstevel@tonic-gate extern struct swapinfo *swapinfo;
236*7c478bd9Sstevel@tonic-gate extern int swap_debug;
237*7c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
238*7c478bd9Sstevel@tonic-gate 
239*7c478bd9Sstevel@tonic-gate #ifdef SWAP_DEBUG
240*7c478bd9Sstevel@tonic-gate #define	SW_RENAME	0x01
241*7c478bd9Sstevel@tonic-gate #define	SW_RESV		0x02
242*7c478bd9Sstevel@tonic-gate #define	SW_ALLOC	0x04
243*7c478bd9Sstevel@tonic-gate #define	SW_CTL		0x08
244*7c478bd9Sstevel@tonic-gate #define	SWAP_PRINT(f, s, x1, x2, x3, x4, x5) \
245*7c478bd9Sstevel@tonic-gate 		if (swap_debug & f) \
246*7c478bd9Sstevel@tonic-gate 			printf(s, x1, x2, x3, x4, x5);
247*7c478bd9Sstevel@tonic-gate #else	/* SWAP_DEBUG */
248*7c478bd9Sstevel@tonic-gate #define	SWAP_PRINT(f, s, x1, x2, x3, x4, x5)
249*7c478bd9Sstevel@tonic-gate #endif	/* SWAP_DEBUG */
250*7c478bd9Sstevel@tonic-gate 
251*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
252*7c478bd9Sstevel@tonic-gate }
253*7c478bd9Sstevel@tonic-gate #endif
254*7c478bd9Sstevel@tonic-gate 
255*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_SWAP_H */
256