swap_pager.h revision 1541
1135446Strhodes/*
2262706Serwin * Copyright (c) 1990 University of Utah.
3135446Strhodes * Copyright (c) 1991, 1993
4135446Strhodes *	The Regents of the University of California.  All rights reserved.
5174187Sdougb *
6135446Strhodes * This code is derived from software contributed to Berkeley by
7135446Strhodes * the Systems Programming Group of the University of Utah Computer
8135446Strhodes * Science Department.
9135446Strhodes *
10135446Strhodes * Redistribution and use in source and binary forms, with or without
11135446Strhodes * modification, are permitted provided that the following conditions
12135446Strhodes * are met:
13135446Strhodes * 1. Redistributions of source code must retain the above copyright
14135446Strhodes *    notice, this list of conditions and the following disclaimer.
15135446Strhodes * 2. Redistributions in binary form must reproduce the above copyright
16135446Strhodes *    notice, this list of conditions and the following disclaimer in the
17135446Strhodes *    documentation and/or other materials provided with the distribution.
18254897Serwin * 3. All advertising materials mentioning features or use of this software
19135446Strhodes *    must display the following acknowledgement:
20186462Sdougb *	This product includes software developed by the University of
21135446Strhodes *	California, Berkeley and its contributors.
22170222Sdougb * 4. Neither the name of the University nor the names of its contributors
23135446Strhodes *    may be used to endorse or promote products derived from this software
24135446Strhodes *    without specific prior written permission.
25135446Strhodes *
26135446Strhodes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27135446Strhodes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28135446Strhodes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29135446Strhodes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30135446Strhodes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31135446Strhodes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32135446Strhodes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33135446Strhodes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34135446Strhodes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35135446Strhodes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36193149Sdougb * SUCH DAMAGE.
37193149Sdougb *
38135446Strhodes *	@(#)swap_pager.h	8.1 (Berkeley) 6/11/93
39135446Strhodes */
40135446Strhodes
41135446Strhodes#ifndef	_SWAP_PAGER_
42135446Strhodes#define	_SWAP_PAGER_	1
43135446Strhodes
44135446Strhodes/*
45135446Strhodes * In the swap pager, the backing store for an object is organized as an
46135446Strhodes * array of some number of "swap blocks".  A swap block consists of a bitmask
47135446Strhodes * and some number of contiguous DEV_BSIZE disk blocks.  The minimum size
48170222Sdougb * of a swap block is:
49135446Strhodes *
50135446Strhodes *	max(PAGE_SIZE, dmmin*DEV_BSIZE)			[ 32k currently ]
51193149Sdougb *
52135446Strhodes * bytes (since the pager interface is page oriented), the maximum size is:
53193149Sdougb *
54193149Sdougb *	min(#bits(swb_mask)*PAGE_SIZE, dmmax*DEV_BSIZE)	[ 128k currently ]
55193149Sdougb *
56193149Sdougb * where dmmin and dmmax are left over from the old VM interface.  The bitmask
57193149Sdougb * (swb_mask) is used by swap_pager_haspage() to determine if a particular
58135446Strhodes * page has actually been written; i.e. the pager copy of the page is valid.
59193149Sdougb * All swap blocks in the backing store of an object will be the same size.
60170222Sdougb *
61193149Sdougb * The reason for variable sized swap blocks is to reduce fragmentation of
62193149Sdougb * swap resources.  Whenever possible we allocate smaller swap blocks to
63193149Sdougb * smaller objects.  The swap block size is determined from a table of
64193149Sdougb * object-size vs. swap-block-size computed at boot time.
65193149Sdougb */
66193149Sdougbtypedef	int	sw_bm_t;	/* pager bitmask */
67135446Strhodes
68186462Sdougbstruct	swblock {
69135446Strhodes	sw_bm_t	 swb_mask;	/* bitmask of valid pages in this block */
70135446Strhodes	daddr_t	 swb_block;	/* starting disk block for this block */
71135446Strhodes};
72135446Strhodestypedef struct swblock	*sw_blk_t;
73135446Strhodes
74193149Sdougb/*
75193149Sdougb * Swap pager private data.
76193149Sdougb */
77135446Strhodesstruct swpager {
78170222Sdougb	vm_size_t    sw_osize;	/* size of object we are backing (bytes) */
79193149Sdougb	int	     sw_bsize;	/* size of swap blocks (DEV_BSIZE units) */
80193149Sdougb	int	     sw_nblocks;/* number of blocks in list (sw_blk_t units) */
81193149Sdougb	sw_blk_t     sw_blocks;	/* pointer to list of swap blocks */
82135446Strhodes	short	     sw_flags;	/* flags */
83193149Sdougb	short	     sw_poip;	/* pageouts in progress */
84193149Sdougb};
85193149Sdougbtypedef struct swpager	*sw_pager_t;
86135446Strhodes
87193149Sdougb#define	SW_WANTED	0x01
88193149Sdougb#define SW_NAMED	0x02
89135446Strhodes
90193149Sdougb#endif	/* _SWAP_PAGER_ */
91135446Strhodes