xref: /freebsd/sys/vm/swap_pager.h (revision 3ccbf2d533f5cfed977fb82b7c1f04c23dcafc85)
1df8bae1dSRodney W. Grimes /*
2df8bae1dSRodney W. Grimes  * Copyright (c) 1990 University of Utah.
326f9a767SRodney W. Grimes  * Copyright (c) 1991 The Regents of the University of California.
426f9a767SRodney W. Grimes  * All rights reserved.
5df8bae1dSRodney W. Grimes  *
6df8bae1dSRodney W. Grimes  * This code is derived from software contributed to Berkeley by
7df8bae1dSRodney W. Grimes  * the Systems Programming Group of the University of Utah Computer
8df8bae1dSRodney W. Grimes  * Science Department.
9df8bae1dSRodney W. Grimes  *
10df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
11df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
12df8bae1dSRodney W. Grimes  * are met:
13df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
14df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
15df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
16df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
17df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
18df8bae1dSRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
19df8bae1dSRodney W. Grimes  *    must display the following acknowledgement:
20df8bae1dSRodney W. Grimes  *	This product includes software developed by the University of
21df8bae1dSRodney W. Grimes  *	California, Berkeley and its contributors.
22df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
23df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
24df8bae1dSRodney W. Grimes  *    without specific prior written permission.
25df8bae1dSRodney W. Grimes  *
26df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
37df8bae1dSRodney W. Grimes  *
3826f9a767SRodney W. Grimes  *	from: @(#)swap_pager.h	7.1 (Berkeley) 12/5/90
39c3aac50fSPeter Wemm  * $FreeBSD$
4026f9a767SRodney W. Grimes  */
4126f9a767SRodney W. Grimes 
4226f9a767SRodney W. Grimes /*
4326f9a767SRodney W. Grimes  * Modifications to the block allocation data structure by John S. Dyson
4426f9a767SRodney W. Grimes  * 18 Dec 93.
45df8bae1dSRodney W. Grimes  */
46df8bae1dSRodney W. Grimes 
473ccbf2d5SPoul-Henning Kamp #ifndef	_VM_SWAP_PAGER_H_
483ccbf2d5SPoul-Henning Kamp #define	_VM_SWAP_PAGER_H_ 1
49df8bae1dSRodney W. Grimes 
50df8bae1dSRodney W. Grimes /*
5164bcb9c8SMatthew Dillon  * SWB_NPAGES must be a power of 2.  It may be set to 1, 2, 4, 8, or 16
5264bcb9c8SMatthew Dillon  * pages per allocation.  We recommend you stick with the default of 8.
5364bcb9c8SMatthew Dillon  * The 16-page limit is due to the radix code (kern/subr_blist.c).
54df8bae1dSRodney W. Grimes  */
55e47ed70bSJohn Dyson #if !defined(SWB_NPAGES)
5626f9a767SRodney W. Grimes #define SWB_NPAGES 8
57e47ed70bSJohn Dyson #endif
58e47ed70bSJohn Dyson 
591c7c3c6aSMatthew Dillon /*
601c7c3c6aSMatthew Dillon  * Piecemeal swap metadata structure.  Swap is stored in a radix tree.
611c7c3c6aSMatthew Dillon  *
621c7c3c6aSMatthew Dillon  * If SWB_NPAGES is 8 and sizeof(char *) == sizeof(daddr_t), our radix
631c7c3c6aSMatthew Dillon  * is basically 8.  Assuming PAGE_SIZE == 4096, one tree level represents
641c7c3c6aSMatthew Dillon  * 32K worth of data, two levels represent 256K, three levels represent
651c7c3c6aSMatthew Dillon  * 2 MBytes.   This is acceptable.
661c7c3c6aSMatthew Dillon  *
671c7c3c6aSMatthew Dillon  * Overall memory utilization is about the same as the old swap structure.
681c7c3c6aSMatthew Dillon  */
691c7c3c6aSMatthew Dillon #define SWCORRECT(n) (sizeof(void *) * (n) / sizeof(daddr_t))
701c7c3c6aSMatthew Dillon #define SWAP_META_PAGES		(SWB_NPAGES * 2)
711c7c3c6aSMatthew Dillon #define SWAP_META_MASK		(SWAP_META_PAGES - 1)
721c7c3c6aSMatthew Dillon 
73df8bae1dSRodney W. Grimes struct swblock {
741c7c3c6aSMatthew Dillon 	struct swblock	*swb_hnext;
751c7c3c6aSMatthew Dillon 	vm_object_t	swb_object;
764dcc5c2dSMatthew Dillon 	vm_pindex_t	swb_index;
771c7c3c6aSMatthew Dillon 	int		swb_count;
781c7c3c6aSMatthew Dillon 	daddr_t		swb_pages[SWAP_META_PAGES];
79df8bae1dSRodney W. Grimes };
80df8bae1dSRodney W. Grimes 
81c4473420SPeter Wemm #ifdef _KERNEL
82bf25be48SBruce Evans extern struct pagerlst swap_pager_un_object_list;
83cd41fc12SDavid Greenman extern int swap_pager_full;
841c7c3c6aSMatthew Dillon extern struct blist *swapblist;
856af7f1e5SBruce Evans extern struct uma_zone *swap_zone;
8692da00bbSMatthew Dillon extern int nswap_lowat, nswap_hiwat;
87bf25be48SBruce Evans 
8811caded3SAlfred Perlstein void swap_pager_putpages(vm_object_t, vm_page_t *, int, boolean_t, int *);
8911caded3SAlfred Perlstein boolean_t swap_pager_haspage(vm_object_t object, vm_pindex_t pindex, int *before, int *after);
9092da00bbSMatthew Dillon void swap_pager_swapoff(int devidx, int *sw_used);
911c7c3c6aSMatthew Dillon 
9211caded3SAlfred Perlstein int swap_pager_swp_alloc(vm_object_t, int);
9311caded3SAlfred Perlstein void swap_pager_copy(vm_object_t, vm_object_t, vm_pindex_t, int);
9411caded3SAlfred Perlstein void swap_pager_freespace(vm_object_t, vm_pindex_t, vm_size_t);
9511caded3SAlfred Perlstein void swap_pager_dmzspace(vm_object_t, vm_pindex_t, vm_size_t);
9611caded3SAlfred Perlstein void swap_pager_swap_init(void);
9711caded3SAlfred Perlstein int swap_pager_reserve(vm_object_t, vm_pindex_t, vm_size_t);
981c7c3c6aSMatthew Dillon 
991c7c3c6aSMatthew Dillon /*
1001c7c3c6aSMatthew Dillon  * newswap functions
1011c7c3c6aSMatthew Dillon  */
1021c7c3c6aSMatthew Dillon 
10311caded3SAlfred Perlstein void swap_pager_page_removed(vm_page_t, vm_object_t);
1041c7c3c6aSMatthew Dillon 
105cdacc6abSPeter Wemm /* choose underlying swap device and queue up I/O */
106cdacc6abSPeter Wemm struct buf;
10711caded3SAlfred Perlstein void swstrategy(struct buf *bp);	/* probably needs to move elsewhere */
108cdacc6abSPeter Wemm 
109a1287949SEivind Eklund #endif				/* _KERNEL */
1103ccbf2d5SPoul-Henning Kamp #endif				/* _VM_SWAP_PAGER_H_ */
111