swap.h revision cb15d5d96b3b2730714c28bfe06cfe7421758b8c
2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 1987, 2010, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
2N/A/* All Rights Reserved */
2N/A
2N/A/*
2N/A * University Copyright- Copyright (c) 1982, 1986, 1988
2N/A * The Regents of the University of California
2N/A * All Rights Reserved
2N/A *
2N/A * University Acknowledgment- Portions of this document are derived from
2N/A * software developed by the University of California, Berkeley, and its
2N/A * contributors.
2N/A */
2N/A
2N/A#ifndef _SYS_SWAP_H
2N/A#define _SYS_SWAP_H
2N/A
2N/A#include <sys/isa_defs.h>
2N/A#include <sys/feature_tests.h>
2N/A#include <vm/anon.h>
2N/A#include <sys/fs/swapnode.h>
2N/A
2N/A#ifdef __cplusplus
2N/Aextern "C" {
2N/A#endif
2N/A
2N/A#if !defined(_LP64) && _FILE_OFFSET_BITS == 64
2N/A#error "Cannot use swapctl in the large files compilation environment"
2N/A#endif
2N/A
2N/A/* The following are for the swapctl system call */
2N/A
2N/A#define SC_ADD 1 /* add a specified resource for swapping */
2N/A#define SC_LIST 2 /* list all the swapping resources */
2N/A#define SC_REMOVE 3 /* remove the specified swapping resource */
2N/A#define SC_GETNSWP 4 /* get number of swap resources configured */
2N/A#define SC_AINFO 5 /* get anonymous memory resource information */
2N/A
2N/Atypedef struct swapres {
2N/A char *sr_name; /* pathname of the resource specified */
2N/A off_t sr_start; /* starting offset of the swapping resource */
2N/A off_t sr_length; /* length of the swap area */
2N/A} swapres_t;
2N/A
2N/Atypedef struct swapent {
2N/A char *ste_path; /* get the name of the swap file */
2N/A off_t ste_start; /* starting block for swapping */
2N/A off_t ste_length; /* length of swap area */
2N/A long ste_pages; /* numbers of pages for swapping */
2N/A long ste_free; /* numbers of ste_pages free */
2N/A int ste_flags; /* see below */
2N/A} swapent_t;
2N/A
2N/Atypedef struct swaptable {
2N/A int swt_n; /* number of swapents following */
2N/A struct swapent swt_ent[1]; /* array of swt_n swapents */
2N/A} swaptbl_t;
2N/A
2N/A
2N/A#if defined(_SYSCALL32)
2N/A
2N/A/* Kernel's view of user ILP32 swapres and swapent structures */
2N/A
2N/Atypedef struct swapres32 {
2N/A caddr32_t sr_name; /* pathname of the resource specified */
2N/A off32_t sr_start; /* starting offset of the swapping resource */
2N/A off32_t sr_length; /* length of the swap area */
2N/A} swapres32_t;
2N/A
2N/Atypedef struct swapent32 {
2N/A caddr32_t ste_path; /* get the name of the swap file */
2N/A off32_t ste_start; /* starting block for swapping */
2N/A off32_t ste_length; /* length of swap area */
2N/A int32_t ste_pages; /* numbers of pages for swapping */
2N/A int32_t ste_free; /* numbers of ste_pages free */
2N/A int32_t ste_flags; /* see below */
2N/A} swapent32_t;
2N/A
2N/Atypedef struct swaptable32 {
2N/A int32_t swt_n; /* number of swapents following */
2N/A struct swapent32 swt_ent[1]; /* array of swt_n swapents */
2N/A} swaptbl32_t;
2N/A
2N/A#endif /* _SYSCALL32 */
2N/A
2N/A#if defined(_KERNEL)
2N/Aextern int swapctl(int, void *, int *);
2N/A#if defined(_LP64) && defined(_SYSCALL32)
2N/Aextern int swapctl32(int, void *, int *);
2N/A#endif /* _LP64 && _SYSCALL32 */
2N/A#else /* !_KERNEL */
2N/A#if defined(__STDC__)
2N/Aextern int swapctl(int, void *);
2N/A#else
2N/Aextern int swapctl();
2N/A#endif
2N/A#endif /* _KERNEL */
2N/A
2N/A
2N/A/* ste_flags values */
2N/A
2N/A#define ST_INDEL 0x01 /* Deletion of file is in progress. */
2N/A /* Prevents others from deleting or */
2N/A /* allocating from it */
2N/A#define ST_DOINGDEL 0x02 /* Set during deletion of file */
2N/A /* Clearing during deletion signals */
2N/A /* that you want to add the file back */
2N/A /* again, and will eventually cause */
2N/A /* it to be added back */
2N/A
2N/A/*
2N/A * VM - virtual swap device.
2N/A */
2N/Astruct swapinfo {
2N/A ulong_t si_soff; /* starting offset (bytes) of file */
2N/A ulong_t si_eoff; /* ending offset (bytes) of file */
2N/A struct vnode *si_vp; /* vnode (commonvp if device) */
2N/A struct swapinfo *si_next; /* next swap area */
2N/A int si_allocs; /* # of conseq. allocs from this area */
2N/A short si_flags; /* flags defined below */
2N/A pgcnt_t si_npgs; /* number of pages of swap space */
2N/A pgcnt_t si_nfpgs; /* number of free pages of swap space */
2N/A int si_pnamelen; /* swap file name length + 1 */
2N/A char *si_pname; /* swap file name */
2N/A ssize_t si_mapsize; /* # bytes allocated for bitmap */
2N/A uint_t *si_swapslots; /* bitmap of slots, unset == free */
2N/A pgcnt_t si_hint; /* first page to check if free */
2N/A ssize_t si_checkcnt; /* # of checks to find freeslot */
2N/A ssize_t si_alloccnt; /* used to find ave checks */
2N/A};
2N/A
2N/A/*
2N/A * Stuff to convert an anon slot pointer to a page name.
2N/A * Because the address of the slot (ap) is a unique identifier, we
2N/A * use it to generate a unique (vp,off), as shown in the comment for
2N/A * swap_alloc().
2N/A *
2N/A * The off bits are shifted PAGESHIFT to directly form a page aligned
2N/A * offset; the vp index bits map 1-1 to a vnode.
2N/A *
2N/A */
2N/A#define MAX_SWAP_VNODES_LOG2 11 /* log2(MAX_SWAP_VNODES) */
#define MAX_SWAP_VNODES (1U << MAX_SWAP_VNODES_LOG2) /* max # swap vnodes */
#define AN_VPMASK (MAX_SWAP_VNODES - 1) /* vp index mask */
#define AN_VPSHIFT MAX_SWAP_VNODES_LOG2
/*
* Convert from an anon slot to associated vnode and offset.
*/
#define swap_xlate(AP, VPP, OFFP) \
{ \
*(VPP) = (AP)->an_vp; \
*(OFFP) = (AP)->an_off; \
}
#define swap_xlate_nopanic swap_xlate
/*
* Get a vnode name for an anon slot.
* The vnum, offset are derived from anon struct address which is
* 16 bytes aligned. anon structs may be kmem_cache_alloc'd concurrently by
* multiple threads and come from a small range of addresses (same slab), in
* which case high order AP bits do not vary much, so choose vnum from low
* order bits which vary the most. Different threads will thus get different
* vnums and vnodes, which avoids vph_mutex_contention on the subsequent
* page_hashin().
*
* +-----------...-------------------+-----------------------+----+
* | swap offset | vnum |0000|
* +-----------...-------------------+-----------------------+----+
* 63 15 14 4 3 0
*/
#define swap_alloc(AP) \
{ \
(AP)->an_vp = swapfs_getvp(((uintptr_t)(AP) >> AN_CACHE_ALIGN_LOG2) \
& AN_VPMASK); \
(AP)->an_off = (anoff_t)((((uintptr_t)(AP)) >> \
AN_VPSHIFT + AN_CACHE_ALIGN_LOG2) << PAGESHIFT); \
}
/*
* Free the page name for the specified anon slot.
* For now there's nothing to do.
*/
#define swap_free(AP)
/* Flags for swap_phys_alloc */
#define SA_NOT 0x01 /* Must have slot from swap dev other than input one */
/* Special error codes for swap_newphysname() */
#define SE_NOSWAP -1 /* No physical swap slots available */
#define SE_NOANON -2 /* No anon slot for swap slot */
#ifdef _KERNEL
extern struct anon *swap_anon(struct vnode *vp, u_offset_t off);
extern int swap_phys_alloc(struct vnode **vpp, u_offset_t *offp, size_t *lenp,
uint_t flags);
extern void swap_phys_free(struct vnode *vp, u_offset_t off, size_t len);
extern int swap_getphysname(struct vnode *vp, u_offset_t off,
struct vnode **pvpp, u_offset_t *poffp);
extern int swap_newphysname(struct vnode *vp, u_offset_t offset,
u_offset_t *offp, size_t *lenp, struct vnode **pvpp, u_offset_t *poffp);
extern struct swapinfo *swapinfo;
extern int swap_debug;
#endif /* _KERNEL */
#ifdef SWAP_DEBUG
#define SW_RENAME 0x01
#define SW_RESV 0x02
#define SW_ALLOC 0x04
#define SW_CTL 0x08
#define SWAP_PRINT(f, s, x1, x2, x3, x4, x5) \
if (swap_debug & f) \
printf(s, x1, x2, x3, x4, x5);
#else /* SWAP_DEBUG */
#define SWAP_PRINT(f, s, x1, x2, x3, x4, x5)
#endif /* SWAP_DEBUG */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_SWAP_H */