1998-11-08 22:45:17 +03:00
|
|
|
/* $NetBSD: vm_swap.c,v 1.64 1998/11/08 19:45:17 mycroft Exp $ */
|
1994-06-29 10:39:25 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1997-06-12 18:51:20 +04:00
|
|
|
* Copyright (c) 1995, 1996, 1997 Matthew R. Green
|
|
|
|
* All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
1997-10-10 09:39:47 +04:00
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
1998-09-13 17:21:37 +04:00
|
|
|
* derived from this software without specific prior written permission
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
1997-06-12 18:51:20 +04:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
1998-09-13 17:21:37 +04:00
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
|
1998-02-19 03:55:04 +03:00
|
|
|
#include "fs_nfs.h"
|
1998-08-29 17:27:50 +04:00
|
|
|
#include "opt_compat_netbsd.h"
|
1998-02-19 03:55:04 +03:00
|
|
|
|
1993-12-17 10:56:32 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/namei.h>
|
1997-06-12 18:51:20 +04:00
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/dmap.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
1997-10-13 23:15:19 +04:00
|
|
|
#include <sys/lock.h>
|
1997-12-15 14:18:41 +03:00
|
|
|
#include <sys/pool.h>
|
1993-12-17 10:56:32 +03:00
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/map.h>
|
|
|
|
#include <sys/file.h>
|
1997-06-12 18:51:20 +04:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/extent.h>
|
1998-08-29 21:01:14 +04:00
|
|
|
#include <sys/swap.h>
|
1994-10-20 07:22:35 +03:00
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/syscallargs.h>
|
|
|
|
|
1997-06-12 18:51:20 +04:00
|
|
|
#include <machine/vmparam.h>
|
|
|
|
|
1996-02-05 04:53:47 +03:00
|
|
|
#include <vm/vm_conf.h>
|
|
|
|
|
1994-04-26 03:53:51 +04:00
|
|
|
#include <miscfs/specfs/specdev.h>
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1997-06-12 18:51:20 +04:00
|
|
|
* The idea here is to provide a single interface for multiple swap devices,
|
|
|
|
* of any kind and priority in a simple and fast way.
|
|
|
|
*
|
|
|
|
* Each swap device has these properties:
|
|
|
|
* * swap in use.
|
|
|
|
* * swap enabled.
|
|
|
|
* * map information in `/dev/drum'.
|
|
|
|
* * vnode pointer.
|
|
|
|
* Files have these additional properties:
|
|
|
|
* * block size.
|
|
|
|
* * maximum byte count in buffer.
|
|
|
|
* * buffer.
|
|
|
|
* * credentials.
|
|
|
|
*
|
|
|
|
* The arguments to swapctl(2) are:
|
|
|
|
* int cmd;
|
|
|
|
* void *arg;
|
|
|
|
* int misc;
|
|
|
|
* The cmd can be one of:
|
|
|
|
* SWAP_NSWAP - swapctl(2) returns the number of swap devices currently in
|
|
|
|
* use.
|
|
|
|
* SWAP_STATS - swapctl(2) takes a struct ent * in (void *arg) and writes
|
|
|
|
* misc or fewer (to zero) entries of configured swap devices,
|
|
|
|
* and returns the number of entries written or -1 on error.
|
|
|
|
* SWAP_ON - swapctl(2) takes a (char *) in arg to be the pathname of a
|
|
|
|
* device or file to begin swapping on, with it's priority in
|
|
|
|
* misc, returning 0 on success and -1 on error.
|
|
|
|
* SWAP_OFF - swapctl(2) takes a (char *) n arg to be the pathname of a
|
|
|
|
* device or file to stop swapping on. returning 0 or -1.
|
|
|
|
* XXX unwritten.
|
|
|
|
* SWAP_CTL - swapctl(2) changes the priority of a swap device, using the
|
|
|
|
* misc value.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
|
1997-06-12 18:51:20 +04:00
|
|
|
#ifdef SWAPDEBUG
|
|
|
|
#define VMSDB_SWON 0x0001
|
|
|
|
#define VMSDB_SWOFF 0x0002
|
|
|
|
#define VMSDB_SWINIT 0x0004
|
|
|
|
#define VMSDB_SWALLOC 0x0008
|
|
|
|
#define VMSDB_SWFLOW 0x0010
|
|
|
|
#define VMSDB_INFO 0x0020
|
|
|
|
int vmswapdebug = 0;
|
1997-12-01 20:10:48 +03:00
|
|
|
|
|
|
|
#define DPRINTF(f, m) do { \
|
|
|
|
if (vmswapdebug & (f)) \
|
|
|
|
printf m; \
|
|
|
|
} while(0)
|
|
|
|
#else
|
|
|
|
#define DPRINTF(f, m)
|
1997-06-12 18:51:20 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define SWAP_TO_FILES
|
|
|
|
|
|
|
|
struct swapdev {
|
1998-08-29 17:27:50 +04:00
|
|
|
struct oswapent swd_ose;
|
|
|
|
#define swd_dev swd_ose.ose_dev
|
|
|
|
#define swd_flags swd_ose.ose_flags
|
|
|
|
#define swd_nblks swd_ose.ose_nblks
|
|
|
|
#define swd_inuse swd_ose.ose_inuse
|
|
|
|
#define swd_priority swd_ose.ose_priority
|
|
|
|
char *swd_path;
|
|
|
|
int swd_pathlen;
|
1997-06-12 18:51:20 +04:00
|
|
|
daddr_t swd_mapoffset;
|
|
|
|
int swd_mapsize;
|
|
|
|
struct extent *swd_ex;
|
|
|
|
struct vnode *swd_vp;
|
|
|
|
CIRCLEQ_ENTRY(swapdev) swd_next;
|
|
|
|
|
|
|
|
#ifdef SWAP_TO_FILES
|
|
|
|
int swd_bsize;
|
|
|
|
int swd_maxactive;
|
|
|
|
struct buf swd_tab;
|
|
|
|
struct ucred *swd_cred;
|
1994-04-26 03:53:51 +04:00
|
|
|
#endif
|
1997-06-12 18:51:20 +04:00
|
|
|
};
|
|
|
|
|
1997-06-16 17:35:17 +04:00
|
|
|
/*
|
|
|
|
* Swap device priority entry; the list is kept sorted on `spi_priority'.
|
|
|
|
*/
|
1997-06-12 18:51:20 +04:00
|
|
|
struct swappri {
|
|
|
|
int spi_priority;
|
|
|
|
CIRCLEQ_HEAD(spi_swapdev, swapdev) spi_swapdev;
|
|
|
|
LIST_ENTRY(swappri) spi_swappri;
|
|
|
|
};
|
1994-01-08 01:34:37 +03:00
|
|
|
|
1996-02-05 04:53:47 +03:00
|
|
|
|
1997-10-13 23:15:19 +04:00
|
|
|
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1997-06-12 18:51:20 +04:00
|
|
|
* The following two structures are used to keep track of data transfers
|
|
|
|
* on swap devices associated with regular files.
|
|
|
|
* NOTE: this code is more or less a copy of vnd.c; we use the same
|
|
|
|
* structure names here to ease porting..
|
|
|
|
*/
|
1997-10-13 23:15:19 +04:00
|
|
|
|
|
|
|
|
1997-06-12 18:51:20 +04:00
|
|
|
struct vndxfer {
|
1997-10-13 23:15:19 +04:00
|
|
|
struct buf *vx_bp; /* Pointer to parent buffer */
|
1997-06-12 18:51:20 +04:00
|
|
|
struct swapdev *vx_sdp;
|
|
|
|
int vx_error;
|
1997-10-13 23:15:19 +04:00
|
|
|
int vx_pending; /* # of pending aux buffers */
|
1997-11-29 03:35:43 +03:00
|
|
|
int vx_flags;
|
|
|
|
#define VX_BUSY 1
|
|
|
|
#define VX_DEAD 2
|
1997-06-12 18:51:20 +04:00
|
|
|
};
|
|
|
|
|
1997-10-13 23:15:19 +04:00
|
|
|
|
1997-06-12 18:51:20 +04:00
|
|
|
struct vndbuf {
|
|
|
|
struct buf vb_buf;
|
|
|
|
struct vndxfer *vb_xfer;
|
|
|
|
};
|
|
|
|
|
1997-10-13 23:15:19 +04:00
|
|
|
/* To get from a buffer to the encapsulating vndbuf */
|
|
|
|
#define BUF_TO_VNDBUF(bp) \
|
1997-10-14 12:50:18 +04:00
|
|
|
((struct vndbuf *)((long)bp - ((long)&((struct vndbuf *)0)->vb_buf)))
|
1997-10-13 23:15:19 +04:00
|
|
|
|
1997-06-12 18:51:20 +04:00
|
|
|
/*
|
1997-10-13 23:15:19 +04:00
|
|
|
* We keep a pool vndbuf's and vndxfer structures.
|
1997-06-12 18:51:20 +04:00
|
|
|
*/
|
1997-12-15 14:18:41 +03:00
|
|
|
struct pool *vndxfer_pool;
|
|
|
|
struct pool *vndbuf_pool;
|
1997-10-13 23:15:19 +04:00
|
|
|
|
|
|
|
#define getvndxfer(vnx) do { \
|
|
|
|
int s = splbio(); \
|
1997-12-15 14:18:41 +03:00
|
|
|
(vnx) = (struct vndxfer *) \
|
1998-07-24 00:52:01 +04:00
|
|
|
pool_get(vndxfer_pool, PR_WAITOK); \
|
1997-10-13 23:15:19 +04:00
|
|
|
splx(s); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define putvndxfer(vnx) \
|
1997-12-15 14:18:41 +03:00
|
|
|
pool_put(vndxfer_pool, (void *)(vnx));
|
1997-10-13 23:15:19 +04:00
|
|
|
|
|
|
|
#define getvndbuf(vbp) do { \
|
|
|
|
int s = splbio(); \
|
1997-12-15 14:18:41 +03:00
|
|
|
(vbp) = (struct vndbuf *) \
|
1998-07-24 00:52:01 +04:00
|
|
|
pool_get(vndbuf_pool, PR_WAITOK); \
|
1997-10-13 23:15:19 +04:00
|
|
|
splx(s); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define putvndbuf(vbp) \
|
1997-12-15 14:18:41 +03:00
|
|
|
pool_put(vndbuf_pool, (void *)(vbp));
|
1997-06-12 18:51:20 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1997-10-10 17:16:24 +04:00
|
|
|
int nswapdev;
|
1997-06-12 18:51:20 +04:00
|
|
|
int swflags;
|
|
|
|
struct extent *swapmap;
|
|
|
|
LIST_HEAD(swap_priority, swappri) swap_priority;
|
|
|
|
|
|
|
|
static int swap_on __P((struct proc *, struct swapdev *));
|
|
|
|
#ifdef SWAP_OFF_WORKS
|
|
|
|
static int swap_off __P((struct proc *, struct swapdev *));
|
|
|
|
#endif
|
|
|
|
static struct swapdev *swap_getsdpfromaddr __P((daddr_t));
|
|
|
|
static void swap_addmap __P((struct swapdev *, int));
|
|
|
|
|
|
|
|
#ifdef SWAP_TO_FILES
|
|
|
|
static void sw_reg_strategy __P((struct swapdev *, struct buf *, int));
|
|
|
|
static void sw_reg_iodone __P((struct buf *));
|
|
|
|
static void sw_reg_start __P((struct swapdev *));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void insert_swapdev __P((struct swapdev *, int));
|
|
|
|
static struct swapdev *find_swapdev __P((struct vnode *, int));
|
|
|
|
static void swaplist_trim __P((void));
|
|
|
|
|
1997-10-17 23:06:05 +04:00
|
|
|
/*
|
|
|
|
* We use two locks to protect the swap device lists.
|
|
|
|
* The long-term lock is used only used to prevent races in
|
|
|
|
* concurrently executing swapctl(2) system calls.
|
|
|
|
*/
|
|
|
|
struct simplelock swaplist_lock;
|
|
|
|
struct lock swaplist_change_lock;
|
1997-06-12 18:51:20 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Insert a swap device on the priority list.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1993-06-27 10:27:29 +04:00
|
|
|
void
|
1997-06-12 18:51:20 +04:00
|
|
|
insert_swapdev(sdp, priority)
|
|
|
|
struct swapdev *sdp;
|
|
|
|
int priority;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-06-12 18:51:20 +04:00
|
|
|
struct swappri *spp, *pspp;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-06-12 18:51:20 +04:00
|
|
|
again:
|
1997-10-17 23:06:05 +04:00
|
|
|
simple_lock(&swaplist_lock);
|
1997-06-12 18:51:20 +04:00
|
|
|
|
1997-06-16 17:35:17 +04:00
|
|
|
/*
|
|
|
|
* Find entry at or after which to insert the new device.
|
|
|
|
*/
|
|
|
|
for (pspp = NULL, spp = swap_priority.lh_first; spp != NULL;
|
|
|
|
spp = spp->spi_swappri.le_next) {
|
|
|
|
if (priority <= spp->spi_priority)
|
1994-04-26 03:53:51 +04:00
|
|
|
break;
|
1997-06-12 18:51:20 +04:00
|
|
|
pspp = spp;
|
1994-04-26 03:53:51 +04:00
|
|
|
}
|
1997-06-12 18:51:20 +04:00
|
|
|
|
|
|
|
if (spp == NULL || spp->spi_priority != priority) {
|
|
|
|
spp = (struct swappri *)
|
|
|
|
malloc(sizeof *spp, M_VMSWAP, M_NOWAIT);
|
|
|
|
|
|
|
|
if (spp == NULL) {
|
1997-10-17 23:06:05 +04:00
|
|
|
simple_unlock(&swaplist_lock);
|
1997-06-12 18:51:20 +04:00
|
|
|
tsleep((caddr_t)&lbolt, PSWP, "memory", 0);
|
|
|
|
goto again;
|
1994-04-26 03:53:51 +04:00
|
|
|
}
|
1997-12-01 20:10:48 +03:00
|
|
|
DPRINTF(VMSDB_SWFLOW,
|
|
|
|
("sw: had to create a new swappri = %d\n", priority));
|
1997-06-12 18:51:20 +04:00
|
|
|
|
|
|
|
spp->spi_priority = priority;
|
|
|
|
CIRCLEQ_INIT(&spp->spi_swapdev);
|
|
|
|
|
|
|
|
if (pspp)
|
|
|
|
LIST_INSERT_AFTER(pspp, spp, spi_swappri);
|
|
|
|
else
|
1997-06-16 17:35:17 +04:00
|
|
|
LIST_INSERT_HEAD(&swap_priority, spp, spi_swappri);
|
1997-06-12 18:51:20 +04:00
|
|
|
|
1994-04-26 03:53:51 +04:00
|
|
|
}
|
1997-06-12 18:51:20 +04:00
|
|
|
/* Onto priority list */
|
|
|
|
CIRCLEQ_INSERT_TAIL(&spp->spi_swapdev, sdp, swd_next);
|
|
|
|
sdp->swd_priority = priority;
|
1997-10-17 23:06:05 +04:00
|
|
|
simple_unlock(&swaplist_lock);
|
1997-06-12 18:51:20 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-06-12 18:51:20 +04:00
|
|
|
/*
|
|
|
|
* Find and optionally remove a swap device from the priority list.
|
|
|
|
*/
|
|
|
|
struct swapdev *
|
|
|
|
find_swapdev(vp, remove)
|
|
|
|
struct vnode *vp;
|
|
|
|
int remove;
|
|
|
|
{
|
|
|
|
struct swapdev *sdp;
|
|
|
|
struct swappri *spp;
|
|
|
|
|
1997-10-17 23:06:05 +04:00
|
|
|
simple_lock(&swaplist_lock);
|
1997-06-12 18:51:20 +04:00
|
|
|
for (spp = swap_priority.lh_first; spp != NULL;
|
|
|
|
spp = spp->spi_swappri.le_next) {
|
|
|
|
for (sdp = spp->spi_swapdev.cqh_first;
|
|
|
|
sdp != (void *)&spp->spi_swapdev;
|
|
|
|
sdp = sdp->swd_next.cqe_next)
|
|
|
|
if (sdp->swd_vp == vp) {
|
|
|
|
if (remove)
|
|
|
|
CIRCLEQ_REMOVE(&spp->spi_swapdev, sdp,
|
|
|
|
swd_next);
|
1997-10-17 23:06:05 +04:00
|
|
|
simple_unlock(&swaplist_lock);
|
1997-06-12 18:51:20 +04:00
|
|
|
return(sdp);
|
|
|
|
}
|
1994-04-21 11:47:31 +04:00
|
|
|
}
|
1997-10-17 23:06:05 +04:00
|
|
|
simple_unlock(&swaplist_lock);
|
1997-06-12 18:51:20 +04:00
|
|
|
return (NULL);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-06-12 18:51:20 +04:00
|
|
|
/*
|
|
|
|
* Scan priority list for empty priority entries.
|
|
|
|
*/
|
1994-01-08 01:34:37 +03:00
|
|
|
void
|
1997-06-12 18:51:20 +04:00
|
|
|
swaplist_trim()
|
|
|
|
{
|
|
|
|
struct swappri *spp;
|
|
|
|
|
1997-10-17 23:06:05 +04:00
|
|
|
simple_lock(&swaplist_lock);
|
1997-06-12 18:51:20 +04:00
|
|
|
restart:
|
|
|
|
for (spp = swap_priority.lh_first; spp != NULL;
|
|
|
|
spp = spp->spi_swappri.le_next) {
|
|
|
|
if (spp->spi_swapdev.cqh_first != (void *)&spp->spi_swapdev)
|
|
|
|
continue;
|
|
|
|
LIST_REMOVE(spp, spi_swappri);
|
|
|
|
free((caddr_t)spp, M_VMSWAP);
|
|
|
|
goto restart;
|
|
|
|
}
|
1997-10-17 23:06:05 +04:00
|
|
|
simple_unlock(&swaplist_lock);
|
1997-06-12 18:51:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sys_swapctl(p, v, retval)
|
|
|
|
struct proc *p;
|
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-06-12 18:51:20 +04:00
|
|
|
struct sys_swapctl_args /* {
|
|
|
|
syscallarg(int) cmd;
|
1997-11-05 00:24:14 +03:00
|
|
|
syscallarg(const void *) arg;
|
1997-06-12 18:51:20 +04:00
|
|
|
syscallarg(int) misc;
|
|
|
|
} */ *uap = (struct sys_swapctl_args *)v;
|
1993-03-21 12:45:37 +03:00
|
|
|
struct vnode *vp;
|
1997-06-12 18:51:20 +04:00
|
|
|
struct nameidata nd;
|
|
|
|
struct swappri *spp;
|
|
|
|
struct swapdev *sdp;
|
|
|
|
struct swapent *sep;
|
1998-08-29 17:27:50 +04:00
|
|
|
char userpath[PATH_MAX + 1];
|
|
|
|
int count, error, misc, len;
|
1997-06-12 18:51:20 +04:00
|
|
|
int priority;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-06-12 18:51:20 +04:00
|
|
|
misc = SCARG(uap, misc);
|
|
|
|
|
1997-12-01 20:10:48 +03:00
|
|
|
DPRINTF(VMSDB_SWFLOW, ("entering sys_swapctl\n"));
|
1997-06-12 18:51:20 +04:00
|
|
|
|
|
|
|
/* how many swap devices */
|
|
|
|
if (SCARG(uap, cmd) == SWAP_NSWAP) {
|
1997-12-01 20:10:48 +03:00
|
|
|
DPRINTF(VMSDB_SWFLOW,("did SWAP_NSWAP: leaving sys_swapctl\n"));
|
1997-06-12 18:51:20 +04:00
|
|
|
*retval = nswapdev;
|
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-06-12 18:51:20 +04:00
|
|
|
|
|
|
|
/* stats on the swap devices. */
|
1998-08-29 17:27:50 +04:00
|
|
|
if (SCARG(uap, cmd) == SWAP_STATS
|
|
|
|
#if defined(COMPAT_13)
|
|
|
|
|| SCARG(uap, cmd) == SWAP_OSTATS
|
|
|
|
#endif
|
|
|
|
) {
|
1997-06-12 18:51:20 +04:00
|
|
|
sep = (struct swapent *)SCARG(uap, arg);
|
|
|
|
count = 0;
|
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
error = lockmgr(&swaplist_change_lock, LK_SHARED, (void *)0);
|
1997-10-17 23:06:05 +04:00
|
|
|
if (error)
|
|
|
|
return (error);
|
1997-06-12 18:51:20 +04:00
|
|
|
for (spp = swap_priority.lh_first; spp != NULL;
|
|
|
|
spp = spp->spi_swappri.le_next) {
|
|
|
|
for (sdp = spp->spi_swapdev.cqh_first;
|
|
|
|
sdp != (void *)&spp->spi_swapdev && misc-- > 0;
|
|
|
|
sdp = sdp->swd_next.cqe_next) {
|
1998-08-29 17:27:50 +04:00
|
|
|
/*
|
|
|
|
* backwards compatibility for system call.
|
|
|
|
* note that we use 'struct oswapent' as an
|
|
|
|
* overlay into both 'struct swapdev' and
|
|
|
|
* the userland 'struct swapent', as we
|
|
|
|
* want to retain backwards compatibility
|
|
|
|
* with NetBSD 1.3.
|
|
|
|
*/
|
|
|
|
error = copyout((caddr_t)&sdp->swd_ose,
|
|
|
|
(caddr_t)sep, sizeof(struct oswapent));
|
|
|
|
|
|
|
|
/* now copy out the path if necessary */
|
|
|
|
#if defined(COMPAT_13)
|
|
|
|
if (error == 0 && SCARG(uap, cmd) == SWAP_STATS)
|
|
|
|
#else
|
|
|
|
if (error == 0)
|
|
|
|
#endif
|
|
|
|
error = copyout((caddr_t)sdp->swd_path,
|
|
|
|
(caddr_t)&sep->se_path,
|
|
|
|
sdp->swd_pathlen);
|
1997-06-12 18:51:20 +04:00
|
|
|
if (error)
|
1998-08-29 17:27:50 +04:00
|
|
|
goto out;
|
1997-06-12 18:51:20 +04:00
|
|
|
count++;
|
1998-08-29 17:27:50 +04:00
|
|
|
#if defined(COMPAT_13)
|
|
|
|
if (SCARG(uap, cmd) == SWAP_OSTATS)
|
|
|
|
((struct oswapent *)sep)++;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
sep++;
|
1994-04-26 03:53:51 +04:00
|
|
|
}
|
|
|
|
}
|
1998-08-29 17:27:50 +04:00
|
|
|
out:
|
1998-03-01 05:20:01 +03:00
|
|
|
(void)lockmgr(&swaplist_change_lock, LK_RELEASE, (void *)0);
|
1997-10-17 23:06:05 +04:00
|
|
|
if (error)
|
|
|
|
return (error);
|
1997-12-01 20:10:48 +03:00
|
|
|
|
|
|
|
DPRINTF(VMSDB_SWFLOW,("did SWAP_STATS: leaving sys_swapctl\n"));
|
|
|
|
|
1997-06-12 18:51:20 +04:00
|
|
|
*retval = count;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if ((error = suser(p->p_ucred, &p->p_acflag)))
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
if (SCARG(uap, arg) == NULL) {
|
|
|
|
/* XXX - interface - arg==NULL: miniroot */
|
|
|
|
vp = rootvp;
|
1998-03-01 05:20:01 +03:00
|
|
|
if (vget(vp, LK_EXCLUSIVE))
|
1997-06-12 18:51:20 +04:00
|
|
|
return (EBUSY);
|
1998-08-29 17:27:50 +04:00
|
|
|
if (SCARG(uap, cmd) == SWAP_ON &&
|
|
|
|
copystr("miniroot", userpath, sizeof userpath, &len))
|
|
|
|
panic("swapctl: miniroot copy failed");
|
1997-06-12 18:51:20 +04:00
|
|
|
} else {
|
1998-08-29 17:27:50 +04:00
|
|
|
int space;
|
|
|
|
char *where;
|
|
|
|
|
|
|
|
if (SCARG(uap, cmd) == SWAP_ON) {
|
|
|
|
if ((error = copyinstr(SCARG(uap, arg), userpath,
|
|
|
|
sizeof userpath, &len)))
|
|
|
|
return (error);
|
1998-09-06 15:59:28 +04:00
|
|
|
space = UIO_SYSSPACE;
|
1998-08-29 17:27:50 +04:00
|
|
|
where = userpath;
|
|
|
|
} else {
|
1998-09-06 15:59:28 +04:00
|
|
|
space = UIO_USERSPACE;
|
1998-08-29 17:27:50 +04:00
|
|
|
where = (char *)SCARG(uap, arg);
|
|
|
|
}
|
|
|
|
NDINIT(&nd, LOOKUP, FOLLOW|LOCKLEAF, space, where, p);
|
1997-06-12 18:51:20 +04:00
|
|
|
if ((error = namei(&nd)))
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
vp = nd.ni_vp;
|
|
|
|
}
|
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
error = lockmgr(&swaplist_change_lock, LK_EXCLUSIVE, (void *)0);
|
1997-10-17 23:06:05 +04:00
|
|
|
if (error)
|
|
|
|
goto bad2;
|
|
|
|
|
1997-06-12 18:51:20 +04:00
|
|
|
switch(SCARG(uap, cmd)) {
|
|
|
|
case SWAP_CTL:
|
|
|
|
priority = SCARG(uap, misc);
|
|
|
|
if ((sdp = find_swapdev(vp, 1)) == NULL) {
|
|
|
|
error = ENOENT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
insert_swapdev(sdp, priority);
|
|
|
|
swaplist_trim();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SWAP_ON:
|
|
|
|
priority = SCARG(uap, misc);
|
|
|
|
|
|
|
|
/* Check for duplicates */
|
|
|
|
if ((sdp = find_swapdev(vp, 0)) != NULL) {
|
|
|
|
error = EBUSY;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
sdp = (struct swapdev *)
|
|
|
|
malloc(sizeof *sdp, M_VMSWAP, M_WAITOK);
|
1998-08-10 01:58:52 +04:00
|
|
|
memset(sdp, 0, sizeof(*sdp));
|
1997-12-01 19:33:15 +03:00
|
|
|
|
1997-06-12 18:51:20 +04:00
|
|
|
sdp->swd_vp = vp;
|
|
|
|
sdp->swd_dev = (vp->v_type == VBLK) ? vp->v_rdev : NODEV;
|
|
|
|
|
|
|
|
if ((error = swap_on(p, sdp)) != 0) {
|
|
|
|
free((caddr_t)sdp, M_VMSWAP);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#ifdef SWAP_TO_FILES
|
|
|
|
/*
|
|
|
|
* XXX Is NFS elaboration necessary?
|
|
|
|
*/
|
|
|
|
if (vp->v_type == VREG)
|
|
|
|
sdp->swd_cred = crdup(p->p_ucred);
|
|
|
|
#endif
|
1998-08-29 17:27:50 +04:00
|
|
|
sdp->swd_pathlen = len;
|
|
|
|
sdp->swd_path = malloc(sdp->swd_pathlen, M_VMSWAP, M_WAITOK);
|
1998-09-07 03:09:39 +04:00
|
|
|
if (copystr(userpath, sdp->swd_path, sdp->swd_pathlen, 0) != 0)
|
|
|
|
panic("swapctl: copystr");
|
1997-06-12 18:51:20 +04:00
|
|
|
insert_swapdev(sdp, priority);
|
|
|
|
|
|
|
|
/* Keep reference to vnode */
|
|
|
|
vref(vp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SWAP_OFF:
|
1997-12-01 20:10:48 +03:00
|
|
|
DPRINTF(VMSDB_SWFLOW, ("doing SWAP_OFF...\n"));
|
1997-06-12 18:51:20 +04:00
|
|
|
#ifdef SWAP_OFF_WORKS
|
|
|
|
if ((sdp = find_swapdev(vp, 0)) == NULL) {
|
|
|
|
error = ENXIO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If a device isn't in use or enabled, we
|
|
|
|
* can't stop swapping from it (again).
|
|
|
|
*/
|
|
|
|
if ((sdp->swd_flags &
|
|
|
|
(SWF_INUSE|SWF_ENABLE)) == 0) {
|
|
|
|
error = EBUSY;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
if ((error = swap_off(p, sdp)) != 0)
|
|
|
|
goto bad;
|
|
|
|
|
|
|
|
/* Find again and remove this time */
|
|
|
|
if ((sdp = find_swapdev(vp, 1)) == NULL) {
|
|
|
|
error = ENXIO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free((caddr_t)sdp, M_VMSWAP);
|
1994-04-26 03:53:51 +04:00
|
|
|
#else
|
1997-06-17 07:37:07 +04:00
|
|
|
error = ENODEV;
|
1997-06-12 18:51:20 +04:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1997-12-01 20:10:48 +03:00
|
|
|
DPRINTF(VMSDB_SWFLOW,
|
|
|
|
("unhandled command: %x\n", SCARG(uap, cmd)));
|
1997-06-12 18:51:20 +04:00
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bad:
|
1998-03-01 05:20:01 +03:00
|
|
|
(void)lockmgr(&swaplist_change_lock, LK_RELEASE, (void *)0);
|
1997-10-17 23:06:05 +04:00
|
|
|
bad2:
|
1997-06-12 18:51:20 +04:00
|
|
|
vput(vp);
|
|
|
|
|
1997-12-01 20:10:48 +03:00
|
|
|
DPRINTF(VMSDB_SWFLOW, ("leaving sys_swapctl: error %d\n", error));
|
1997-06-12 18:51:20 +04:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* swap_on() attempts to begin swapping on a swapdev. we check that this
|
|
|
|
* device is OK to swap from, miss the start of any disk (to avoid any
|
|
|
|
* disk labels that may exist).
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
swap_on(p, sdp)
|
|
|
|
struct proc *p;
|
|
|
|
struct swapdev *sdp;
|
|
|
|
{
|
|
|
|
static int count = 0;
|
|
|
|
struct vnode *vp = sdp->swd_vp;
|
|
|
|
int error, nblks, size;
|
|
|
|
long addr;
|
|
|
|
char *storage;
|
|
|
|
int storagesize;
|
|
|
|
#ifdef SWAP_TO_FILES
|
|
|
|
struct vattr va;
|
|
|
|
#endif
|
|
|
|
#ifdef NFS
|
|
|
|
extern int (**nfsv2_vnodeop_p) __P((void *));
|
|
|
|
#endif /* NFS */
|
|
|
|
dev_t dev = sdp->swd_dev;
|
|
|
|
char *name;
|
|
|
|
|
1997-12-15 14:18:41 +03:00
|
|
|
|
1997-06-12 18:51:20 +04:00
|
|
|
/* If root on swap, then the skip open/close operations. */
|
|
|
|
if (vp != rootvp) {
|
|
|
|
if ((error = VOP_OPEN(vp, FREAD|FWRITE, p->p_ucred, p)))
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1997-12-01 20:10:48 +03:00
|
|
|
DPRINTF(VMSDB_INFO,
|
|
|
|
("swap_on: dev = %d, major(dev) = %d\n", dev, major(dev)));
|
1997-06-12 18:51:20 +04:00
|
|
|
|
|
|
|
switch (vp->v_type) {
|
|
|
|
case VBLK:
|
|
|
|
if (bdevsw[major(dev)].d_psize == 0 ||
|
|
|
|
(nblks = (*bdevsw[major(dev)].d_psize)(dev)) == -1) {
|
|
|
|
error = ENXIO;
|
|
|
|
goto bad;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-06-12 18:51:20 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef SWAP_TO_FILES
|
|
|
|
case VREG:
|
|
|
|
if ((error = VOP_GETATTR(vp, &va, p->p_ucred, p)))
|
|
|
|
goto bad;
|
|
|
|
nblks = (int)btodb(va.va_size);
|
|
|
|
if ((error =
|
|
|
|
VFS_STATFS(vp->v_mount, &vp->v_mount->mnt_stat, p)) != 0)
|
|
|
|
goto bad;
|
|
|
|
|
|
|
|
sdp->swd_bsize = vp->v_mount->mnt_stat.f_iosize;
|
|
|
|
#ifdef NFS
|
|
|
|
if (vp->v_op == nfsv2_vnodeop_p)
|
|
|
|
sdp->swd_maxactive = 2; /* XXX */
|
|
|
|
else
|
|
|
|
#endif /* NFS */
|
|
|
|
sdp->swd_maxactive = 8; /* XXX */
|
|
|
|
break;
|
1994-04-26 03:53:51 +04:00
|
|
|
#endif
|
1997-06-12 18:51:20 +04:00
|
|
|
|
|
|
|
default:
|
|
|
|
error = ENXIO;
|
|
|
|
goto bad;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-06-12 18:51:20 +04:00
|
|
|
if (nblks == 0) {
|
1997-12-01 20:10:48 +03:00
|
|
|
DPRINTF(VMSDB_SWFLOW, ("swap_on: nblks == 0\n"));
|
1997-06-12 18:51:20 +04:00
|
|
|
error = EINVAL;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
sdp->swd_flags |= SWF_INUSE;
|
|
|
|
sdp->swd_nblks = nblks;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* skip over first cluster of a device in case of labels or
|
|
|
|
* boot blocks.
|
|
|
|
*/
|
|
|
|
if (vp->v_type == VBLK) {
|
|
|
|
size = (int)(nblks - ctod(CLSIZE));
|
|
|
|
addr = (long)ctod(CLSIZE);
|
|
|
|
} else {
|
|
|
|
size = (int)nblks;
|
|
|
|
addr = (long)0;
|
|
|
|
}
|
|
|
|
|
1997-12-01 20:10:48 +03:00
|
|
|
DPRINTF(VMSDB_SWON,
|
|
|
|
("swap_on: dev %x: size %d, addr %ld\n", dev, size, addr));
|
1997-06-12 18:51:20 +04:00
|
|
|
|
|
|
|
name = malloc(12, M_VMSWAP, M_WAITOK);
|
|
|
|
sprintf(name, "swap0x%04x", count++);
|
|
|
|
/* XXX make this based on ram as well. */
|
|
|
|
storagesize = EXTENT_FIXED_STORAGE_SIZE(maxproc * 2);
|
|
|
|
storage = malloc(storagesize, M_VMSWAP, M_WAITOK);
|
1997-10-10 17:16:24 +04:00
|
|
|
sdp->swd_ex = extent_create(name, 0, nblks, M_VMSWAP,
|
1997-06-16 17:35:17 +04:00
|
|
|
storage, storagesize, EX_WAITOK);
|
1997-10-10 17:16:24 +04:00
|
|
|
if (addr) {
|
|
|
|
if (extent_alloc_region(sdp->swd_ex, 0, addr, EX_WAITOK))
|
|
|
|
panic("disklabel region");
|
|
|
|
sdp->swd_inuse += addr;
|
|
|
|
}
|
|
|
|
|
1997-06-12 18:51:20 +04:00
|
|
|
|
|
|
|
if (vp == rootvp) {
|
|
|
|
struct mount *mp;
|
|
|
|
struct statfs *sp;
|
|
|
|
int rootblks;
|
|
|
|
|
|
|
|
/* Get size from root FS (mountroot did statfs) */
|
|
|
|
mp = rootvnode->v_mount;
|
|
|
|
sp = &mp->mnt_stat;
|
|
|
|
rootblks = sp->f_blocks * (sp->f_bsize / DEV_BSIZE);
|
|
|
|
if (rootblks > nblks)
|
|
|
|
panic("miniroot size");
|
|
|
|
|
|
|
|
if (extent_alloc_region(sdp->swd_ex, addr, rootblks, EX_WAITOK))
|
|
|
|
panic("miniroot region");
|
|
|
|
|
|
|
|
printf("Preserved %d blocks of miniroot leaving %d pages of swap
|
|
|
|
\n",
|
|
|
|
rootblks, dtoc(size - rootblks));
|
|
|
|
}
|
|
|
|
|
1997-10-13 23:15:19 +04:00
|
|
|
if (vp->v_type == VREG) {
|
|
|
|
/* Allocate additional vnx and vnd buffers */
|
|
|
|
int n, s;
|
|
|
|
/*
|
|
|
|
* Allocation Policy:
|
|
|
|
* (8 * swd_maxactive) vnx headers per swap dev
|
|
|
|
* (16 * swd_maxactive) vnd buffers per swap dev
|
|
|
|
*/
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
n = 8 * sdp->swd_maxactive;
|
1998-02-20 02:56:37 +03:00
|
|
|
(void)pool_prime(vndxfer_pool, n, 0);
|
1997-10-13 23:15:19 +04:00
|
|
|
|
|
|
|
n = 16 * sdp->swd_maxactive;
|
1998-02-20 02:56:37 +03:00
|
|
|
(void)pool_prime(vndbuf_pool, n, 0);
|
1997-12-15 14:18:41 +03:00
|
|
|
|
1997-10-13 23:15:19 +04:00
|
|
|
splx(s);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1997-06-12 18:51:20 +04:00
|
|
|
swap_addmap(sdp, size);
|
|
|
|
nswapdev++;
|
|
|
|
sdp->swd_flags |= SWF_ENABLE;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
bad:
|
|
|
|
if (vp != rootvp)
|
|
|
|
(void)VOP_CLOSE(vp, FREAD|FWRITE, p->p_ucred, p);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SWAP_OFF_WORKS
|
|
|
|
static int
|
|
|
|
swap_off(p, sdp)
|
|
|
|
struct proc *p;
|
|
|
|
struct swapdev *sdp;
|
|
|
|
{
|
1997-06-16 17:35:17 +04:00
|
|
|
char *name;
|
|
|
|
|
1997-06-12 18:51:20 +04:00
|
|
|
/* turn off the enable flag */
|
|
|
|
sdp->swd_flags &= ~SWF_ENABLE;
|
|
|
|
|
1997-12-01 20:10:48 +03:00
|
|
|
DPRINTF(VMSDB_SWOFF, ("swap_off: %x\n", sdp->swd_dev));
|
1997-06-12 18:51:20 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX write me
|
|
|
|
*
|
|
|
|
* the idea is to find out which processes are using this swap
|
|
|
|
* device, and page them all in.
|
|
|
|
*
|
|
|
|
* eventually, we should try to move them out to other swap areas
|
|
|
|
* if available.
|
1997-06-16 17:35:17 +04:00
|
|
|
*
|
|
|
|
* The alternative is to create a redirection map for this swap
|
|
|
|
* device. This should work by moving all the pages of data from
|
|
|
|
* the ex-swap device to another one, and making an entry in the
|
|
|
|
* redirection map for it. locking is going to be important for
|
|
|
|
* this!
|
1997-06-12 18:51:20 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* until the above code is written, we must ENODEV */
|
|
|
|
return ENODEV;
|
|
|
|
|
|
|
|
extent_free(swapmap, sdp->swd_mapoffset, sdp->swd_mapsize, EX_WAITOK);
|
|
|
|
nswapdev--;
|
1997-06-16 17:35:17 +04:00
|
|
|
name = sdp->swd_ex->ex_name;
|
1997-06-12 18:51:20 +04:00
|
|
|
extent_destroy(sdp->swd_ex);
|
1997-06-16 17:35:17 +04:00
|
|
|
free(name, M_VMSWAP);
|
1997-06-12 18:51:20 +04:00
|
|
|
free((caddr_t)sdp->swd_ex, M_VMSWAP);
|
|
|
|
if (sdp->swp_vp != rootvp)
|
|
|
|
(void) VOP_CLOSE(sdp->swd_vp, FREAD|FWRITE, p->p_ucred, p);
|
|
|
|
if (sdp->swd_vp)
|
|
|
|
vrele(sdp->swd_vp);
|
|
|
|
free((caddr_t)sdp, M_VMSWAP);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* to decide where to allocate what part of swap, we must "round robin"
|
|
|
|
* the swap devices in swap_priority of the same priority until they are
|
|
|
|
* full. we do this with a list of swap priorities that have circle
|
|
|
|
* queues of swapdevs.
|
|
|
|
*
|
|
|
|
* the following functions control allocation and freeing of part of the
|
|
|
|
* swap area. you call swap_alloc() with a size and it returns an address.
|
|
|
|
* later you call swap_free() and it frees the use of that swap area.
|
|
|
|
*
|
|
|
|
* daddr_t swap_alloc(int size);
|
|
|
|
* void swap_free(int size, daddr_t addr);
|
|
|
|
*/
|
|
|
|
|
|
|
|
daddr_t
|
|
|
|
swap_alloc(size)
|
|
|
|
int size;
|
|
|
|
{
|
|
|
|
struct swapdev *sdp;
|
|
|
|
struct swappri *spp;
|
|
|
|
u_long result;
|
|
|
|
|
|
|
|
if (nswapdev < 1)
|
|
|
|
return 0;
|
|
|
|
|
1997-10-17 23:06:05 +04:00
|
|
|
simple_lock(&swaplist_lock);
|
1997-06-12 18:51:20 +04:00
|
|
|
for (spp = swap_priority.lh_first; spp != NULL;
|
|
|
|
spp = spp->spi_swappri.le_next) {
|
|
|
|
for (sdp = spp->spi_swapdev.cqh_first;
|
|
|
|
sdp != (void *)&spp->spi_swapdev;
|
|
|
|
sdp = sdp->swd_next.cqe_next) {
|
|
|
|
/* if it's not enabled, then we can't swap from it */
|
|
|
|
if ((sdp->swd_flags & SWF_ENABLE) == 0 ||
|
|
|
|
/* XXX IS THIS CORRECT ? */
|
|
|
|
#if 1
|
|
|
|
(sdp->swd_inuse + size > sdp->swd_nblks) ||
|
|
|
|
#endif
|
|
|
|
extent_alloc(sdp->swd_ex, size, EX_NOALIGN,
|
|
|
|
EX_NOBOUNDARY, EX_MALLOCOK|EX_NOWAIT,
|
|
|
|
&result) != 0) {
|
|
|
|
continue;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-06-12 18:51:20 +04:00
|
|
|
CIRCLEQ_REMOVE(&spp->spi_swapdev, sdp, swd_next);
|
|
|
|
CIRCLEQ_INSERT_TAIL(&spp->spi_swapdev, sdp, swd_next);
|
|
|
|
sdp->swd_inuse += size;
|
1997-10-17 23:06:05 +04:00
|
|
|
simple_unlock(&swaplist_lock);
|
1997-06-12 18:51:20 +04:00
|
|
|
return (daddr_t)(result + sdp->swd_mapoffset);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
1997-10-17 23:06:05 +04:00
|
|
|
simple_unlock(&swaplist_lock);
|
1997-06-12 18:51:20 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
swap_free(size, addr)
|
|
|
|
int size;
|
|
|
|
daddr_t addr;
|
|
|
|
{
|
|
|
|
struct swapdev *sdp = swap_getsdpfromaddr(addr);
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (sdp == NULL)
|
|
|
|
panic("swap_free: unmapped address\n");
|
|
|
|
if (nswapdev < 1)
|
|
|
|
panic("swap_free: nswapdev < 1\n");
|
|
|
|
#endif
|
|
|
|
extent_free(sdp->swd_ex, addr - sdp->swd_mapoffset, size,
|
|
|
|
EX_MALLOCOK|EX_NOWAIT);
|
|
|
|
sdp->swd_inuse -= size;
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (sdp->swd_inuse < 0)
|
|
|
|
panic("swap_free: inuse < 0");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We have a physical -> virtual mapping to address here. There are several
|
|
|
|
* different physical address spaces (one for each swap partition) that are
|
|
|
|
* to be mapped onto a single virtual address space.
|
|
|
|
*/
|
|
|
|
#define ADDR_IN_MAP(addr, sdp) \
|
|
|
|
(((addr) >= (sdp)->swd_mapoffset) && \
|
|
|
|
((addr) < ((sdp)->swd_mapoffset + (sdp)->swd_mapsize)))
|
|
|
|
|
|
|
|
struct swapdev *
|
|
|
|
swap_getsdpfromaddr(addr)
|
|
|
|
daddr_t addr;
|
|
|
|
{
|
|
|
|
struct swapdev *sdp;
|
|
|
|
struct swappri *spp;
|
|
|
|
|
1997-10-17 23:06:05 +04:00
|
|
|
simple_lock(&swaplist_lock);
|
1997-06-12 18:51:20 +04:00
|
|
|
for (spp = swap_priority.lh_first; spp != NULL;
|
|
|
|
spp = spp->spi_swappri.le_next)
|
|
|
|
for (sdp = spp->spi_swapdev.cqh_first;
|
|
|
|
sdp != (void *)&spp->spi_swapdev;
|
|
|
|
sdp = sdp->swd_next.cqe_next)
|
|
|
|
if (ADDR_IN_MAP(addr, sdp)) {
|
1997-10-17 23:06:05 +04:00
|
|
|
simple_unlock(&swaplist_lock);
|
1997-06-12 18:51:20 +04:00
|
|
|
return sdp;
|
|
|
|
}
|
1997-10-17 23:06:05 +04:00
|
|
|
simple_unlock(&swaplist_lock);
|
1997-06-12 18:51:20 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
swap_addmap(sdp, size)
|
|
|
|
struct swapdev *sdp;
|
|
|
|
int size;
|
|
|
|
{
|
|
|
|
u_long result;
|
|
|
|
|
|
|
|
if (extent_alloc(swapmap, size, EX_NOALIGN, EX_NOBOUNDARY,
|
|
|
|
EX_WAITOK, &result))
|
|
|
|
panic("swap_addmap");
|
|
|
|
|
|
|
|
sdp->swd_mapoffset = result;
|
|
|
|
sdp->swd_mapsize = size;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1996-02-05 04:53:47 +03:00
|
|
|
/*ARGSUSED*/
|
1995-07-04 11:15:28 +04:00
|
|
|
int
|
1996-02-05 04:53:47 +03:00
|
|
|
swread(dev, uio, ioflag)
|
1995-07-04 11:15:28 +04:00
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
1996-02-05 04:53:47 +03:00
|
|
|
int ioflag;
|
1995-07-04 11:15:28 +04:00
|
|
|
{
|
|
|
|
|
1995-07-19 17:04:02 +04:00
|
|
|
return (physio(swstrategy, NULL, dev, B_READ, minphys, uio));
|
1995-07-04 11:15:28 +04:00
|
|
|
}
|
|
|
|
|
1996-02-05 04:53:47 +03:00
|
|
|
/*ARGSUSED*/
|
1995-07-04 11:15:28 +04:00
|
|
|
int
|
1996-02-05 04:53:47 +03:00
|
|
|
swwrite(dev, uio, ioflag)
|
1995-07-04 11:15:28 +04:00
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
1996-02-05 04:53:47 +03:00
|
|
|
int ioflag;
|
1995-07-04 11:15:28 +04:00
|
|
|
{
|
|
|
|
|
1995-07-19 17:04:02 +04:00
|
|
|
return (physio(swstrategy, NULL, dev, B_WRITE, minphys, uio));
|
1995-07-04 11:15:28 +04:00
|
|
|
}
|
|
|
|
|
1997-06-12 18:51:20 +04:00
|
|
|
void
|
|
|
|
swstrategy(bp)
|
|
|
|
struct buf *bp;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-06-12 18:51:20 +04:00
|
|
|
struct swapdev *sdp;
|
|
|
|
struct vnode *vp;
|
|
|
|
int bn;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-06-12 18:51:20 +04:00
|
|
|
bn = bp->b_blkno;
|
|
|
|
sdp = swap_getsdpfromaddr(bn);
|
|
|
|
if (sdp == NULL) {
|
|
|
|
bp->b_error = EINVAL;
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
biodone(bp);
|
|
|
|
return;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-06-12 18:51:20 +04:00
|
|
|
|
|
|
|
bn -= sdp->swd_mapoffset;
|
|
|
|
|
1997-12-01 20:10:48 +03:00
|
|
|
DPRINTF(VMSDB_SWFLOW,
|
|
|
|
("swstrategy(%s): mapoff %x, bn %x, bcount %ld\n",
|
1997-06-12 18:51:20 +04:00
|
|
|
((bp->b_flags & B_READ) == 0) ? "write" : "read",
|
1997-12-01 20:10:48 +03:00
|
|
|
sdp->swd_mapoffset, bn, bp->b_bcount));
|
1997-06-12 18:51:20 +04:00
|
|
|
|
|
|
|
switch (sdp->swd_vp->v_type) {
|
|
|
|
default:
|
|
|
|
panic("swstrategy: vnode type %x", sdp->swd_vp->v_type);
|
|
|
|
case VBLK:
|
|
|
|
bp->b_blkno = bn;
|
|
|
|
vp = sdp->swd_vp;
|
|
|
|
bp->b_dev = sdp->swd_dev;
|
|
|
|
VHOLD(vp);
|
|
|
|
if ((bp->b_flags & B_READ) == 0) {
|
|
|
|
int s = splbio();
|
|
|
|
vwakeup(bp);
|
|
|
|
vp->v_numoutput++;
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bp->b_vp != NULL)
|
|
|
|
brelvp(bp);
|
|
|
|
|
|
|
|
bp->b_vp = vp;
|
|
|
|
VOP_STRATEGY(bp);
|
|
|
|
return;
|
|
|
|
#ifdef SWAP_TO_FILES
|
|
|
|
case VREG:
|
|
|
|
sw_reg_strategy(sdp, bp, bn);
|
|
|
|
return;
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-06-12 18:51:20 +04:00
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SWAP_TO_FILES
|
|
|
|
|
|
|
|
static void
|
|
|
|
sw_reg_strategy(sdp, bp, bn)
|
|
|
|
struct swapdev *sdp;
|
|
|
|
struct buf *bp;
|
|
|
|
int bn;
|
|
|
|
{
|
|
|
|
struct vnode *vp;
|
|
|
|
struct vndxfer *vnx;
|
|
|
|
daddr_t nbn;
|
|
|
|
caddr_t addr;
|
|
|
|
int s, off, nra, error, sz, resid;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Translate the device logical block numbers into physical
|
|
|
|
* block numbers of the underlying filesystem device.
|
|
|
|
*/
|
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
addr = bp->b_data;
|
|
|
|
bn = dbtob(bn);
|
|
|
|
|
|
|
|
/* Allocate a header for this transfer and link it to the buffer */
|
1997-10-13 23:15:19 +04:00
|
|
|
getvndxfer(vnx);
|
1997-11-29 03:35:43 +03:00
|
|
|
vnx->vx_flags = VX_BUSY;
|
1997-06-12 18:51:20 +04:00
|
|
|
vnx->vx_error = 0;
|
|
|
|
vnx->vx_pending = 0;
|
|
|
|
vnx->vx_bp = bp;
|
|
|
|
vnx->vx_sdp = sdp;
|
|
|
|
|
1997-11-29 03:35:43 +03:00
|
|
|
error = 0;
|
1997-06-12 18:51:20 +04:00
|
|
|
for (resid = bp->b_resid; resid; resid -= sz) {
|
1997-11-29 03:35:43 +03:00
|
|
|
struct vndbuf *nbp;
|
|
|
|
|
1997-06-12 18:51:20 +04:00
|
|
|
nra = 0;
|
|
|
|
error = VOP_BMAP(sdp->swd_vp, bn / sdp->swd_bsize,
|
|
|
|
&vp, &nbn, &nra);
|
|
|
|
|
|
|
|
if (error == 0 && (long)nbn == -1)
|
|
|
|
error = EIO;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there was an error or a hole in the file...punt.
|
|
|
|
* Note that we may have to wait for any operations
|
|
|
|
* that we have already fired off before releasing
|
|
|
|
* the buffer.
|
|
|
|
*
|
|
|
|
* XXX we could deal with holes here but it would be
|
|
|
|
* a hassle (in the write case).
|
|
|
|
*/
|
|
|
|
if (error) {
|
|
|
|
s = splbio();
|
1997-11-29 03:35:43 +03:00
|
|
|
vnx->vx_error = error;
|
|
|
|
goto out;
|
1997-06-12 18:51:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((off = bn % sdp->swd_bsize) != 0)
|
|
|
|
sz = sdp->swd_bsize - off;
|
|
|
|
else
|
|
|
|
sz = (1 + nra) * sdp->swd_bsize;
|
|
|
|
|
|
|
|
if (resid < sz)
|
|
|
|
sz = resid;
|
|
|
|
|
1997-12-01 20:10:48 +03:00
|
|
|
DPRINTF(VMSDB_SWFLOW,
|
|
|
|
("sw_reg_strategy: vp %p/%p bn 0x%x/0x%x"
|
|
|
|
" sz 0x%x\n", sdp->swd_vp, vp, bn, nbn, sz));
|
1997-06-12 18:51:20 +04:00
|
|
|
|
1997-10-13 23:15:19 +04:00
|
|
|
getvndbuf(nbp);
|
1998-11-08 22:45:17 +03:00
|
|
|
nbp->vb_buf.b_flags = bp->b_flags | B_NOCACHE | B_CALL;
|
1997-06-12 18:51:20 +04:00
|
|
|
nbp->vb_buf.b_bcount = sz;
|
|
|
|
nbp->vb_buf.b_bufsize = bp->b_bufsize;
|
|
|
|
nbp->vb_buf.b_error = 0;
|
|
|
|
nbp->vb_buf.b_data = addr;
|
|
|
|
nbp->vb_buf.b_blkno = nbn + btodb(off);
|
|
|
|
nbp->vb_buf.b_proc = bp->b_proc;
|
|
|
|
nbp->vb_buf.b_iodone = sw_reg_iodone;
|
|
|
|
nbp->vb_buf.b_vp = NULLVP;
|
|
|
|
nbp->vb_buf.b_rcred = sdp->swd_cred;
|
|
|
|
nbp->vb_buf.b_wcred = sdp->swd_cred;
|
|
|
|
if (bp->b_dirtyend == 0) {
|
|
|
|
nbp->vb_buf.b_dirtyoff = 0;
|
|
|
|
nbp->vb_buf.b_dirtyend = sz;
|
|
|
|
} else {
|
|
|
|
nbp->vb_buf.b_dirtyoff =
|
|
|
|
max(0, bp->b_dirtyoff - (bp->b_bcount-resid));
|
|
|
|
nbp->vb_buf.b_dirtyend =
|
|
|
|
min(sz,
|
|
|
|
max(0, bp->b_dirtyend - (bp->b_bcount-resid)));
|
|
|
|
}
|
|
|
|
if (bp->b_validend == 0) {
|
|
|
|
nbp->vb_buf.b_validoff = 0;
|
|
|
|
nbp->vb_buf.b_validend = sz;
|
|
|
|
} else {
|
|
|
|
nbp->vb_buf.b_validoff =
|
|
|
|
max(0, bp->b_validoff - (bp->b_bcount-resid));
|
|
|
|
nbp->vb_buf.b_validend =
|
|
|
|
min(sz,
|
|
|
|
max(0, bp->b_validend - (bp->b_bcount-resid)));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-06-12 18:51:20 +04:00
|
|
|
|
|
|
|
nbp->vb_xfer = vnx;
|
|
|
|
|
1994-04-26 03:53:51 +04:00
|
|
|
/*
|
1997-06-12 18:51:20 +04:00
|
|
|
* Just sort by block number
|
1994-04-26 03:53:51 +04:00
|
|
|
*/
|
1997-06-12 18:51:20 +04:00
|
|
|
nbp->vb_buf.b_cylinder = nbp->vb_buf.b_blkno;
|
|
|
|
s = splbio();
|
1997-11-29 03:35:43 +03:00
|
|
|
if (vnx->vx_error != 0) {
|
|
|
|
putvndbuf(nbp);
|
|
|
|
goto out;
|
|
|
|
}
|
1997-06-12 18:51:20 +04:00
|
|
|
vnx->vx_pending++;
|
|
|
|
bgetvp(vp, &nbp->vb_buf);
|
|
|
|
disksort(&sdp->swd_tab, &nbp->vb_buf);
|
1997-11-29 03:35:43 +03:00
|
|
|
sw_reg_start(sdp);
|
1997-06-12 18:51:20 +04:00
|
|
|
splx(s);
|
|
|
|
|
|
|
|
bn += sz;
|
|
|
|
addr += sz;
|
1994-04-26 03:53:51 +04:00
|
|
|
}
|
1997-11-29 03:35:43 +03:00
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
|
|
|
|
out: /* Arrive here at splbio */
|
|
|
|
vnx->vx_flags &= ~VX_BUSY;
|
|
|
|
if (vnx->vx_pending == 0) {
|
|
|
|
if (vnx->vx_error != 0) {
|
|
|
|
bp->b_error = vnx->vx_error;
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
}
|
|
|
|
putvndxfer(vnx);
|
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
splx(s);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-06-12 18:51:20 +04:00
|
|
|
* Feed requests sequentially.
|
|
|
|
* We do it this way to keep from flooding NFS servers if we are connected
|
|
|
|
* to an NFS file. This places the burden on the client rather than the
|
|
|
|
* server.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1997-06-12 18:51:20 +04:00
|
|
|
static void
|
|
|
|
sw_reg_start(sdp)
|
|
|
|
struct swapdev *sdp;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-06-12 18:51:20 +04:00
|
|
|
struct buf *bp;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-12-02 16:47:37 +03:00
|
|
|
if ((sdp->swd_flags & SWF_BUSY) != 0)
|
|
|
|
/* Recursion control */
|
1997-11-29 03:35:43 +03:00
|
|
|
return;
|
|
|
|
|
1997-12-02 16:47:37 +03:00
|
|
|
sdp->swd_flags |= SWF_BUSY;
|
1997-11-29 03:35:43 +03:00
|
|
|
|
|
|
|
while (sdp->swd_tab.b_active < sdp->swd_maxactive) {
|
|
|
|
bp = sdp->swd_tab.b_actf;
|
|
|
|
if (bp == NULL)
|
|
|
|
break;
|
|
|
|
sdp->swd_tab.b_actf = bp->b_actf;
|
|
|
|
sdp->swd_tab.b_active++;
|
1997-06-12 18:51:20 +04:00
|
|
|
|
1997-12-01 20:10:48 +03:00
|
|
|
DPRINTF(VMSDB_SWFLOW,
|
|
|
|
("sw_reg_start: bp %p vp %p blkno %x addr %p cnt %lx\n",
|
|
|
|
bp, bp->b_vp, bp->b_blkno,bp->b_data, bp->b_bcount));
|
|
|
|
|
1997-11-29 03:35:43 +03:00
|
|
|
if ((bp->b_flags & B_READ) == 0)
|
|
|
|
bp->b_vp->v_numoutput++;
|
|
|
|
VOP_STRATEGY(bp);
|
|
|
|
}
|
1997-12-02 16:47:37 +03:00
|
|
|
sdp->swd_flags &= ~SWF_BUSY;
|
1997-06-12 18:51:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sw_reg_iodone(bp)
|
|
|
|
struct buf *bp;
|
|
|
|
{
|
1997-10-13 23:15:19 +04:00
|
|
|
register struct vndbuf *vbp = BUF_TO_VNDBUF(bp);
|
1997-06-12 18:51:20 +04:00
|
|
|
register struct vndxfer *vnx = (struct vndxfer *)vbp->vb_xfer;
|
|
|
|
register struct buf *pbp = vnx->vx_bp;
|
|
|
|
struct swapdev *sdp = vnx->vx_sdp;
|
|
|
|
int s, resid;
|
|
|
|
|
1997-12-01 20:10:48 +03:00
|
|
|
DPRINTF(VMSDB_SWFLOW,
|
|
|
|
("sw_reg_iodone: vbp %p vp %p blkno %x addr %p "
|
|
|
|
"cnt %lx(%lx)\n",
|
|
|
|
vbp, vbp->vb_buf.b_vp, vbp->vb_buf.b_blkno,
|
|
|
|
vbp->vb_buf.b_data, vbp->vb_buf.b_bcount,
|
|
|
|
vbp->vb_buf.b_resid));
|
1997-06-12 18:51:20 +04:00
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
resid = vbp->vb_buf.b_bcount - vbp->vb_buf.b_resid;
|
|
|
|
pbp->b_resid -= resid;
|
|
|
|
vnx->vx_pending--;
|
|
|
|
|
|
|
|
if (vbp->vb_buf.b_error) {
|
1997-12-01 20:10:48 +03:00
|
|
|
DPRINTF(VMSDB_INFO, ("sw_reg_iodone: vbp %p error %d\n", vbp,
|
|
|
|
vbp->vb_buf.b_error));
|
1997-06-12 18:51:20 +04:00
|
|
|
|
|
|
|
vnx->vx_error = vbp->vb_buf.b_error;
|
1995-09-19 01:21:00 +04:00
|
|
|
}
|
1997-06-12 18:51:20 +04:00
|
|
|
|
|
|
|
if (vbp->vb_buf.b_vp != NULLVP)
|
|
|
|
brelvp(&vbp->vb_buf);
|
|
|
|
|
|
|
|
putvndbuf(vbp);
|
|
|
|
|
1994-04-26 03:53:51 +04:00
|
|
|
/*
|
1997-06-12 18:51:20 +04:00
|
|
|
* Wrap up this transaction if it has run to completion or, in
|
|
|
|
* case of an error, when all auxiliary buffers have returned.
|
1994-04-26 03:53:51 +04:00
|
|
|
*/
|
1997-11-29 03:35:43 +03:00
|
|
|
if (vnx->vx_error != 0) {
|
|
|
|
pbp->b_flags |= B_ERROR;
|
|
|
|
pbp->b_error = vnx->vx_error;
|
|
|
|
if ((vnx->vx_flags & VX_BUSY) == 0 && vnx->vx_pending == 0) {
|
1997-12-01 20:10:48 +03:00
|
|
|
|
|
|
|
DPRINTF(VMSDB_SWFLOW,
|
|
|
|
("swiodone: pbp %p iodone: error %d\n",
|
|
|
|
pbp, vnx->vx_error));
|
1997-11-29 03:35:43 +03:00
|
|
|
putvndxfer(vnx);
|
|
|
|
biodone(pbp);
|
1994-04-26 03:53:51 +04:00
|
|
|
}
|
1997-12-01 19:33:15 +03:00
|
|
|
} else if (pbp->b_resid == 0) {
|
1997-11-29 03:35:43 +03:00
|
|
|
|
1997-12-01 19:33:15 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
1997-11-29 03:35:43 +03:00
|
|
|
if (vnx->vx_pending != 0)
|
|
|
|
panic("swiodone: vnx pending: %d", vnx->vx_pending);
|
1997-12-01 19:33:15 +03:00
|
|
|
#endif
|
1997-11-29 03:35:43 +03:00
|
|
|
|
|
|
|
if ((vnx->vx_flags & VX_BUSY) == 0) {
|
1997-12-01 20:10:48 +03:00
|
|
|
DPRINTF(VMSDB_SWFLOW,
|
|
|
|
("swiodone: pbp %p iodone\n", pbp));
|
1997-12-01 19:33:15 +03:00
|
|
|
putvndxfer(vnx);
|
1997-11-29 03:35:43 +03:00
|
|
|
biodone(pbp);
|
|
|
|
}
|
1994-04-26 03:53:51 +04:00
|
|
|
}
|
1997-06-12 18:51:20 +04:00
|
|
|
|
1997-11-29 03:35:43 +03:00
|
|
|
sdp->swd_tab.b_active--;
|
|
|
|
sw_reg_start(sdp);
|
1997-06-12 18:51:20 +04:00
|
|
|
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
#endif /* SWAP_TO_FILES */
|
|
|
|
|
|
|
|
void
|
|
|
|
swapinit()
|
|
|
|
{
|
|
|
|
struct buf *sp = swbuf;
|
|
|
|
struct proc *p = &proc0; /* XXX */
|
|
|
|
int i;
|
|
|
|
|
1997-12-01 20:10:48 +03:00
|
|
|
DPRINTF(VMSDB_SWINIT, ("swapinit\n"));
|
|
|
|
|
1997-06-12 18:51:20 +04:00
|
|
|
nswapdev = 0;
|
1997-06-13 19:37:17 +04:00
|
|
|
if (bdevvp(swapdev, &swapdev_vp))
|
|
|
|
panic("swapinit: can setup swapdev_vp");
|
1997-06-12 18:51:20 +04:00
|
|
|
|
1997-10-17 23:06:05 +04:00
|
|
|
simple_lock_init(&swaplist_lock);
|
|
|
|
lockinit(&swaplist_change_lock, PSWP, "swap change", 0, 0);
|
1997-06-12 18:51:20 +04:00
|
|
|
LIST_INIT(&swap_priority);
|
1995-09-19 01:21:00 +04:00
|
|
|
|
|
|
|
/*
|
1997-06-12 18:51:20 +04:00
|
|
|
* Create swap block resource map. The range [1..INT_MAX] allows
|
|
|
|
* for a grand total of 2 gigablocks of swap resource.
|
|
|
|
* (start at 1 because "block #0" will be interpreted as
|
|
|
|
* an allocation failure).
|
1995-09-19 01:21:00 +04:00
|
|
|
*/
|
1997-06-12 18:51:20 +04:00
|
|
|
swapmap = extent_create("swapmap", 1, INT_MAX,
|
|
|
|
M_VMSWAP, 0, 0, EX_WAITOK);
|
|
|
|
if (swapmap == 0)
|
|
|
|
panic("swapinit: extent_create failed");
|
1995-09-19 01:21:00 +04:00
|
|
|
|
1997-06-12 18:51:20 +04:00
|
|
|
/*
|
|
|
|
* Now set up swap buffer headers.
|
|
|
|
*/
|
|
|
|
bswlist.b_actf = sp;
|
|
|
|
for (i = 0; i < nswbuf - 1; i++, sp++) {
|
|
|
|
sp->b_actf = sp + 1;
|
|
|
|
sp->b_rcred = sp->b_wcred = p->p_ucred;
|
|
|
|
sp->b_vnbufs.le_next = NOLIST;
|
1995-09-19 01:21:00 +04:00
|
|
|
}
|
1997-06-12 18:51:20 +04:00
|
|
|
sp->b_rcred = sp->b_wcred = p->p_ucred;
|
|
|
|
sp->b_vnbufs.le_next = NOLIST;
|
|
|
|
sp->b_actf = NULL;
|
1997-12-01 20:10:48 +03:00
|
|
|
|
1997-12-15 14:18:41 +03:00
|
|
|
vndxfer_pool =
|
1998-07-24 00:52:01 +04:00
|
|
|
pool_create(sizeof(struct vndxfer), 0, 0, 0, "swp vnx", 0,
|
|
|
|
NULL, NULL, 0);
|
1997-12-15 14:18:41 +03:00
|
|
|
if (vndxfer_pool == NULL)
|
|
|
|
panic("swapinit: pool_create failed");
|
|
|
|
|
|
|
|
vndbuf_pool =
|
1998-07-24 00:52:01 +04:00
|
|
|
pool_create(sizeof(struct vndbuf), 0, 0, 0, "swp vnd", 0,
|
|
|
|
NULL, NULL, 0);
|
1997-12-15 14:18:41 +03:00
|
|
|
if (vndbuf_pool == NULL)
|
|
|
|
panic("swapinit: pool_create failed");
|
|
|
|
|
1997-12-01 20:10:48 +03:00
|
|
|
DPRINTF(VMSDB_SWINIT, ("leaving swapinit\n"));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|