xref: /onnv-gate/usr/src/uts/common/fs/swapfs/swap_subr.c (revision 5331:3047ad28a67b)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
53898Srsb  * Common Development and Distribution License (the "License").
63898Srsb  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
223898Srsb  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <sys/types.h>
290Sstevel@tonic-gate #include <sys/param.h>
300Sstevel@tonic-gate #include <sys/systm.h>
310Sstevel@tonic-gate #include <sys/errno.h>
320Sstevel@tonic-gate #include <sys/kmem.h>
330Sstevel@tonic-gate #include <sys/vnode.h>
343898Srsb #include <sys/vfs_opreg.h>
350Sstevel@tonic-gate #include <sys/swap.h>
360Sstevel@tonic-gate #include <sys/sysmacros.h>
370Sstevel@tonic-gate #include <sys/buf.h>
380Sstevel@tonic-gate #include <sys/callb.h>
390Sstevel@tonic-gate #include <sys/debug.h>
400Sstevel@tonic-gate #include <vm/seg.h>
410Sstevel@tonic-gate #include <sys/fs/swapnode.h>
420Sstevel@tonic-gate #include <fs/fs_subr.h>
430Sstevel@tonic-gate #include <sys/cmn_err.h>
440Sstevel@tonic-gate #include <sys/mem_config.h>
450Sstevel@tonic-gate #include <sys/atomic.h>
460Sstevel@tonic-gate 
470Sstevel@tonic-gate extern const fs_operation_def_t swap_vnodeops_template[];
480Sstevel@tonic-gate 
490Sstevel@tonic-gate /*
500Sstevel@tonic-gate  * swapfs_minfree is the amount of physical memory (actually remaining
510Sstevel@tonic-gate  * availrmem) that we want to keep free for the rest of the system.  This
520Sstevel@tonic-gate  * means that swapfs can only grow to availrmem - swapfs_minfree.  This
530Sstevel@tonic-gate  * can be set as just constant value or a certain percentage of installed
540Sstevel@tonic-gate  * physical memory. It is set in swapinit().
550Sstevel@tonic-gate  *
560Sstevel@tonic-gate  * Users who want to change the amount of memory that can be used as swap
570Sstevel@tonic-gate  * space should do so by setting swapfs_desfree at boot time,
580Sstevel@tonic-gate  * not swapfs_minfree.
590Sstevel@tonic-gate  */
600Sstevel@tonic-gate 
610Sstevel@tonic-gate pgcnt_t swapfs_desfree = 0;
620Sstevel@tonic-gate pgcnt_t swapfs_minfree = 0;
630Sstevel@tonic-gate pgcnt_t swapfs_reserve = 0;
640Sstevel@tonic-gate 
650Sstevel@tonic-gate #ifdef SWAPFS_DEBUG
660Sstevel@tonic-gate int swapfs_debug;
670Sstevel@tonic-gate #endif /* SWAPFS_DEBUG */
680Sstevel@tonic-gate 
690Sstevel@tonic-gate 
700Sstevel@tonic-gate static int swapfs_vpcount;
710Sstevel@tonic-gate static kmutex_t swapfs_lock;
720Sstevel@tonic-gate static struct async_reqs *sw_ar, *sw_pendlist, *sw_freelist;
730Sstevel@tonic-gate 
740Sstevel@tonic-gate static struct vnode **swap_vnodes;	/* ptr's to swap vnodes */
750Sstevel@tonic-gate 
760Sstevel@tonic-gate static void swap_init_mem_config(void);
770Sstevel@tonic-gate 
780Sstevel@tonic-gate static pgcnt_t initial_swapfs_desfree;
790Sstevel@tonic-gate static pgcnt_t initial_swapfs_minfree;
800Sstevel@tonic-gate static pgcnt_t initial_swapfs_reserve;
810Sstevel@tonic-gate 
820Sstevel@tonic-gate static int swap_sync(struct vfs *vfsp, short flag, struct cred *cr);
830Sstevel@tonic-gate 
840Sstevel@tonic-gate static void
850Sstevel@tonic-gate swapfs_recalc_save_initial(void)
860Sstevel@tonic-gate {
870Sstevel@tonic-gate 	initial_swapfs_desfree = swapfs_desfree;
880Sstevel@tonic-gate 	initial_swapfs_minfree = swapfs_minfree;
890Sstevel@tonic-gate 	initial_swapfs_reserve = swapfs_reserve;
900Sstevel@tonic-gate }
910Sstevel@tonic-gate 
920Sstevel@tonic-gate static int
930Sstevel@tonic-gate swapfs_recalc(pgcnt_t pgs)
940Sstevel@tonic-gate {
950Sstevel@tonic-gate 	pgcnt_t new_swapfs_desfree;
960Sstevel@tonic-gate 	pgcnt_t new_swapfs_minfree;
970Sstevel@tonic-gate 	pgcnt_t new_swapfs_reserve;
980Sstevel@tonic-gate 
990Sstevel@tonic-gate 	new_swapfs_desfree = initial_swapfs_desfree;
1000Sstevel@tonic-gate 	new_swapfs_minfree = initial_swapfs_minfree;
1010Sstevel@tonic-gate 	new_swapfs_reserve = initial_swapfs_reserve;
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate 	if (new_swapfs_desfree == 0)
1040Sstevel@tonic-gate 		new_swapfs_desfree = btopr(7 * 512 * 1024); /* 3-1/2Mb */;
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate 	if (new_swapfs_minfree == 0) {
1070Sstevel@tonic-gate 		/*
1080Sstevel@tonic-gate 		 * We set this lower than we'd like here, 2Mb, because we
1090Sstevel@tonic-gate 		 * always boot on swapfs. It's up to a safer value,
1100Sstevel@tonic-gate 		 * swapfs_desfree, when/if we add physical swap devices
1110Sstevel@tonic-gate 		 * in swapadd(). Users who want to change the amount of
1120Sstevel@tonic-gate 		 * memory that can be used as swap space should do so by
1130Sstevel@tonic-gate 		 * setting swapfs_desfree at boot time, not swapfs_minfree.
1140Sstevel@tonic-gate 		 * However, swapfs_minfree is tunable by install as a
1150Sstevel@tonic-gate 		 * workaround for bugid 1147463.
1160Sstevel@tonic-gate 		 */
1170Sstevel@tonic-gate 		new_swapfs_minfree = MAX(btopr(2 * 1024 * 1024), pgs >> 3);
1180Sstevel@tonic-gate 	}
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate 	/*
1210Sstevel@tonic-gate 	 * priv processes can reserve memory as swap as long as availrmem
1220Sstevel@tonic-gate 	 * remains greater than swapfs_minfree; in the case of non-priv
1230Sstevel@tonic-gate 	 * processes, memory can be reserved as swap only if availrmem
1240Sstevel@tonic-gate 	 * doesn't fall below (swapfs_minfree + swapfs_reserve). Thus,
1250Sstevel@tonic-gate 	 * swapfs_reserve amount of memswap is not available to non-priv
1260Sstevel@tonic-gate 	 * processes. This protects daemons such as automounter dying
1270Sstevel@tonic-gate 	 * as a result of application processes eating away almost entire
1280Sstevel@tonic-gate 	 * membased swap. This safeguard becomes useless if apps are run
1290Sstevel@tonic-gate 	 * with root access.
1300Sstevel@tonic-gate 	 *
1310Sstevel@tonic-gate 	 * set swapfs_reserve to a minimum of 4Mb or 1/128 of physmem whichever
1320Sstevel@tonic-gate 	 * is greater up to the limit of 128 MB.
1330Sstevel@tonic-gate 	 */
1340Sstevel@tonic-gate 	if (new_swapfs_reserve == 0)
1350Sstevel@tonic-gate 		new_swapfs_reserve = MIN(btopr(128 * 1024 * 1024),
1360Sstevel@tonic-gate 		    MAX(btopr(4 * 1024 * 1024), pgs >> 7));
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate 	/* Test basic numeric viability. */
1390Sstevel@tonic-gate 	if (new_swapfs_minfree > pgs)
1400Sstevel@tonic-gate 		return (0);
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate 	/* Equivalent test to anon_resvmem() check. */
1430Sstevel@tonic-gate 	if (availrmem < new_swapfs_minfree) {
1440Sstevel@tonic-gate 		/*
1450Sstevel@tonic-gate 		 * If ism pages are being used, then there must be agreement
1460Sstevel@tonic-gate 		 * between these two policies.
1470Sstevel@tonic-gate 		 */
1480Sstevel@tonic-gate 		if ((availrmem > segspt_minfree) && (segspt_minfree > 0)) {
1490Sstevel@tonic-gate 			new_swapfs_minfree = segspt_minfree;
1500Sstevel@tonic-gate 		} else {
1510Sstevel@tonic-gate 			return (0);
1520Sstevel@tonic-gate 		}
1530Sstevel@tonic-gate 	}
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate 	swapfs_desfree = new_swapfs_desfree;
1560Sstevel@tonic-gate 	swapfs_minfree = new_swapfs_minfree;
1570Sstevel@tonic-gate 	swapfs_reserve = new_swapfs_reserve;
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate 	return (1);
1600Sstevel@tonic-gate }
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate /*ARGSUSED1*/
1630Sstevel@tonic-gate int
1640Sstevel@tonic-gate swapinit(int fstype, char *name)
1650Sstevel@tonic-gate {							/* reserve for mp */
1660Sstevel@tonic-gate 	ssize_t sw_freelist_size = klustsize / PAGESIZE * 2;
1670Sstevel@tonic-gate 	int i, error;
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate 	static const fs_operation_def_t swap_vfsops[] = {
1703898Srsb 		VFSNAME_SYNC, { .vfs_sync = swap_sync },
1710Sstevel@tonic-gate 		NULL, NULL
1720Sstevel@tonic-gate 	};
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate 	SWAPFS_PRINT(SWAP_SUBR, "swapinit\n", 0, 0, 0, 0, 0);
1750Sstevel@tonic-gate 	mutex_init(&swapfs_lock, NULL, MUTEX_DEFAULT, NULL);
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate 	swap_vnodes = kmem_zalloc(MAX_SWAP_VNODES * sizeof (struct vnode *),
1780Sstevel@tonic-gate 	    KM_SLEEP);
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate 	swapfs_recalc_save_initial();
1810Sstevel@tonic-gate 	if (!swapfs_recalc(physmem))
1820Sstevel@tonic-gate 		cmn_err(CE_PANIC, "swapfs_minfree(%lu) > physmem(%lu)",
1830Sstevel@tonic-gate 		    swapfs_minfree, physmem);
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate 	/*
1860Sstevel@tonic-gate 	 * Arrange for a callback on memory size change.
1870Sstevel@tonic-gate 	 */
1880Sstevel@tonic-gate 	swap_init_mem_config();
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate 	sw_ar = (struct async_reqs *)
1910Sstevel@tonic-gate 	    kmem_zalloc(sw_freelist_size*sizeof (struct async_reqs), KM_SLEEP);
1920Sstevel@tonic-gate 
1930Sstevel@tonic-gate 	error = vfs_setfsops(fstype, swap_vfsops, NULL);
1940Sstevel@tonic-gate 	if (error != 0) {
1950Sstevel@tonic-gate 		cmn_err(CE_WARN, "swapinit: bad vfs ops template");
1960Sstevel@tonic-gate 		return (error);
1970Sstevel@tonic-gate 	}
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate 	error = vn_make_ops(name, swap_vnodeops_template, &swap_vnodeops);
2000Sstevel@tonic-gate 	if (error != 0) {
2010Sstevel@tonic-gate 		(void) vfs_freevfsops_by_type(fstype);
2020Sstevel@tonic-gate 		cmn_err(CE_WARN, "swapinit: bad vnode ops template");
2030Sstevel@tonic-gate 		return (error);
2040Sstevel@tonic-gate 	}
2050Sstevel@tonic-gate 	sw_freelist = sw_ar;
2060Sstevel@tonic-gate 	for (i = 0; i < sw_freelist_size - 1; i++)
2070Sstevel@tonic-gate 		sw_ar[i].a_next = &sw_ar[i + 1];
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate 	return (0);
2100Sstevel@tonic-gate }
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate /*
2130Sstevel@tonic-gate  * Get a swapfs vnode corresponding to the specified identifier.
2140Sstevel@tonic-gate  */
2150Sstevel@tonic-gate struct vnode *
2160Sstevel@tonic-gate swapfs_getvp(ulong_t vidx)
2170Sstevel@tonic-gate {
2180Sstevel@tonic-gate 	struct vnode *vp;
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate 	vp = swap_vnodes[vidx];
2210Sstevel@tonic-gate 	if (vp) {
2220Sstevel@tonic-gate 		return (vp);
2230Sstevel@tonic-gate 	}
2240Sstevel@tonic-gate 
2250Sstevel@tonic-gate 	mutex_enter(&swapfs_lock);
2260Sstevel@tonic-gate 	vp = swap_vnodes[vidx];
2270Sstevel@tonic-gate 	if (vp == NULL) {
2280Sstevel@tonic-gate 		vp = vn_alloc(KM_SLEEP);
2290Sstevel@tonic-gate 		vn_setops(vp, swap_vnodeops);
2300Sstevel@tonic-gate 		vp->v_type = VREG;
2310Sstevel@tonic-gate 		vp->v_flag |= (VISSWAP|VISSWAPFS);
2320Sstevel@tonic-gate 		swap_vnodes[vidx] = vp;
2330Sstevel@tonic-gate 		swapfs_vpcount++;
2340Sstevel@tonic-gate 	}
2350Sstevel@tonic-gate 	mutex_exit(&swapfs_lock);
2360Sstevel@tonic-gate 	return (vp);
2370Sstevel@tonic-gate }
2380Sstevel@tonic-gate 
2390Sstevel@tonic-gate int swap_lo;
2400Sstevel@tonic-gate 
2410Sstevel@tonic-gate /*ARGSUSED*/
2420Sstevel@tonic-gate static int
2430Sstevel@tonic-gate swap_sync(struct vfs *vfsp, short flag, struct cred *cr)
2440Sstevel@tonic-gate {
2450Sstevel@tonic-gate 	struct vnode *vp;
2460Sstevel@tonic-gate 	int i;
2470Sstevel@tonic-gate 
2480Sstevel@tonic-gate 	if (!(flag & SYNC_ALL))
2490Sstevel@tonic-gate 		return (1);
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate 	/*
2520Sstevel@tonic-gate 	 * assumes that we are the only one left to access this so that
2530Sstevel@tonic-gate 	 * no need to use swapfs_lock (since it's staticly defined)
2540Sstevel@tonic-gate 	 */
2550Sstevel@tonic-gate 	for (i = 0; i < MAX_SWAP_VNODES; i++) {
2560Sstevel@tonic-gate 		vp = swap_vnodes[i];
2570Sstevel@tonic-gate 		if (vp) {
2580Sstevel@tonic-gate 			VN_HOLD(vp);
2590Sstevel@tonic-gate 			(void) VOP_PUTPAGE(vp, (offset_t)0, 0,
260*5331Samw 			    (B_ASYNC | B_FREE), kcred, NULL);
2610Sstevel@tonic-gate 			VN_RELE(vp);
2620Sstevel@tonic-gate 		}
2630Sstevel@tonic-gate 	}
2640Sstevel@tonic-gate 	return (0);
2650Sstevel@tonic-gate }
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate extern int sw_pending_size;
2680Sstevel@tonic-gate 
2690Sstevel@tonic-gate /*
2700Sstevel@tonic-gate  * Take an async request off the pending queue
2710Sstevel@tonic-gate  */
2720Sstevel@tonic-gate struct async_reqs *
2730Sstevel@tonic-gate sw_getreq()
2740Sstevel@tonic-gate {
2750Sstevel@tonic-gate 	struct async_reqs *arg;
2760Sstevel@tonic-gate 
2770Sstevel@tonic-gate 	mutex_enter(&swapfs_lock);
2780Sstevel@tonic-gate 	arg = sw_pendlist;
2790Sstevel@tonic-gate 	if (arg) {
2800Sstevel@tonic-gate 		sw_pendlist = arg->a_next;
2810Sstevel@tonic-gate 		arg->a_next = NULL;
2820Sstevel@tonic-gate 		sw_pending_size -= PAGESIZE;
2830Sstevel@tonic-gate 	}
2840Sstevel@tonic-gate 	ASSERT(sw_pending_size >= 0);
2850Sstevel@tonic-gate 	mutex_exit(&swapfs_lock);
2860Sstevel@tonic-gate 	return (arg);
2870Sstevel@tonic-gate }
2880Sstevel@tonic-gate 
2890Sstevel@tonic-gate /*
2900Sstevel@tonic-gate  * Put an async request on the pending queue
2910Sstevel@tonic-gate  */
2920Sstevel@tonic-gate void
2930Sstevel@tonic-gate sw_putreq(struct async_reqs *arg)
2940Sstevel@tonic-gate {
2950Sstevel@tonic-gate 	/* Hold onto it */
2960Sstevel@tonic-gate 	VN_HOLD(arg->a_vp);
2970Sstevel@tonic-gate 
2980Sstevel@tonic-gate 	mutex_enter(&swapfs_lock);
2990Sstevel@tonic-gate 	arg->a_next = sw_pendlist;
3000Sstevel@tonic-gate 	sw_pendlist = arg;
3010Sstevel@tonic-gate 	sw_pending_size += PAGESIZE;
3020Sstevel@tonic-gate 	mutex_exit(&swapfs_lock);
3030Sstevel@tonic-gate }
3040Sstevel@tonic-gate 
3050Sstevel@tonic-gate /*
3060Sstevel@tonic-gate  * Put an async request back on the pending queue
3070Sstevel@tonic-gate  */
3080Sstevel@tonic-gate void
3090Sstevel@tonic-gate sw_putbackreq(struct async_reqs *arg)
3100Sstevel@tonic-gate {
3110Sstevel@tonic-gate 	mutex_enter(&swapfs_lock);
3120Sstevel@tonic-gate 	arg->a_next = sw_pendlist;
3130Sstevel@tonic-gate 	sw_pendlist = arg;
3140Sstevel@tonic-gate 	sw_pending_size += PAGESIZE;
3150Sstevel@tonic-gate 	mutex_exit(&swapfs_lock);
3160Sstevel@tonic-gate }
3170Sstevel@tonic-gate 
3180Sstevel@tonic-gate /*
3190Sstevel@tonic-gate  * Take an async request structure off the free list
3200Sstevel@tonic-gate  */
3210Sstevel@tonic-gate struct async_reqs *
3220Sstevel@tonic-gate sw_getfree()
3230Sstevel@tonic-gate {
3240Sstevel@tonic-gate 	struct async_reqs *arg;
3250Sstevel@tonic-gate 
3260Sstevel@tonic-gate 	mutex_enter(&swapfs_lock);
3270Sstevel@tonic-gate 	arg = sw_freelist;
3280Sstevel@tonic-gate 	if (arg) {
3290Sstevel@tonic-gate 		sw_freelist = arg->a_next;
3300Sstevel@tonic-gate 		arg->a_next = NULL;
3310Sstevel@tonic-gate 	}
3320Sstevel@tonic-gate 	mutex_exit(&swapfs_lock);
3330Sstevel@tonic-gate 	return (arg);
3340Sstevel@tonic-gate }
3350Sstevel@tonic-gate 
3360Sstevel@tonic-gate /*
3370Sstevel@tonic-gate  * Put an async request structure on the free list
3380Sstevel@tonic-gate  */
3390Sstevel@tonic-gate void
3400Sstevel@tonic-gate sw_putfree(struct async_reqs *arg)
3410Sstevel@tonic-gate {
3420Sstevel@tonic-gate 	/* Release our hold - should have locked the page by now */
3430Sstevel@tonic-gate 	VN_RELE(arg->a_vp);
3440Sstevel@tonic-gate 
3450Sstevel@tonic-gate 	mutex_enter(&swapfs_lock);
3460Sstevel@tonic-gate 	arg->a_next = sw_freelist;
3470Sstevel@tonic-gate 	sw_freelist = arg;
3480Sstevel@tonic-gate 	mutex_exit(&swapfs_lock);
3490Sstevel@tonic-gate }
3500Sstevel@tonic-gate 
3510Sstevel@tonic-gate static pgcnt_t swapfs_pending_delete;
3520Sstevel@tonic-gate 
3530Sstevel@tonic-gate /*ARGSUSED*/
3540Sstevel@tonic-gate static void
3550Sstevel@tonic-gate swap_mem_config_post_add(
3560Sstevel@tonic-gate 	void *arg,
3570Sstevel@tonic-gate 	pgcnt_t delta_swaps)
3580Sstevel@tonic-gate {
3590Sstevel@tonic-gate 	(void) swapfs_recalc(physmem - swapfs_pending_delete);
3600Sstevel@tonic-gate }
3610Sstevel@tonic-gate 
3620Sstevel@tonic-gate /*ARGSUSED*/
3630Sstevel@tonic-gate static int
3640Sstevel@tonic-gate swap_mem_config_pre_del(
3650Sstevel@tonic-gate 	void *arg,
3660Sstevel@tonic-gate 	pgcnt_t delta_swaps)
3670Sstevel@tonic-gate {
3680Sstevel@tonic-gate 	pgcnt_t nv;
3690Sstevel@tonic-gate 
3700Sstevel@tonic-gate 	nv = atomic_add_long_nv(&swapfs_pending_delete, (spgcnt_t)delta_swaps);
3710Sstevel@tonic-gate 	if (!swapfs_recalc(physmem - nv)) {
3720Sstevel@tonic-gate 		/*
3730Sstevel@tonic-gate 		 * Tidy-up is done by the call to post_del which
3740Sstevel@tonic-gate 		 * is always made.
3750Sstevel@tonic-gate 		 */
3760Sstevel@tonic-gate 		return (EBUSY);
3770Sstevel@tonic-gate 	}
3780Sstevel@tonic-gate 	return (0);
3790Sstevel@tonic-gate }
3800Sstevel@tonic-gate 
3810Sstevel@tonic-gate /*ARGSUSED*/
3820Sstevel@tonic-gate static void
3830Sstevel@tonic-gate swap_mem_config_post_del(
3840Sstevel@tonic-gate 	void *arg,
3850Sstevel@tonic-gate 	pgcnt_t delta_swaps,
3860Sstevel@tonic-gate 	int cancelled)
3870Sstevel@tonic-gate {
3880Sstevel@tonic-gate 	pgcnt_t nv;
3890Sstevel@tonic-gate 
3900Sstevel@tonic-gate 	nv = atomic_add_long_nv(&swapfs_pending_delete, -(spgcnt_t)delta_swaps);
3910Sstevel@tonic-gate 	(void) swapfs_recalc(physmem - nv);
3920Sstevel@tonic-gate }
3930Sstevel@tonic-gate 
3940Sstevel@tonic-gate static kphysm_setup_vector_t swap_mem_config_vec = {
3950Sstevel@tonic-gate 	KPHYSM_SETUP_VECTOR_VERSION,
3960Sstevel@tonic-gate 	swap_mem_config_post_add,
3970Sstevel@tonic-gate 	swap_mem_config_pre_del,
3980Sstevel@tonic-gate 	swap_mem_config_post_del,
3990Sstevel@tonic-gate };
4000Sstevel@tonic-gate 
4010Sstevel@tonic-gate static void
4020Sstevel@tonic-gate swap_init_mem_config(void)
4030Sstevel@tonic-gate {
4040Sstevel@tonic-gate 	int ret;
4050Sstevel@tonic-gate 
4060Sstevel@tonic-gate 	ret = kphysm_setup_func_register(&swap_mem_config_vec, (void *)NULL);
4070Sstevel@tonic-gate 	ASSERT(ret == 0);
4080Sstevel@tonic-gate }
409