Deleted Added
full compact
swap_pager.c (156420) swap_pager.c (157628)
1/*-
2 * Copyright (c) 1998 Matthew Dillon,
3 * Copyright (c) 1994 John S. Dyson
4 * Copyright (c) 1990 University of Utah.
5 * Copyright (c) 1982, 1986, 1989, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by

--- 53 unchanged lines hidden (view full) ---

62 *
63 * from: Utah $Hdr: swap_pager.c 1.4 91/04/30$
64 *
65 * @(#)swap_pager.c 8.9 (Berkeley) 3/21/94
66 * @(#)vm_swap.c 8.5 (Berkeley) 2/17/94
67 */
68
69#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1998 Matthew Dillon,
3 * Copyright (c) 1994 John S. Dyson
4 * Copyright (c) 1990 University of Utah.
5 * Copyright (c) 1982, 1986, 1989, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by

--- 53 unchanged lines hidden (view full) ---

62 *
63 * from: Utah $Hdr: swap_pager.c 1.4 91/04/30$
64 *
65 * @(#)swap_pager.c 8.9 (Berkeley) 3/21/94
66 * @(#)vm_swap.c 8.5 (Berkeley) 2/17/94
67 */
68
69#include <sys/cdefs.h>
70__FBSDID("$FreeBSD: head/sys/vm/swap_pager.c 156420 2006-03-08 06:31:46Z imp $");
70__FBSDID("$FreeBSD: head/sys/vm/swap_pager.c 157628 2006-04-10 10:03:41Z pjd $");
71
72#include "opt_mac.h"
73#include "opt_swap.h"
74#include "opt_vm.h"
75
76#include <sys/param.h>
77#include <sys/systm.h>
78#include <sys/conf.h>

--- 181 unchanged lines hidden (view full) ---

260static int nswap_hiwat = 512; /* in pages, swap_pager_almost_full warn */
261
262SYSCTL_INT(_vm, OID_AUTO, dmmax,
263 CTLFLAG_RD, &dmmax, 0, "Maximum size of a swap block");
264
265static void swp_sizecheck(void);
266static void swp_pager_async_iodone(struct buf *bp);
267static int swapongeom(struct thread *, struct vnode *);
71
72#include "opt_mac.h"
73#include "opt_swap.h"
74#include "opt_vm.h"
75
76#include <sys/param.h>
77#include <sys/systm.h>
78#include <sys/conf.h>

--- 181 unchanged lines hidden (view full) ---

260static int nswap_hiwat = 512; /* in pages, swap_pager_almost_full warn */
261
262SYSCTL_INT(_vm, OID_AUTO, dmmax,
263 CTLFLAG_RD, &dmmax, 0, "Maximum size of a swap block");
264
265static void swp_sizecheck(void);
266static void swp_pager_async_iodone(struct buf *bp);
267static int swapongeom(struct thread *, struct vnode *);
268static int swapoff_one(struct swdevt *sp, struct thread *td);
268static int swaponvp(struct thread *, struct vnode *, u_long);
269
270/*
271 * Swap bitmap functions
272 */
273static void swp_pager_freeswapspace(daddr_t blk, int npages);
274static daddr_t swp_pager_getswapspace(int npages);
275

--- 1828 unchanged lines hidden (view full) ---

2104 */
2105/* ARGSUSED */
2106int
2107swapoff(struct thread *td, struct swapoff_args *uap)
2108{
2109 struct vnode *vp;
2110 struct nameidata nd;
2111 struct swdevt *sp;
269static int swaponvp(struct thread *, struct vnode *, u_long);
270
271/*
272 * Swap bitmap functions
273 */
274static void swp_pager_freeswapspace(daddr_t blk, int npages);
275static daddr_t swp_pager_getswapspace(int npages);
276

--- 1828 unchanged lines hidden (view full) ---

2105 */
2106/* ARGSUSED */
2107int
2108swapoff(struct thread *td, struct swapoff_args *uap)
2109{
2110 struct vnode *vp;
2111 struct nameidata nd;
2112 struct swdevt *sp;
2112 u_long nblks, dvbase;
2113 int error;
2114
2113 int error;
2114
2115 mtx_lock(&Giant);
2116
2117 error = suser(td);
2118 if (error)
2115 error = suser(td);
2116 if (error)
2119 goto done2;
2117 return (error);
2120
2118
2119 mtx_lock(&Giant);
2121 while (swdev_syscall_active)
2122 tsleep(&swdev_syscall_active, PUSER - 1, "swpoff", 0);
2123 swdev_syscall_active = 1;
2124
2125 NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->name, td);
2126 error = namei(&nd);
2127 if (error)
2128 goto done;
2129 NDFREE(&nd, NDF_ONLY_PNBUF);
2130 vp = nd.ni_vp;
2131
2132 mtx_lock(&sw_dev_mtx);
2133 TAILQ_FOREACH(sp, &swtailq, sw_list) {
2134 if (sp->sw_vp == vp)
2120 while (swdev_syscall_active)
2121 tsleep(&swdev_syscall_active, PUSER - 1, "swpoff", 0);
2122 swdev_syscall_active = 1;
2123
2124 NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->name, td);
2125 error = namei(&nd);
2126 if (error)
2127 goto done;
2128 NDFREE(&nd, NDF_ONLY_PNBUF);
2129 vp = nd.ni_vp;
2130
2131 mtx_lock(&sw_dev_mtx);
2132 TAILQ_FOREACH(sp, &swtailq, sw_list) {
2133 if (sp->sw_vp == vp)
2135 goto found;
2134 break;
2136 }
2137 mtx_unlock(&sw_dev_mtx);
2135 }
2136 mtx_unlock(&sw_dev_mtx);
2138 error = EINVAL;
2139 goto done;
2140found:
2141 mtx_unlock(&sw_dev_mtx);
2137 if (sp == NULL) {
2138 error = EINVAL;
2139 goto done;
2140 }
2141 error = swapoff_one(sp, td);
2142done:
2143 swdev_syscall_active = 0;
2144 wakeup_one(&swdev_syscall_active);
2145 mtx_unlock(&Giant);
2146 return (error);
2147}
2148
2149static int
2150swapoff_one(struct swdevt *sp, struct thread *td)
2151{
2152 u_long nblks, dvbase;
2142#ifdef MAC
2153#ifdef MAC
2143 (void) vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
2144 error = mac_check_system_swapoff(td->td_ucred, vp);
2145 (void) VOP_UNLOCK(vp, 0, td);
2154 int error;
2155#endif
2156
2157 mtx_assert(&Giant, MA_OWNED);
2158#ifdef MAC
2159 (void) vn_lock(sp->sw_vp, LK_EXCLUSIVE | LK_RETRY, td);
2160 error = mac_check_system_swapoff(td->td_ucred, sp->sw_vp);
2161 (void) VOP_UNLOCK(sp->sw_vp, 0, td);
2146 if (error != 0)
2162 if (error != 0)
2147 goto done;
2163 return (error);
2148#endif
2164#endif
2149
2150 nblks = sp->sw_nblks;
2151
2152 /*
2153 * We can turn off this swap device safely only if the
2154 * available virtual memory in the system will fit the amount
2155 * of data we will have to page back in, plus an epsilon so
2156 * the system doesn't become critically low on swap space.
2157 */
2158 if (cnt.v_free_count + cnt.v_cache_count + swap_pager_avail <
2159 nblks + nswap_lowat) {
2165 nblks = sp->sw_nblks;
2166
2167 /*
2168 * We can turn off this swap device safely only if the
2169 * available virtual memory in the system will fit the amount
2170 * of data we will have to page back in, plus an epsilon so
2171 * the system doesn't become critically low on swap space.
2172 */
2173 if (cnt.v_free_count + cnt.v_cache_count + swap_pager_avail <
2174 nblks + nswap_lowat) {
2160 error = ENOMEM;
2161 goto done;
2175 return (ENOMEM);
2162 }
2163
2164 /*
2165 * Prevent further allocations on this device.
2166 */
2167 mtx_lock(&sw_dev_mtx);
2168 sp->sw_flags |= SW_CLOSING;
2169 for (dvbase = 0; dvbase < sp->sw_end; dvbase += dmmax) {

--- 16 unchanged lines hidden (view full) ---

2186 swap_pager_full = 2;
2187 swap_pager_almost_full = 1;
2188 }
2189 if (swdevhd == sp)
2190 swdevhd = NULL;
2191 mtx_unlock(&sw_dev_mtx);
2192 blist_destroy(sp->sw_blist);
2193 free(sp, M_VMPGDATA);
2176 }
2177
2178 /*
2179 * Prevent further allocations on this device.
2180 */
2181 mtx_lock(&sw_dev_mtx);
2182 sp->sw_flags |= SW_CLOSING;
2183 for (dvbase = 0; dvbase < sp->sw_end; dvbase += dmmax) {

--- 16 unchanged lines hidden (view full) ---

2200 swap_pager_full = 2;
2201 swap_pager_almost_full = 1;
2202 }
2203 if (swdevhd == sp)
2204 swdevhd = NULL;
2205 mtx_unlock(&sw_dev_mtx);
2206 blist_destroy(sp->sw_blist);
2207 free(sp, M_VMPGDATA);
2208 return (0);
2209}
2194
2210
2195done:
2211void
2212swapoff_all(void)
2213{
2214 struct swdevt *sp, *spt;
2215 const char *devname;
2216 int error;
2217
2218 mtx_lock(&Giant);
2219 while (swdev_syscall_active)
2220 tsleep(&swdev_syscall_active, PUSER - 1, "swpoff", 0);
2221 swdev_syscall_active = 1;
2222
2223 mtx_lock(&sw_dev_mtx);
2224 TAILQ_FOREACH_SAFE(sp, &swtailq, sw_list, spt) {
2225 mtx_unlock(&sw_dev_mtx);
2226 if (vn_isdisk(sp->sw_vp, NULL))
2227 devname = sp->sw_vp->v_rdev->si_name;
2228 else
2229 devname = "[file]";
2230 error = swapoff_one(sp, &thread0);
2231 if (error != 0) {
2232 printf("Cannot remove swap device %s (error=%d), "
2233 "skipping.\n", devname, error);
2234 } else if (bootverbose) {
2235 printf("Swap device %s removed.\n", devname);
2236 }
2237 mtx_lock(&sw_dev_mtx);
2238 }
2239 mtx_unlock(&sw_dev_mtx);
2240
2196 swdev_syscall_active = 0;
2197 wakeup_one(&swdev_syscall_active);
2241 swdev_syscall_active = 0;
2242 wakeup_one(&swdev_syscall_active);
2198done2:
2199 mtx_unlock(&Giant);
2243 mtx_unlock(&Giant);
2200 return (error);
2201}
2202
2203void
2204swap_pager_status(int *total, int *used)
2205{
2206 struct swdevt *sp;
2207
2208 *total = 0;

--- 330 unchanged lines hidden ---
2244}
2245
2246void
2247swap_pager_status(int *total, int *used)
2248{
2249 struct swdevt *sp;
2250
2251 *total = 0;

--- 330 unchanged lines hidden ---