xref: /titanic_52/usr/src/uts/common/sys/swap.h (revision cb15d5d96b3b2730714c28bfe06cfe7421758b8c)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*cb15d5d9SPeter Rival  * Common Development and Distribution License (the "License").
6*cb15d5d9SPeter Rival  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*cb15d5d9SPeter Rival  * Copyright (c) 1987, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
267c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
307c478bd9Sstevel@tonic-gate  * The Regents of the University of California
317c478bd9Sstevel@tonic-gate  * All Rights Reserved
327c478bd9Sstevel@tonic-gate  *
337c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
347c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
357c478bd9Sstevel@tonic-gate  * contributors.
367c478bd9Sstevel@tonic-gate  */
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #ifndef	_SYS_SWAP_H
397c478bd9Sstevel@tonic-gate #define	_SYS_SWAP_H
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
427c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
437c478bd9Sstevel@tonic-gate #include <vm/anon.h>
447c478bd9Sstevel@tonic-gate #include <sys/fs/swapnode.h>
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
477c478bd9Sstevel@tonic-gate extern "C" {
487c478bd9Sstevel@tonic-gate #endif
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
517c478bd9Sstevel@tonic-gate #error  "Cannot use swapctl in the large files compilation environment"
527c478bd9Sstevel@tonic-gate #endif
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /* The following are for the swapctl system call */
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate #define	SC_ADD		1	/* add a specified resource for swapping */
577c478bd9Sstevel@tonic-gate #define	SC_LIST		2	/* list all the swapping resources */
587c478bd9Sstevel@tonic-gate #define	SC_REMOVE	3	/* remove the specified swapping resource */
597c478bd9Sstevel@tonic-gate #define	SC_GETNSWP	4	/* get number of swap resources configured */
607c478bd9Sstevel@tonic-gate #define	SC_AINFO	5	/* get anonymous memory resource information */
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate typedef struct swapres {
637c478bd9Sstevel@tonic-gate 	char	*sr_name;	/* pathname of the resource specified */
647c478bd9Sstevel@tonic-gate 	off_t	sr_start;	/* starting offset of the swapping resource */
657c478bd9Sstevel@tonic-gate 	off_t 	sr_length;	/* length of the swap area */
667c478bd9Sstevel@tonic-gate } swapres_t;
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate typedef struct swapent {
697c478bd9Sstevel@tonic-gate 	char 	*ste_path;	/* get the name of the swap file */
707c478bd9Sstevel@tonic-gate 	off_t	ste_start;	/* starting block for swapping */
717c478bd9Sstevel@tonic-gate 	off_t	ste_length;	/* length of swap area */
727c478bd9Sstevel@tonic-gate 	long	ste_pages;	/* numbers of pages for swapping */
737c478bd9Sstevel@tonic-gate 	long	ste_free;	/* numbers of ste_pages free */
747c478bd9Sstevel@tonic-gate 	int	ste_flags;	/* see below */
757c478bd9Sstevel@tonic-gate } swapent_t;
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate typedef struct swaptable {
787c478bd9Sstevel@tonic-gate 	int	swt_n;			/* number of swapents following */
797c478bd9Sstevel@tonic-gate 	struct	swapent	swt_ent[1];	/* array of swt_n swapents */
807c478bd9Sstevel@tonic-gate } swaptbl_t;
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32)
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate /* Kernel's view of user ILP32 swapres and swapent structures */
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate typedef struct swapres32 {
887c478bd9Sstevel@tonic-gate 	caddr32_t sr_name;	/* pathname of the resource specified */
897c478bd9Sstevel@tonic-gate 	off32_t	sr_start;	/* starting offset of the swapping resource */
907c478bd9Sstevel@tonic-gate 	off32_t	sr_length;	/* length of the swap area */
917c478bd9Sstevel@tonic-gate } swapres32_t;
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate typedef struct swapent32 {
947c478bd9Sstevel@tonic-gate 	caddr32_t ste_path;	/* get the name of the swap file */
957c478bd9Sstevel@tonic-gate 	off32_t	ste_start;	/* starting block for swapping */
967c478bd9Sstevel@tonic-gate 	off32_t	ste_length;	/* length of swap area */
977c478bd9Sstevel@tonic-gate 	int32_t	ste_pages;	/* numbers of pages for swapping */
987c478bd9Sstevel@tonic-gate 	int32_t	ste_free;	/* numbers of ste_pages free */
997c478bd9Sstevel@tonic-gate 	int32_t	ste_flags;	/* see below */
1007c478bd9Sstevel@tonic-gate } swapent32_t;
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate typedef struct	swaptable32 {
1037c478bd9Sstevel@tonic-gate 	int32_t	swt_n;			/* number of swapents following */
1047c478bd9Sstevel@tonic-gate 	struct	swapent32 swt_ent[1];	/* array of swt_n swapents */
1057c478bd9Sstevel@tonic-gate } swaptbl32_t;
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
1107c478bd9Sstevel@tonic-gate extern int swapctl(int, void *, int *);
1117c478bd9Sstevel@tonic-gate #if defined(_LP64) && defined(_SYSCALL32)
1127c478bd9Sstevel@tonic-gate extern int swapctl32(int, void *, int *);
1137c478bd9Sstevel@tonic-gate #endif /* _LP64 && _SYSCALL32 */
1147c478bd9Sstevel@tonic-gate #else /* !_KERNEL */
1157c478bd9Sstevel@tonic-gate #if defined(__STDC__)
1167c478bd9Sstevel@tonic-gate extern int swapctl(int, void *);
1177c478bd9Sstevel@tonic-gate #else
1187c478bd9Sstevel@tonic-gate extern int swapctl();
1197c478bd9Sstevel@tonic-gate #endif
1207c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate /* ste_flags values */
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate #define	ST_INDEL	0x01		/* Deletion of file is in progress. */
1267c478bd9Sstevel@tonic-gate 					/* Prevents others from deleting or */
1277c478bd9Sstevel@tonic-gate 					/* allocating from it */
1287c478bd9Sstevel@tonic-gate #define	ST_DOINGDEL	0x02		/* Set during deletion of file */
1297c478bd9Sstevel@tonic-gate 					/* Clearing during deletion signals */
1307c478bd9Sstevel@tonic-gate 					/* that you want to add the file back */
1317c478bd9Sstevel@tonic-gate 					/* again, and will eventually cause */
1327c478bd9Sstevel@tonic-gate 					/* it to be added back */
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate /*
1357c478bd9Sstevel@tonic-gate  * VM - virtual swap device.
1367c478bd9Sstevel@tonic-gate  */
1377c478bd9Sstevel@tonic-gate struct	swapinfo {
1387c478bd9Sstevel@tonic-gate 	ulong_t si_soff;		/* starting offset (bytes) of file */
1397c478bd9Sstevel@tonic-gate 	ulong_t si_eoff;		/* ending offset (bytes) of file */
1407c478bd9Sstevel@tonic-gate 	struct	vnode *si_vp;		/* vnode (commonvp if device) */
1417c478bd9Sstevel@tonic-gate 	struct	swapinfo *si_next;	/* next swap area */
1427c478bd9Sstevel@tonic-gate 	int	si_allocs;		/* # of conseq. allocs from this area */
1437c478bd9Sstevel@tonic-gate 	short	si_flags;		/* flags defined below */
1447c478bd9Sstevel@tonic-gate 	pgcnt_t	si_npgs;		/* number of pages of swap space */
1457c478bd9Sstevel@tonic-gate 	pgcnt_t	si_nfpgs;		/* number of free pages of swap space */
1467c478bd9Sstevel@tonic-gate 	int 	si_pnamelen;		/* swap file name length + 1 */
1477c478bd9Sstevel@tonic-gate 	char 	*si_pname;		/* swap file name */
1487c478bd9Sstevel@tonic-gate 	ssize_t	si_mapsize;		/* # bytes allocated for bitmap */
1497c478bd9Sstevel@tonic-gate 	uint_t 	*si_swapslots;		/* bitmap of slots, unset == free */
1507c478bd9Sstevel@tonic-gate 	pgcnt_t	si_hint;		/* first page to check if free */
1517c478bd9Sstevel@tonic-gate 	ssize_t	si_checkcnt;		/* # of checks to find freeslot */
1527c478bd9Sstevel@tonic-gate 	ssize_t	si_alloccnt;		/* used to find ave checks */
1537c478bd9Sstevel@tonic-gate };
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate /*
1567c478bd9Sstevel@tonic-gate  * Stuff to convert an anon slot pointer to a page name.
1577c478bd9Sstevel@tonic-gate  * Because the address of the slot (ap) is a unique identifier, we
158*cb15d5d9SPeter Rival  * use it to generate a unique (vp,off), as shown in the comment for
159*cb15d5d9SPeter Rival  * swap_alloc().
1607c478bd9Sstevel@tonic-gate  *
1617c478bd9Sstevel@tonic-gate  * The off bits are shifted PAGESHIFT to directly form a page aligned
1627c478bd9Sstevel@tonic-gate  * offset; the vp index bits map 1-1 to a vnode.
1637c478bd9Sstevel@tonic-gate  *
1647c478bd9Sstevel@tonic-gate  */
165*cb15d5d9SPeter Rival #define	MAX_SWAP_VNODES_LOG2	11		/* log2(MAX_SWAP_VNODES) */
166*cb15d5d9SPeter Rival #define	MAX_SWAP_VNODES	(1U << MAX_SWAP_VNODES_LOG2)	/* max # swap vnodes */
167*cb15d5d9SPeter Rival #define	AN_VPMASK	(MAX_SWAP_VNODES - 1)	/* vp index mask */
168*cb15d5d9SPeter Rival #define	AN_VPSHIFT	MAX_SWAP_VNODES_LOG2
1697c478bd9Sstevel@tonic-gate /*
1707c478bd9Sstevel@tonic-gate  * Convert from an anon slot to associated vnode and offset.
1717c478bd9Sstevel@tonic-gate  */
1727c478bd9Sstevel@tonic-gate #define	swap_xlate(AP, VPP, OFFP)					\
1737c478bd9Sstevel@tonic-gate {									\
1747c478bd9Sstevel@tonic-gate 	*(VPP) = (AP)->an_vp;						\
1757c478bd9Sstevel@tonic-gate 	*(OFFP) = (AP)->an_off;						\
1767c478bd9Sstevel@tonic-gate }
1777c478bd9Sstevel@tonic-gate #define	swap_xlate_nopanic	swap_xlate
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate /*
1807c478bd9Sstevel@tonic-gate  * Get a vnode name for an anon slot.
1817c478bd9Sstevel@tonic-gate  * The vnum, offset are derived from anon struct address which is
182*cb15d5d9SPeter Rival  * 16 bytes aligned.  anon structs may be kmem_cache_alloc'd concurrently by
183*cb15d5d9SPeter Rival  * multiple threads and come from a small range of addresses (same slab), in
184*cb15d5d9SPeter Rival  * which case high order AP bits do not vary much, so choose vnum from low
185*cb15d5d9SPeter Rival  * order bits which vary the most.  Different threads will thus get different
186*cb15d5d9SPeter Rival  * vnums and vnodes, which avoids vph_mutex_contention on the subsequent
187*cb15d5d9SPeter Rival  * page_hashin().
1887c478bd9Sstevel@tonic-gate  *
189*cb15d5d9SPeter Rival  * +-----------...-------------------+-----------------------+----+
190*cb15d5d9SPeter Rival  * |        swap offset              |           vnum        |0000|
191*cb15d5d9SPeter Rival  * +-----------...-------------------+-----------------------+----+
192*cb15d5d9SPeter Rival  *  63                             15 14                    4 3   0
1937c478bd9Sstevel@tonic-gate  */
1947c478bd9Sstevel@tonic-gate #define	swap_alloc(AP)							\
1957c478bd9Sstevel@tonic-gate {									\
196*cb15d5d9SPeter Rival 	(AP)->an_vp = swapfs_getvp(((uintptr_t)(AP) >> AN_CACHE_ALIGN_LOG2) \
197*cb15d5d9SPeter Rival 	    & AN_VPMASK); 						\
198*cb15d5d9SPeter Rival 	(AP)->an_off = (anoff_t)((((uintptr_t)(AP)) >>			\
199*cb15d5d9SPeter Rival 	    AN_VPSHIFT + AN_CACHE_ALIGN_LOG2) << PAGESHIFT);		\
2007c478bd9Sstevel@tonic-gate }
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate /*
2037c478bd9Sstevel@tonic-gate  * Free the page name for the specified anon slot.
2047c478bd9Sstevel@tonic-gate  * For now there's nothing to do.
2057c478bd9Sstevel@tonic-gate  */
2067c478bd9Sstevel@tonic-gate #define	swap_free(AP)
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate /* Flags for swap_phys_alloc */
2097c478bd9Sstevel@tonic-gate #define	SA_NOT 	0x01 	/* Must have slot from swap dev other than input one */
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate /* Special error codes for swap_newphysname() */
2127c478bd9Sstevel@tonic-gate #define	SE_NOSWAP	-1	/* No physical swap slots available */
2137c478bd9Sstevel@tonic-gate #define	SE_NOANON	-2	/* No anon slot for swap slot */
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate #ifdef _KERNEL
2167c478bd9Sstevel@tonic-gate extern struct anon *swap_anon(struct vnode *vp, u_offset_t off);
2177c478bd9Sstevel@tonic-gate extern int swap_phys_alloc(struct vnode **vpp, u_offset_t *offp, size_t *lenp,
2187c478bd9Sstevel@tonic-gate     uint_t flags);
2197c478bd9Sstevel@tonic-gate extern void swap_phys_free(struct vnode *vp, u_offset_t off, size_t len);
2207c478bd9Sstevel@tonic-gate extern int swap_getphysname(struct vnode *vp, u_offset_t off,
2217c478bd9Sstevel@tonic-gate     struct vnode **pvpp, u_offset_t *poffp);
2227c478bd9Sstevel@tonic-gate extern int swap_newphysname(struct vnode *vp, u_offset_t offset,
2237c478bd9Sstevel@tonic-gate     u_offset_t *offp, size_t *lenp, struct vnode **pvpp, u_offset_t *poffp);
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate extern struct swapinfo *swapinfo;
2267c478bd9Sstevel@tonic-gate extern int swap_debug;
2277c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate #ifdef SWAP_DEBUG
2307c478bd9Sstevel@tonic-gate #define	SW_RENAME	0x01
2317c478bd9Sstevel@tonic-gate #define	SW_RESV		0x02
2327c478bd9Sstevel@tonic-gate #define	SW_ALLOC	0x04
2337c478bd9Sstevel@tonic-gate #define	SW_CTL		0x08
2347c478bd9Sstevel@tonic-gate #define	SWAP_PRINT(f, s, x1, x2, x3, x4, x5) \
2357c478bd9Sstevel@tonic-gate 		if (swap_debug & f) \
2367c478bd9Sstevel@tonic-gate 			printf(s, x1, x2, x3, x4, x5);
2377c478bd9Sstevel@tonic-gate #else	/* SWAP_DEBUG */
2387c478bd9Sstevel@tonic-gate #define	SWAP_PRINT(f, s, x1, x2, x3, x4, x5)
2397c478bd9Sstevel@tonic-gate #endif	/* SWAP_DEBUG */
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2427c478bd9Sstevel@tonic-gate }
2437c478bd9Sstevel@tonic-gate #endif
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate #endif	/* _SYS_SWAP_H */
246