2005-01-07 02:29:27 +00:00
|
|
|
/*-
|
1999-01-21 08:29:12 +00:00
|
|
|
* Copyright (c) 1998 Matthew Dillon,
|
1994-05-25 09:21:21 +00:00
|
|
|
* Copyright (c) 1994 John S. Dyson
|
1994-05-24 10:09:53 +00:00
|
|
|
* Copyright (c) 1990 University of Utah.
|
2003-07-18 10:02:44 +00:00
|
|
|
* Copyright (c) 1982, 1986, 1989, 1993
|
1994-05-24 10:09:53 +00:00
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* the Systems Programming Group of the University of Utah Computer
|
|
|
|
* Science Department.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
2000-03-27 20:41:17 +00:00
|
|
|
* must display the following acknowledgement:
|
1994-05-24 10:09:53 +00:00
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, 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.
|
|
|
|
*
|
1999-01-21 08:29:12 +00:00
|
|
|
* New Swap System
|
|
|
|
* Matthew Dillon
|
|
|
|
*
|
|
|
|
* Radix Bitmap 'blists'.
|
|
|
|
*
|
|
|
|
* - The new swapper uses the new radix bitmap code. This should scale
|
|
|
|
* to arbitrarily small or arbitrarily large swap spaces and an almost
|
|
|
|
* arbitrary degree of fragmentation.
|
|
|
|
*
|
|
|
|
* Features:
|
|
|
|
*
|
|
|
|
* - on the fly reallocation of swap during putpages. The new system
|
|
|
|
* does not try to keep previously allocated swap blocks for dirty
|
2012-09-05 12:24:50 +00:00
|
|
|
* pages.
|
1999-01-21 08:29:12 +00:00
|
|
|
*
|
|
|
|
* - on the fly deallocation of swap
|
|
|
|
*
|
|
|
|
* - No more garbage collection required. Unnecessarily allocated swap
|
|
|
|
* blocks only exist for dirty vm_page_t's now and these are already
|
|
|
|
* cycled (in a high-load system) by the pager. We also do on-the-fly
|
|
|
|
* removal of invalidated swap blocks when a page is destroyed
|
|
|
|
* or renamed.
|
|
|
|
*
|
1994-05-24 10:09:53 +00:00
|
|
|
* from: Utah $Hdr: swap_pager.c 1.4 91/04/30$
|
|
|
|
*
|
|
|
|
* @(#)swap_pager.c 8.9 (Berkeley) 3/21/94
|
2003-07-18 10:02:44 +00:00
|
|
|
* @(#)vm_swap.c 8.5 (Berkeley) 2/17/94
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
|
|
|
|
2003-06-11 23:50:51 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2003-07-18 10:02:44 +00:00
|
|
|
#include "opt_swap.h"
|
|
|
|
#include "opt_vm.h"
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1999-08-23 23:55:03 +00:00
|
|
|
#include <sys/conf.h>
|
1995-04-16 13:58:42 +00:00
|
|
|
#include <sys/kernel.h>
|
2006-11-06 13:42:10 +00:00
|
|
|
#include <sys/priv.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/proc.h>
|
2000-05-05 09:59:14 +00:00
|
|
|
#include <sys/bio.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/buf.h>
|
2003-07-18 10:02:44 +00:00
|
|
|
#include <sys/disk.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/namei.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/malloc.h>
|
2011-04-05 20:23:59 +00:00
|
|
|
#include <sys/racct.h>
|
Implement global and per-uid accounting of the anonymous memory. Add
rlimit RLIMIT_SWAP that limits the amount of swap that may be reserved
for the uid.
The accounting information (charge) is associated with either map entry,
or vm object backing the entry, assuming the object is the first one
in the shadow chain and entry does not require COW. Charge is moved
from entry to object on allocation of the object, e.g. during the mmap,
assuming the object is allocated, or on the first page fault on the
entry. It moves back to the entry on forks due to COW setup.
The per-entry granularity of accounting makes the charge process fair
for processes that change uid during lifetime, and decrements charge
for proper uid when region is unmapped.
The interface of vm_pager_allocate(9) is extended by adding struct ucred *,
that is used to charge appropriate uid when allocation if performed by
kernel, e.g. md(4).
Several syscalls, among them is fork(2), may now return ENOMEM when
global or per-uid limits are enforced.
In collaboration with: pho
Reviewed by: alc
Approved by: re (kensmith)
2009-06-23 20:45:22 +00:00
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sys/resourcevar.h>
|
2013-03-09 02:32:23 +00:00
|
|
|
#include <sys/rwlock.h>
|
1999-02-18 19:57:33 +00:00
|
|
|
#include <sys/sysctl.h>
|
2003-07-18 10:02:44 +00:00
|
|
|
#include <sys/sysproto.h>
|
1999-01-21 08:29:12 +00:00
|
|
|
#include <sys/blist.h>
|
|
|
|
#include <sys/lock.h>
|
2001-07-04 16:20:28 +00:00
|
|
|
#include <sys/sx.h>
|
Implement a low-memory deadlock solution.
Removed most of the hacks that were trying to deal with low-memory
situations prior to now.
The new code is based on the concept that I/O must be able to function in
a low memory situation. All major modules related to I/O (except
networking) have been adjusted to allow allocation out of the system
reserve memory pool. These modules now detect a low memory situation but
rather then block they instead continue to operate, then return resources
to the memory pool instead of cache them or leave them wired.
Code has been added to stall in a low-memory situation prior to a vnode
being locked.
Thus situations where a process blocks in a low-memory condition while
holding a locked vnode have been reduced to near nothing. Not only will
I/O continue to operate, but many prior deadlock conditions simply no
longer exist.
Implement a number of VFS/BIO fixes
(found by Ian): in biodone(), bogus-page replacement code, the loop
was not properly incrementing loop variables prior to a continue
statement. We do not believe this code can be hit anyway but we
aren't taking any chances. We'll turn the whole section into a
panic (as it already is in brelse()) after the release is rolled.
In biodone(), the foff calculation was incorrectly
clamped to the iosize, causing the wrong foff to be calculated
for pages in the case of an I/O error or biodone() called without
initiating I/O. The problem always caused a panic before. Now it
doesn't. The problem is mainly an issue with NFS.
Fixed casts for ~PAGE_MASK. This code worked properly before only
because the calculations use signed arithmatic. Better to properly
extend PAGE_MASK first before inverting it for the 64 bit masking
op.
In brelse(), the bogus_page fixup code was improperly throwing
away the original contents of 'm' when it did the j-loop to
fix the bogus pages. The result was that it would potentially
invalidate parts of the *WRONG* page(!), leading to corruption.
There may still be cases where a background bitmap write is
being duplicated, causing potential corruption. We have identified
a potentially serious bug related to this but the fix is still TBD.
So instead this patch contains a KASSERT to detect the problem
and panic the machine rather then continue to corrupt the filesystem.
The problem does not occur very often.. it is very hard to
reproduce, and it may or may not be the cause of the corruption
people have reported.
Review by: (VFS/BIO: mckusick, Ian Dowse <iedowse@maths.tcd.ie>)
Testing by: (VM/Deadlock) Paul Saab <ps@yahoo-inc.com>
2000-11-18 23:06:26 +00:00
|
|
|
#include <sys/vmmeter.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2006-10-22 11:52:19 +00:00
|
|
|
#include <security/mac/mac_framework.h>
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <vm/vm.h>
|
2000-12-13 10:01:00 +00:00
|
|
|
#include <vm/pmap.h>
|
|
|
|
#include <vm/vm_map.h>
|
|
|
|
#include <vm/vm_kern.h>
|
1995-12-07 12:48:31 +00:00
|
|
|
#include <vm/vm_object.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <vm/vm_page.h>
|
1995-12-07 12:48:31 +00:00
|
|
|
#include <vm/vm_pager.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <vm/vm_pageout.h>
|
2003-07-18 10:02:44 +00:00
|
|
|
#include <vm/vm_param.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <vm/swap_pager.h>
|
1995-12-07 12:48:31 +00:00
|
|
|
#include <vm/vm_extern.h>
|
2002-03-20 04:02:59 +00:00
|
|
|
#include <vm/uma.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2003-08-30 16:44:26 +00:00
|
|
|
#include <geom/geom.h>
|
|
|
|
|
2003-07-18 10:47:58 +00:00
|
|
|
/*
|
2011-08-22 20:44:18 +00:00
|
|
|
* SWB_NPAGES must be a power of 2. It may be set to 1, 2, 4, 8, 16
|
|
|
|
* or 32 pages per allocation.
|
|
|
|
* The 32-page limit is due to the radix code (kern/subr_blist.c).
|
2003-07-18 10:47:58 +00:00
|
|
|
*/
|
|
|
|
#ifndef MAX_PAGEOUT_CLUSTER
|
|
|
|
#define MAX_PAGEOUT_CLUSTER 16
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(SWB_NPAGES)
|
|
|
|
#define SWB_NPAGES MAX_PAGEOUT_CLUSTER
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2011-08-22 20:44:18 +00:00
|
|
|
* The swblock structure maps an object and a small, fixed-size range
|
|
|
|
* of page indices to disk addresses within a swap area.
|
|
|
|
* The collection of these mappings is implemented as a hash table.
|
|
|
|
* Unused disk addresses within a swap area are allocated and managed
|
|
|
|
* using a blist.
|
2003-07-18 10:47:58 +00:00
|
|
|
*/
|
|
|
|
#define SWCORRECT(n) (sizeof(void *) * (n) / sizeof(daddr_t))
|
|
|
|
#define SWAP_META_PAGES (SWB_NPAGES * 2)
|
|
|
|
#define SWAP_META_MASK (SWAP_META_PAGES - 1)
|
|
|
|
|
2003-07-18 10:02:44 +00:00
|
|
|
struct swblock {
|
|
|
|
struct swblock *swb_hnext;
|
|
|
|
vm_object_t swb_object;
|
|
|
|
vm_pindex_t swb_index;
|
|
|
|
int swb_count;
|
|
|
|
daddr_t swb_pages[SWAP_META_PAGES];
|
|
|
|
};
|
|
|
|
|
2011-01-18 04:54:43 +00:00
|
|
|
static MALLOC_DEFINE(M_VMPGDATA, "vm_pgdata", "swap pager private data");
|
2003-08-30 16:10:28 +00:00
|
|
|
static struct mtx sw_dev_mtx;
|
2003-08-03 13:35:31 +00:00
|
|
|
static TAILQ_HEAD(, swdevt) swtailq = TAILQ_HEAD_INITIALIZER(swtailq);
|
|
|
|
static struct swdevt *swdevhd; /* Allocate from here next */
|
|
|
|
static int nswapdev; /* Number of swap devices */
|
|
|
|
int swap_pager_avail;
|
2016-05-22 23:25:01 +00:00
|
|
|
static struct sx swdev_syscall_lock; /* serialize swap(on|off) */
|
2003-07-18 10:02:44 +00:00
|
|
|
|
Implement global and per-uid accounting of the anonymous memory. Add
rlimit RLIMIT_SWAP that limits the amount of swap that may be reserved
for the uid.
The accounting information (charge) is associated with either map entry,
or vm object backing the entry, assuming the object is the first one
in the shadow chain and entry does not require COW. Charge is moved
from entry to object on allocation of the object, e.g. during the mmap,
assuming the object is allocated, or on the first page fault on the
entry. It moves back to the entry on forks due to COW setup.
The per-entry granularity of accounting makes the charge process fair
for processes that change uid during lifetime, and decrements charge
for proper uid when region is unmapped.
The interface of vm_pager_allocate(9) is extended by adding struct ucred *,
that is used to charge appropriate uid when allocation if performed by
kernel, e.g. md(4).
Several syscalls, among them is fork(2), may now return ENOMEM when
global or per-uid limits are enforced.
In collaboration with: pho
Reviewed by: alc
Approved by: re (kensmith)
2009-06-23 20:45:22 +00:00
|
|
|
static vm_ooffset_t swap_total;
|
2012-09-05 12:24:50 +00:00
|
|
|
SYSCTL_QUAD(_vm, OID_AUTO, swap_total, CTLFLAG_RD, &swap_total, 0,
|
2009-11-02 16:56:59 +00:00
|
|
|
"Total amount of available swap storage.");
|
Implement global and per-uid accounting of the anonymous memory. Add
rlimit RLIMIT_SWAP that limits the amount of swap that may be reserved
for the uid.
The accounting information (charge) is associated with either map entry,
or vm object backing the entry, assuming the object is the first one
in the shadow chain and entry does not require COW. Charge is moved
from entry to object on allocation of the object, e.g. during the mmap,
assuming the object is allocated, or on the first page fault on the
entry. It moves back to the entry on forks due to COW setup.
The per-entry granularity of accounting makes the charge process fair
for processes that change uid during lifetime, and decrements charge
for proper uid when region is unmapped.
The interface of vm_pager_allocate(9) is extended by adding struct ucred *,
that is used to charge appropriate uid when allocation if performed by
kernel, e.g. md(4).
Several syscalls, among them is fork(2), may now return ENOMEM when
global or per-uid limits are enforced.
In collaboration with: pho
Reviewed by: alc
Approved by: re (kensmith)
2009-06-23 20:45:22 +00:00
|
|
|
static vm_ooffset_t swap_reserved;
|
2012-09-05 12:24:50 +00:00
|
|
|
SYSCTL_QUAD(_vm, OID_AUTO, swap_reserved, CTLFLAG_RD, &swap_reserved, 0,
|
2009-11-02 16:56:59 +00:00
|
|
|
"Amount of swap storage needed to back all allocated anonymous memory.");
|
Implement global and per-uid accounting of the anonymous memory. Add
rlimit RLIMIT_SWAP that limits the amount of swap that may be reserved
for the uid.
The accounting information (charge) is associated with either map entry,
or vm object backing the entry, assuming the object is the first one
in the shadow chain and entry does not require COW. Charge is moved
from entry to object on allocation of the object, e.g. during the mmap,
assuming the object is allocated, or on the first page fault on the
entry. It moves back to the entry on forks due to COW setup.
The per-entry granularity of accounting makes the charge process fair
for processes that change uid during lifetime, and decrements charge
for proper uid when region is unmapped.
The interface of vm_pager_allocate(9) is extended by adding struct ucred *,
that is used to charge appropriate uid when allocation if performed by
kernel, e.g. md(4).
Several syscalls, among them is fork(2), may now return ENOMEM when
global or per-uid limits are enforced.
In collaboration with: pho
Reviewed by: alc
Approved by: re (kensmith)
2009-06-23 20:45:22 +00:00
|
|
|
static int overcommit = 0;
|
2012-09-05 12:24:50 +00:00
|
|
|
SYSCTL_INT(_vm, OID_AUTO, overcommit, CTLFLAG_RW, &overcommit, 0,
|
2009-11-02 16:56:59 +00:00
|
|
|
"Configure virtual memory overcommit behavior. See tuning(7) "
|
|
|
|
"for details.");
|
2014-04-26 12:18:17 +00:00
|
|
|
static unsigned long swzone;
|
|
|
|
SYSCTL_ULONG(_vm, OID_AUTO, swzone, CTLFLAG_RD, &swzone, 0,
|
|
|
|
"Actual size of swap metadata zone");
|
|
|
|
static unsigned long swap_maxpages;
|
|
|
|
SYSCTL_ULONG(_vm, OID_AUTO, swap_maxpages, CTLFLAG_RD, &swap_maxpages, 0,
|
|
|
|
"Maximum amount of swap supported");
|
Implement global and per-uid accounting of the anonymous memory. Add
rlimit RLIMIT_SWAP that limits the amount of swap that may be reserved
for the uid.
The accounting information (charge) is associated with either map entry,
or vm object backing the entry, assuming the object is the first one
in the shadow chain and entry does not require COW. Charge is moved
from entry to object on allocation of the object, e.g. during the mmap,
assuming the object is allocated, or on the first page fault on the
entry. It moves back to the entry on forks due to COW setup.
The per-entry granularity of accounting makes the charge process fair
for processes that change uid during lifetime, and decrements charge
for proper uid when region is unmapped.
The interface of vm_pager_allocate(9) is extended by adding struct ucred *,
that is used to charge appropriate uid when allocation if performed by
kernel, e.g. md(4).
Several syscalls, among them is fork(2), may now return ENOMEM when
global or per-uid limits are enforced.
In collaboration with: pho
Reviewed by: alc
Approved by: re (kensmith)
2009-06-23 20:45:22 +00:00
|
|
|
|
|
|
|
/* bits from overcommit */
|
|
|
|
#define SWAP_RESERVE_FORCE_ON (1 << 0)
|
|
|
|
#define SWAP_RESERVE_RLIMIT_ON (1 << 1)
|
|
|
|
#define SWAP_RESERVE_ALLOW_NONWIRED (1 << 2)
|
|
|
|
|
|
|
|
int
|
|
|
|
swap_reserve(vm_ooffset_t incr)
|
|
|
|
{
|
|
|
|
|
2010-12-02 17:37:16 +00:00
|
|
|
return (swap_reserve_by_cred(incr, curthread->td_ucred));
|
Implement global and per-uid accounting of the anonymous memory. Add
rlimit RLIMIT_SWAP that limits the amount of swap that may be reserved
for the uid.
The accounting information (charge) is associated with either map entry,
or vm object backing the entry, assuming the object is the first one
in the shadow chain and entry does not require COW. Charge is moved
from entry to object on allocation of the object, e.g. during the mmap,
assuming the object is allocated, or on the first page fault on the
entry. It moves back to the entry on forks due to COW setup.
The per-entry granularity of accounting makes the charge process fair
for processes that change uid during lifetime, and decrements charge
for proper uid when region is unmapped.
The interface of vm_pager_allocate(9) is extended by adding struct ucred *,
that is used to charge appropriate uid when allocation if performed by
kernel, e.g. md(4).
Several syscalls, among them is fork(2), may now return ENOMEM when
global or per-uid limits are enforced.
In collaboration with: pho
Reviewed by: alc
Approved by: re (kensmith)
2009-06-23 20:45:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-12-02 17:37:16 +00:00
|
|
|
swap_reserve_by_cred(vm_ooffset_t incr, struct ucred *cred)
|
Implement global and per-uid accounting of the anonymous memory. Add
rlimit RLIMIT_SWAP that limits the amount of swap that may be reserved
for the uid.
The accounting information (charge) is associated with either map entry,
or vm object backing the entry, assuming the object is the first one
in the shadow chain and entry does not require COW. Charge is moved
from entry to object on allocation of the object, e.g. during the mmap,
assuming the object is allocated, or on the first page fault on the
entry. It moves back to the entry on forks due to COW setup.
The per-entry granularity of accounting makes the charge process fair
for processes that change uid during lifetime, and decrements charge
for proper uid when region is unmapped.
The interface of vm_pager_allocate(9) is extended by adding struct ucred *,
that is used to charge appropriate uid when allocation if performed by
kernel, e.g. md(4).
Several syscalls, among them is fork(2), may now return ENOMEM when
global or per-uid limits are enforced.
In collaboration with: pho
Reviewed by: alc
Approved by: re (kensmith)
2009-06-23 20:45:22 +00:00
|
|
|
{
|
2009-10-18 12:55:39 +00:00
|
|
|
vm_ooffset_t r, s;
|
Implement global and per-uid accounting of the anonymous memory. Add
rlimit RLIMIT_SWAP that limits the amount of swap that may be reserved
for the uid.
The accounting information (charge) is associated with either map entry,
or vm object backing the entry, assuming the object is the first one
in the shadow chain and entry does not require COW. Charge is moved
from entry to object on allocation of the object, e.g. during the mmap,
assuming the object is allocated, or on the first page fault on the
entry. It moves back to the entry on forks due to COW setup.
The per-entry granularity of accounting makes the charge process fair
for processes that change uid during lifetime, and decrements charge
for proper uid when region is unmapped.
The interface of vm_pager_allocate(9) is extended by adding struct ucred *,
that is used to charge appropriate uid when allocation if performed by
kernel, e.g. md(4).
Several syscalls, among them is fork(2), may now return ENOMEM when
global or per-uid limits are enforced.
In collaboration with: pho
Reviewed by: alc
Approved by: re (kensmith)
2009-06-23 20:45:22 +00:00
|
|
|
int res, error;
|
|
|
|
static int curfail;
|
|
|
|
static struct timeval lastfail;
|
2010-12-02 17:37:16 +00:00
|
|
|
struct uidinfo *uip;
|
2012-09-05 12:24:50 +00:00
|
|
|
|
2010-12-02 17:37:16 +00:00
|
|
|
uip = cred->cr_ruidinfo;
|
Implement global and per-uid accounting of the anonymous memory. Add
rlimit RLIMIT_SWAP that limits the amount of swap that may be reserved
for the uid.
The accounting information (charge) is associated with either map entry,
or vm object backing the entry, assuming the object is the first one
in the shadow chain and entry does not require COW. Charge is moved
from entry to object on allocation of the object, e.g. during the mmap,
assuming the object is allocated, or on the first page fault on the
entry. It moves back to the entry on forks due to COW setup.
The per-entry granularity of accounting makes the charge process fair
for processes that change uid during lifetime, and decrements charge
for proper uid when region is unmapped.
The interface of vm_pager_allocate(9) is extended by adding struct ucred *,
that is used to charge appropriate uid when allocation if performed by
kernel, e.g. md(4).
Several syscalls, among them is fork(2), may now return ENOMEM when
global or per-uid limits are enforced.
In collaboration with: pho
Reviewed by: alc
Approved by: re (kensmith)
2009-06-23 20:45:22 +00:00
|
|
|
|
|
|
|
if (incr & PAGE_MASK)
|
|
|
|
panic("swap_reserve: & PAGE_MASK");
|
|
|
|
|
2011-07-06 20:06:44 +00:00
|
|
|
#ifdef RACCT
|
2015-04-29 10:23:02 +00:00
|
|
|
if (racct_enable) {
|
|
|
|
PROC_LOCK(curproc);
|
|
|
|
error = racct_add(curproc, RACCT_SWAP, incr);
|
|
|
|
PROC_UNLOCK(curproc);
|
|
|
|
if (error != 0)
|
|
|
|
return (0);
|
|
|
|
}
|
2011-07-06 20:06:44 +00:00
|
|
|
#endif
|
2011-04-05 20:23:59 +00:00
|
|
|
|
Implement global and per-uid accounting of the anonymous memory. Add
rlimit RLIMIT_SWAP that limits the amount of swap that may be reserved
for the uid.
The accounting information (charge) is associated with either map entry,
or vm object backing the entry, assuming the object is the first one
in the shadow chain and entry does not require COW. Charge is moved
from entry to object on allocation of the object, e.g. during the mmap,
assuming the object is allocated, or on the first page fault on the
entry. It moves back to the entry on forks due to COW setup.
The per-entry granularity of accounting makes the charge process fair
for processes that change uid during lifetime, and decrements charge
for proper uid when region is unmapped.
The interface of vm_pager_allocate(9) is extended by adding struct ucred *,
that is used to charge appropriate uid when allocation if performed by
kernel, e.g. md(4).
Several syscalls, among them is fork(2), may now return ENOMEM when
global or per-uid limits are enforced.
In collaboration with: pho
Reviewed by: alc
Approved by: re (kensmith)
2009-06-23 20:45:22 +00:00
|
|
|
res = 0;
|
|
|
|
mtx_lock(&sw_dev_mtx);
|
|
|
|
r = swap_reserved + incr;
|
|
|
|
if (overcommit & SWAP_RESERVE_ALLOW_NONWIRED) {
|
2014-03-22 10:26:09 +00:00
|
|
|
s = vm_cnt.v_page_count - vm_cnt.v_free_reserved - vm_cnt.v_wire_count;
|
Implement global and per-uid accounting of the anonymous memory. Add
rlimit RLIMIT_SWAP that limits the amount of swap that may be reserved
for the uid.
The accounting information (charge) is associated with either map entry,
or vm object backing the entry, assuming the object is the first one
in the shadow chain and entry does not require COW. Charge is moved
from entry to object on allocation of the object, e.g. during the mmap,
assuming the object is allocated, or on the first page fault on the
entry. It moves back to the entry on forks due to COW setup.
The per-entry granularity of accounting makes the charge process fair
for processes that change uid during lifetime, and decrements charge
for proper uid when region is unmapped.
The interface of vm_pager_allocate(9) is extended by adding struct ucred *,
that is used to charge appropriate uid when allocation if performed by
kernel, e.g. md(4).
Several syscalls, among them is fork(2), may now return ENOMEM when
global or per-uid limits are enforced.
In collaboration with: pho
Reviewed by: alc
Approved by: re (kensmith)
2009-06-23 20:45:22 +00:00
|
|
|
s *= PAGE_SIZE;
|
|
|
|
} else
|
|
|
|
s = 0;
|
|
|
|
s += swap_total;
|
|
|
|
if ((overcommit & SWAP_RESERVE_FORCE_ON) == 0 || r <= s ||
|
|
|
|
(error = priv_check(curthread, PRIV_VM_SWAP_NOQUOTA)) == 0) {
|
|
|
|
res = 1;
|
|
|
|
swap_reserved = r;
|
|
|
|
}
|
|
|
|
mtx_unlock(&sw_dev_mtx);
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
UIDINFO_VMSIZE_LOCK(uip);
|
2009-10-18 12:55:39 +00:00
|
|
|
if ((overcommit & SWAP_RESERVE_RLIMIT_ON) != 0 &&
|
2015-06-10 10:48:12 +00:00
|
|
|
uip->ui_vmsize + incr > lim_cur(curthread, RLIMIT_SWAP) &&
|
2009-10-18 12:55:39 +00:00
|
|
|
priv_check(curthread, PRIV_VM_SWAP_NORLIMIT))
|
Implement global and per-uid accounting of the anonymous memory. Add
rlimit RLIMIT_SWAP that limits the amount of swap that may be reserved
for the uid.
The accounting information (charge) is associated with either map entry,
or vm object backing the entry, assuming the object is the first one
in the shadow chain and entry does not require COW. Charge is moved
from entry to object on allocation of the object, e.g. during the mmap,
assuming the object is allocated, or on the first page fault on the
entry. It moves back to the entry on forks due to COW setup.
The per-entry granularity of accounting makes the charge process fair
for processes that change uid during lifetime, and decrements charge
for proper uid when region is unmapped.
The interface of vm_pager_allocate(9) is extended by adding struct ucred *,
that is used to charge appropriate uid when allocation if performed by
kernel, e.g. md(4).
Several syscalls, among them is fork(2), may now return ENOMEM when
global or per-uid limits are enforced.
In collaboration with: pho
Reviewed by: alc
Approved by: re (kensmith)
2009-06-23 20:45:22 +00:00
|
|
|
res = 0;
|
|
|
|
else
|
|
|
|
uip->ui_vmsize += incr;
|
|
|
|
UIDINFO_VMSIZE_UNLOCK(uip);
|
|
|
|
if (!res) {
|
|
|
|
mtx_lock(&sw_dev_mtx);
|
|
|
|
swap_reserved -= incr;
|
|
|
|
mtx_unlock(&sw_dev_mtx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!res && ppsratecheck(&lastfail, &curfail, 1)) {
|
|
|
|
printf("uid %d, pid %d: swap reservation for %jd bytes failed\n",
|
2011-12-12 10:04:04 +00:00
|
|
|
uip->ui_uid, curproc->p_pid, incr);
|
Implement global and per-uid accounting of the anonymous memory. Add
rlimit RLIMIT_SWAP that limits the amount of swap that may be reserved
for the uid.
The accounting information (charge) is associated with either map entry,
or vm object backing the entry, assuming the object is the first one
in the shadow chain and entry does not require COW. Charge is moved
from entry to object on allocation of the object, e.g. during the mmap,
assuming the object is allocated, or on the first page fault on the
entry. It moves back to the entry on forks due to COW setup.
The per-entry granularity of accounting makes the charge process fair
for processes that change uid during lifetime, and decrements charge
for proper uid when region is unmapped.
The interface of vm_pager_allocate(9) is extended by adding struct ucred *,
that is used to charge appropriate uid when allocation if performed by
kernel, e.g. md(4).
Several syscalls, among them is fork(2), may now return ENOMEM when
global or per-uid limits are enforced.
In collaboration with: pho
Reviewed by: alc
Approved by: re (kensmith)
2009-06-23 20:45:22 +00:00
|
|
|
}
|
|
|
|
|
2011-07-06 20:06:44 +00:00
|
|
|
#ifdef RACCT
|
2011-04-05 20:23:59 +00:00
|
|
|
if (!res) {
|
|
|
|
PROC_LOCK(curproc);
|
|
|
|
racct_sub(curproc, RACCT_SWAP, incr);
|
|
|
|
PROC_UNLOCK(curproc);
|
|
|
|
}
|
2011-07-06 20:06:44 +00:00
|
|
|
#endif
|
2011-04-05 20:23:59 +00:00
|
|
|
|
Implement global and per-uid accounting of the anonymous memory. Add
rlimit RLIMIT_SWAP that limits the amount of swap that may be reserved
for the uid.
The accounting information (charge) is associated with either map entry,
or vm object backing the entry, assuming the object is the first one
in the shadow chain and entry does not require COW. Charge is moved
from entry to object on allocation of the object, e.g. during the mmap,
assuming the object is allocated, or on the first page fault on the
entry. It moves back to the entry on forks due to COW setup.
The per-entry granularity of accounting makes the charge process fair
for processes that change uid during lifetime, and decrements charge
for proper uid when region is unmapped.
The interface of vm_pager_allocate(9) is extended by adding struct ucred *,
that is used to charge appropriate uid when allocation if performed by
kernel, e.g. md(4).
Several syscalls, among them is fork(2), may now return ENOMEM when
global or per-uid limits are enforced.
In collaboration with: pho
Reviewed by: alc
Approved by: re (kensmith)
2009-06-23 20:45:22 +00:00
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
swap_reserve_force(vm_ooffset_t incr)
|
|
|
|
{
|
|
|
|
struct uidinfo *uip;
|
|
|
|
|
|
|
|
mtx_lock(&sw_dev_mtx);
|
|
|
|
swap_reserved += incr;
|
|
|
|
mtx_unlock(&sw_dev_mtx);
|
|
|
|
|
2011-07-06 20:06:44 +00:00
|
|
|
#ifdef RACCT
|
2011-04-05 20:23:59 +00:00
|
|
|
PROC_LOCK(curproc);
|
|
|
|
racct_add_force(curproc, RACCT_SWAP, incr);
|
|
|
|
PROC_UNLOCK(curproc);
|
2011-07-06 20:06:44 +00:00
|
|
|
#endif
|
2011-04-05 20:23:59 +00:00
|
|
|
|
Implement global and per-uid accounting of the anonymous memory. Add
rlimit RLIMIT_SWAP that limits the amount of swap that may be reserved
for the uid.
The accounting information (charge) is associated with either map entry,
or vm object backing the entry, assuming the object is the first one
in the shadow chain and entry does not require COW. Charge is moved
from entry to object on allocation of the object, e.g. during the mmap,
assuming the object is allocated, or on the first page fault on the
entry. It moves back to the entry on forks due to COW setup.
The per-entry granularity of accounting makes the charge process fair
for processes that change uid during lifetime, and decrements charge
for proper uid when region is unmapped.
The interface of vm_pager_allocate(9) is extended by adding struct ucred *,
that is used to charge appropriate uid when allocation if performed by
kernel, e.g. md(4).
Several syscalls, among them is fork(2), may now return ENOMEM when
global or per-uid limits are enforced.
In collaboration with: pho
Reviewed by: alc
Approved by: re (kensmith)
2009-06-23 20:45:22 +00:00
|
|
|
uip = curthread->td_ucred->cr_ruidinfo;
|
|
|
|
PROC_LOCK(curproc);
|
|
|
|
UIDINFO_VMSIZE_LOCK(uip);
|
|
|
|
uip->ui_vmsize += incr;
|
|
|
|
UIDINFO_VMSIZE_UNLOCK(uip);
|
|
|
|
PROC_UNLOCK(curproc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
swap_release(vm_ooffset_t decr)
|
|
|
|
{
|
2010-12-02 17:37:16 +00:00
|
|
|
struct ucred *cred;
|
Implement global and per-uid accounting of the anonymous memory. Add
rlimit RLIMIT_SWAP that limits the amount of swap that may be reserved
for the uid.
The accounting information (charge) is associated with either map entry,
or vm object backing the entry, assuming the object is the first one
in the shadow chain and entry does not require COW. Charge is moved
from entry to object on allocation of the object, e.g. during the mmap,
assuming the object is allocated, or on the first page fault on the
entry. It moves back to the entry on forks due to COW setup.
The per-entry granularity of accounting makes the charge process fair
for processes that change uid during lifetime, and decrements charge
for proper uid when region is unmapped.
The interface of vm_pager_allocate(9) is extended by adding struct ucred *,
that is used to charge appropriate uid when allocation if performed by
kernel, e.g. md(4).
Several syscalls, among them is fork(2), may now return ENOMEM when
global or per-uid limits are enforced.
In collaboration with: pho
Reviewed by: alc
Approved by: re (kensmith)
2009-06-23 20:45:22 +00:00
|
|
|
|
|
|
|
PROC_LOCK(curproc);
|
2010-12-02 17:37:16 +00:00
|
|
|
cred = curthread->td_ucred;
|
|
|
|
swap_release_by_cred(decr, cred);
|
Implement global and per-uid accounting of the anonymous memory. Add
rlimit RLIMIT_SWAP that limits the amount of swap that may be reserved
for the uid.
The accounting information (charge) is associated with either map entry,
or vm object backing the entry, assuming the object is the first one
in the shadow chain and entry does not require COW. Charge is moved
from entry to object on allocation of the object, e.g. during the mmap,
assuming the object is allocated, or on the first page fault on the
entry. It moves back to the entry on forks due to COW setup.
The per-entry granularity of accounting makes the charge process fair
for processes that change uid during lifetime, and decrements charge
for proper uid when region is unmapped.
The interface of vm_pager_allocate(9) is extended by adding struct ucred *,
that is used to charge appropriate uid when allocation if performed by
kernel, e.g. md(4).
Several syscalls, among them is fork(2), may now return ENOMEM when
global or per-uid limits are enforced.
In collaboration with: pho
Reviewed by: alc
Approved by: re (kensmith)
2009-06-23 20:45:22 +00:00
|
|
|
PROC_UNLOCK(curproc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-12-02 17:37:16 +00:00
|
|
|
swap_release_by_cred(vm_ooffset_t decr, struct ucred *cred)
|
Implement global and per-uid accounting of the anonymous memory. Add
rlimit RLIMIT_SWAP that limits the amount of swap that may be reserved
for the uid.
The accounting information (charge) is associated with either map entry,
or vm object backing the entry, assuming the object is the first one
in the shadow chain and entry does not require COW. Charge is moved
from entry to object on allocation of the object, e.g. during the mmap,
assuming the object is allocated, or on the first page fault on the
entry. It moves back to the entry on forks due to COW setup.
The per-entry granularity of accounting makes the charge process fair
for processes that change uid during lifetime, and decrements charge
for proper uid when region is unmapped.
The interface of vm_pager_allocate(9) is extended by adding struct ucred *,
that is used to charge appropriate uid when allocation if performed by
kernel, e.g. md(4).
Several syscalls, among them is fork(2), may now return ENOMEM when
global or per-uid limits are enforced.
In collaboration with: pho
Reviewed by: alc
Approved by: re (kensmith)
2009-06-23 20:45:22 +00:00
|
|
|
{
|
2010-12-02 17:37:16 +00:00
|
|
|
struct uidinfo *uip;
|
2012-09-05 12:24:50 +00:00
|
|
|
|
2010-12-02 17:37:16 +00:00
|
|
|
uip = cred->cr_ruidinfo;
|
Implement global and per-uid accounting of the anonymous memory. Add
rlimit RLIMIT_SWAP that limits the amount of swap that may be reserved
for the uid.
The accounting information (charge) is associated with either map entry,
or vm object backing the entry, assuming the object is the first one
in the shadow chain and entry does not require COW. Charge is moved
from entry to object on allocation of the object, e.g. during the mmap,
assuming the object is allocated, or on the first page fault on the
entry. It moves back to the entry on forks due to COW setup.
The per-entry granularity of accounting makes the charge process fair
for processes that change uid during lifetime, and decrements charge
for proper uid when region is unmapped.
The interface of vm_pager_allocate(9) is extended by adding struct ucred *,
that is used to charge appropriate uid when allocation if performed by
kernel, e.g. md(4).
Several syscalls, among them is fork(2), may now return ENOMEM when
global or per-uid limits are enforced.
In collaboration with: pho
Reviewed by: alc
Approved by: re (kensmith)
2009-06-23 20:45:22 +00:00
|
|
|
|
|
|
|
if (decr & PAGE_MASK)
|
|
|
|
panic("swap_release: & PAGE_MASK");
|
|
|
|
|
|
|
|
mtx_lock(&sw_dev_mtx);
|
|
|
|
if (swap_reserved < decr)
|
|
|
|
panic("swap_reserved < decr");
|
|
|
|
swap_reserved -= decr;
|
|
|
|
mtx_unlock(&sw_dev_mtx);
|
|
|
|
|
|
|
|
UIDINFO_VMSIZE_LOCK(uip);
|
|
|
|
if (uip->ui_vmsize < decr)
|
|
|
|
printf("negative vmsize for uid = %d\n", uip->ui_uid);
|
|
|
|
uip->ui_vmsize -= decr;
|
|
|
|
UIDINFO_VMSIZE_UNLOCK(uip);
|
2011-04-05 20:23:59 +00:00
|
|
|
|
|
|
|
racct_sub_cred(cred, RACCT_SWAP, decr);
|
Implement global and per-uid accounting of the anonymous memory. Add
rlimit RLIMIT_SWAP that limits the amount of swap that may be reserved
for the uid.
The accounting information (charge) is associated with either map entry,
or vm object backing the entry, assuming the object is the first one
in the shadow chain and entry does not require COW. Charge is moved
from entry to object on allocation of the object, e.g. during the mmap,
assuming the object is allocated, or on the first page fault on the
entry. It moves back to the entry on forks due to COW setup.
The per-entry granularity of accounting makes the charge process fair
for processes that change uid during lifetime, and decrements charge
for proper uid when region is unmapped.
The interface of vm_pager_allocate(9) is extended by adding struct ucred *,
that is used to charge appropriate uid when allocation if performed by
kernel, e.g. md(4).
Several syscalls, among them is fork(2), may now return ENOMEM when
global or per-uid limits are enforced.
In collaboration with: pho
Reviewed by: alc
Approved by: re (kensmith)
2009-06-23 20:45:22 +00:00
|
|
|
}
|
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
#define SWM_FREE 0x02 /* free, period */
|
|
|
|
#define SWM_POP 0x04 /* pop out */
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2004-01-24 21:31:06 +00:00
|
|
|
int swap_pager_full = 2; /* swap space exhaustion (task killing) */
|
|
|
|
static int swap_pager_almost_full = 1; /* swap space exhaustion (w/hysteresis)*/
|
1999-01-21 08:29:12 +00:00
|
|
|
static int nsw_rcount; /* free read buffers */
|
1999-02-18 19:57:33 +00:00
|
|
|
static int nsw_wcount_sync; /* limit write buffers / synchronous */
|
|
|
|
static int nsw_wcount_async; /* limit write buffers / asynchronous */
|
|
|
|
static int nsw_wcount_async_max;/* assigned maximum */
|
|
|
|
static int nsw_cluster_max; /* maximum VOP I/O allowed */
|
1995-12-14 09:55:16 +00:00
|
|
|
|
2015-05-02 20:27:37 +00:00
|
|
|
static int sysctl_swap_async_max(SYSCTL_HANDLER_ARGS);
|
2016-05-22 23:28:23 +00:00
|
|
|
SYSCTL_PROC(_vm, OID_AUTO, swap_async_max, CTLTYPE_INT | CTLFLAG_RW |
|
|
|
|
CTLFLAG_MPSAFE, NULL, 0, sysctl_swap_async_max, "I",
|
|
|
|
"Maximum running async swap ops");
|
2015-05-02 20:27:37 +00:00
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
static struct swblock **swhash;
|
|
|
|
static int swhash_mask;
|
2003-10-26 19:55:35 +00:00
|
|
|
static struct mtx swhash_mtx;
|
|
|
|
|
2001-07-04 16:20:28 +00:00
|
|
|
static struct sx sw_alloc_sx;
|
1999-02-18 19:57:33 +00:00
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
|
|
|
* "named" and "unnamed" anon region objects. Try to reduce the overhead
|
|
|
|
* of searching a named list by hashing it just a little.
|
|
|
|
*/
|
1995-12-14 09:55:16 +00:00
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
#define NOBJLISTS 8
|
1994-05-25 09:21:21 +00:00
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
#define NOBJLIST(handle) \
|
1999-08-23 23:55:03 +00:00
|
|
|
(&swap_pager_object_list[((int)(intptr_t)handle >> 4) & (NOBJLISTS-1)])
|
1994-05-25 09:21:21 +00:00
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
static struct pagerlst swap_pager_object_list[NOBJLISTS];
|
2003-07-18 10:02:44 +00:00
|
|
|
static uma_zone_t swap_zone;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
NOTE: libkvm, w, ps, 'top', and any other utility which depends on struct
proc or any VM system structure will have to be rebuilt!!!
Much needed overhaul of the VM system. Included in this first round of
changes:
1) Improved pager interfaces: init, alloc, dealloc, getpages, putpages,
haspage, and sync operations are supported. The haspage interface now
provides information about clusterability. All pager routines now take
struct vm_object's instead of "pagers".
2) Improved data structures. In the previous paradigm, there is constant
confusion caused by pagers being both a data structure ("allocate a
pager") and a collection of routines. The idea of a pager structure has
escentially been eliminated. Objects now have types, and this type is
used to index the appropriate pager. In most cases, items in the pager
structure were duplicated in the object data structure and thus were
unnecessary. In the few cases that remained, a un_pager structure union
was created in the object to contain these items.
3) Because of the cleanup of #1 & #2, a lot of unnecessary layering can now
be removed. For instance, vm_object_enter(), vm_object_lookup(),
vm_object_remove(), and the associated object hash list were some of the
things that were removed.
4) simple_lock's removed. Discussion with several people reveals that the
SMP locking primitives used in the VM system aren't likely the mechanism
that we'll be adopting. Even if it were, the locking that was in the code
was very inadequate and would have to be mostly re-done anyway. The
locking in a uni-processor kernel was a no-op but went a long way toward
making the code difficult to read and debug.
5) Places that attempted to kludge-up the fact that we don't have kernel
thread support have been fixed to reflect the reality that we are really
dealing with processes, not threads. The VM system didn't have complete
thread support, so the comments and mis-named routines were just wrong.
We now use tsleep and wakeup directly in the lock routines, for instance.
6) Where appropriate, the pagers have been improved, especially in the
pager_alloc routines. Most of the pager_allocs have been rewritten and
are now faster and easier to maintain.
7) The pagedaemon pageout clustering algorithm has been rewritten and
now tries harder to output an even number of pages before and after
the requested page. This is sort of the reverse of the ideal pagein
algorithm and should provide better overall performance.
8) Unnecessary (incorrect) casts to caddr_t in calls to tsleep & wakeup
have been removed. Some other unnecessary casts have also been removed.
9) Some almost useless debugging code removed.
10) Terminology of shadow objects vs. backing objects straightened out.
The fact that the vm_object data structure escentially had this
backwards really confused things. The use of "shadow" and "backing
object" throughout the code is now internally consistent and correct
in the Mach terminology.
11) Several minor bug fixes, including one in the vm daemon that caused
0 RSS objects to not get purged as intended.
12) A "default pager" has now been created which cleans up the transition
of objects to the "swap" type. The previous checks throughout the code
for swp->pg_data != NULL were really ugly. This change also provides
the rudiments for future backing of "anonymous" memory by something
other than the swap pager (via the vnode pager, for example), and it
allows the decision about which of these pagers to use to be made
dynamically (although will need some additional decision code to do
this, of course).
13) (dyson) MAP_COPY has been deprecated and the corresponding "copy
object" code has been removed. MAP_COPY was undocumented and non-
standard. It was furthermore broken in several ways which caused its
behavior to degrade to MAP_PRIVATE. Binaries that use MAP_COPY will
continue to work correctly, but via the slightly different semantics
of MAP_PRIVATE.
14) (dyson) Sharing maps have been removed. It's marginal usefulness in a
threads design can be worked around in other ways. Both #12 and #13
were done to simplify the code and improve readability and maintain-
ability. (As were most all of these changes)
TODO:
1) Rewrite most of the vnode pager to use VOP_GETPAGES/PUTPAGES. Doing
this will reduce the vnode pager to a mere fraction of its current size.
2) Rewrite vm_fault and the swap/vnode pagers to use the clustering
information provided by the new haspage pager interface. This will
substantially reduce the overhead by eliminating a large number of
VOP_BMAP() calls. The VOP_BMAP() filesystem interface should be
improved to provide both a "behind" and "ahead" indication of
contiguousness.
3) Implement the extended features of pager_haspage in swap_pager_haspage().
It currently just says 0 pages ahead/behind.
4) Re-implement the swap device (swstrategy) in a more elegant way, perhaps
via a much more general mechanism that could also be used for disk
striping of regular filesystems.
5) Do something to improve the architecture of vm_object_collapse(). The
fact that it makes calls into the swap pager and knows too much about
how the swap pager operates really bothers me. It also doesn't allow
for collapsing of non-swap pager objects ("unnamed" objects backed by
other pagers).
1995-07-13 08:48:48 +00:00
|
|
|
/*
|
1999-01-21 08:29:12 +00:00
|
|
|
* pagerops for OBJT_SWAP - "swap pager". Some ops are also global procedure
|
|
|
|
* calls hooked from other parts of the VM system and do not appear here.
|
|
|
|
* (see vm/swap_pager.h).
|
NOTE: libkvm, w, ps, 'top', and any other utility which depends on struct
proc or any VM system structure will have to be rebuilt!!!
Much needed overhaul of the VM system. Included in this first round of
changes:
1) Improved pager interfaces: init, alloc, dealloc, getpages, putpages,
haspage, and sync operations are supported. The haspage interface now
provides information about clusterability. All pager routines now take
struct vm_object's instead of "pagers".
2) Improved data structures. In the previous paradigm, there is constant
confusion caused by pagers being both a data structure ("allocate a
pager") and a collection of routines. The idea of a pager structure has
escentially been eliminated. Objects now have types, and this type is
used to index the appropriate pager. In most cases, items in the pager
structure were duplicated in the object data structure and thus were
unnecessary. In the few cases that remained, a un_pager structure union
was created in the object to contain these items.
3) Because of the cleanup of #1 & #2, a lot of unnecessary layering can now
be removed. For instance, vm_object_enter(), vm_object_lookup(),
vm_object_remove(), and the associated object hash list were some of the
things that were removed.
4) simple_lock's removed. Discussion with several people reveals that the
SMP locking primitives used in the VM system aren't likely the mechanism
that we'll be adopting. Even if it were, the locking that was in the code
was very inadequate and would have to be mostly re-done anyway. The
locking in a uni-processor kernel was a no-op but went a long way toward
making the code difficult to read and debug.
5) Places that attempted to kludge-up the fact that we don't have kernel
thread support have been fixed to reflect the reality that we are really
dealing with processes, not threads. The VM system didn't have complete
thread support, so the comments and mis-named routines were just wrong.
We now use tsleep and wakeup directly in the lock routines, for instance.
6) Where appropriate, the pagers have been improved, especially in the
pager_alloc routines. Most of the pager_allocs have been rewritten and
are now faster and easier to maintain.
7) The pagedaemon pageout clustering algorithm has been rewritten and
now tries harder to output an even number of pages before and after
the requested page. This is sort of the reverse of the ideal pagein
algorithm and should provide better overall performance.
8) Unnecessary (incorrect) casts to caddr_t in calls to tsleep & wakeup
have been removed. Some other unnecessary casts have also been removed.
9) Some almost useless debugging code removed.
10) Terminology of shadow objects vs. backing objects straightened out.
The fact that the vm_object data structure escentially had this
backwards really confused things. The use of "shadow" and "backing
object" throughout the code is now internally consistent and correct
in the Mach terminology.
11) Several minor bug fixes, including one in the vm daemon that caused
0 RSS objects to not get purged as intended.
12) A "default pager" has now been created which cleans up the transition
of objects to the "swap" type. The previous checks throughout the code
for swp->pg_data != NULL were really ugly. This change also provides
the rudiments for future backing of "anonymous" memory by something
other than the swap pager (via the vnode pager, for example), and it
allows the decision about which of these pagers to use to be made
dynamically (although will need some additional decision code to do
this, of course).
13) (dyson) MAP_COPY has been deprecated and the corresponding "copy
object" code has been removed. MAP_COPY was undocumented and non-
standard. It was furthermore broken in several ways which caused its
behavior to degrade to MAP_PRIVATE. Binaries that use MAP_COPY will
continue to work correctly, but via the slightly different semantics
of MAP_PRIVATE.
14) (dyson) Sharing maps have been removed. It's marginal usefulness in a
threads design can be worked around in other ways. Both #12 and #13
were done to simplify the code and improve readability and maintain-
ability. (As were most all of these changes)
TODO:
1) Rewrite most of the vnode pager to use VOP_GETPAGES/PUTPAGES. Doing
this will reduce the vnode pager to a mere fraction of its current size.
2) Rewrite vm_fault and the swap/vnode pagers to use the clustering
information provided by the new haspage pager interface. This will
substantially reduce the overhead by eliminating a large number of
VOP_BMAP() calls. The VOP_BMAP() filesystem interface should be
improved to provide both a "behind" and "ahead" indication of
contiguousness.
3) Implement the extended features of pager_haspage in swap_pager_haspage().
It currently just says 0 pages ahead/behind.
4) Re-implement the swap device (swstrategy) in a more elegant way, perhaps
via a much more general mechanism that could also be used for disk
striping of regular filesystems.
5) Do something to improve the architecture of vm_object_collapse(). The
fact that it makes calls into the swap pager and knows too much about
how the swap pager operates really bothers me. It also doesn't allow
for collapsing of non-swap pager objects ("unnamed" objects backed by
other pagers).
1995-07-13 08:48:48 +00:00
|
|
|
*/
|
1995-11-16 09:51:22 +00:00
|
|
|
static vm_object_t
|
2002-03-19 22:20:14 +00:00
|
|
|
swap_pager_alloc(void *handle, vm_ooffset_t size,
|
Implement global and per-uid accounting of the anonymous memory. Add
rlimit RLIMIT_SWAP that limits the amount of swap that may be reserved
for the uid.
The accounting information (charge) is associated with either map entry,
or vm object backing the entry, assuming the object is the first one
in the shadow chain and entry does not require COW. Charge is moved
from entry to object on allocation of the object, e.g. during the mmap,
assuming the object is allocated, or on the first page fault on the
entry. It moves back to the entry on forks due to COW setup.
The per-entry granularity of accounting makes the charge process fair
for processes that change uid during lifetime, and decrements charge
for proper uid when region is unmapped.
The interface of vm_pager_allocate(9) is extended by adding struct ucred *,
that is used to charge appropriate uid when allocation if performed by
kernel, e.g. md(4).
Several syscalls, among them is fork(2), may now return ENOMEM when
global or per-uid limits are enforced.
In collaboration with: pho
Reviewed by: alc
Approved by: re (kensmith)
2009-06-23 20:45:22 +00:00
|
|
|
vm_prot_t prot, vm_ooffset_t offset, struct ucred *);
|
2002-03-19 22:20:14 +00:00
|
|
|
static void swap_pager_dealloc(vm_object_t object);
|
A change to KPI of vm_pager_get_pages() and underlying VOP_GETPAGES().
o With new KPI consumers can request contiguous ranges of pages, and
unlike before, all pages will be kept busied on return, like it was
done before with the 'reqpage' only. Now the reqpage goes away. With
new interface it is easier to implement code protected from race
conditions.
Such arrayed requests for now should be preceeded by a call to
vm_pager_haspage() to make sure that request is possible. This
could be improved later, making vm_pager_haspage() obsolete.
Strenghtening the promises on the business of the array of pages
allows us to remove such hacks as swp_pager_free_nrpage() and
vm_pager_free_nonreq().
o New KPI accepts two integer pointers that may optionally point at
values for read ahead and read behind, that a pager may do, if it
can. These pages are completely owned by pager, and not controlled
by the caller.
This shifts the UFS-specific readahead logic from vm_fault.c, which
should be file system agnostic, into vnode_pager.c. It also removes
one VOP_BMAP() request per hard fault.
Discussed with: kib, alc, jeff, scottl
Sponsored by: Nginx, Inc.
Sponsored by: Netflix
2015-12-16 21:30:45 +00:00
|
|
|
static int swap_pager_getpages(vm_object_t, vm_page_t *, int, int *,
|
|
|
|
int *);
|
|
|
|
static int swap_pager_getpages_async(vm_object_t, vm_page_t *, int, int *,
|
|
|
|
int *, pgo_getpages_iodone_t, void *);
|
2003-08-06 12:08:27 +00:00
|
|
|
static void swap_pager_putpages(vm_object_t, vm_page_t *, int, boolean_t, int *);
|
2003-06-20 20:20:06 +00:00
|
|
|
static boolean_t
|
|
|
|
swap_pager_haspage(vm_object_t object, vm_pindex_t pindex, int *before, int *after);
|
2002-03-19 22:20:14 +00:00
|
|
|
static void swap_pager_init(void);
|
|
|
|
static void swap_pager_unswapped(vm_page_t);
|
Close a race in swapoff(). Here are the gory details:
In order to avoid livelock, swapoff() skips over objects with a
nonzero pip count and makes another pass if necessary. Since it is
impossible to know which objects we care about, it would choose an
arbitrary object with a nonzero pip count and wait for it before
making another pass, the theory being that this object would finish
paging about as quickly as the ones we care about. Unfortunately,
we may have slept since we acquired a reference to this object.
Hack around this problem by tsleep()ing on the pointer anyway, but
timeout after a fixed interval. More elegant solutions are possible,
but the ones I considered unnecessarily complicate this rare case.
Also, kill some nits that seem to have crept into the swapoff() code
in the last 75 revisions or so:
- Don't pass both sp and sp->sw_used to swap_pager_swapoff(), since
the latter can be derived from the former.
- Replace swp_pager_find_dev() with something simpler. There's no
need to iterate over the entire list of swap devices just to determine
if a given block is assigned to the one we're interested in.
- Expand the scope of the swhash_mtx in a couple of places so that it
isn't released and reacquired once for every hash bucket.
- Don't drop the swhash_mtx while holding a reference to an object.
We need to lock the object first. Unfortunately, doing so would
violate the established lock order, so use VM_OBJECT_TRYLOCK() and
try again on a subsequent pass if the object is already locked.
- Refactor swp_pager_force_pagein() and swap_pager_swapoff() a bit.
2004-11-05 05:36:56 +00:00
|
|
|
static void swap_pager_swapoff(struct swdevt *sp);
|
1995-12-14 09:55:16 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
struct pagerops swappagerops = {
|
2003-08-05 06:54:56 +00:00
|
|
|
.pgo_init = swap_pager_init, /* early system initialization of pager */
|
|
|
|
.pgo_alloc = swap_pager_alloc, /* allocate an OBJT_SWAP object */
|
|
|
|
.pgo_dealloc = swap_pager_dealloc, /* deallocate an OBJT_SWAP object */
|
|
|
|
.pgo_getpages = swap_pager_getpages, /* pagein */
|
2014-11-23 12:01:52 +00:00
|
|
|
.pgo_getpages_async = swap_pager_getpages_async, /* pagein (async) */
|
2003-08-05 06:54:56 +00:00
|
|
|
.pgo_putpages = swap_pager_putpages, /* pageout */
|
|
|
|
.pgo_haspage = swap_pager_haspage, /* get backing store status for page */
|
|
|
|
.pgo_pageunswapped = swap_pager_unswapped, /* remove swap related to page */
|
1994-05-24 10:09:53 +00:00
|
|
|
};
|
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
|
|
|
* dmmax is in page-sized chunks with the new swap system. It was
|
2000-10-13 16:44:34 +00:00
|
|
|
* dev-bsized chunks in the old. dmmax is always a power of 2.
|
1999-01-21 08:29:12 +00:00
|
|
|
*
|
|
|
|
* swap_*() routines are externally accessible. swp_*() routines are
|
|
|
|
* internal.
|
|
|
|
*/
|
2003-08-06 12:08:27 +00:00
|
|
|
static int dmmax;
|
2003-07-18 10:02:44 +00:00
|
|
|
static int nswap_lowat = 128; /* in pages, swap_pager_almost_full warn */
|
|
|
|
static int nswap_hiwat = 512; /* in pages, swap_pager_almost_full warn */
|
1999-01-21 08:29:12 +00:00
|
|
|
|
2016-07-28 15:49:51 +00:00
|
|
|
SYSCTL_INT(_vm, OID_AUTO, dmmax, CTLFLAG_RD, &dmmax, 0,
|
|
|
|
"Maximum size of a swap block");
|
2000-11-20 00:39:04 +00:00
|
|
|
|
2003-07-22 20:54:26 +00:00
|
|
|
static void swp_sizecheck(void);
|
2002-03-19 22:20:14 +00:00
|
|
|
static void swp_pager_async_iodone(struct buf *bp);
|
2016-07-28 15:57:01 +00:00
|
|
|
static int swapongeom(struct vnode *);
|
2003-08-30 11:33:25 +00:00
|
|
|
static int swaponvp(struct thread *, struct vnode *, u_long);
|
2008-01-08 14:58:41 +00:00
|
|
|
static int swapoff_one(struct swdevt *sp, struct ucred *cred);
|
1999-01-21 08:29:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Swap bitmap functions
|
|
|
|
*/
|
2003-07-22 20:54:26 +00:00
|
|
|
static void swp_pager_freeswapspace(daddr_t blk, int npages);
|
|
|
|
static daddr_t swp_pager_getswapspace(int npages);
|
1994-05-25 09:21:21 +00:00
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
|
|
|
* Metadata functions
|
|
|
|
*/
|
2003-07-22 20:54:26 +00:00
|
|
|
static struct swblock **swp_pager_hash(vm_object_t object, vm_pindex_t index);
|
2002-03-19 22:20:14 +00:00
|
|
|
static void swp_pager_meta_build(vm_object_t, vm_pindex_t, daddr_t);
|
2016-12-24 09:57:31 +00:00
|
|
|
static void swp_pager_meta_free(vm_object_t, vm_pindex_t, vm_pindex_t);
|
2002-03-19 22:20:14 +00:00
|
|
|
static void swp_pager_meta_free_all(vm_object_t);
|
|
|
|
static daddr_t swp_pager_meta_ctl(vm_object_t, vm_pindex_t, int);
|
1999-01-21 08:29:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* SWP_SIZECHECK() - update swap_pager_full indication
|
2012-09-05 12:24:50 +00:00
|
|
|
*
|
1999-02-21 08:30:49 +00:00
|
|
|
* update the swap_pager_almost_full indication and warn when we are
|
|
|
|
* about to run out of swap space, using lowat/hiwat hysteresis.
|
|
|
|
*
|
|
|
|
* Clear swap_pager_full ( task killing ) indication when lowat is met.
|
1999-01-21 08:29:12 +00:00
|
|
|
*
|
|
|
|
* No restrictions on call
|
|
|
|
* This routine may not block.
|
|
|
|
*/
|
2003-07-22 20:54:26 +00:00
|
|
|
static void
|
2003-08-30 08:32:42 +00:00
|
|
|
swp_sizecheck(void)
|
These changes embody the support of the fully coherent merged VM buffer cache,
much higher filesystem I/O performance, and much better paging performance. It
represents the culmination of over 6 months of R&D.
The majority of the merged VM/cache work is by John Dyson.
The following highlights the most significant changes. Additionally, there are
(mostly minor) changes to the various filesystem modules (nfs, msdosfs, etc) to
support the new VM/buffer scheme.
vfs_bio.c:
Significant rewrite of most of vfs_bio to support the merged VM buffer cache
scheme. The scheme is almost fully compatible with the old filesystem
interface. Significant improvement in the number of opportunities for write
clustering.
vfs_cluster.c, vfs_subr.c
Upgrade and performance enhancements in vfs layer code to support merged
VM/buffer cache. Fixup of vfs_cluster to eliminate the bogus pagemove stuff.
vm_object.c:
Yet more improvements in the collapse code. Elimination of some windows that
can cause list corruption.
vm_pageout.c:
Fixed it, it really works better now. Somehow in 2.0, some "enhancements"
broke the code. This code has been reworked from the ground-up.
vm_fault.c, vm_page.c, pmap.c, vm_object.c
Support for small-block filesystems with merged VM/buffer cache scheme.
pmap.c vm_map.c
Dynamic kernel VM size, now we dont have to pre-allocate excessive numbers of
kernel PTs.
vm_glue.c
Much simpler and more effective swapping code. No more gratuitous swapping.
proc.h
Fixed the problem that the p_lock flag was not being cleared on a fork.
swap_pager.c, vnode_pager.c
Removal of old vfs_bio cruft to support the past pseudo-coherency. Now the
code doesn't need it anymore.
machdep.c
Changes to better support the parameter values for the merged VM/buffer cache
scheme.
machdep.c, kern_exec.c, vm_glue.c
Implemented a seperate submap for temporary exec string space and another one
to contain process upages. This eliminates all map fragmentation problems
that previously existed.
ffs_inode.c, ufs_inode.c, ufs_readwrite.c
Changes for merged VM/buffer cache. Add "bypass" support for sneaking in on
busy buffers.
Submitted by: John Dyson and David Greenman
1995-01-09 16:06:02 +00:00
|
|
|
{
|
2001-05-19 01:28:09 +00:00
|
|
|
|
2003-08-03 13:35:31 +00:00
|
|
|
if (swap_pager_avail < nswap_lowat) {
|
1999-02-21 08:30:49 +00:00
|
|
|
if (swap_pager_almost_full == 0) {
|
1996-01-31 13:14:21 +00:00
|
|
|
printf("swap_pager: out of swap space\n");
|
1999-02-21 08:30:49 +00:00
|
|
|
swap_pager_almost_full = 1;
|
1999-02-06 07:22:21 +00:00
|
|
|
}
|
1999-02-21 08:30:49 +00:00
|
|
|
} else {
|
1994-05-25 09:21:21 +00:00
|
|
|
swap_pager_full = 0;
|
2003-08-03 13:35:31 +00:00
|
|
|
if (swap_pager_avail > nswap_hiwat)
|
1999-02-21 08:30:49 +00:00
|
|
|
swap_pager_almost_full = 0;
|
1999-01-21 08:29:12 +00:00
|
|
|
}
|
1994-05-25 09:21:21 +00:00
|
|
|
}
|
|
|
|
|
2003-07-22 06:55:48 +00:00
|
|
|
/*
|
|
|
|
* SWP_PAGER_HASH() - hash swap meta data
|
|
|
|
*
|
2003-07-22 20:54:26 +00:00
|
|
|
* This is an helper function which hashes the swapblk given
|
2003-07-22 06:55:48 +00:00
|
|
|
* the object and page index. It returns a pointer to a pointer
|
|
|
|
* to the object, or a pointer to a NULL pointer if it could not
|
|
|
|
* find a swapblk.
|
|
|
|
*/
|
2003-07-22 20:54:26 +00:00
|
|
|
static struct swblock **
|
2003-07-22 06:55:48 +00:00
|
|
|
swp_pager_hash(vm_object_t object, vm_pindex_t index)
|
|
|
|
{
|
|
|
|
struct swblock **pswap;
|
|
|
|
struct swblock *swap;
|
|
|
|
|
|
|
|
index &= ~(vm_pindex_t)SWAP_META_MASK;
|
|
|
|
pswap = &swhash[(index ^ (int)(intptr_t)object) & swhash_mask];
|
|
|
|
while ((swap = *pswap) != NULL) {
|
|
|
|
if (swap->swb_object == object &&
|
|
|
|
swap->swb_index == index
|
|
|
|
) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pswap = &swap->swb_hnext;
|
|
|
|
}
|
|
|
|
return (pswap);
|
|
|
|
}
|
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
|
|
|
* SWAP_PAGER_INIT() - initialize the swap pager!
|
|
|
|
*
|
2012-09-05 12:24:50 +00:00
|
|
|
* Expected to be started from system init. NOTE: This code is run
|
1999-01-21 08:29:12 +00:00
|
|
|
* before much else so be careful what you depend on. Most of the VM
|
|
|
|
* system has yet to be initialized at this point.
|
|
|
|
*/
|
1995-11-14 20:53:20 +00:00
|
|
|
static void
|
2003-08-30 08:32:42 +00:00
|
|
|
swap_pager_init(void)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
|
|
|
/*
|
1999-01-21 08:29:12 +00:00
|
|
|
* Initialize object lists
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
1999-01-21 08:29:12 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < NOBJLISTS; ++i)
|
|
|
|
TAILQ_INIT(&swap_pager_object_list[i]);
|
2003-08-30 16:10:28 +00:00
|
|
|
mtx_init(&sw_dev_mtx, "swapdev", NULL, MTX_DEF);
|
2016-06-13 03:39:16 +00:00
|
|
|
sx_init(&sw_alloc_sx, "swspsx");
|
2016-05-22 23:25:01 +00:00
|
|
|
sx_init(&swdev_syscall_lock, "swsysc");
|
1994-05-25 09:21:21 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
1999-01-21 08:29:12 +00:00
|
|
|
* Device Stripe, in PAGE_SIZE'd blocks
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
1999-01-21 08:29:12 +00:00
|
|
|
dmmax = SWB_NPAGES * 2;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
|
|
|
* SWAP_PAGER_SWAP_INIT() - swap pager initialization from pageout process
|
|
|
|
*
|
|
|
|
* Expected to be started from pageout process once, prior to entering
|
|
|
|
* its main loop.
|
|
|
|
*/
|
NOTE: libkvm, w, ps, 'top', and any other utility which depends on struct
proc or any VM system structure will have to be rebuilt!!!
Much needed overhaul of the VM system. Included in this first round of
changes:
1) Improved pager interfaces: init, alloc, dealloc, getpages, putpages,
haspage, and sync operations are supported. The haspage interface now
provides information about clusterability. All pager routines now take
struct vm_object's instead of "pagers".
2) Improved data structures. In the previous paradigm, there is constant
confusion caused by pagers being both a data structure ("allocate a
pager") and a collection of routines. The idea of a pager structure has
escentially been eliminated. Objects now have types, and this type is
used to index the appropriate pager. In most cases, items in the pager
structure were duplicated in the object data structure and thus were
unnecessary. In the few cases that remained, a un_pager structure union
was created in the object to contain these items.
3) Because of the cleanup of #1 & #2, a lot of unnecessary layering can now
be removed. For instance, vm_object_enter(), vm_object_lookup(),
vm_object_remove(), and the associated object hash list were some of the
things that were removed.
4) simple_lock's removed. Discussion with several people reveals that the
SMP locking primitives used in the VM system aren't likely the mechanism
that we'll be adopting. Even if it were, the locking that was in the code
was very inadequate and would have to be mostly re-done anyway. The
locking in a uni-processor kernel was a no-op but went a long way toward
making the code difficult to read and debug.
5) Places that attempted to kludge-up the fact that we don't have kernel
thread support have been fixed to reflect the reality that we are really
dealing with processes, not threads. The VM system didn't have complete
thread support, so the comments and mis-named routines were just wrong.
We now use tsleep and wakeup directly in the lock routines, for instance.
6) Where appropriate, the pagers have been improved, especially in the
pager_alloc routines. Most of the pager_allocs have been rewritten and
are now faster and easier to maintain.
7) The pagedaemon pageout clustering algorithm has been rewritten and
now tries harder to output an even number of pages before and after
the requested page. This is sort of the reverse of the ideal pagein
algorithm and should provide better overall performance.
8) Unnecessary (incorrect) casts to caddr_t in calls to tsleep & wakeup
have been removed. Some other unnecessary casts have also been removed.
9) Some almost useless debugging code removed.
10) Terminology of shadow objects vs. backing objects straightened out.
The fact that the vm_object data structure escentially had this
backwards really confused things. The use of "shadow" and "backing
object" throughout the code is now internally consistent and correct
in the Mach terminology.
11) Several minor bug fixes, including one in the vm daemon that caused
0 RSS objects to not get purged as intended.
12) A "default pager" has now been created which cleans up the transition
of objects to the "swap" type. The previous checks throughout the code
for swp->pg_data != NULL were really ugly. This change also provides
the rudiments for future backing of "anonymous" memory by something
other than the swap pager (via the vnode pager, for example), and it
allows the decision about which of these pagers to use to be made
dynamically (although will need some additional decision code to do
this, of course).
13) (dyson) MAP_COPY has been deprecated and the corresponding "copy
object" code has been removed. MAP_COPY was undocumented and non-
standard. It was furthermore broken in several ways which caused its
behavior to degrade to MAP_PRIVATE. Binaries that use MAP_COPY will
continue to work correctly, but via the slightly different semantics
of MAP_PRIVATE.
14) (dyson) Sharing maps have been removed. It's marginal usefulness in a
threads design can be worked around in other ways. Both #12 and #13
were done to simplify the code and improve readability and maintain-
ability. (As were most all of these changes)
TODO:
1) Rewrite most of the vnode pager to use VOP_GETPAGES/PUTPAGES. Doing
this will reduce the vnode pager to a mere fraction of its current size.
2) Rewrite vm_fault and the swap/vnode pagers to use the clustering
information provided by the new haspage pager interface. This will
substantially reduce the overhead by eliminating a large number of
VOP_BMAP() calls. The VOP_BMAP() filesystem interface should be
improved to provide both a "behind" and "ahead" indication of
contiguousness.
3) Implement the extended features of pager_haspage in swap_pager_haspage().
It currently just says 0 pages ahead/behind.
4) Re-implement the swap device (swstrategy) in a more elegant way, perhaps
via a much more general mechanism that could also be used for disk
striping of regular filesystems.
5) Do something to improve the architecture of vm_object_collapse(). The
fact that it makes calls into the swap pager and knows too much about
how the swap pager operates really bothers me. It also doesn't allow
for collapsing of non-swap pager objects ("unnamed" objects backed by
other pagers).
1995-07-13 08:48:48 +00:00
|
|
|
void
|
2003-08-30 08:32:42 +00:00
|
|
|
swap_pager_swap_init(void)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2014-04-26 12:18:17 +00:00
|
|
|
unsigned long n, n2;
|
These changes embody the support of the fully coherent merged VM buffer cache,
much higher filesystem I/O performance, and much better paging performance. It
represents the culmination of over 6 months of R&D.
The majority of the merged VM/cache work is by John Dyson.
The following highlights the most significant changes. Additionally, there are
(mostly minor) changes to the various filesystem modules (nfs, msdosfs, etc) to
support the new VM/buffer scheme.
vfs_bio.c:
Significant rewrite of most of vfs_bio to support the merged VM buffer cache
scheme. The scheme is almost fully compatible with the old filesystem
interface. Significant improvement in the number of opportunities for write
clustering.
vfs_cluster.c, vfs_subr.c
Upgrade and performance enhancements in vfs layer code to support merged
VM/buffer cache. Fixup of vfs_cluster to eliminate the bogus pagemove stuff.
vm_object.c:
Yet more improvements in the collapse code. Elimination of some windows that
can cause list corruption.
vm_pageout.c:
Fixed it, it really works better now. Somehow in 2.0, some "enhancements"
broke the code. This code has been reworked from the ground-up.
vm_fault.c, vm_page.c, pmap.c, vm_object.c
Support for small-block filesystems with merged VM/buffer cache scheme.
pmap.c vm_map.c
Dynamic kernel VM size, now we dont have to pre-allocate excessive numbers of
kernel PTs.
vm_glue.c
Much simpler and more effective swapping code. No more gratuitous swapping.
proc.h
Fixed the problem that the p_lock flag was not being cleared on a fork.
swap_pager.c, vnode_pager.c
Removal of old vfs_bio cruft to support the past pseudo-coherency. Now the
code doesn't need it anymore.
machdep.c
Changes to better support the parameter values for the merged VM/buffer cache
scheme.
machdep.c, kern_exec.c, vm_glue.c
Implemented a seperate submap for temporary exec string space and another one
to contain process upages. This eliminates all map fragmentation problems
that previously existed.
ffs_inode.c, ufs_inode.c, ufs_readwrite.c
Changes for merged VM/buffer cache. Add "bypass" support for sneaking in on
busy buffers.
Submitted by: John Dyson and David Greenman
1995-01-09 16:06:02 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
1999-01-21 08:29:12 +00:00
|
|
|
* Number of in-transit swap bp operations. Don't
|
|
|
|
* exhaust the pbufs completely. Make sure we
|
|
|
|
* initialize workable values (0 will work for hysteresis
|
|
|
|
* but it isn't very efficient).
|
|
|
|
*
|
1999-02-18 19:57:33 +00:00
|
|
|
* The nsw_cluster_max is constrained by the bp->b_pages[]
|
1999-01-21 08:29:12 +00:00
|
|
|
* array (MAXPHYS/PAGE_SIZE) and our locally defined
|
|
|
|
* MAX_PAGEOUT_CLUSTER. Also be aware that swap ops are
|
|
|
|
* constrained by the swap device interleave stripe size.
|
1999-02-18 19:57:33 +00:00
|
|
|
*
|
2012-09-05 12:24:50 +00:00
|
|
|
* Currently we hardwire nsw_wcount_async to 4. This limit is
|
1999-02-18 19:57:33 +00:00
|
|
|
* designed to prevent other I/O from having high latencies due to
|
|
|
|
* our pageout I/O. The value 4 works well for one or two active swap
|
|
|
|
* devices but is probably a little low if you have more. Even so,
|
|
|
|
* a higher value would probably generate only a limited improvement
|
|
|
|
* with three or four active swap devices since the system does not
|
|
|
|
* typically have to pageout at extreme bandwidths. We will want
|
|
|
|
* at least 2 per swap devices, and 4 is a pretty good value if you
|
|
|
|
* have one NFS swap device due to the command/ack latency over NFS.
|
|
|
|
* So it all works out pretty well.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
1999-02-21 08:34:15 +00:00
|
|
|
nsw_cluster_max = min((MAXPHYS/PAGE_SIZE), MAX_PAGEOUT_CLUSTER);
|
1999-02-18 19:57:33 +00:00
|
|
|
|
2001-06-22 21:12:19 +00:00
|
|
|
mtx_lock(&pbuf_mtx);
|
1999-01-21 08:29:12 +00:00
|
|
|
nsw_rcount = (nswbuf + 1) / 2;
|
1999-02-18 19:57:33 +00:00
|
|
|
nsw_wcount_sync = (nswbuf + 3) / 4;
|
|
|
|
nsw_wcount_async = 4;
|
|
|
|
nsw_wcount_async_max = nsw_wcount_async;
|
2001-06-22 21:12:19 +00:00
|
|
|
mtx_unlock(&pbuf_mtx);
|
1999-01-21 08:29:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize our zone. Right now I'm just guessing on the number
|
|
|
|
* we need based on the number of pages in the system. Each swblock
|
2014-04-26 12:18:17 +00:00
|
|
|
* can hold 32 pages, so this is probably overkill. This reservation
|
2002-08-31 21:15:29 +00:00
|
|
|
* is typically limited to around 32MB by default.
|
1999-01-21 08:29:12 +00:00
|
|
|
*/
|
2014-03-22 10:26:09 +00:00
|
|
|
n = vm_cnt.v_page_count / 2;
|
2001-08-20 00:41:12 +00:00
|
|
|
if (maxswzone && n > maxswzone / sizeof(struct swblock))
|
|
|
|
n = maxswzone / sizeof(struct swblock);
|
2012-09-04 21:06:53 +00:00
|
|
|
n2 = n;
|
2002-03-20 04:02:59 +00:00
|
|
|
swap_zone = uma_zcreate("SWAPMETA", sizeof(struct swblock), NULL, NULL,
|
2003-10-26 19:55:35 +00:00
|
|
|
NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE | UMA_ZONE_VM);
|
2005-03-18 21:22:48 +00:00
|
|
|
if (swap_zone == NULL)
|
|
|
|
panic("failed to create swap_zone.");
|
2001-08-02 07:54:58 +00:00
|
|
|
do {
|
2013-02-26 23:35:27 +00:00
|
|
|
if (uma_zone_reserve_kva(swap_zone, n))
|
2001-08-02 07:54:58 +00:00
|
|
|
break;
|
|
|
|
/*
|
|
|
|
* if the allocation failed, try a zone two thirds the
|
|
|
|
* size of the previous attempt.
|
|
|
|
*/
|
|
|
|
n -= ((n + 2) / 3);
|
|
|
|
} while (n > 0);
|
2000-12-13 10:01:00 +00:00
|
|
|
if (n2 != n)
|
2014-04-26 12:18:17 +00:00
|
|
|
printf("Swap zone entries reduced from %lu to %lu.\n", n2, n);
|
|
|
|
swap_maxpages = n * SWAP_META_PAGES;
|
|
|
|
swzone = n * sizeof(struct swblock);
|
2012-09-04 21:06:53 +00:00
|
|
|
n2 = n;
|
NOTE: libkvm, w, ps, 'top', and any other utility which depends on struct
proc or any VM system structure will have to be rebuilt!!!
Much needed overhaul of the VM system. Included in this first round of
changes:
1) Improved pager interfaces: init, alloc, dealloc, getpages, putpages,
haspage, and sync operations are supported. The haspage interface now
provides information about clusterability. All pager routines now take
struct vm_object's instead of "pagers".
2) Improved data structures. In the previous paradigm, there is constant
confusion caused by pagers being both a data structure ("allocate a
pager") and a collection of routines. The idea of a pager structure has
escentially been eliminated. Objects now have types, and this type is
used to index the appropriate pager. In most cases, items in the pager
structure were duplicated in the object data structure and thus were
unnecessary. In the few cases that remained, a un_pager structure union
was created in the object to contain these items.
3) Because of the cleanup of #1 & #2, a lot of unnecessary layering can now
be removed. For instance, vm_object_enter(), vm_object_lookup(),
vm_object_remove(), and the associated object hash list were some of the
things that were removed.
4) simple_lock's removed. Discussion with several people reveals that the
SMP locking primitives used in the VM system aren't likely the mechanism
that we'll be adopting. Even if it were, the locking that was in the code
was very inadequate and would have to be mostly re-done anyway. The
locking in a uni-processor kernel was a no-op but went a long way toward
making the code difficult to read and debug.
5) Places that attempted to kludge-up the fact that we don't have kernel
thread support have been fixed to reflect the reality that we are really
dealing with processes, not threads. The VM system didn't have complete
thread support, so the comments and mis-named routines were just wrong.
We now use tsleep and wakeup directly in the lock routines, for instance.
6) Where appropriate, the pagers have been improved, especially in the
pager_alloc routines. Most of the pager_allocs have been rewritten and
are now faster and easier to maintain.
7) The pagedaemon pageout clustering algorithm has been rewritten and
now tries harder to output an even number of pages before and after
the requested page. This is sort of the reverse of the ideal pagein
algorithm and should provide better overall performance.
8) Unnecessary (incorrect) casts to caddr_t in calls to tsleep & wakeup
have been removed. Some other unnecessary casts have also been removed.
9) Some almost useless debugging code removed.
10) Terminology of shadow objects vs. backing objects straightened out.
The fact that the vm_object data structure escentially had this
backwards really confused things. The use of "shadow" and "backing
object" throughout the code is now internally consistent and correct
in the Mach terminology.
11) Several minor bug fixes, including one in the vm daemon that caused
0 RSS objects to not get purged as intended.
12) A "default pager" has now been created which cleans up the transition
of objects to the "swap" type. The previous checks throughout the code
for swp->pg_data != NULL were really ugly. This change also provides
the rudiments for future backing of "anonymous" memory by something
other than the swap pager (via the vnode pager, for example), and it
allows the decision about which of these pagers to use to be made
dynamically (although will need some additional decision code to do
this, of course).
13) (dyson) MAP_COPY has been deprecated and the corresponding "copy
object" code has been removed. MAP_COPY was undocumented and non-
standard. It was furthermore broken in several ways which caused its
behavior to degrade to MAP_PRIVATE. Binaries that use MAP_COPY will
continue to work correctly, but via the slightly different semantics
of MAP_PRIVATE.
14) (dyson) Sharing maps have been removed. It's marginal usefulness in a
threads design can be worked around in other ways. Both #12 and #13
were done to simplify the code and improve readability and maintain-
ability. (As were most all of these changes)
TODO:
1) Rewrite most of the vnode pager to use VOP_GETPAGES/PUTPAGES. Doing
this will reduce the vnode pager to a mere fraction of its current size.
2) Rewrite vm_fault and the swap/vnode pagers to use the clustering
information provided by the new haspage pager interface. This will
substantially reduce the overhead by eliminating a large number of
VOP_BMAP() calls. The VOP_BMAP() filesystem interface should be
improved to provide both a "behind" and "ahead" indication of
contiguousness.
3) Implement the extended features of pager_haspage in swap_pager_haspage().
It currently just says 0 pages ahead/behind.
4) Re-implement the swap device (swstrategy) in a more elegant way, perhaps
via a much more general mechanism that could also be used for disk
striping of regular filesystems.
5) Do something to improve the architecture of vm_object_collapse(). The
fact that it makes calls into the swap pager and knows too much about
how the swap pager operates really bothers me. It also doesn't allow
for collapsing of non-swap pager objects ("unnamed" objects backed by
other pagers).
1995-07-13 08:48:48 +00:00
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
|
|
|
* Initialize our meta-data hash table. The swapper does not need to
|
2012-09-05 12:24:50 +00:00
|
|
|
* be quite as efficient as the VM system, so we do not use an
|
1999-01-21 08:29:12 +00:00
|
|
|
* oversized hash table.
|
|
|
|
*
|
|
|
|
* n: size of hash table, must be power of 2
|
|
|
|
* swhash_mask: hash table index mask
|
|
|
|
*/
|
2001-08-02 07:54:58 +00:00
|
|
|
for (n = 1; n < n2 / 8; n *= 2)
|
1999-01-21 08:29:12 +00:00
|
|
|
;
|
2003-02-19 05:47:46 +00:00
|
|
|
swhash = malloc(sizeof(struct swblock *) * n, M_VMPGDATA, M_WAITOK | M_ZERO);
|
1999-01-21 08:29:12 +00:00
|
|
|
swhash_mask = n - 1;
|
2003-10-26 19:55:35 +00:00
|
|
|
mtx_init(&swhash_mtx, "swap_pager swhash", NULL, MTX_DEF);
|
NOTE: libkvm, w, ps, 'top', and any other utility which depends on struct
proc or any VM system structure will have to be rebuilt!!!
Much needed overhaul of the VM system. Included in this first round of
changes:
1) Improved pager interfaces: init, alloc, dealloc, getpages, putpages,
haspage, and sync operations are supported. The haspage interface now
provides information about clusterability. All pager routines now take
struct vm_object's instead of "pagers".
2) Improved data structures. In the previous paradigm, there is constant
confusion caused by pagers being both a data structure ("allocate a
pager") and a collection of routines. The idea of a pager structure has
escentially been eliminated. Objects now have types, and this type is
used to index the appropriate pager. In most cases, items in the pager
structure were duplicated in the object data structure and thus were
unnecessary. In the few cases that remained, a un_pager structure union
was created in the object to contain these items.
3) Because of the cleanup of #1 & #2, a lot of unnecessary layering can now
be removed. For instance, vm_object_enter(), vm_object_lookup(),
vm_object_remove(), and the associated object hash list were some of the
things that were removed.
4) simple_lock's removed. Discussion with several people reveals that the
SMP locking primitives used in the VM system aren't likely the mechanism
that we'll be adopting. Even if it were, the locking that was in the code
was very inadequate and would have to be mostly re-done anyway. The
locking in a uni-processor kernel was a no-op but went a long way toward
making the code difficult to read and debug.
5) Places that attempted to kludge-up the fact that we don't have kernel
thread support have been fixed to reflect the reality that we are really
dealing with processes, not threads. The VM system didn't have complete
thread support, so the comments and mis-named routines were just wrong.
We now use tsleep and wakeup directly in the lock routines, for instance.
6) Where appropriate, the pagers have been improved, especially in the
pager_alloc routines. Most of the pager_allocs have been rewritten and
are now faster and easier to maintain.
7) The pagedaemon pageout clustering algorithm has been rewritten and
now tries harder to output an even number of pages before and after
the requested page. This is sort of the reverse of the ideal pagein
algorithm and should provide better overall performance.
8) Unnecessary (incorrect) casts to caddr_t in calls to tsleep & wakeup
have been removed. Some other unnecessary casts have also been removed.
9) Some almost useless debugging code removed.
10) Terminology of shadow objects vs. backing objects straightened out.
The fact that the vm_object data structure escentially had this
backwards really confused things. The use of "shadow" and "backing
object" throughout the code is now internally consistent and correct
in the Mach terminology.
11) Several minor bug fixes, including one in the vm daemon that caused
0 RSS objects to not get purged as intended.
12) A "default pager" has now been created which cleans up the transition
of objects to the "swap" type. The previous checks throughout the code
for swp->pg_data != NULL were really ugly. This change also provides
the rudiments for future backing of "anonymous" memory by something
other than the swap pager (via the vnode pager, for example), and it
allows the decision about which of these pagers to use to be made
dynamically (although will need some additional decision code to do
this, of course).
13) (dyson) MAP_COPY has been deprecated and the corresponding "copy
object" code has been removed. MAP_COPY was undocumented and non-
standard. It was furthermore broken in several ways which caused its
behavior to degrade to MAP_PRIVATE. Binaries that use MAP_COPY will
continue to work correctly, but via the slightly different semantics
of MAP_PRIVATE.
14) (dyson) Sharing maps have been removed. It's marginal usefulness in a
threads design can be worked around in other ways. Both #12 and #13
were done to simplify the code and improve readability and maintain-
ability. (As were most all of these changes)
TODO:
1) Rewrite most of the vnode pager to use VOP_GETPAGES/PUTPAGES. Doing
this will reduce the vnode pager to a mere fraction of its current size.
2) Rewrite vm_fault and the swap/vnode pagers to use the clustering
information provided by the new haspage pager interface. This will
substantially reduce the overhead by eliminating a large number of
VOP_BMAP() calls. The VOP_BMAP() filesystem interface should be
improved to provide both a "behind" and "ahead" indication of
contiguousness.
3) Implement the extended features of pager_haspage in swap_pager_haspage().
It currently just says 0 pages ahead/behind.
4) Re-implement the swap device (swstrategy) in a more elegant way, perhaps
via a much more general mechanism that could also be used for disk
striping of regular filesystems.
5) Do something to improve the architecture of vm_object_collapse(). The
fact that it makes calls into the swap pager and knows too much about
how the swap pager operates really bothers me. It also doesn't allow
for collapsing of non-swap pager objects ("unnamed" objects backed by
other pagers).
1995-07-13 08:48:48 +00:00
|
|
|
}
|
|
|
|
|
2016-06-13 03:42:46 +00:00
|
|
|
static vm_object_t
|
|
|
|
swap_pager_alloc_init(void *handle, struct ucred *cred, vm_ooffset_t size,
|
|
|
|
vm_ooffset_t offset)
|
|
|
|
{
|
|
|
|
vm_object_t object;
|
|
|
|
|
|
|
|
if (cred != NULL) {
|
|
|
|
if (!swap_reserve_by_cred(size, cred))
|
|
|
|
return (NULL);
|
|
|
|
crhold(cred);
|
|
|
|
}
|
|
|
|
object = vm_object_allocate(OBJT_SWAP, OFF_TO_IDX(offset +
|
|
|
|
PAGE_MASK + size));
|
|
|
|
object->handle = handle;
|
|
|
|
if (cred != NULL) {
|
|
|
|
object->cred = cred;
|
|
|
|
object->charge = size;
|
|
|
|
}
|
|
|
|
object->un_pager.swp.swp_bcount = 0;
|
|
|
|
return (object);
|
|
|
|
}
|
|
|
|
|
NOTE: libkvm, w, ps, 'top', and any other utility which depends on struct
proc or any VM system structure will have to be rebuilt!!!
Much needed overhaul of the VM system. Included in this first round of
changes:
1) Improved pager interfaces: init, alloc, dealloc, getpages, putpages,
haspage, and sync operations are supported. The haspage interface now
provides information about clusterability. All pager routines now take
struct vm_object's instead of "pagers".
2) Improved data structures. In the previous paradigm, there is constant
confusion caused by pagers being both a data structure ("allocate a
pager") and a collection of routines. The idea of a pager structure has
escentially been eliminated. Objects now have types, and this type is
used to index the appropriate pager. In most cases, items in the pager
structure were duplicated in the object data structure and thus were
unnecessary. In the few cases that remained, a un_pager structure union
was created in the object to contain these items.
3) Because of the cleanup of #1 & #2, a lot of unnecessary layering can now
be removed. For instance, vm_object_enter(), vm_object_lookup(),
vm_object_remove(), and the associated object hash list were some of the
things that were removed.
4) simple_lock's removed. Discussion with several people reveals that the
SMP locking primitives used in the VM system aren't likely the mechanism
that we'll be adopting. Even if it were, the locking that was in the code
was very inadequate and would have to be mostly re-done anyway. The
locking in a uni-processor kernel was a no-op but went a long way toward
making the code difficult to read and debug.
5) Places that attempted to kludge-up the fact that we don't have kernel
thread support have been fixed to reflect the reality that we are really
dealing with processes, not threads. The VM system didn't have complete
thread support, so the comments and mis-named routines were just wrong.
We now use tsleep and wakeup directly in the lock routines, for instance.
6) Where appropriate, the pagers have been improved, especially in the
pager_alloc routines. Most of the pager_allocs have been rewritten and
are now faster and easier to maintain.
7) The pagedaemon pageout clustering algorithm has been rewritten and
now tries harder to output an even number of pages before and after
the requested page. This is sort of the reverse of the ideal pagein
algorithm and should provide better overall performance.
8) Unnecessary (incorrect) casts to caddr_t in calls to tsleep & wakeup
have been removed. Some other unnecessary casts have also been removed.
9) Some almost useless debugging code removed.
10) Terminology of shadow objects vs. backing objects straightened out.
The fact that the vm_object data structure escentially had this
backwards really confused things. The use of "shadow" and "backing
object" throughout the code is now internally consistent and correct
in the Mach terminology.
11) Several minor bug fixes, including one in the vm daemon that caused
0 RSS objects to not get purged as intended.
12) A "default pager" has now been created which cleans up the transition
of objects to the "swap" type. The previous checks throughout the code
for swp->pg_data != NULL were really ugly. This change also provides
the rudiments for future backing of "anonymous" memory by something
other than the swap pager (via the vnode pager, for example), and it
allows the decision about which of these pagers to use to be made
dynamically (although will need some additional decision code to do
this, of course).
13) (dyson) MAP_COPY has been deprecated and the corresponding "copy
object" code has been removed. MAP_COPY was undocumented and non-
standard. It was furthermore broken in several ways which caused its
behavior to degrade to MAP_PRIVATE. Binaries that use MAP_COPY will
continue to work correctly, but via the slightly different semantics
of MAP_PRIVATE.
14) (dyson) Sharing maps have been removed. It's marginal usefulness in a
threads design can be worked around in other ways. Both #12 and #13
were done to simplify the code and improve readability and maintain-
ability. (As were most all of these changes)
TODO:
1) Rewrite most of the vnode pager to use VOP_GETPAGES/PUTPAGES. Doing
this will reduce the vnode pager to a mere fraction of its current size.
2) Rewrite vm_fault and the swap/vnode pagers to use the clustering
information provided by the new haspage pager interface. This will
substantially reduce the overhead by eliminating a large number of
VOP_BMAP() calls. The VOP_BMAP() filesystem interface should be
improved to provide both a "behind" and "ahead" indication of
contiguousness.
3) Implement the extended features of pager_haspage in swap_pager_haspage().
It currently just says 0 pages ahead/behind.
4) Re-implement the swap device (swstrategy) in a more elegant way, perhaps
via a much more general mechanism that could also be used for disk
striping of regular filesystems.
5) Do something to improve the architecture of vm_object_collapse(). The
fact that it makes calls into the swap pager and knows too much about
how the swap pager operates really bothers me. It also doesn't allow
for collapsing of non-swap pager objects ("unnamed" objects backed by
other pagers).
1995-07-13 08:48:48 +00:00
|
|
|
/*
|
1999-01-21 08:29:12 +00:00
|
|
|
* SWAP_PAGER_ALLOC() - allocate a new OBJT_SWAP VM object and instantiate
|
|
|
|
* its metadata structures.
|
|
|
|
*
|
|
|
|
* This routine is called from the mmap and fork code to create a new
|
2016-06-13 03:42:46 +00:00
|
|
|
* OBJT_SWAP object.
|
2002-06-22 08:03:21 +00:00
|
|
|
*
|
2016-06-13 03:42:46 +00:00
|
|
|
* This routine must ensure that no live duplicate is created for
|
|
|
|
* the named object request, which is protected against by
|
|
|
|
* holding the sw_alloc_sx lock in case handle != NULL.
|
NOTE: libkvm, w, ps, 'top', and any other utility which depends on struct
proc or any VM system structure will have to be rebuilt!!!
Much needed overhaul of the VM system. Included in this first round of
changes:
1) Improved pager interfaces: init, alloc, dealloc, getpages, putpages,
haspage, and sync operations are supported. The haspage interface now
provides information about clusterability. All pager routines now take
struct vm_object's instead of "pagers".
2) Improved data structures. In the previous paradigm, there is constant
confusion caused by pagers being both a data structure ("allocate a
pager") and a collection of routines. The idea of a pager structure has
escentially been eliminated. Objects now have types, and this type is
used to index the appropriate pager. In most cases, items in the pager
structure were duplicated in the object data structure and thus were
unnecessary. In the few cases that remained, a un_pager structure union
was created in the object to contain these items.
3) Because of the cleanup of #1 & #2, a lot of unnecessary layering can now
be removed. For instance, vm_object_enter(), vm_object_lookup(),
vm_object_remove(), and the associated object hash list were some of the
things that were removed.
4) simple_lock's removed. Discussion with several people reveals that the
SMP locking primitives used in the VM system aren't likely the mechanism
that we'll be adopting. Even if it were, the locking that was in the code
was very inadequate and would have to be mostly re-done anyway. The
locking in a uni-processor kernel was a no-op but went a long way toward
making the code difficult to read and debug.
5) Places that attempted to kludge-up the fact that we don't have kernel
thread support have been fixed to reflect the reality that we are really
dealing with processes, not threads. The VM system didn't have complete
thread support, so the comments and mis-named routines were just wrong.
We now use tsleep and wakeup directly in the lock routines, for instance.
6) Where appropriate, the pagers have been improved, especially in the
pager_alloc routines. Most of the pager_allocs have been rewritten and
are now faster and easier to maintain.
7) The pagedaemon pageout clustering algorithm has been rewritten and
now tries harder to output an even number of pages before and after
the requested page. This is sort of the reverse of the ideal pagein
algorithm and should provide better overall performance.
8) Unnecessary (incorrect) casts to caddr_t in calls to tsleep & wakeup
have been removed. Some other unnecessary casts have also been removed.
9) Some almost useless debugging code removed.
10) Terminology of shadow objects vs. backing objects straightened out.
The fact that the vm_object data structure escentially had this
backwards really confused things. The use of "shadow" and "backing
object" throughout the code is now internally consistent and correct
in the Mach terminology.
11) Several minor bug fixes, including one in the vm daemon that caused
0 RSS objects to not get purged as intended.
12) A "default pager" has now been created which cleans up the transition
of objects to the "swap" type. The previous checks throughout the code
for swp->pg_data != NULL were really ugly. This change also provides
the rudiments for future backing of "anonymous" memory by something
other than the swap pager (via the vnode pager, for example), and it
allows the decision about which of these pagers to use to be made
dynamically (although will need some additional decision code to do
this, of course).
13) (dyson) MAP_COPY has been deprecated and the corresponding "copy
object" code has been removed. MAP_COPY was undocumented and non-
standard. It was furthermore broken in several ways which caused its
behavior to degrade to MAP_PRIVATE. Binaries that use MAP_COPY will
continue to work correctly, but via the slightly different semantics
of MAP_PRIVATE.
14) (dyson) Sharing maps have been removed. It's marginal usefulness in a
threads design can be worked around in other ways. Both #12 and #13
were done to simplify the code and improve readability and maintain-
ability. (As were most all of these changes)
TODO:
1) Rewrite most of the vnode pager to use VOP_GETPAGES/PUTPAGES. Doing
this will reduce the vnode pager to a mere fraction of its current size.
2) Rewrite vm_fault and the swap/vnode pagers to use the clustering
information provided by the new haspage pager interface. This will
substantially reduce the overhead by eliminating a large number of
VOP_BMAP() calls. The VOP_BMAP() filesystem interface should be
improved to provide both a "behind" and "ahead" indication of
contiguousness.
3) Implement the extended features of pager_haspage in swap_pager_haspage().
It currently just says 0 pages ahead/behind.
4) Re-implement the swap device (swstrategy) in a more elegant way, perhaps
via a much more general mechanism that could also be used for disk
striping of regular filesystems.
5) Do something to improve the architecture of vm_object_collapse(). The
fact that it makes calls into the swap pager and knows too much about
how the swap pager operates really bothers me. It also doesn't allow
for collapsing of non-swap pager objects ("unnamed" objects backed by
other pagers).
1995-07-13 08:48:48 +00:00
|
|
|
*/
|
1995-11-14 20:53:20 +00:00
|
|
|
static vm_object_t
|
1998-10-13 08:24:45 +00:00
|
|
|
swap_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot,
|
Implement global and per-uid accounting of the anonymous memory. Add
rlimit RLIMIT_SWAP that limits the amount of swap that may be reserved
for the uid.
The accounting information (charge) is associated with either map entry,
or vm object backing the entry, assuming the object is the first one
in the shadow chain and entry does not require COW. Charge is moved
from entry to object on allocation of the object, e.g. during the mmap,
assuming the object is allocated, or on the first page fault on the
entry. It moves back to the entry on forks due to COW setup.
The per-entry granularity of accounting makes the charge process fair
for processes that change uid during lifetime, and decrements charge
for proper uid when region is unmapped.
The interface of vm_pager_allocate(9) is extended by adding struct ucred *,
that is used to charge appropriate uid when allocation if performed by
kernel, e.g. md(4).
Several syscalls, among them is fork(2), may now return ENOMEM when
global or per-uid limits are enforced.
In collaboration with: pho
Reviewed by: alc
Approved by: re (kensmith)
2009-06-23 20:45:22 +00:00
|
|
|
vm_ooffset_t offset, struct ucred *cred)
|
NOTE: libkvm, w, ps, 'top', and any other utility which depends on struct
proc or any VM system structure will have to be rebuilt!!!
Much needed overhaul of the VM system. Included in this first round of
changes:
1) Improved pager interfaces: init, alloc, dealloc, getpages, putpages,
haspage, and sync operations are supported. The haspage interface now
provides information about clusterability. All pager routines now take
struct vm_object's instead of "pagers".
2) Improved data structures. In the previous paradigm, there is constant
confusion caused by pagers being both a data structure ("allocate a
pager") and a collection of routines. The idea of a pager structure has
escentially been eliminated. Objects now have types, and this type is
used to index the appropriate pager. In most cases, items in the pager
structure were duplicated in the object data structure and thus were
unnecessary. In the few cases that remained, a un_pager structure union
was created in the object to contain these items.
3) Because of the cleanup of #1 & #2, a lot of unnecessary layering can now
be removed. For instance, vm_object_enter(), vm_object_lookup(),
vm_object_remove(), and the associated object hash list were some of the
things that were removed.
4) simple_lock's removed. Discussion with several people reveals that the
SMP locking primitives used in the VM system aren't likely the mechanism
that we'll be adopting. Even if it were, the locking that was in the code
was very inadequate and would have to be mostly re-done anyway. The
locking in a uni-processor kernel was a no-op but went a long way toward
making the code difficult to read and debug.
5) Places that attempted to kludge-up the fact that we don't have kernel
thread support have been fixed to reflect the reality that we are really
dealing with processes, not threads. The VM system didn't have complete
thread support, so the comments and mis-named routines were just wrong.
We now use tsleep and wakeup directly in the lock routines, for instance.
6) Where appropriate, the pagers have been improved, especially in the
pager_alloc routines. Most of the pager_allocs have been rewritten and
are now faster and easier to maintain.
7) The pagedaemon pageout clustering algorithm has been rewritten and
now tries harder to output an even number of pages before and after
the requested page. This is sort of the reverse of the ideal pagein
algorithm and should provide better overall performance.
8) Unnecessary (incorrect) casts to caddr_t in calls to tsleep & wakeup
have been removed. Some other unnecessary casts have also been removed.
9) Some almost useless debugging code removed.
10) Terminology of shadow objects vs. backing objects straightened out.
The fact that the vm_object data structure escentially had this
backwards really confused things. The use of "shadow" and "backing
object" throughout the code is now internally consistent and correct
in the Mach terminology.
11) Several minor bug fixes, including one in the vm daemon that caused
0 RSS objects to not get purged as intended.
12) A "default pager" has now been created which cleans up the transition
of objects to the "swap" type. The previous checks throughout the code
for swp->pg_data != NULL were really ugly. This change also provides
the rudiments for future backing of "anonymous" memory by something
other than the swap pager (via the vnode pager, for example), and it
allows the decision about which of these pagers to use to be made
dynamically (although will need some additional decision code to do
this, of course).
13) (dyson) MAP_COPY has been deprecated and the corresponding "copy
object" code has been removed. MAP_COPY was undocumented and non-
standard. It was furthermore broken in several ways which caused its
behavior to degrade to MAP_PRIVATE. Binaries that use MAP_COPY will
continue to work correctly, but via the slightly different semantics
of MAP_PRIVATE.
14) (dyson) Sharing maps have been removed. It's marginal usefulness in a
threads design can be worked around in other ways. Both #12 and #13
were done to simplify the code and improve readability and maintain-
ability. (As were most all of these changes)
TODO:
1) Rewrite most of the vnode pager to use VOP_GETPAGES/PUTPAGES. Doing
this will reduce the vnode pager to a mere fraction of its current size.
2) Rewrite vm_fault and the swap/vnode pagers to use the clustering
information provided by the new haspage pager interface. This will
substantially reduce the overhead by eliminating a large number of
VOP_BMAP() calls. The VOP_BMAP() filesystem interface should be
improved to provide both a "behind" and "ahead" indication of
contiguousness.
3) Implement the extended features of pager_haspage in swap_pager_haspage().
It currently just says 0 pages ahead/behind.
4) Re-implement the swap device (swstrategy) in a more elegant way, perhaps
via a much more general mechanism that could also be used for disk
striping of regular filesystems.
5) Do something to improve the architecture of vm_object_collapse(). The
fact that it makes calls into the swap pager and knows too much about
how the swap pager operates really bothers me. It also doesn't allow
for collapsing of non-swap pager objects ("unnamed" objects backed by
other pagers).
1995-07-13 08:48:48 +00:00
|
|
|
{
|
|
|
|
vm_object_t object;
|
2004-01-04 20:55:15 +00:00
|
|
|
|
2016-06-13 03:42:46 +00:00
|
|
|
if (handle != NULL) {
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
|
|
|
* Reference existing named region or allocate new one. There
|
|
|
|
* should not be a race here against swp_pager_meta_build()
|
|
|
|
* as called from vm_page_remove() in regards to the lookup
|
|
|
|
* of the handle.
|
|
|
|
*/
|
2001-07-04 16:20:28 +00:00
|
|
|
sx_xlock(&sw_alloc_sx);
|
1999-01-21 08:29:12 +00:00
|
|
|
object = vm_pager_object_lookup(NOBJLIST(handle), handle);
|
Consider a scenario in which one processor, call it Pt, is performing
vm_object_terminate() on a device-backed object at the same time that
another processor, call it Pa, is performing dev_pager_alloc() on the
same device. The problem is that vm_pager_object_lookup() should not be
allowed to return a doomed object, i.e., an object with OBJ_DEAD set,
but it does. In detail, the unfortunate sequence of events is: Pt in
vm_object_terminate() holds the doomed object's lock and sets OBJ_DEAD
on the object. Pa in dev_pager_alloc() holds dev_pager_sx and calls
vm_pager_object_lookup(), which returns the doomed object. Next, Pa
calls vm_object_reference(), which requires the doomed object's lock, so
Pa waits for Pt to release the doomed object's lock. Pt proceeds to the
point in vm_object_terminate() where it releases the doomed object's
lock. Pa is now able to complete vm_object_reference() because it can
now complete the acquisition of the doomed object's lock. So, now the
doomed object has a reference count of one! Pa releases dev_pager_sx
and returns the doomed object from dev_pager_alloc(). Pt now acquires
dev_pager_mtx, removes the doomed object from dev_pager_object_list,
releases dev_pager_mtx, and finally calls uma_zfree with the doomed
object. However, the doomed object is still in use by Pa.
Repeating my key point, vm_pager_object_lookup() must not return a
doomed object. Moreover, the test for the object's state, i.e.,
doomed or not, and the increment of the object's reference count
should be carried out atomically.
Reviewed by: kib
Approved by: re (kensmith)
MFC after: 3 weeks
2007-08-05 21:04:32 +00:00
|
|
|
if (object == NULL) {
|
2016-06-13 03:42:46 +00:00
|
|
|
object = swap_pager_alloc_init(handle, cred, size,
|
|
|
|
offset);
|
|
|
|
if (object != NULL) {
|
|
|
|
TAILQ_INSERT_TAIL(NOBJLIST(object->handle),
|
|
|
|
object, pager_object_list);
|
Implement global and per-uid accounting of the anonymous memory. Add
rlimit RLIMIT_SWAP that limits the amount of swap that may be reserved
for the uid.
The accounting information (charge) is associated with either map entry,
or vm object backing the entry, assuming the object is the first one
in the shadow chain and entry does not require COW. Charge is moved
from entry to object on allocation of the object, e.g. during the mmap,
assuming the object is allocated, or on the first page fault on the
entry. It moves back to the entry on forks due to COW setup.
The per-entry granularity of accounting makes the charge process fair
for processes that change uid during lifetime, and decrements charge
for proper uid when region is unmapped.
The interface of vm_pager_allocate(9) is extended by adding struct ucred *,
that is used to charge appropriate uid when allocation if performed by
kernel, e.g. md(4).
Several syscalls, among them is fork(2), may now return ENOMEM when
global or per-uid limits are enforced.
In collaboration with: pho
Reviewed by: alc
Approved by: re (kensmith)
2009-06-23 20:45:22 +00:00
|
|
|
}
|
NOTE: libkvm, w, ps, 'top', and any other utility which depends on struct
proc or any VM system structure will have to be rebuilt!!!
Much needed overhaul of the VM system. Included in this first round of
changes:
1) Improved pager interfaces: init, alloc, dealloc, getpages, putpages,
haspage, and sync operations are supported. The haspage interface now
provides information about clusterability. All pager routines now take
struct vm_object's instead of "pagers".
2) Improved data structures. In the previous paradigm, there is constant
confusion caused by pagers being both a data structure ("allocate a
pager") and a collection of routines. The idea of a pager structure has
escentially been eliminated. Objects now have types, and this type is
used to index the appropriate pager. In most cases, items in the pager
structure were duplicated in the object data structure and thus were
unnecessary. In the few cases that remained, a un_pager structure union
was created in the object to contain these items.
3) Because of the cleanup of #1 & #2, a lot of unnecessary layering can now
be removed. For instance, vm_object_enter(), vm_object_lookup(),
vm_object_remove(), and the associated object hash list were some of the
things that were removed.
4) simple_lock's removed. Discussion with several people reveals that the
SMP locking primitives used in the VM system aren't likely the mechanism
that we'll be adopting. Even if it were, the locking that was in the code
was very inadequate and would have to be mostly re-done anyway. The
locking in a uni-processor kernel was a no-op but went a long way toward
making the code difficult to read and debug.
5) Places that attempted to kludge-up the fact that we don't have kernel
thread support have been fixed to reflect the reality that we are really
dealing with processes, not threads. The VM system didn't have complete
thread support, so the comments and mis-named routines were just wrong.
We now use tsleep and wakeup directly in the lock routines, for instance.
6) Where appropriate, the pagers have been improved, especially in the
pager_alloc routines. Most of the pager_allocs have been rewritten and
are now faster and easier to maintain.
7) The pagedaemon pageout clustering algorithm has been rewritten and
now tries harder to output an even number of pages before and after
the requested page. This is sort of the reverse of the ideal pagein
algorithm and should provide better overall performance.
8) Unnecessary (incorrect) casts to caddr_t in calls to tsleep & wakeup
have been removed. Some other unnecessary casts have also been removed.
9) Some almost useless debugging code removed.
10) Terminology of shadow objects vs. backing objects straightened out.
The fact that the vm_object data structure escentially had this
backwards really confused things. The use of "shadow" and "backing
object" throughout the code is now internally consistent and correct
in the Mach terminology.
11) Several minor bug fixes, including one in the vm daemon that caused
0 RSS objects to not get purged as intended.
12) A "default pager" has now been created which cleans up the transition
of objects to the "swap" type. The previous checks throughout the code
for swp->pg_data != NULL were really ugly. This change also provides
the rudiments for future backing of "anonymous" memory by something
other than the swap pager (via the vnode pager, for example), and it
allows the decision about which of these pagers to use to be made
dynamically (although will need some additional decision code to do
this, of course).
13) (dyson) MAP_COPY has been deprecated and the corresponding "copy
object" code has been removed. MAP_COPY was undocumented and non-
standard. It was furthermore broken in several ways which caused its
behavior to degrade to MAP_PRIVATE. Binaries that use MAP_COPY will
continue to work correctly, but via the slightly different semantics
of MAP_PRIVATE.
14) (dyson) Sharing maps have been removed. It's marginal usefulness in a
threads design can be worked around in other ways. Both #12 and #13
were done to simplify the code and improve readability and maintain-
ability. (As were most all of these changes)
TODO:
1) Rewrite most of the vnode pager to use VOP_GETPAGES/PUTPAGES. Doing
this will reduce the vnode pager to a mere fraction of its current size.
2) Rewrite vm_fault and the swap/vnode pagers to use the clustering
information provided by the new haspage pager interface. This will
substantially reduce the overhead by eliminating a large number of
VOP_BMAP() calls. The VOP_BMAP() filesystem interface should be
improved to provide both a "behind" and "ahead" indication of
contiguousness.
3) Implement the extended features of pager_haspage in swap_pager_haspage().
It currently just says 0 pages ahead/behind.
4) Re-implement the swap device (swstrategy) in a more elegant way, perhaps
via a much more general mechanism that could also be used for disk
striping of regular filesystems.
5) Do something to improve the architecture of vm_object_collapse(). The
fact that it makes calls into the swap pager and knows too much about
how the swap pager operates really bothers me. It also doesn't allow
for collapsing of non-swap pager objects ("unnamed" objects backed by
other pagers).
1995-07-13 08:48:48 +00:00
|
|
|
}
|
2001-07-04 16:20:28 +00:00
|
|
|
sx_xunlock(&sw_alloc_sx);
|
1994-05-24 10:09:53 +00:00
|
|
|
} else {
|
2016-06-13 03:42:46 +00:00
|
|
|
object = swap_pager_alloc_init(handle, cred, size, offset);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
NOTE: libkvm, w, ps, 'top', and any other utility which depends on struct
proc or any VM system structure will have to be rebuilt!!!
Much needed overhaul of the VM system. Included in this first round of
changes:
1) Improved pager interfaces: init, alloc, dealloc, getpages, putpages,
haspage, and sync operations are supported. The haspage interface now
provides information about clusterability. All pager routines now take
struct vm_object's instead of "pagers".
2) Improved data structures. In the previous paradigm, there is constant
confusion caused by pagers being both a data structure ("allocate a
pager") and a collection of routines. The idea of a pager structure has
escentially been eliminated. Objects now have types, and this type is
used to index the appropriate pager. In most cases, items in the pager
structure were duplicated in the object data structure and thus were
unnecessary. In the few cases that remained, a un_pager structure union
was created in the object to contain these items.
3) Because of the cleanup of #1 & #2, a lot of unnecessary layering can now
be removed. For instance, vm_object_enter(), vm_object_lookup(),
vm_object_remove(), and the associated object hash list were some of the
things that were removed.
4) simple_lock's removed. Discussion with several people reveals that the
SMP locking primitives used in the VM system aren't likely the mechanism
that we'll be adopting. Even if it were, the locking that was in the code
was very inadequate and would have to be mostly re-done anyway. The
locking in a uni-processor kernel was a no-op but went a long way toward
making the code difficult to read and debug.
5) Places that attempted to kludge-up the fact that we don't have kernel
thread support have been fixed to reflect the reality that we are really
dealing with processes, not threads. The VM system didn't have complete
thread support, so the comments and mis-named routines were just wrong.
We now use tsleep and wakeup directly in the lock routines, for instance.
6) Where appropriate, the pagers have been improved, especially in the
pager_alloc routines. Most of the pager_allocs have been rewritten and
are now faster and easier to maintain.
7) The pagedaemon pageout clustering algorithm has been rewritten and
now tries harder to output an even number of pages before and after
the requested page. This is sort of the reverse of the ideal pagein
algorithm and should provide better overall performance.
8) Unnecessary (incorrect) casts to caddr_t in calls to tsleep & wakeup
have been removed. Some other unnecessary casts have also been removed.
9) Some almost useless debugging code removed.
10) Terminology of shadow objects vs. backing objects straightened out.
The fact that the vm_object data structure escentially had this
backwards really confused things. The use of "shadow" and "backing
object" throughout the code is now internally consistent and correct
in the Mach terminology.
11) Several minor bug fixes, including one in the vm daemon that caused
0 RSS objects to not get purged as intended.
12) A "default pager" has now been created which cleans up the transition
of objects to the "swap" type. The previous checks throughout the code
for swp->pg_data != NULL were really ugly. This change also provides
the rudiments for future backing of "anonymous" memory by something
other than the swap pager (via the vnode pager, for example), and it
allows the decision about which of these pagers to use to be made
dynamically (although will need some additional decision code to do
this, of course).
13) (dyson) MAP_COPY has been deprecated and the corresponding "copy
object" code has been removed. MAP_COPY was undocumented and non-
standard. It was furthermore broken in several ways which caused its
behavior to degrade to MAP_PRIVATE. Binaries that use MAP_COPY will
continue to work correctly, but via the slightly different semantics
of MAP_PRIVATE.
14) (dyson) Sharing maps have been removed. It's marginal usefulness in a
threads design can be worked around in other ways. Both #12 and #13
were done to simplify the code and improve readability and maintain-
ability. (As were most all of these changes)
TODO:
1) Rewrite most of the vnode pager to use VOP_GETPAGES/PUTPAGES. Doing
this will reduce the vnode pager to a mere fraction of its current size.
2) Rewrite vm_fault and the swap/vnode pagers to use the clustering
information provided by the new haspage pager interface. This will
substantially reduce the overhead by eliminating a large number of
VOP_BMAP() calls. The VOP_BMAP() filesystem interface should be
improved to provide both a "behind" and "ahead" indication of
contiguousness.
3) Implement the extended features of pager_haspage in swap_pager_haspage().
It currently just says 0 pages ahead/behind.
4) Re-implement the swap device (swstrategy) in a more elegant way, perhaps
via a much more general mechanism that could also be used for disk
striping of regular filesystems.
5) Do something to improve the architecture of vm_object_collapse(). The
fact that it makes calls into the swap pager and knows too much about
how the swap pager operates really bothers me. It also doesn't allow
for collapsing of non-swap pager objects ("unnamed" objects backed by
other pagers).
1995-07-13 08:48:48 +00:00
|
|
|
return (object);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
1994-05-25 09:21:21 +00:00
|
|
|
/*
|
1999-01-21 08:29:12 +00:00
|
|
|
* SWAP_PAGER_DEALLOC() - remove swap metadata from object
|
|
|
|
*
|
2012-09-05 12:24:50 +00:00
|
|
|
* The swap backing for the object is destroyed. The code is
|
1999-01-21 08:29:12 +00:00
|
|
|
* designed such that we can reinstantiate it later, but this
|
|
|
|
* routine is typically called only when the entire object is
|
|
|
|
* about to be destroyed.
|
|
|
|
*
|
2011-08-22 20:44:18 +00:00
|
|
|
* The object must be locked.
|
1994-05-25 09:21:21 +00:00
|
|
|
*/
|
1999-01-21 08:29:12 +00:00
|
|
|
static void
|
2003-08-30 08:32:42 +00:00
|
|
|
swap_pager_dealloc(vm_object_t object)
|
1994-05-25 09:21:21 +00:00
|
|
|
{
|
1999-09-17 05:09:24 +00:00
|
|
|
|
2016-06-13 03:42:46 +00:00
|
|
|
VM_OBJECT_ASSERT_WLOCKED(object);
|
|
|
|
KASSERT((object->flags & OBJ_DEAD) != 0, ("dealloc of reachable obj"));
|
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
|
|
|
* Remove from list right away so lookups will fail if we block for
|
|
|
|
* pageout completion.
|
|
|
|
*/
|
2003-12-29 04:21:44 +00:00
|
|
|
if (object->handle != NULL) {
|
2016-06-13 03:42:46 +00:00
|
|
|
VM_OBJECT_WUNLOCK(object);
|
|
|
|
sx_xlock(&sw_alloc_sx);
|
|
|
|
TAILQ_REMOVE(NOBJLIST(object->handle), object,
|
|
|
|
pager_object_list);
|
|
|
|
sx_xunlock(&sw_alloc_sx);
|
|
|
|
VM_OBJECT_WLOCK(object);
|
1994-05-25 09:21:21 +00:00
|
|
|
}
|
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
vm_object_pip_wait(object, "swpdea");
|
These changes embody the support of the fully coherent merged VM buffer cache,
much higher filesystem I/O performance, and much better paging performance. It
represents the culmination of over 6 months of R&D.
The majority of the merged VM/cache work is by John Dyson.
The following highlights the most significant changes. Additionally, there are
(mostly minor) changes to the various filesystem modules (nfs, msdosfs, etc) to
support the new VM/buffer scheme.
vfs_bio.c:
Significant rewrite of most of vfs_bio to support the merged VM buffer cache
scheme. The scheme is almost fully compatible with the old filesystem
interface. Significant improvement in the number of opportunities for write
clustering.
vfs_cluster.c, vfs_subr.c
Upgrade and performance enhancements in vfs layer code to support merged
VM/buffer cache. Fixup of vfs_cluster to eliminate the bogus pagemove stuff.
vm_object.c:
Yet more improvements in the collapse code. Elimination of some windows that
can cause list corruption.
vm_pageout.c:
Fixed it, it really works better now. Somehow in 2.0, some "enhancements"
broke the code. This code has been reworked from the ground-up.
vm_fault.c, vm_page.c, pmap.c, vm_object.c
Support for small-block filesystems with merged VM/buffer cache scheme.
pmap.c vm_map.c
Dynamic kernel VM size, now we dont have to pre-allocate excessive numbers of
kernel PTs.
vm_glue.c
Much simpler and more effective swapping code. No more gratuitous swapping.
proc.h
Fixed the problem that the p_lock flag was not being cleared on a fork.
swap_pager.c, vnode_pager.c
Removal of old vfs_bio cruft to support the past pseudo-coherency. Now the
code doesn't need it anymore.
machdep.c
Changes to better support the parameter values for the merged VM/buffer cache
scheme.
machdep.c, kern_exec.c, vm_glue.c
Implemented a seperate submap for temporary exec string space and another one
to contain process upages. This eliminates all map fragmentation problems
that previously existed.
ffs_inode.c, ufs_inode.c, ufs_readwrite.c
Changes for merged VM/buffer cache. Add "bypass" support for sneaking in on
busy buffers.
Submitted by: John Dyson and David Greenman
1995-01-09 16:06:02 +00:00
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
2012-09-05 12:24:50 +00:00
|
|
|
* Free all remaining metadata. We only bother to free it from
|
1999-01-21 08:29:12 +00:00
|
|
|
* the swap meta data. We do not attempt to free swapblk's still
|
|
|
|
* associated with vm_page_t's for this object. We do not care
|
|
|
|
* if paging is still in progress on some objects.
|
|
|
|
*/
|
|
|
|
swp_pager_meta_free_all(object);
|
2015-05-08 19:43:37 +00:00
|
|
|
object->handle = NULL;
|
|
|
|
object->type = OBJT_DEAD;
|
1994-05-25 09:21:21 +00:00
|
|
|
}
|
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
/************************************************************************
|
|
|
|
* SWAP PAGER BITMAP ROUTINES *
|
|
|
|
************************************************************************/
|
|
|
|
|
1994-05-25 09:21:21 +00:00
|
|
|
/*
|
1999-01-21 08:29:12 +00:00
|
|
|
* SWP_PAGER_GETSWAPSPACE() - allocate raw swap space
|
|
|
|
*
|
|
|
|
* Allocate swap for the requested number of pages. The starting
|
|
|
|
* swap block number (a page index) is returned or SWAPBLK_NONE
|
|
|
|
* if the allocation failed.
|
|
|
|
*
|
|
|
|
* Also has the side effect of advising that somebody made a mistake
|
|
|
|
* when they configured swap and didn't configure enough.
|
|
|
|
*
|
2011-08-22 20:44:18 +00:00
|
|
|
* This routine may not sleep.
|
2003-08-03 13:35:31 +00:00
|
|
|
*
|
|
|
|
* We allocate in round-robin fashion from the configured devices.
|
1994-05-25 09:21:21 +00:00
|
|
|
*/
|
2003-07-22 20:54:26 +00:00
|
|
|
static daddr_t
|
2003-08-30 08:32:42 +00:00
|
|
|
swp_pager_getswapspace(int npages)
|
These changes embody the support of the fully coherent merged VM buffer cache,
much higher filesystem I/O performance, and much better paging performance. It
represents the culmination of over 6 months of R&D.
The majority of the merged VM/cache work is by John Dyson.
The following highlights the most significant changes. Additionally, there are
(mostly minor) changes to the various filesystem modules (nfs, msdosfs, etc) to
support the new VM/buffer scheme.
vfs_bio.c:
Significant rewrite of most of vfs_bio to support the merged VM buffer cache
scheme. The scheme is almost fully compatible with the old filesystem
interface. Significant improvement in the number of opportunities for write
clustering.
vfs_cluster.c, vfs_subr.c
Upgrade and performance enhancements in vfs layer code to support merged
VM/buffer cache. Fixup of vfs_cluster to eliminate the bogus pagemove stuff.
vm_object.c:
Yet more improvements in the collapse code. Elimination of some windows that
can cause list corruption.
vm_pageout.c:
Fixed it, it really works better now. Somehow in 2.0, some "enhancements"
broke the code. This code has been reworked from the ground-up.
vm_fault.c, vm_page.c, pmap.c, vm_object.c
Support for small-block filesystems with merged VM/buffer cache scheme.
pmap.c vm_map.c
Dynamic kernel VM size, now we dont have to pre-allocate excessive numbers of
kernel PTs.
vm_glue.c
Much simpler and more effective swapping code. No more gratuitous swapping.
proc.h
Fixed the problem that the p_lock flag was not being cleared on a fork.
swap_pager.c, vnode_pager.c
Removal of old vfs_bio cruft to support the past pseudo-coherency. Now the
code doesn't need it anymore.
machdep.c
Changes to better support the parameter values for the merged VM/buffer cache
scheme.
machdep.c, kern_exec.c, vm_glue.c
Implemented a seperate submap for temporary exec string space and another one
to contain process upages. This eliminates all map fragmentation problems
that previously existed.
ffs_inode.c, ufs_inode.c, ufs_readwrite.c
Changes for merged VM/buffer cache. Add "bypass" support for sneaking in on
busy buffers.
Submitted by: John Dyson and David Greenman
1995-01-09 16:06:02 +00:00
|
|
|
{
|
1999-01-21 08:29:12 +00:00
|
|
|
daddr_t blk;
|
2003-08-03 13:35:31 +00:00
|
|
|
struct swdevt *sp;
|
|
|
|
int i;
|
1997-12-24 15:05:25 +00:00
|
|
|
|
2003-08-03 13:35:31 +00:00
|
|
|
blk = SWAPBLK_NONE;
|
2003-08-30 16:10:28 +00:00
|
|
|
mtx_lock(&sw_dev_mtx);
|
2003-08-03 13:35:31 +00:00
|
|
|
sp = swdevhd;
|
|
|
|
for (i = 0; i < nswapdev; i++) {
|
|
|
|
if (sp == NULL)
|
|
|
|
sp = TAILQ_FIRST(&swtailq);
|
|
|
|
if (!(sp->sw_flags & SW_CLOSING)) {
|
|
|
|
blk = blist_alloc(sp->sw_blist, npages);
|
|
|
|
if (blk != SWAPBLK_NONE) {
|
|
|
|
blk += sp->sw_first;
|
|
|
|
sp->sw_used += npages;
|
2003-10-30 07:11:06 +00:00
|
|
|
swap_pager_avail -= npages;
|
2003-08-03 13:35:31 +00:00
|
|
|
swp_sizecheck();
|
|
|
|
swdevhd = TAILQ_NEXT(sp, sw_list);
|
2003-10-30 07:11:06 +00:00
|
|
|
goto done;
|
2003-08-03 13:35:31 +00:00
|
|
|
}
|
1999-02-06 07:22:21 +00:00
|
|
|
}
|
2003-08-03 13:35:31 +00:00
|
|
|
sp = TAILQ_NEXT(sp, sw_list);
|
1994-11-13 15:36:48 +00:00
|
|
|
}
|
2003-08-03 13:35:31 +00:00
|
|
|
if (swap_pager_full != 2) {
|
2003-08-30 16:10:28 +00:00
|
|
|
printf("swap_pager_getswapspace(%d): failed\n", npages);
|
2003-08-03 13:35:31 +00:00
|
|
|
swap_pager_full = 2;
|
|
|
|
swap_pager_almost_full = 1;
|
|
|
|
}
|
|
|
|
swdevhd = NULL;
|
2003-10-30 07:11:06 +00:00
|
|
|
done:
|
|
|
|
mtx_unlock(&sw_dev_mtx);
|
2002-03-10 21:52:48 +00:00
|
|
|
return (blk);
|
1994-05-25 09:21:21 +00:00
|
|
|
}
|
|
|
|
|
Close a race in swapoff(). Here are the gory details:
In order to avoid livelock, swapoff() skips over objects with a
nonzero pip count and makes another pass if necessary. Since it is
impossible to know which objects we care about, it would choose an
arbitrary object with a nonzero pip count and wait for it before
making another pass, the theory being that this object would finish
paging about as quickly as the ones we care about. Unfortunately,
we may have slept since we acquired a reference to this object.
Hack around this problem by tsleep()ing on the pointer anyway, but
timeout after a fixed interval. More elegant solutions are possible,
but the ones I considered unnecessarily complicate this rare case.
Also, kill some nits that seem to have crept into the swapoff() code
in the last 75 revisions or so:
- Don't pass both sp and sp->sw_used to swap_pager_swapoff(), since
the latter can be derived from the former.
- Replace swp_pager_find_dev() with something simpler. There's no
need to iterate over the entire list of swap devices just to determine
if a given block is assigned to the one we're interested in.
- Expand the scope of the swhash_mtx in a couple of places so that it
isn't released and reacquired once for every hash bucket.
- Don't drop the swhash_mtx while holding a reference to an object.
We need to lock the object first. Unfortunately, doing so would
violate the established lock order, so use VM_OBJECT_TRYLOCK() and
try again on a subsequent pass if the object is already locked.
- Refactor swp_pager_force_pagein() and swap_pager_swapoff() a bit.
2004-11-05 05:36:56 +00:00
|
|
|
static int
|
|
|
|
swp_pager_isondev(daddr_t blk, struct swdevt *sp)
|
2003-08-03 13:35:31 +00:00
|
|
|
{
|
|
|
|
|
Close a race in swapoff(). Here are the gory details:
In order to avoid livelock, swapoff() skips over objects with a
nonzero pip count and makes another pass if necessary. Since it is
impossible to know which objects we care about, it would choose an
arbitrary object with a nonzero pip count and wait for it before
making another pass, the theory being that this object would finish
paging about as quickly as the ones we care about. Unfortunately,
we may have slept since we acquired a reference to this object.
Hack around this problem by tsleep()ing on the pointer anyway, but
timeout after a fixed interval. More elegant solutions are possible,
but the ones I considered unnecessarily complicate this rare case.
Also, kill some nits that seem to have crept into the swapoff() code
in the last 75 revisions or so:
- Don't pass both sp and sp->sw_used to swap_pager_swapoff(), since
the latter can be derived from the former.
- Replace swp_pager_find_dev() with something simpler. There's no
need to iterate over the entire list of swap devices just to determine
if a given block is assigned to the one we're interested in.
- Expand the scope of the swhash_mtx in a couple of places so that it
isn't released and reacquired once for every hash bucket.
- Don't drop the swhash_mtx while holding a reference to an object.
We need to lock the object first. Unfortunately, doing so would
violate the established lock order, so use VM_OBJECT_TRYLOCK() and
try again on a subsequent pass if the object is already locked.
- Refactor swp_pager_force_pagein() and swap_pager_swapoff() a bit.
2004-11-05 05:36:56 +00:00
|
|
|
return (blk >= sp->sw_first && blk < sp->sw_end);
|
2003-08-03 13:35:31 +00:00
|
|
|
}
|
2012-09-05 12:24:50 +00:00
|
|
|
|
2003-08-30 09:42:00 +00:00
|
|
|
static void
|
|
|
|
swp_pager_strategy(struct buf *bp)
|
|
|
|
{
|
|
|
|
struct swdevt *sp;
|
|
|
|
|
2003-08-30 16:10:28 +00:00
|
|
|
mtx_lock(&sw_dev_mtx);
|
2003-08-30 09:42:00 +00:00
|
|
|
TAILQ_FOREACH(sp, &swtailq, sw_list) {
|
|
|
|
if (bp->b_blkno >= sp->sw_first && bp->b_blkno < sp->sw_end) {
|
2003-08-30 16:10:28 +00:00
|
|
|
mtx_unlock(&sw_dev_mtx);
|
2013-03-19 14:39:27 +00:00
|
|
|
if ((sp->sw_flags & SW_UNMAPPED) != 0 &&
|
|
|
|
unmapped_buf_allowed) {
|
|
|
|
bp->b_data = unmapped_buf;
|
|
|
|
bp->b_offset = 0;
|
|
|
|
} else {
|
|
|
|
pmap_qenter((vm_offset_t)bp->b_data,
|
|
|
|
&bp->b_pages[0], bp->b_bcount / PAGE_SIZE);
|
|
|
|
}
|
2003-08-30 09:42:00 +00:00
|
|
|
sp->sw_strategy(bp, sp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2003-08-30 16:10:28 +00:00
|
|
|
panic("Swapdev not found");
|
2003-08-30 09:42:00 +00:00
|
|
|
}
|
2012-09-05 12:24:50 +00:00
|
|
|
|
2003-08-03 13:35:31 +00:00
|
|
|
|
1994-05-25 09:21:21 +00:00
|
|
|
/*
|
2012-09-05 12:24:50 +00:00
|
|
|
* SWP_PAGER_FREESWAPSPACE() - free raw swap space
|
1999-01-21 08:29:12 +00:00
|
|
|
*
|
|
|
|
* This routine returns the specified swap blocks back to the bitmap.
|
|
|
|
*
|
2011-08-22 20:44:18 +00:00
|
|
|
* This routine may not sleep.
|
1994-05-25 09:21:21 +00:00
|
|
|
*/
|
2003-07-22 20:54:26 +00:00
|
|
|
static void
|
2003-08-03 13:35:31 +00:00
|
|
|
swp_pager_freeswapspace(daddr_t blk, int npages)
|
These changes embody the support of the fully coherent merged VM buffer cache,
much higher filesystem I/O performance, and much better paging performance. It
represents the culmination of over 6 months of R&D.
The majority of the merged VM/cache work is by John Dyson.
The following highlights the most significant changes. Additionally, there are
(mostly minor) changes to the various filesystem modules (nfs, msdosfs, etc) to
support the new VM/buffer scheme.
vfs_bio.c:
Significant rewrite of most of vfs_bio to support the merged VM buffer cache
scheme. The scheme is almost fully compatible with the old filesystem
interface. Significant improvement in the number of opportunities for write
clustering.
vfs_cluster.c, vfs_subr.c
Upgrade and performance enhancements in vfs layer code to support merged
VM/buffer cache. Fixup of vfs_cluster to eliminate the bogus pagemove stuff.
vm_object.c:
Yet more improvements in the collapse code. Elimination of some windows that
can cause list corruption.
vm_pageout.c:
Fixed it, it really works better now. Somehow in 2.0, some "enhancements"
broke the code. This code has been reworked from the ground-up.
vm_fault.c, vm_page.c, pmap.c, vm_object.c
Support for small-block filesystems with merged VM/buffer cache scheme.
pmap.c vm_map.c
Dynamic kernel VM size, now we dont have to pre-allocate excessive numbers of
kernel PTs.
vm_glue.c
Much simpler and more effective swapping code. No more gratuitous swapping.
proc.h
Fixed the problem that the p_lock flag was not being cleared on a fork.
swap_pager.c, vnode_pager.c
Removal of old vfs_bio cruft to support the past pseudo-coherency. Now the
code doesn't need it anymore.
machdep.c
Changes to better support the parameter values for the merged VM/buffer cache
scheme.
machdep.c, kern_exec.c, vm_glue.c
Implemented a seperate submap for temporary exec string space and another one
to contain process upages. This eliminates all map fragmentation problems
that previously existed.
ffs_inode.c, ufs_inode.c, ufs_readwrite.c
Changes for merged VM/buffer cache. Add "bypass" support for sneaking in on
busy buffers.
Submitted by: John Dyson and David Greenman
1995-01-09 16:06:02 +00:00
|
|
|
{
|
2003-08-03 13:35:31 +00:00
|
|
|
struct swdevt *sp;
|
2002-12-15 19:17:57 +00:00
|
|
|
|
2003-10-30 09:12:43 +00:00
|
|
|
mtx_lock(&sw_dev_mtx);
|
|
|
|
TAILQ_FOREACH(sp, &swtailq, sw_list) {
|
|
|
|
if (blk >= sp->sw_first && blk < sp->sw_end) {
|
|
|
|
sp->sw_used -= npages;
|
|
|
|
/*
|
|
|
|
* If we are attempting to stop swapping on
|
|
|
|
* this device, we don't want to mark any
|
2012-09-05 12:24:50 +00:00
|
|
|
* blocks free lest they be reused.
|
2003-10-30 09:12:43 +00:00
|
|
|
*/
|
|
|
|
if ((sp->sw_flags & SW_CLOSING) == 0) {
|
|
|
|
blist_free(sp->sw_blist, blk - sp->sw_first,
|
|
|
|
npages);
|
|
|
|
swap_pager_avail += npages;
|
|
|
|
swp_sizecheck();
|
|
|
|
}
|
|
|
|
mtx_unlock(&sw_dev_mtx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
panic("Swapdev not found");
|
1994-05-25 09:21:21 +00:00
|
|
|
}
|
1999-01-21 08:29:12 +00:00
|
|
|
|
1994-05-25 09:21:21 +00:00
|
|
|
/*
|
1999-01-21 08:29:12 +00:00
|
|
|
* SWAP_PAGER_FREESPACE() - frees swap blocks associated with a page
|
|
|
|
* range within an object.
|
|
|
|
*
|
|
|
|
* This is a globally accessible routine.
|
|
|
|
*
|
|
|
|
* This routine removes swapblk assignments from swap metadata.
|
|
|
|
*
|
2012-09-05 12:24:50 +00:00
|
|
|
* The external callers of this routine typically have already destroyed
|
|
|
|
* or renamed vm_page_t's associated with this range in the object so
|
1999-01-21 08:29:12 +00:00
|
|
|
* we should be ok.
|
2013-05-28 22:07:23 +00:00
|
|
|
*
|
|
|
|
* The object must be locked.
|
1994-05-25 09:21:21 +00:00
|
|
|
*/
|
|
|
|
void
|
2003-08-30 08:32:42 +00:00
|
|
|
swap_pager_freespace(vm_object_t object, vm_pindex_t start, vm_size_t size)
|
1994-05-25 09:21:21 +00:00
|
|
|
{
|
2001-05-19 01:28:09 +00:00
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
swp_pager_meta_free(object, start, size);
|
1999-09-17 05:09:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SWAP_PAGER_RESERVE() - reserve swap blocks in object
|
|
|
|
*
|
2012-09-05 12:24:50 +00:00
|
|
|
* Assigns swap blocks to the specified range within the object. The
|
2013-07-09 13:22:30 +00:00
|
|
|
* swap blocks are not zeroed. Any previous swap assignment is destroyed.
|
1999-09-17 05:09:24 +00:00
|
|
|
*
|
|
|
|
* Returns 0 on success, -1 on failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
swap_pager_reserve(vm_object_t object, vm_pindex_t start, vm_size_t size)
|
|
|
|
{
|
|
|
|
int n = 0;
|
|
|
|
daddr_t blk = SWAPBLK_NONE;
|
|
|
|
vm_pindex_t beg = start; /* save start index */
|
|
|
|
|
2013-03-09 02:32:23 +00:00
|
|
|
VM_OBJECT_WLOCK(object);
|
1999-09-17 05:09:24 +00:00
|
|
|
while (size) {
|
|
|
|
if (n == 0) {
|
|
|
|
n = BLIST_MAX_ALLOC;
|
|
|
|
while ((blk = swp_pager_getswapspace(n)) == SWAPBLK_NONE) {
|
|
|
|
n >>= 1;
|
|
|
|
if (n == 0) {
|
|
|
|
swp_pager_meta_free(object, beg, start - beg);
|
2013-03-09 02:32:23 +00:00
|
|
|
VM_OBJECT_WUNLOCK(object);
|
2002-03-10 21:52:48 +00:00
|
|
|
return (-1);
|
1999-09-17 05:09:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
swp_pager_meta_build(object, start, blk);
|
|
|
|
--size;
|
|
|
|
++start;
|
|
|
|
++blk;
|
|
|
|
--n;
|
|
|
|
}
|
|
|
|
swp_pager_meta_free(object, start, n);
|
2013-03-09 02:32:23 +00:00
|
|
|
VM_OBJECT_WUNLOCK(object);
|
2002-03-10 21:52:48 +00:00
|
|
|
return (0);
|
1994-05-25 09:21:21 +00:00
|
|
|
}
|
|
|
|
|
1996-05-23 00:45:58 +00:00
|
|
|
/*
|
1999-01-21 08:29:12 +00:00
|
|
|
* SWAP_PAGER_COPY() - copy blocks from source pager to destination pager
|
|
|
|
* and destroy the source.
|
|
|
|
*
|
|
|
|
* Copy any valid swapblks from the source to the destination. In
|
|
|
|
* cases where both the source and destination have a valid swapblk,
|
|
|
|
* we keep the destination's.
|
|
|
|
*
|
2011-08-22 20:44:18 +00:00
|
|
|
* This routine is allowed to sleep. It may sleep allocating metadata
|
1999-01-21 08:29:12 +00:00
|
|
|
* indirectly through swp_pager_meta_build() or if paging is still in
|
2012-09-05 12:24:50 +00:00
|
|
|
* progress on the source.
|
1999-01-21 08:29:12 +00:00
|
|
|
*
|
|
|
|
* The source object contains no vm_page_t's (which is just as well)
|
|
|
|
*
|
|
|
|
* The source object is of type OBJT_SWAP.
|
|
|
|
*
|
2011-08-22 20:44:18 +00:00
|
|
|
* The source and destination objects must be locked.
|
|
|
|
* Both object locks may temporarily be released.
|
1996-05-23 00:45:58 +00:00
|
|
|
*/
|
|
|
|
void
|
2003-08-30 08:32:42 +00:00
|
|
|
swap_pager_copy(vm_object_t srcobject, vm_object_t dstobject,
|
|
|
|
vm_pindex_t offset, int destroysource)
|
1996-05-23 00:45:58 +00:00
|
|
|
{
|
|
|
|
vm_pindex_t i;
|
1999-09-17 05:09:24 +00:00
|
|
|
|
2013-03-09 02:32:23 +00:00
|
|
|
VM_OBJECT_ASSERT_WLOCKED(srcobject);
|
|
|
|
VM_OBJECT_ASSERT_WLOCKED(dstobject);
|
2001-05-19 01:28:09 +00:00
|
|
|
|
1995-02-02 09:09:15 +00:00
|
|
|
/*
|
2012-09-05 12:24:50 +00:00
|
|
|
* If destroysource is set, we remove the source object from the
|
|
|
|
* swap_pager internal queue now.
|
1995-02-02 09:09:15 +00:00
|
|
|
*/
|
2016-06-13 03:42:46 +00:00
|
|
|
if (destroysource && srcobject->handle != NULL) {
|
|
|
|
vm_object_pip_add(srcobject, 1);
|
|
|
|
VM_OBJECT_WUNLOCK(srcobject);
|
|
|
|
vm_object_pip_add(dstobject, 1);
|
|
|
|
VM_OBJECT_WUNLOCK(dstobject);
|
|
|
|
sx_xlock(&sw_alloc_sx);
|
|
|
|
TAILQ_REMOVE(NOBJLIST(srcobject->handle), srcobject,
|
|
|
|
pager_object_list);
|
|
|
|
sx_xunlock(&sw_alloc_sx);
|
|
|
|
VM_OBJECT_WLOCK(dstobject);
|
|
|
|
vm_object_pip_wakeup(dstobject);
|
|
|
|
VM_OBJECT_WLOCK(srcobject);
|
|
|
|
vm_object_pip_wakeup(srcobject);
|
1995-02-02 09:09:15 +00:00
|
|
|
}
|
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
|
|
|
* transfer source to destination.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < dstobject->size; ++i) {
|
|
|
|
daddr_t dstaddr;
|
1994-05-25 09:21:21 +00:00
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
|
|
|
* Locate (without changing) the swapblk on the destination,
|
|
|
|
* unless it is invalid in which case free it silently, or
|
|
|
|
* if the destination is a resident page, in which case the
|
|
|
|
* source is thrown away.
|
|
|
|
*/
|
|
|
|
dstaddr = swp_pager_meta_ctl(dstobject, i, 0);
|
1994-05-25 09:21:21 +00:00
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
if (dstaddr == SWAPBLK_NONE) {
|
|
|
|
/*
|
|
|
|
* Destination has no swapblk and is not resident,
|
|
|
|
* copy source.
|
|
|
|
*/
|
|
|
|
daddr_t srcaddr;
|
1994-05-25 09:21:21 +00:00
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
srcaddr = swp_pager_meta_ctl(
|
2012-09-05 12:24:50 +00:00
|
|
|
srcobject,
|
1999-01-21 08:29:12 +00:00
|
|
|
i + offset,
|
|
|
|
SWM_POP
|
|
|
|
);
|
1994-05-25 09:21:21 +00:00
|
|
|
|
2003-10-25 23:42:17 +00:00
|
|
|
if (srcaddr != SWAPBLK_NONE) {
|
2003-11-01 08:57:26 +00:00
|
|
|
/*
|
|
|
|
* swp_pager_meta_build() can sleep.
|
|
|
|
*/
|
|
|
|
vm_object_pip_add(srcobject, 1);
|
2013-03-09 02:32:23 +00:00
|
|
|
VM_OBJECT_WUNLOCK(srcobject);
|
2003-11-01 08:57:26 +00:00
|
|
|
vm_object_pip_add(dstobject, 1);
|
1999-09-17 05:09:24 +00:00
|
|
|
swp_pager_meta_build(dstobject, i, srcaddr);
|
2003-11-01 08:57:26 +00:00
|
|
|
vm_object_pip_wakeup(dstobject);
|
2013-03-09 02:32:23 +00:00
|
|
|
VM_OBJECT_WLOCK(srcobject);
|
2003-11-01 08:57:26 +00:00
|
|
|
vm_object_pip_wakeup(srcobject);
|
2003-10-25 23:42:17 +00:00
|
|
|
}
|
1999-01-21 08:29:12 +00:00
|
|
|
} else {
|
1994-05-25 09:21:21 +00:00
|
|
|
/*
|
1999-01-21 08:29:12 +00:00
|
|
|
* Destination has valid swapblk or it is represented
|
|
|
|
* by a resident page. We destroy the sourceblock.
|
1994-05-25 09:21:21 +00:00
|
|
|
*/
|
2012-09-05 12:24:50 +00:00
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
swp_pager_meta_ctl(srcobject, i + offset, SWM_FREE);
|
1994-05-25 09:21:21 +00:00
|
|
|
}
|
|
|
|
}
|
These changes embody the support of the fully coherent merged VM buffer cache,
much higher filesystem I/O performance, and much better paging performance. It
represents the culmination of over 6 months of R&D.
The majority of the merged VM/cache work is by John Dyson.
The following highlights the most significant changes. Additionally, there are
(mostly minor) changes to the various filesystem modules (nfs, msdosfs, etc) to
support the new VM/buffer scheme.
vfs_bio.c:
Significant rewrite of most of vfs_bio to support the merged VM buffer cache
scheme. The scheme is almost fully compatible with the old filesystem
interface. Significant improvement in the number of opportunities for write
clustering.
vfs_cluster.c, vfs_subr.c
Upgrade and performance enhancements in vfs layer code to support merged
VM/buffer cache. Fixup of vfs_cluster to eliminate the bogus pagemove stuff.
vm_object.c:
Yet more improvements in the collapse code. Elimination of some windows that
can cause list corruption.
vm_pageout.c:
Fixed it, it really works better now. Somehow in 2.0, some "enhancements"
broke the code. This code has been reworked from the ground-up.
vm_fault.c, vm_page.c, pmap.c, vm_object.c
Support for small-block filesystems with merged VM/buffer cache scheme.
pmap.c vm_map.c
Dynamic kernel VM size, now we dont have to pre-allocate excessive numbers of
kernel PTs.
vm_glue.c
Much simpler and more effective swapping code. No more gratuitous swapping.
proc.h
Fixed the problem that the p_lock flag was not being cleared on a fork.
swap_pager.c, vnode_pager.c
Removal of old vfs_bio cruft to support the past pseudo-coherency. Now the
code doesn't need it anymore.
machdep.c
Changes to better support the parameter values for the merged VM/buffer cache
scheme.
machdep.c, kern_exec.c, vm_glue.c
Implemented a seperate submap for temporary exec string space and another one
to contain process upages. This eliminates all map fragmentation problems
that previously existed.
ffs_inode.c, ufs_inode.c, ufs_readwrite.c
Changes for merged VM/buffer cache. Add "bypass" support for sneaking in on
busy buffers.
Submitted by: John Dyson and David Greenman
1995-01-09 16:06:02 +00:00
|
|
|
|
|
|
|
/*
|
1999-01-21 08:29:12 +00:00
|
|
|
* Free left over swap blocks in source.
|
|
|
|
*
|
2016-05-02 20:16:29 +00:00
|
|
|
* We have to revert the type to OBJT_DEFAULT so we do not accidentally
|
1999-01-21 08:29:12 +00:00
|
|
|
* double-remove the object from the swap queues.
|
These changes embody the support of the fully coherent merged VM buffer cache,
much higher filesystem I/O performance, and much better paging performance. It
represents the culmination of over 6 months of R&D.
The majority of the merged VM/cache work is by John Dyson.
The following highlights the most significant changes. Additionally, there are
(mostly minor) changes to the various filesystem modules (nfs, msdosfs, etc) to
support the new VM/buffer scheme.
vfs_bio.c:
Significant rewrite of most of vfs_bio to support the merged VM buffer cache
scheme. The scheme is almost fully compatible with the old filesystem
interface. Significant improvement in the number of opportunities for write
clustering.
vfs_cluster.c, vfs_subr.c
Upgrade and performance enhancements in vfs layer code to support merged
VM/buffer cache. Fixup of vfs_cluster to eliminate the bogus pagemove stuff.
vm_object.c:
Yet more improvements in the collapse code. Elimination of some windows that
can cause list corruption.
vm_pageout.c:
Fixed it, it really works better now. Somehow in 2.0, some "enhancements"
broke the code. This code has been reworked from the ground-up.
vm_fault.c, vm_page.c, pmap.c, vm_object.c
Support for small-block filesystems with merged VM/buffer cache scheme.
pmap.c vm_map.c
Dynamic kernel VM size, now we dont have to pre-allocate excessive numbers of
kernel PTs.
vm_glue.c
Much simpler and more effective swapping code. No more gratuitous swapping.
proc.h
Fixed the problem that the p_lock flag was not being cleared on a fork.
swap_pager.c, vnode_pager.c
Removal of old vfs_bio cruft to support the past pseudo-coherency. Now the
code doesn't need it anymore.
machdep.c
Changes to better support the parameter values for the merged VM/buffer cache
scheme.
machdep.c, kern_exec.c, vm_glue.c
Implemented a seperate submap for temporary exec string space and another one
to contain process upages. This eliminates all map fragmentation problems
that previously existed.
ffs_inode.c, ufs_inode.c, ufs_readwrite.c
Changes for merged VM/buffer cache. Add "bypass" support for sneaking in on
busy buffers.
Submitted by: John Dyson and David Greenman
1995-01-09 16:06:02 +00:00
|
|
|
*/
|
1999-01-21 08:29:12 +00:00
|
|
|
if (destroysource) {
|
|
|
|
swp_pager_meta_free_all(srcobject);
|
|
|
|
/*
|
|
|
|
* Reverting the type is not necessary, the caller is going
|
|
|
|
* to destroy srcobject directly, but I'm doing it here
|
2000-03-26 15:20:23 +00:00
|
|
|
* for consistency since we've removed the object from its
|
1999-01-21 08:29:12 +00:00
|
|
|
* queues.
|
|
|
|
*/
|
|
|
|
srcobject->type = OBJT_DEFAULT;
|
1994-05-25 09:21:21 +00:00
|
|
|
}
|
|
|
|
}
|
These changes embody the support of the fully coherent merged VM buffer cache,
much higher filesystem I/O performance, and much better paging performance. It
represents the culmination of over 6 months of R&D.
The majority of the merged VM/cache work is by John Dyson.
The following highlights the most significant changes. Additionally, there are
(mostly minor) changes to the various filesystem modules (nfs, msdosfs, etc) to
support the new VM/buffer scheme.
vfs_bio.c:
Significant rewrite of most of vfs_bio to support the merged VM buffer cache
scheme. The scheme is almost fully compatible with the old filesystem
interface. Significant improvement in the number of opportunities for write
clustering.
vfs_cluster.c, vfs_subr.c
Upgrade and performance enhancements in vfs layer code to support merged
VM/buffer cache. Fixup of vfs_cluster to eliminate the bogus pagemove stuff.
vm_object.c:
Yet more improvements in the collapse code. Elimination of some windows that
can cause list corruption.
vm_pageout.c:
Fixed it, it really works better now. Somehow in 2.0, some "enhancements"
broke the code. This code has been reworked from the ground-up.
vm_fault.c, vm_page.c, pmap.c, vm_object.c
Support for small-block filesystems with merged VM/buffer cache scheme.
pmap.c vm_map.c
Dynamic kernel VM size, now we dont have to pre-allocate excessive numbers of
kernel PTs.
vm_glue.c
Much simpler and more effective swapping code. No more gratuitous swapping.
proc.h
Fixed the problem that the p_lock flag was not being cleared on a fork.
swap_pager.c, vnode_pager.c
Removal of old vfs_bio cruft to support the past pseudo-coherency. Now the
code doesn't need it anymore.
machdep.c
Changes to better support the parameter values for the merged VM/buffer cache
scheme.
machdep.c, kern_exec.c, vm_glue.c
Implemented a seperate submap for temporary exec string space and another one
to contain process upages. This eliminates all map fragmentation problems
that previously existed.
ffs_inode.c, ufs_inode.c, ufs_readwrite.c
Changes for merged VM/buffer cache. Add "bypass" support for sneaking in on
busy buffers.
Submitted by: John Dyson and David Greenman
1995-01-09 16:06:02 +00:00
|
|
|
|
1994-05-25 09:21:21 +00:00
|
|
|
/*
|
1999-01-21 08:29:12 +00:00
|
|
|
* SWAP_PAGER_HASPAGE() - determine if we have good backing store for
|
|
|
|
* the requested page.
|
|
|
|
*
|
|
|
|
* We determine whether good backing store exists for the requested
|
|
|
|
* page and return TRUE if it does, FALSE if it doesn't.
|
|
|
|
*
|
|
|
|
* If TRUE, we also try to determine how much valid, contiguous backing
|
2016-08-30 05:56:21 +00:00
|
|
|
* store exists before and after the requested page.
|
1994-05-25 09:21:21 +00:00
|
|
|
*/
|
2003-06-20 20:20:06 +00:00
|
|
|
static boolean_t
|
2016-08-30 05:56:21 +00:00
|
|
|
swap_pager_haspage(vm_object_t object, vm_pindex_t pindex, int *before,
|
|
|
|
int *after)
|
1994-05-25 09:21:21 +00:00
|
|
|
{
|
2016-08-30 05:56:21 +00:00
|
|
|
daddr_t blk, blk0;
|
|
|
|
int i;
|
1994-05-25 09:21:21 +00:00
|
|
|
|
2013-05-28 22:07:23 +00:00
|
|
|
VM_OBJECT_ASSERT_LOCKED(object);
|
2016-08-30 05:56:21 +00:00
|
|
|
|
These changes embody the support of the fully coherent merged VM buffer cache,
much higher filesystem I/O performance, and much better paging performance. It
represents the culmination of over 6 months of R&D.
The majority of the merged VM/cache work is by John Dyson.
The following highlights the most significant changes. Additionally, there are
(mostly minor) changes to the various filesystem modules (nfs, msdosfs, etc) to
support the new VM/buffer scheme.
vfs_bio.c:
Significant rewrite of most of vfs_bio to support the merged VM buffer cache
scheme. The scheme is almost fully compatible with the old filesystem
interface. Significant improvement in the number of opportunities for write
clustering.
vfs_cluster.c, vfs_subr.c
Upgrade and performance enhancements in vfs layer code to support merged
VM/buffer cache. Fixup of vfs_cluster to eliminate the bogus pagemove stuff.
vm_object.c:
Yet more improvements in the collapse code. Elimination of some windows that
can cause list corruption.
vm_pageout.c:
Fixed it, it really works better now. Somehow in 2.0, some "enhancements"
broke the code. This code has been reworked from the ground-up.
vm_fault.c, vm_page.c, pmap.c, vm_object.c
Support for small-block filesystems with merged VM/buffer cache scheme.
pmap.c vm_map.c
Dynamic kernel VM size, now we dont have to pre-allocate excessive numbers of
kernel PTs.
vm_glue.c
Much simpler and more effective swapping code. No more gratuitous swapping.
proc.h
Fixed the problem that the p_lock flag was not being cleared on a fork.
swap_pager.c, vnode_pager.c
Removal of old vfs_bio cruft to support the past pseudo-coherency. Now the
code doesn't need it anymore.
machdep.c
Changes to better support the parameter values for the merged VM/buffer cache
scheme.
machdep.c, kern_exec.c, vm_glue.c
Implemented a seperate submap for temporary exec string space and another one
to contain process upages. This eliminates all map fragmentation problems
that previously existed.
ffs_inode.c, ufs_inode.c, ufs_readwrite.c
Changes for merged VM/buffer cache. Add "bypass" support for sneaking in on
busy buffers.
Submitted by: John Dyson and David Greenman
1995-01-09 16:06:02 +00:00
|
|
|
/*
|
1999-01-21 08:29:12 +00:00
|
|
|
* do we have good backing store at the requested index ?
|
These changes embody the support of the fully coherent merged VM buffer cache,
much higher filesystem I/O performance, and much better paging performance. It
represents the culmination of over 6 months of R&D.
The majority of the merged VM/cache work is by John Dyson.
The following highlights the most significant changes. Additionally, there are
(mostly minor) changes to the various filesystem modules (nfs, msdosfs, etc) to
support the new VM/buffer scheme.
vfs_bio.c:
Significant rewrite of most of vfs_bio to support the merged VM buffer cache
scheme. The scheme is almost fully compatible with the old filesystem
interface. Significant improvement in the number of opportunities for write
clustering.
vfs_cluster.c, vfs_subr.c
Upgrade and performance enhancements in vfs layer code to support merged
VM/buffer cache. Fixup of vfs_cluster to eliminate the bogus pagemove stuff.
vm_object.c:
Yet more improvements in the collapse code. Elimination of some windows that
can cause list corruption.
vm_pageout.c:
Fixed it, it really works better now. Somehow in 2.0, some "enhancements"
broke the code. This code has been reworked from the ground-up.
vm_fault.c, vm_page.c, pmap.c, vm_object.c
Support for small-block filesystems with merged VM/buffer cache scheme.
pmap.c vm_map.c
Dynamic kernel VM size, now we dont have to pre-allocate excessive numbers of
kernel PTs.
vm_glue.c
Much simpler and more effective swapping code. No more gratuitous swapping.
proc.h
Fixed the problem that the p_lock flag was not being cleared on a fork.
swap_pager.c, vnode_pager.c
Removal of old vfs_bio cruft to support the past pseudo-coherency. Now the
code doesn't need it anymore.
machdep.c
Changes to better support the parameter values for the merged VM/buffer cache
scheme.
machdep.c, kern_exec.c, vm_glue.c
Implemented a seperate submap for temporary exec string space and another one
to contain process upages. This eliminates all map fragmentation problems
that previously existed.
ffs_inode.c, ufs_inode.c, ufs_readwrite.c
Changes for merged VM/buffer cache. Add "bypass" support for sneaking in on
busy buffers.
Submitted by: John Dyson and David Greenman
1995-01-09 16:06:02 +00:00
|
|
|
*/
|
1999-01-21 08:29:12 +00:00
|
|
|
blk0 = swp_pager_meta_ctl(object, pindex, 0);
|
1999-09-17 05:09:24 +00:00
|
|
|
if (blk0 == SWAPBLK_NONE) {
|
1999-01-21 08:29:12 +00:00
|
|
|
if (before)
|
|
|
|
*before = 0;
|
|
|
|
if (after)
|
|
|
|
*after = 0;
|
|
|
|
return (FALSE);
|
1994-05-25 09:21:21 +00:00
|
|
|
}
|
|
|
|
|
These changes embody the support of the fully coherent merged VM buffer cache,
much higher filesystem I/O performance, and much better paging performance. It
represents the culmination of over 6 months of R&D.
The majority of the merged VM/cache work is by John Dyson.
The following highlights the most significant changes. Additionally, there are
(mostly minor) changes to the various filesystem modules (nfs, msdosfs, etc) to
support the new VM/buffer scheme.
vfs_bio.c:
Significant rewrite of most of vfs_bio to support the merged VM buffer cache
scheme. The scheme is almost fully compatible with the old filesystem
interface. Significant improvement in the number of opportunities for write
clustering.
vfs_cluster.c, vfs_subr.c
Upgrade and performance enhancements in vfs layer code to support merged
VM/buffer cache. Fixup of vfs_cluster to eliminate the bogus pagemove stuff.
vm_object.c:
Yet more improvements in the collapse code. Elimination of some windows that
can cause list corruption.
vm_pageout.c:
Fixed it, it really works better now. Somehow in 2.0, some "enhancements"
broke the code. This code has been reworked from the ground-up.
vm_fault.c, vm_page.c, pmap.c, vm_object.c
Support for small-block filesystems with merged VM/buffer cache scheme.
pmap.c vm_map.c
Dynamic kernel VM size, now we dont have to pre-allocate excessive numbers of
kernel PTs.
vm_glue.c
Much simpler and more effective swapping code. No more gratuitous swapping.
proc.h
Fixed the problem that the p_lock flag was not being cleared on a fork.
swap_pager.c, vnode_pager.c
Removal of old vfs_bio cruft to support the past pseudo-coherency. Now the
code doesn't need it anymore.
machdep.c
Changes to better support the parameter values for the merged VM/buffer cache
scheme.
machdep.c, kern_exec.c, vm_glue.c
Implemented a seperate submap for temporary exec string space and another one
to contain process upages. This eliminates all map fragmentation problems
that previously existed.
ffs_inode.c, ufs_inode.c, ufs_readwrite.c
Changes for merged VM/buffer cache. Add "bypass" support for sneaking in on
busy buffers.
Submitted by: John Dyson and David Greenman
1995-01-09 16:06:02 +00:00
|
|
|
/*
|
1999-01-21 08:29:12 +00:00
|
|
|
* find backwards-looking contiguous good backing store
|
These changes embody the support of the fully coherent merged VM buffer cache,
much higher filesystem I/O performance, and much better paging performance. It
represents the culmination of over 6 months of R&D.
The majority of the merged VM/cache work is by John Dyson.
The following highlights the most significant changes. Additionally, there are
(mostly minor) changes to the various filesystem modules (nfs, msdosfs, etc) to
support the new VM/buffer scheme.
vfs_bio.c:
Significant rewrite of most of vfs_bio to support the merged VM buffer cache
scheme. The scheme is almost fully compatible with the old filesystem
interface. Significant improvement in the number of opportunities for write
clustering.
vfs_cluster.c, vfs_subr.c
Upgrade and performance enhancements in vfs layer code to support merged
VM/buffer cache. Fixup of vfs_cluster to eliminate the bogus pagemove stuff.
vm_object.c:
Yet more improvements in the collapse code. Elimination of some windows that
can cause list corruption.
vm_pageout.c:
Fixed it, it really works better now. Somehow in 2.0, some "enhancements"
broke the code. This code has been reworked from the ground-up.
vm_fault.c, vm_page.c, pmap.c, vm_object.c
Support for small-block filesystems with merged VM/buffer cache scheme.
pmap.c vm_map.c
Dynamic kernel VM size, now we dont have to pre-allocate excessive numbers of
kernel PTs.
vm_glue.c
Much simpler and more effective swapping code. No more gratuitous swapping.
proc.h
Fixed the problem that the p_lock flag was not being cleared on a fork.
swap_pager.c, vnode_pager.c
Removal of old vfs_bio cruft to support the past pseudo-coherency. Now the
code doesn't need it anymore.
machdep.c
Changes to better support the parameter values for the merged VM/buffer cache
scheme.
machdep.c, kern_exec.c, vm_glue.c
Implemented a seperate submap for temporary exec string space and another one
to contain process upages. This eliminates all map fragmentation problems
that previously existed.
ffs_inode.c, ufs_inode.c, ufs_readwrite.c
Changes for merged VM/buffer cache. Add "bypass" support for sneaking in on
busy buffers.
Submitted by: John Dyson and David Greenman
1995-01-09 16:06:02 +00:00
|
|
|
*/
|
1999-01-21 08:29:12 +00:00
|
|
|
if (before != NULL) {
|
2016-08-30 05:56:21 +00:00
|
|
|
for (i = 1; i < SWB_NPAGES; i++) {
|
1999-01-21 08:29:12 +00:00
|
|
|
if (i > pindex)
|
|
|
|
break;
|
|
|
|
blk = swp_pager_meta_ctl(object, pindex - i, 0);
|
|
|
|
if (blk != blk0 - i)
|
|
|
|
break;
|
|
|
|
}
|
2016-08-30 05:56:21 +00:00
|
|
|
*before = i - 1;
|
1999-01-21 08:29:12 +00:00
|
|
|
}
|
These changes embody the support of the fully coherent merged VM buffer cache,
much higher filesystem I/O performance, and much better paging performance. It
represents the culmination of over 6 months of R&D.
The majority of the merged VM/cache work is by John Dyson.
The following highlights the most significant changes. Additionally, there are
(mostly minor) changes to the various filesystem modules (nfs, msdosfs, etc) to
support the new VM/buffer scheme.
vfs_bio.c:
Significant rewrite of most of vfs_bio to support the merged VM buffer cache
scheme. The scheme is almost fully compatible with the old filesystem
interface. Significant improvement in the number of opportunities for write
clustering.
vfs_cluster.c, vfs_subr.c
Upgrade and performance enhancements in vfs layer code to support merged
VM/buffer cache. Fixup of vfs_cluster to eliminate the bogus pagemove stuff.
vm_object.c:
Yet more improvements in the collapse code. Elimination of some windows that
can cause list corruption.
vm_pageout.c:
Fixed it, it really works better now. Somehow in 2.0, some "enhancements"
broke the code. This code has been reworked from the ground-up.
vm_fault.c, vm_page.c, pmap.c, vm_object.c
Support for small-block filesystems with merged VM/buffer cache scheme.
pmap.c vm_map.c
Dynamic kernel VM size, now we dont have to pre-allocate excessive numbers of
kernel PTs.
vm_glue.c
Much simpler and more effective swapping code. No more gratuitous swapping.
proc.h
Fixed the problem that the p_lock flag was not being cleared on a fork.
swap_pager.c, vnode_pager.c
Removal of old vfs_bio cruft to support the past pseudo-coherency. Now the
code doesn't need it anymore.
machdep.c
Changes to better support the parameter values for the merged VM/buffer cache
scheme.
machdep.c, kern_exec.c, vm_glue.c
Implemented a seperate submap for temporary exec string space and another one
to contain process upages. This eliminates all map fragmentation problems
that previously existed.
ffs_inode.c, ufs_inode.c, ufs_readwrite.c
Changes for merged VM/buffer cache. Add "bypass" support for sneaking in on
busy buffers.
Submitted by: John Dyson and David Greenman
1995-01-09 16:06:02 +00:00
|
|
|
|
|
|
|
/*
|
1999-01-21 08:29:12 +00:00
|
|
|
* find forward-looking contiguous good backing store
|
These changes embody the support of the fully coherent merged VM buffer cache,
much higher filesystem I/O performance, and much better paging performance. It
represents the culmination of over 6 months of R&D.
The majority of the merged VM/cache work is by John Dyson.
The following highlights the most significant changes. Additionally, there are
(mostly minor) changes to the various filesystem modules (nfs, msdosfs, etc) to
support the new VM/buffer scheme.
vfs_bio.c:
Significant rewrite of most of vfs_bio to support the merged VM buffer cache
scheme. The scheme is almost fully compatible with the old filesystem
interface. Significant improvement in the number of opportunities for write
clustering.
vfs_cluster.c, vfs_subr.c
Upgrade and performance enhancements in vfs layer code to support merged
VM/buffer cache. Fixup of vfs_cluster to eliminate the bogus pagemove stuff.
vm_object.c:
Yet more improvements in the collapse code. Elimination of some windows that
can cause list corruption.
vm_pageout.c:
Fixed it, it really works better now. Somehow in 2.0, some "enhancements"
broke the code. This code has been reworked from the ground-up.
vm_fault.c, vm_page.c, pmap.c, vm_object.c
Support for small-block filesystems with merged VM/buffer cache scheme.
pmap.c vm_map.c
Dynamic kernel VM size, now we dont have to pre-allocate excessive numbers of
kernel PTs.
vm_glue.c
Much simpler and more effective swapping code. No more gratuitous swapping.
proc.h
Fixed the problem that the p_lock flag was not being cleared on a fork.
swap_pager.c, vnode_pager.c
Removal of old vfs_bio cruft to support the past pseudo-coherency. Now the
code doesn't need it anymore.
machdep.c
Changes to better support the parameter values for the merged VM/buffer cache
scheme.
machdep.c, kern_exec.c, vm_glue.c
Implemented a seperate submap for temporary exec string space and another one
to contain process upages. This eliminates all map fragmentation problems
that previously existed.
ffs_inode.c, ufs_inode.c, ufs_readwrite.c
Changes for merged VM/buffer cache. Add "bypass" support for sneaking in on
busy buffers.
Submitted by: John Dyson and David Greenman
1995-01-09 16:06:02 +00:00
|
|
|
*/
|
1999-01-21 08:29:12 +00:00
|
|
|
if (after != NULL) {
|
2016-08-30 05:56:21 +00:00
|
|
|
for (i = 1; i < SWB_NPAGES; i++) {
|
1999-01-21 08:29:12 +00:00
|
|
|
blk = swp_pager_meta_ctl(object, pindex + i, 0);
|
|
|
|
if (blk != blk0 + i)
|
|
|
|
break;
|
1995-09-04 04:44:26 +00:00
|
|
|
}
|
2016-08-30 05:56:21 +00:00
|
|
|
*after = i - 1;
|
1994-05-25 09:21:21 +00:00
|
|
|
}
|
1999-01-21 08:29:12 +00:00
|
|
|
return (TRUE);
|
1998-02-23 08:22:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-01-21 08:29:12 +00:00
|
|
|
* SWAP_PAGER_PAGE_UNSWAPPED() - remove swap backing store related to page
|
|
|
|
*
|
|
|
|
* This removes any associated swap backing store, whether valid or
|
2012-09-05 12:24:50 +00:00
|
|
|
* not, from the page.
|
1999-01-21 08:29:12 +00:00
|
|
|
*
|
|
|
|
* This routine is typically called when a page is made dirty, at
|
|
|
|
* which point any associated swap can be freed. MADV_FREE also
|
|
|
|
* calls us in a special-case situation
|
|
|
|
*
|
|
|
|
* NOTE!!! If the page is clean and the swap was valid, the caller
|
|
|
|
* should make the page dirty before calling this routine. This routine
|
|
|
|
* does NOT change the m->dirty status of the page. Also: MADV_FREE
|
|
|
|
* depends on it.
|
|
|
|
*
|
2011-08-22 20:44:18 +00:00
|
|
|
* This routine may not sleep.
|
2013-05-28 22:07:23 +00:00
|
|
|
*
|
|
|
|
* The object containing the page must be locked.
|
1998-02-23 08:22:48 +00:00
|
|
|
*/
|
1994-05-25 09:21:21 +00:00
|
|
|
static void
|
2003-08-30 08:32:42 +00:00
|
|
|
swap_pager_unswapped(vm_page_t m)
|
1994-05-25 09:21:21 +00:00
|
|
|
{
|
2003-08-30 08:32:42 +00:00
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
swp_pager_meta_ctl(m->object, m->pindex, SWM_FREE);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2016-08-30 05:56:21 +00:00
|
|
|
* swap_pager_getpages() - bring pages in from swap
|
1999-01-21 08:29:12 +00:00
|
|
|
*
|
2016-08-30 05:56:21 +00:00
|
|
|
* Attempt to page in the pages in array "m" of length "count". The caller
|
|
|
|
* may optionally specify that additional pages preceding and succeeding
|
|
|
|
* the specified range be paged in. The number of such pages is returned
|
|
|
|
* in the "rbehind" and "rahead" parameters, and they will be in the
|
|
|
|
* inactive queue upon return.
|
1999-01-21 08:29:12 +00:00
|
|
|
*
|
2016-08-30 05:56:21 +00:00
|
|
|
* The pages in "m" must be busied and will remain busied upon return.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
1995-12-14 09:55:16 +00:00
|
|
|
static int
|
A change to KPI of vm_pager_get_pages() and underlying VOP_GETPAGES().
o With new KPI consumers can request contiguous ranges of pages, and
unlike before, all pages will be kept busied on return, like it was
done before with the 'reqpage' only. Now the reqpage goes away. With
new interface it is easier to implement code protected from race
conditions.
Such arrayed requests for now should be preceeded by a call to
vm_pager_haspage() to make sure that request is possible. This
could be improved later, making vm_pager_haspage() obsolete.
Strenghtening the promises on the business of the array of pages
allows us to remove such hacks as swp_pager_free_nrpage() and
vm_pager_free_nonreq().
o New KPI accepts two integer pointers that may optionally point at
values for read ahead and read behind, that a pager may do, if it
can. These pages are completely owned by pager, and not controlled
by the caller.
This shifts the UFS-specific readahead logic from vm_fault.c, which
should be file system agnostic, into vnode_pager.c. It also removes
one VOP_BMAP() request per hard fault.
Discussed with: kib, alc, jeff, scottl
Sponsored by: Nginx, Inc.
Sponsored by: Netflix
2015-12-16 21:30:45 +00:00
|
|
|
swap_pager_getpages(vm_object_t object, vm_page_t *m, int count, int *rbehind,
|
|
|
|
int *rahead)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
1999-01-21 08:29:12 +00:00
|
|
|
struct buf *bp;
|
2016-08-30 05:56:21 +00:00
|
|
|
vm_page_t mpred, msucc, p;
|
|
|
|
vm_pindex_t pindex;
|
1999-01-21 08:29:12 +00:00
|
|
|
daddr_t blk;
|
2016-09-04 00:25:49 +00:00
|
|
|
int i, j, maxahead, maxbehind, reqcount, shift;
|
1999-01-21 08:29:12 +00:00
|
|
|
|
2016-08-30 05:56:21 +00:00
|
|
|
reqcount = count;
|
1999-01-21 08:29:12 +00:00
|
|
|
|
2016-08-30 05:56:21 +00:00
|
|
|
VM_OBJECT_WUNLOCK(object);
|
|
|
|
bp = getpbuf(&nsw_rcount);
|
|
|
|
VM_OBJECT_WLOCK(object);
|
1999-01-21 08:29:12 +00:00
|
|
|
|
2016-09-04 00:25:49 +00:00
|
|
|
if (!swap_pager_haspage(object, m[0]->pindex, &maxbehind, &maxahead)) {
|
2016-08-30 05:56:21 +00:00
|
|
|
relpbuf(bp, &nsw_rcount);
|
|
|
|
return (VM_PAGER_FAIL);
|
|
|
|
}
|
A change to KPI of vm_pager_get_pages() and underlying VOP_GETPAGES().
o With new KPI consumers can request contiguous ranges of pages, and
unlike before, all pages will be kept busied on return, like it was
done before with the 'reqpage' only. Now the reqpage goes away. With
new interface it is easier to implement code protected from race
conditions.
Such arrayed requests for now should be preceeded by a call to
vm_pager_haspage() to make sure that request is possible. This
could be improved later, making vm_pager_haspage() obsolete.
Strenghtening the promises on the business of the array of pages
allows us to remove such hacks as swp_pager_free_nrpage() and
vm_pager_free_nonreq().
o New KPI accepts two integer pointers that may optionally point at
values for read ahead and read behind, that a pager may do, if it
can. These pages are completely owned by pager, and not controlled
by the caller.
This shifts the UFS-specific readahead logic from vm_fault.c, which
should be file system agnostic, into vnode_pager.c. It also removes
one VOP_BMAP() request per hard fault.
Discussed with: kib, alc, jeff, scottl
Sponsored by: Nginx, Inc.
Sponsored by: Netflix
2015-12-16 21:30:45 +00:00
|
|
|
|
2003-06-13 03:02:28 +00:00
|
|
|
/*
|
2016-08-30 05:56:21 +00:00
|
|
|
* Clip the readahead and readbehind ranges to exclude resident pages.
|
2003-06-13 03:02:28 +00:00
|
|
|
*/
|
2016-08-30 05:56:21 +00:00
|
|
|
if (rahead != NULL) {
|
2016-09-04 00:25:49 +00:00
|
|
|
KASSERT(reqcount - 1 <= maxahead,
|
2016-08-30 05:56:21 +00:00
|
|
|
("page count %d extends beyond swap block", reqcount));
|
2016-09-04 00:25:49 +00:00
|
|
|
*rahead = imin(*rahead, maxahead - (reqcount - 1));
|
2016-08-30 05:56:21 +00:00
|
|
|
pindex = m[reqcount - 1]->pindex;
|
|
|
|
msucc = TAILQ_NEXT(m[reqcount - 1], listq);
|
|
|
|
if (msucc != NULL && msucc->pindex - pindex - 1 < *rahead)
|
|
|
|
*rahead = msucc->pindex - pindex - 1;
|
|
|
|
}
|
|
|
|
if (rbehind != NULL) {
|
2016-09-04 00:25:49 +00:00
|
|
|
*rbehind = imin(*rbehind, maxbehind);
|
2016-08-30 05:56:21 +00:00
|
|
|
pindex = m[0]->pindex;
|
|
|
|
mpred = TAILQ_PREV(m[0], pglist, listq);
|
|
|
|
if (mpred != NULL && pindex - mpred->pindex - 1 < *rbehind)
|
|
|
|
*rbehind = pindex - mpred->pindex - 1;
|
|
|
|
}
|
|
|
|
|
1998-02-23 08:22:48 +00:00
|
|
|
/*
|
2016-08-30 05:56:21 +00:00
|
|
|
* Allocate readahead and readbehind pages.
|
1998-02-23 08:22:48 +00:00
|
|
|
*/
|
2016-08-30 05:56:21 +00:00
|
|
|
shift = rbehind != NULL ? *rbehind : 0;
|
|
|
|
if (shift != 0) {
|
|
|
|
for (i = 1; i <= shift; i++) {
|
|
|
|
p = vm_page_alloc(object, m[0]->pindex - i,
|
2016-11-15 18:22:50 +00:00
|
|
|
VM_ALLOC_NORMAL);
|
2016-08-30 05:56:21 +00:00
|
|
|
if (p == NULL) {
|
|
|
|
/* Shift allocated pages to the left. */
|
|
|
|
for (j = 0; j < i - 1; j++)
|
|
|
|
bp->b_pages[j] =
|
|
|
|
bp->b_pages[j + shift - i + 1];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
bp->b_pages[shift - i] = p;
|
|
|
|
}
|
|
|
|
shift = i - 1;
|
|
|
|
*rbehind = shift;
|
|
|
|
}
|
|
|
|
for (i = 0; i < reqcount; i++)
|
|
|
|
bp->b_pages[i + shift] = m[i];
|
|
|
|
if (rahead != NULL) {
|
|
|
|
for (i = 0; i < *rahead; i++) {
|
|
|
|
p = vm_page_alloc(object,
|
2016-11-15 18:22:50 +00:00
|
|
|
m[reqcount - 1]->pindex + i + 1, VM_ALLOC_NORMAL);
|
2016-08-30 05:56:21 +00:00
|
|
|
if (p == NULL)
|
|
|
|
break;
|
|
|
|
bp->b_pages[shift + reqcount + i] = p;
|
|
|
|
}
|
|
|
|
*rahead = i;
|
|
|
|
}
|
|
|
|
if (rbehind != NULL)
|
|
|
|
count += *rbehind;
|
|
|
|
if (rahead != NULL)
|
|
|
|
count += *rahead;
|
|
|
|
|
|
|
|
vm_object_pip_add(object, count);
|
1994-05-25 09:21:21 +00:00
|
|
|
|
2016-08-30 05:56:21 +00:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
bp->b_pages[i]->oflags |= VPO_SWAPINPROG;
|
|
|
|
|
|
|
|
pindex = bp->b_pages[0]->pindex;
|
|
|
|
blk = swp_pager_meta_ctl(object, pindex, 0);
|
|
|
|
KASSERT(blk != SWAPBLK_NONE,
|
|
|
|
("no swap blocking containing %p(%jx)", object, (uintmax_t)pindex));
|
|
|
|
|
|
|
|
VM_OBJECT_WUNLOCK(object);
|
|
|
|
|
|
|
|
bp->b_flags |= B_PAGING;
|
2000-03-20 10:44:49 +00:00
|
|
|
bp->b_iocmd = BIO_READ;
|
1999-01-21 08:29:12 +00:00
|
|
|
bp->b_iodone = swp_pager_async_iodone;
|
2002-02-27 19:18:10 +00:00
|
|
|
bp->b_rcred = crhold(thread0.td_ucred);
|
|
|
|
bp->b_wcred = crhold(thread0.td_ucred);
|
A change to KPI of vm_pager_get_pages() and underlying VOP_GETPAGES().
o With new KPI consumers can request contiguous ranges of pages, and
unlike before, all pages will be kept busied on return, like it was
done before with the 'reqpage' only. Now the reqpage goes away. With
new interface it is easier to implement code protected from race
conditions.
Such arrayed requests for now should be preceeded by a call to
vm_pager_haspage() to make sure that request is possible. This
could be improved later, making vm_pager_haspage() obsolete.
Strenghtening the promises on the business of the array of pages
allows us to remove such hacks as swp_pager_free_nrpage() and
vm_pager_free_nonreq().
o New KPI accepts two integer pointers that may optionally point at
values for read ahead and read behind, that a pager may do, if it
can. These pages are completely owned by pager, and not controlled
by the caller.
This shifts the UFS-specific readahead logic from vm_fault.c, which
should be file system agnostic, into vnode_pager.c. It also removes
one VOP_BMAP() request per hard fault.
Discussed with: kib, alc, jeff, scottl
Sponsored by: Nginx, Inc.
Sponsored by: Netflix
2015-12-16 21:30:45 +00:00
|
|
|
bp->b_blkno = blk;
|
|
|
|
bp->b_bcount = PAGE_SIZE * count;
|
|
|
|
bp->b_bufsize = PAGE_SIZE * count;
|
|
|
|
bp->b_npages = count;
|
2016-08-30 05:56:21 +00:00
|
|
|
bp->b_pgbefore = rbehind != NULL ? *rbehind : 0;
|
|
|
|
bp->b_pgafter = rahead != NULL ? *rahead : 0;
|
1994-05-25 09:21:21 +00:00
|
|
|
|
- Remove 'struct vmmeter' from 'struct pcpu', leaving only global vmmeter
in place. To do per-cpu stats, convert all fields that previously were
maintained in the vmmeters that sit in pcpus to counter(9).
- Since some vmmeter stats may be touched at very early stages of boot,
before we have set up UMA and we can do counter_u64_alloc(), provide an
early counter mechanism:
o Leave one spare uint64_t in struct pcpu, named pc_early_dummy_counter.
o Point counter(9) fields of vmmeter to pcpu[0].pc_early_dummy_counter,
so that at early stages of boot, before counters are allocated we already
point to a counter that can be safely written to.
o For sparc64 that required a whole dummy pcpu[MAXCPU] array.
Further related changes:
- Don't include vmmeter.h into pcpu.h.
- vm.stats.vm.v_swappgsout and vm.stats.vm.v_swappgsin changed to 64-bit,
to match kernel representation.
- struct vmmeter hidden under _KERNEL, and only vmstat(1) is an exclusion.
This is based on benno@'s 4-year old patch:
https://lists.freebsd.org/pipermail/freebsd-arch/2013-July/014471.html
Reviewed by: kib, gallatin, marius, lidl
Differential Revision: https://reviews.freebsd.org/D10156
2017-04-17 17:34:47 +00:00
|
|
|
VM_CNT_INC(v_swapin);
|
|
|
|
VM_CNT_ADD(v_swappgsin, count);
|
1999-01-21 08:29:12 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
1999-01-21 08:29:12 +00:00
|
|
|
* perform the I/O. NOTE!!! bp cannot be considered valid after
|
|
|
|
* this point because we automatically release it on completion.
|
|
|
|
* Instead, we look at the one page we are interested in which we
|
|
|
|
* still hold a lock on even through the I/O completion.
|
|
|
|
*
|
|
|
|
* The other pages in our m[] array are also released on completion,
|
|
|
|
* so we cannot assume they are valid anymore either.
|
|
|
|
*
|
2003-08-06 06:53:31 +00:00
|
|
|
* NOTE: b_blkno is destroyed by the call to swapdev_strategy
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
1999-06-27 22:08:38 +00:00
|
|
|
BUF_KERNPROC(bp);
|
2003-08-30 09:42:00 +00:00
|
|
|
swp_pager_strategy(bp);
|
1994-05-25 09:21:21 +00:00
|
|
|
|
|
|
|
/*
|
2016-08-30 05:56:21 +00:00
|
|
|
* Wait for the pages we want to complete. VPO_SWAPINPROG is always
|
1999-01-21 08:29:12 +00:00
|
|
|
* cleared on completion. If an I/O error occurs, SWAPBLK_NONE
|
2016-08-30 05:56:21 +00:00
|
|
|
* is set in the metadata for each page in the request.
|
1994-05-25 09:21:21 +00:00
|
|
|
*/
|
2013-03-09 02:32:23 +00:00
|
|
|
VM_OBJECT_WLOCK(object);
|
A change to KPI of vm_pager_get_pages() and underlying VOP_GETPAGES().
o With new KPI consumers can request contiguous ranges of pages, and
unlike before, all pages will be kept busied on return, like it was
done before with the 'reqpage' only. Now the reqpage goes away. With
new interface it is easier to implement code protected from race
conditions.
Such arrayed requests for now should be preceeded by a call to
vm_pager_haspage() to make sure that request is possible. This
could be improved later, making vm_pager_haspage() obsolete.
Strenghtening the promises on the business of the array of pages
allows us to remove such hacks as swp_pager_free_nrpage() and
vm_pager_free_nonreq().
o New KPI accepts two integer pointers that may optionally point at
values for read ahead and read behind, that a pager may do, if it
can. These pages are completely owned by pager, and not controlled
by the caller.
This shifts the UFS-specific readahead logic from vm_fault.c, which
should be file system agnostic, into vnode_pager.c. It also removes
one VOP_BMAP() request per hard fault.
Discussed with: kib, alc, jeff, scottl
Sponsored by: Nginx, Inc.
Sponsored by: Netflix
2015-12-16 21:30:45 +00:00
|
|
|
while ((m[0]->oflags & VPO_SWAPINPROG) != 0) {
|
|
|
|
m[0]->oflags |= VPO_SWAPSLEEP;
|
- Remove 'struct vmmeter' from 'struct pcpu', leaving only global vmmeter
in place. To do per-cpu stats, convert all fields that previously were
maintained in the vmmeters that sit in pcpus to counter(9).
- Since some vmmeter stats may be touched at very early stages of boot,
before we have set up UMA and we can do counter_u64_alloc(), provide an
early counter mechanism:
o Leave one spare uint64_t in struct pcpu, named pc_early_dummy_counter.
o Point counter(9) fields of vmmeter to pcpu[0].pc_early_dummy_counter,
so that at early stages of boot, before counters are allocated we already
point to a counter that can be safely written to.
o For sparc64 that required a whole dummy pcpu[MAXCPU] array.
Further related changes:
- Don't include vmmeter.h into pcpu.h.
- vm.stats.vm.v_swappgsout and vm.stats.vm.v_swappgsin changed to 64-bit,
to match kernel representation.
- struct vmmeter hidden under _KERNEL, and only vmstat(1) is an exclusion.
This is based on benno@'s 4-year old patch:
https://lists.freebsd.org/pipermail/freebsd-arch/2013-July/014471.html
Reviewed by: kib, gallatin, marius, lidl
Differential Revision: https://reviews.freebsd.org/D10156
2017-04-17 17:34:47 +00:00
|
|
|
VM_CNT_INC(v_intrans);
|
2013-08-09 11:11:11 +00:00
|
|
|
if (VM_OBJECT_SLEEP(object, &object->paging_in_progress, PSWP,
|
|
|
|
"swread", hz * 20)) {
|
2004-07-06 02:27:30 +00:00
|
|
|
printf(
|
2004-11-04 07:59:57 +00:00
|
|
|
"swap_pager: indefinite wait buffer: bufobj: %p, blkno: %jd, size: %ld\n",
|
|
|
|
bp->b_bufobj, (intmax_t)bp->b_blkno, bp->b_bcount);
|
1996-06-10 04:58:48 +00:00
|
|
|
}
|
1994-05-25 09:21:21 +00:00
|
|
|
}
|
|
|
|
|
1998-02-23 08:22:48 +00:00
|
|
|
/*
|
A change to KPI of vm_pager_get_pages() and underlying VOP_GETPAGES().
o With new KPI consumers can request contiguous ranges of pages, and
unlike before, all pages will be kept busied on return, like it was
done before with the 'reqpage' only. Now the reqpage goes away. With
new interface it is easier to implement code protected from race
conditions.
Such arrayed requests for now should be preceeded by a call to
vm_pager_haspage() to make sure that request is possible. This
could be improved later, making vm_pager_haspage() obsolete.
Strenghtening the promises on the business of the array of pages
allows us to remove such hacks as swp_pager_free_nrpage() and
vm_pager_free_nonreq().
o New KPI accepts two integer pointers that may optionally point at
values for read ahead and read behind, that a pager may do, if it
can. These pages are completely owned by pager, and not controlled
by the caller.
This shifts the UFS-specific readahead logic from vm_fault.c, which
should be file system agnostic, into vnode_pager.c. It also removes
one VOP_BMAP() request per hard fault.
Discussed with: kib, alc, jeff, scottl
Sponsored by: Nginx, Inc.
Sponsored by: Netflix
2015-12-16 21:30:45 +00:00
|
|
|
* If we had an unrecoverable read error pages will not be valid.
|
1998-02-23 08:22:48 +00:00
|
|
|
*/
|
2016-08-30 05:56:21 +00:00
|
|
|
for (i = 0; i < reqcount; i++)
|
A change to KPI of vm_pager_get_pages() and underlying VOP_GETPAGES().
o With new KPI consumers can request contiguous ranges of pages, and
unlike before, all pages will be kept busied on return, like it was
done before with the 'reqpage' only. Now the reqpage goes away. With
new interface it is easier to implement code protected from race
conditions.
Such arrayed requests for now should be preceeded by a call to
vm_pager_haspage() to make sure that request is possible. This
could be improved later, making vm_pager_haspage() obsolete.
Strenghtening the promises on the business of the array of pages
allows us to remove such hacks as swp_pager_free_nrpage() and
vm_pager_free_nonreq().
o New KPI accepts two integer pointers that may optionally point at
values for read ahead and read behind, that a pager may do, if it
can. These pages are completely owned by pager, and not controlled
by the caller.
This shifts the UFS-specific readahead logic from vm_fault.c, which
should be file system agnostic, into vnode_pager.c. It also removes
one VOP_BMAP() request per hard fault.
Discussed with: kib, alc, jeff, scottl
Sponsored by: Nginx, Inc.
Sponsored by: Netflix
2015-12-16 21:30:45 +00:00
|
|
|
if (m[i]->valid != VM_PAGE_BITS_ALL)
|
|
|
|
return (VM_PAGER_ERROR);
|
|
|
|
|
|
|
|
return (VM_PAGER_OK);
|
1999-01-21 08:29:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A final note: in a low swap situation, we cannot deallocate swap
|
|
|
|
* and mark a page dirty here because the caller is likely to mark
|
2012-09-05 12:24:50 +00:00
|
|
|
* the page clean when we return, causing the page to possibly revert
|
1999-01-21 08:29:12 +00:00
|
|
|
* to all-zero's later.
|
|
|
|
*/
|
1994-05-25 09:21:21 +00:00
|
|
|
}
|
|
|
|
|
2014-11-23 12:01:52 +00:00
|
|
|
/*
|
|
|
|
* swap_pager_getpages_async():
|
|
|
|
*
|
|
|
|
* Right now this is emulation of asynchronous operation on top of
|
|
|
|
* swap_pager_getpages().
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
swap_pager_getpages_async(vm_object_t object, vm_page_t *m, int count,
|
A change to KPI of vm_pager_get_pages() and underlying VOP_GETPAGES().
o With new KPI consumers can request contiguous ranges of pages, and
unlike before, all pages will be kept busied on return, like it was
done before with the 'reqpage' only. Now the reqpage goes away. With
new interface it is easier to implement code protected from race
conditions.
Such arrayed requests for now should be preceeded by a call to
vm_pager_haspage() to make sure that request is possible. This
could be improved later, making vm_pager_haspage() obsolete.
Strenghtening the promises on the business of the array of pages
allows us to remove such hacks as swp_pager_free_nrpage() and
vm_pager_free_nonreq().
o New KPI accepts two integer pointers that may optionally point at
values for read ahead and read behind, that a pager may do, if it
can. These pages are completely owned by pager, and not controlled
by the caller.
This shifts the UFS-specific readahead logic from vm_fault.c, which
should be file system agnostic, into vnode_pager.c. It also removes
one VOP_BMAP() request per hard fault.
Discussed with: kib, alc, jeff, scottl
Sponsored by: Nginx, Inc.
Sponsored by: Netflix
2015-12-16 21:30:45 +00:00
|
|
|
int *rbehind, int *rahead, pgo_getpages_iodone_t iodone, void *arg)
|
2014-11-23 12:01:52 +00:00
|
|
|
{
|
|
|
|
int r, error;
|
|
|
|
|
A change to KPI of vm_pager_get_pages() and underlying VOP_GETPAGES().
o With new KPI consumers can request contiguous ranges of pages, and
unlike before, all pages will be kept busied on return, like it was
done before with the 'reqpage' only. Now the reqpage goes away. With
new interface it is easier to implement code protected from race
conditions.
Such arrayed requests for now should be preceeded by a call to
vm_pager_haspage() to make sure that request is possible. This
could be improved later, making vm_pager_haspage() obsolete.
Strenghtening the promises on the business of the array of pages
allows us to remove such hacks as swp_pager_free_nrpage() and
vm_pager_free_nonreq().
o New KPI accepts two integer pointers that may optionally point at
values for read ahead and read behind, that a pager may do, if it
can. These pages are completely owned by pager, and not controlled
by the caller.
This shifts the UFS-specific readahead logic from vm_fault.c, which
should be file system agnostic, into vnode_pager.c. It also removes
one VOP_BMAP() request per hard fault.
Discussed with: kib, alc, jeff, scottl
Sponsored by: Nginx, Inc.
Sponsored by: Netflix
2015-12-16 21:30:45 +00:00
|
|
|
r = swap_pager_getpages(object, m, count, rbehind, rahead);
|
2014-11-23 12:01:52 +00:00
|
|
|
VM_OBJECT_WUNLOCK(object);
|
|
|
|
switch (r) {
|
|
|
|
case VM_PAGER_OK:
|
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
case VM_PAGER_ERROR:
|
|
|
|
error = EIO;
|
|
|
|
break;
|
|
|
|
case VM_PAGER_FAIL:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
default:
|
2014-11-23 18:32:21 +00:00
|
|
|
panic("unhandled swap_pager_getpages() error %d", r);
|
2014-11-23 12:01:52 +00:00
|
|
|
}
|
|
|
|
(iodone)(arg, m, count, error);
|
|
|
|
VM_OBJECT_WLOCK(object);
|
|
|
|
|
|
|
|
return (r);
|
|
|
|
}
|
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
2012-09-05 12:24:50 +00:00
|
|
|
* swap_pager_putpages:
|
1999-01-21 08:29:12 +00:00
|
|
|
*
|
|
|
|
* Assign swap (if necessary) and initiate I/O on the specified pages.
|
|
|
|
*
|
|
|
|
* We support both OBJT_DEFAULT and OBJT_SWAP objects. DEFAULT objects
|
|
|
|
* are automatically converted to SWAP objects.
|
|
|
|
*
|
2012-09-05 12:24:50 +00:00
|
|
|
* In a low memory situation we may block in VOP_STRATEGY(), but the new
|
|
|
|
* vm_page reservation system coupled with properly written VFS devices
|
1999-01-21 08:29:12 +00:00
|
|
|
* should ensure that no low-memory deadlock occurs. This is an area
|
|
|
|
* which needs work.
|
|
|
|
*
|
|
|
|
* The parent has N vm_object_pip_add() references prior to
|
|
|
|
* calling us and will remove references for rtvals[] that are
|
|
|
|
* not set to VM_PAGER_PEND. We need to remove the rest on I/O
|
|
|
|
* completion.
|
|
|
|
*
|
|
|
|
* The parent has soft-busy'd the pages it passes us and will unbusy
|
|
|
|
* those whos rtvals[] entry is not set to VM_PAGER_PEND on return.
|
|
|
|
* We need to unbusy the rest on I/O completion.
|
|
|
|
*/
|
2015-10-05 21:29:17 +00:00
|
|
|
static void
|
2003-08-30 08:32:42 +00:00
|
|
|
swap_pager_putpages(vm_object_t object, vm_page_t *m, int count,
|
2014-11-04 19:56:04 +00:00
|
|
|
int flags, int *rtvals)
|
1994-05-25 09:21:21 +00:00
|
|
|
{
|
2014-11-04 19:56:04 +00:00
|
|
|
int i, n;
|
|
|
|
boolean_t sync;
|
1999-01-21 08:29:12 +00:00
|
|
|
|
|
|
|
if (count && m[0]->object != object) {
|
2012-09-05 12:24:50 +00:00
|
|
|
panic("swap_pager_putpages: object mismatch %p/%p",
|
|
|
|
object,
|
1999-01-21 08:29:12 +00:00
|
|
|
m[0]->object
|
|
|
|
);
|
|
|
|
}
|
2003-10-25 23:42:17 +00:00
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
|
|
|
* Step 1
|
|
|
|
*
|
|
|
|
* Turn object into OBJT_SWAP
|
|
|
|
* check for bogus sysops
|
|
|
|
* force sync if not pageout process
|
|
|
|
*/
|
1999-09-17 05:09:24 +00:00
|
|
|
if (object->type != OBJT_SWAP)
|
|
|
|
swp_pager_meta_build(object, 0, SWAPBLK_NONE);
|
2013-03-09 02:32:23 +00:00
|
|
|
VM_OBJECT_WUNLOCK(object);
|
1998-02-23 08:22:48 +00:00
|
|
|
|
2014-11-04 19:56:04 +00:00
|
|
|
n = 0;
|
1998-02-23 08:22:48 +00:00
|
|
|
if (curproc != pageproc)
|
|
|
|
sync = TRUE;
|
2014-11-04 19:56:04 +00:00
|
|
|
else
|
|
|
|
sync = (flags & VM_PAGER_PUT_SYNC) != 0;
|
1994-05-25 09:21:21 +00:00
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
|
|
|
* Step 2
|
|
|
|
*
|
|
|
|
* Assign swap blocks and issue I/O. We reallocate swap on the fly.
|
|
|
|
* The page is left dirty until the pageout operation completes
|
|
|
|
* successfully.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < count; i += n) {
|
|
|
|
int j;
|
|
|
|
struct buf *bp;
|
|
|
|
daddr_t blk;
|
1994-05-25 09:21:21 +00:00
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
|
|
|
* Maximum I/O size is limited by a number of factors.
|
|
|
|
*/
|
|
|
|
n = min(BLIST_MAX_ALLOC, count - i);
|
1999-02-18 19:57:33 +00:00
|
|
|
n = min(n, nsw_cluster_max);
|
1994-05-25 09:21:21 +00:00
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
|
|
|
* Get biggest block of swap we can. If we fail, fall
|
|
|
|
* back and try to allocate a smaller block. Don't go
|
|
|
|
* overboard trying to allocate space if it would overly
|
|
|
|
* fragment swap.
|
|
|
|
*/
|
|
|
|
while (
|
|
|
|
(blk = swp_pager_getswapspace(n)) == SWAPBLK_NONE &&
|
|
|
|
n > 4
|
|
|
|
) {
|
|
|
|
n >>= 1;
|
|
|
|
}
|
|
|
|
if (blk == SWAPBLK_NONE) {
|
1999-09-17 05:09:24 +00:00
|
|
|
for (j = 0; j < n; ++j)
|
1999-01-21 08:29:12 +00:00
|
|
|
rtvals[i+j] = VM_PAGER_FAIL;
|
|
|
|
continue;
|
1994-05-25 09:21:21 +00:00
|
|
|
}
|
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
|
|
|
* All I/O parameters have been satisfied, build the I/O
|
|
|
|
* request and assign the swap space.
|
|
|
|
*/
|
1999-02-18 19:57:33 +00:00
|
|
|
if (sync == TRUE) {
|
|
|
|
bp = getpbuf(&nsw_wcount_sync);
|
|
|
|
} else {
|
|
|
|
bp = getpbuf(&nsw_wcount_async);
|
2000-03-20 10:44:49 +00:00
|
|
|
bp->b_flags = B_ASYNC;
|
1999-02-18 19:57:33 +00:00
|
|
|
}
|
2003-08-06 09:22:47 +00:00
|
|
|
bp->b_flags |= B_PAGING;
|
2000-03-22 08:40:13 +00:00
|
|
|
bp->b_iocmd = BIO_WRITE;
|
1998-02-03 00:50:36 +00:00
|
|
|
|
2002-02-27 19:18:10 +00:00
|
|
|
bp->b_rcred = crhold(thread0.td_ucred);
|
|
|
|
bp->b_wcred = crhold(thread0.td_ucred);
|
1999-01-21 08:29:12 +00:00
|
|
|
bp->b_bcount = PAGE_SIZE * n;
|
|
|
|
bp->b_bufsize = PAGE_SIZE * n;
|
|
|
|
bp->b_blkno = blk;
|
1998-02-03 00:50:36 +00:00
|
|
|
|
2013-03-09 02:32:23 +00:00
|
|
|
VM_OBJECT_WLOCK(object);
|
1999-01-21 08:29:12 +00:00
|
|
|
for (j = 0; j < n; ++j) {
|
|
|
|
vm_page_t mreq = m[i+j];
|
1994-05-25 09:21:21 +00:00
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
swp_pager_meta_build(
|
2012-09-05 12:24:50 +00:00
|
|
|
mreq->object,
|
1999-01-21 08:29:12 +00:00
|
|
|
mreq->pindex,
|
1999-09-17 05:09:24 +00:00
|
|
|
blk + j
|
1999-01-21 08:29:12 +00:00
|
|
|
);
|
1999-01-24 06:04:52 +00:00
|
|
|
vm_page_dirty(mreq);
|
2006-08-09 17:43:27 +00:00
|
|
|
mreq->oflags |= VPO_SWAPINPROG;
|
1999-01-21 08:29:12 +00:00
|
|
|
bp->b_pages[j] = mreq;
|
1994-05-25 09:21:21 +00:00
|
|
|
}
|
2013-03-09 02:32:23 +00:00
|
|
|
VM_OBJECT_WUNLOCK(object);
|
1999-01-21 08:29:12 +00:00
|
|
|
bp->b_npages = n;
|
1999-03-14 09:20:01 +00:00
|
|
|
/*
|
|
|
|
* Must set dirty range for NFS to work.
|
|
|
|
*/
|
|
|
|
bp->b_dirtyoff = 0;
|
|
|
|
bp->b_dirtyend = bp->b_bcount;
|
1994-08-29 06:23:19 +00:00
|
|
|
|
- Remove 'struct vmmeter' from 'struct pcpu', leaving only global vmmeter
in place. To do per-cpu stats, convert all fields that previously were
maintained in the vmmeters that sit in pcpus to counter(9).
- Since some vmmeter stats may be touched at very early stages of boot,
before we have set up UMA and we can do counter_u64_alloc(), provide an
early counter mechanism:
o Leave one spare uint64_t in struct pcpu, named pc_early_dummy_counter.
o Point counter(9) fields of vmmeter to pcpu[0].pc_early_dummy_counter,
so that at early stages of boot, before counters are allocated we already
point to a counter that can be safely written to.
o For sparc64 that required a whole dummy pcpu[MAXCPU] array.
Further related changes:
- Don't include vmmeter.h into pcpu.h.
- vm.stats.vm.v_swappgsout and vm.stats.vm.v_swappgsin changed to 64-bit,
to match kernel representation.
- struct vmmeter hidden under _KERNEL, and only vmstat(1) is an exclusion.
This is based on benno@'s 4-year old patch:
https://lists.freebsd.org/pipermail/freebsd-arch/2013-July/014471.html
Reviewed by: kib, gallatin, marius, lidl
Differential Revision: https://reviews.freebsd.org/D10156
2017-04-17 17:34:47 +00:00
|
|
|
VM_CNT_INC(v_swapout);
|
|
|
|
VM_CNT_ADD(v_swappgsout, bp->b_npages);
|
1994-05-25 09:21:21 +00:00
|
|
|
|
2015-08-21 17:00:39 +00:00
|
|
|
/*
|
|
|
|
* We unconditionally set rtvals[] to VM_PAGER_PEND so that we
|
|
|
|
* can call the async completion routine at the end of a
|
|
|
|
* synchronous I/O operation. Otherwise, our caller would
|
|
|
|
* perform duplicate unbusy and wakeup operations on the page
|
|
|
|
* and object, respectively.
|
|
|
|
*/
|
|
|
|
for (j = 0; j < n; j++)
|
|
|
|
rtvals[i + j] = VM_PAGER_PEND;
|
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
|
|
|
* asynchronous
|
|
|
|
*
|
2003-08-06 06:53:31 +00:00
|
|
|
* NOTE: b_blkno is destroyed by the call to swapdev_strategy
|
1999-01-21 08:29:12 +00:00
|
|
|
*/
|
|
|
|
if (sync == FALSE) {
|
|
|
|
bp->b_iodone = swp_pager_async_iodone;
|
1999-06-26 02:47:16 +00:00
|
|
|
BUF_KERNPROC(bp);
|
2003-08-30 09:42:00 +00:00
|
|
|
swp_pager_strategy(bp);
|
1999-01-21 08:29:12 +00:00
|
|
|
continue;
|
|
|
|
}
|
1994-05-25 09:21:21 +00:00
|
|
|
|
|
|
|
/*
|
1999-01-21 08:29:12 +00:00
|
|
|
* synchronous
|
|
|
|
*
|
2003-08-06 06:53:31 +00:00
|
|
|
* NOTE: b_blkno is destroyed by the call to swapdev_strategy
|
1994-05-25 09:21:21 +00:00
|
|
|
*/
|
2004-02-23 03:15:13 +00:00
|
|
|
bp->b_iodone = bdone;
|
2003-08-30 09:42:00 +00:00
|
|
|
swp_pager_strategy(bp);
|
1999-01-21 08:29:12 +00:00
|
|
|
|
1994-05-25 09:21:21 +00:00
|
|
|
/*
|
2015-08-21 17:00:39 +00:00
|
|
|
* Wait for the sync I/O to complete.
|
1994-05-25 09:21:21 +00:00
|
|
|
*/
|
2004-02-23 03:15:13 +00:00
|
|
|
bwait(bp, PVM, "swwrt");
|
2015-08-21 17:00:39 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
1999-01-21 08:29:12 +00:00
|
|
|
* Now that we are through with the bp, we can call the
|
|
|
|
* normal async completion, which frees everything up.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
1999-01-21 08:29:12 +00:00
|
|
|
swp_pager_async_iodone(bp);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
2013-03-09 02:32:23 +00:00
|
|
|
VM_OBJECT_WLOCK(object);
|
1999-01-21 08:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* swp_pager_async_iodone:
|
|
|
|
*
|
|
|
|
* Completion routine for asynchronous reads and writes from/to swap.
|
|
|
|
* Also called manually by synchronous code to finish up a bp.
|
|
|
|
*
|
2011-08-22 20:44:18 +00:00
|
|
|
* This routine may not sleep.
|
1999-01-21 08:29:12 +00:00
|
|
|
*/
|
|
|
|
static void
|
2003-08-30 08:32:42 +00:00
|
|
|
swp_pager_async_iodone(struct buf *bp)
|
1999-01-21 08:29:12 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
vm_object_t object = NULL;
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
1999-01-21 08:29:12 +00:00
|
|
|
* report error
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
2000-04-02 15:24:56 +00:00
|
|
|
if (bp->b_ioflags & BIO_ERROR) {
|
1998-07-11 07:46:16 +00:00
|
|
|
printf(
|
1999-01-21 08:29:12 +00:00
|
|
|
"swap_pager: I/O error - %s failed; blkno %ld,"
|
|
|
|
"size %ld, error %d\n",
|
2000-03-20 10:44:49 +00:00
|
|
|
((bp->b_iocmd == BIO_READ) ? "pagein" : "pageout"),
|
2012-09-05 12:24:50 +00:00
|
|
|
(long)bp->b_blkno,
|
1999-01-21 08:29:12 +00:00
|
|
|
(long)bp->b_bcount,
|
|
|
|
bp->b_error
|
|
|
|
);
|
1994-10-25 07:06:20 +00:00
|
|
|
}
|
1994-05-25 09:21:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* remove the mapping for kernel virtual
|
|
|
|
*/
|
2015-07-23 19:13:41 +00:00
|
|
|
if (buf_mapped(bp))
|
2013-03-19 14:39:27 +00:00
|
|
|
pmap_qremove((vm_offset_t)bp->b_data, bp->b_npages);
|
2015-07-23 19:13:41 +00:00
|
|
|
else
|
|
|
|
bp->b_data = bp->b_kvabase;
|
1994-05-25 09:21:21 +00:00
|
|
|
|
2003-06-13 06:17:42 +00:00
|
|
|
if (bp->b_npages) {
|
|
|
|
object = bp->b_pages[0]->object;
|
2013-03-09 02:32:23 +00:00
|
|
|
VM_OBJECT_WLOCK(object);
|
2003-06-13 06:17:42 +00:00
|
|
|
}
|
2010-04-30 00:46:43 +00:00
|
|
|
|
1994-05-25 09:21:21 +00:00
|
|
|
/*
|
1999-01-21 08:29:12 +00:00
|
|
|
* cleanup pages. If an error occurs writing to swap, we are in
|
|
|
|
* very serious trouble. If it happens to be a disk error, though,
|
|
|
|
* we may be able to recover by reassigning the swap later on. So
|
2012-09-05 12:24:50 +00:00
|
|
|
* in this case we remove the m->swapblk assignment for the page
|
1999-01-21 08:29:12 +00:00
|
|
|
* but do not free it in the rlist. The errornous block(s) are thus
|
|
|
|
* never reallocated as swap. Redirty the page and continue.
|
1994-05-25 09:21:21 +00:00
|
|
|
*/
|
1999-01-21 08:29:12 +00:00
|
|
|
for (i = 0; i < bp->b_npages; ++i) {
|
|
|
|
vm_page_t m = bp->b_pages[i];
|
|
|
|
|
2006-08-09 17:43:27 +00:00
|
|
|
m->oflags &= ~VPO_SWAPINPROG;
|
2013-08-09 11:11:11 +00:00
|
|
|
if (m->oflags & VPO_SWAPSLEEP) {
|
|
|
|
m->oflags &= ~VPO_SWAPSLEEP;
|
|
|
|
wakeup(&object->paging_in_progress);
|
|
|
|
}
|
1999-01-21 08:29:12 +00:00
|
|
|
|
2000-04-02 15:24:56 +00:00
|
|
|
if (bp->b_ioflags & BIO_ERROR) {
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
|
|
|
* If an error occurs I'd love to throw the swapblk
|
|
|
|
* away without freeing it back to swapspace, so it
|
2012-09-05 12:24:50 +00:00
|
|
|
* can never be used again. But I can't from an
|
1999-01-21 08:29:12 +00:00
|
|
|
* interrupt.
|
|
|
|
*/
|
2000-03-20 10:44:49 +00:00
|
|
|
if (bp->b_iocmd == BIO_READ) {
|
1994-05-25 09:21:21 +00:00
|
|
|
/*
|
1999-01-21 08:29:12 +00:00
|
|
|
* NOTE: for reads, m->dirty will probably
|
2000-03-26 15:20:23 +00:00
|
|
|
* be overridden by the original caller of
|
1999-01-21 08:29:12 +00:00
|
|
|
* getpages so don't play cute tricks here.
|
1994-05-25 09:21:21 +00:00
|
|
|
*/
|
1999-01-21 08:29:12 +00:00
|
|
|
m->valid = 0;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* If a write error occurs, reactivate page
|
|
|
|
* so it doesn't clog the inactive list,
|
|
|
|
* then finish the I/O.
|
|
|
|
*/
|
1999-01-24 06:04:52 +00:00
|
|
|
vm_page_dirty(m);
|
2010-05-08 20:34:01 +00:00
|
|
|
vm_page_lock(m);
|
1999-01-21 08:29:12 +00:00
|
|
|
vm_page_activate(m);
|
2010-05-08 20:34:01 +00:00
|
|
|
vm_page_unlock(m);
|
2013-08-09 11:11:11 +00:00
|
|
|
vm_page_sunbusy(m);
|
1994-05-25 09:21:21 +00:00
|
|
|
}
|
2000-03-20 10:44:49 +00:00
|
|
|
} else if (bp->b_iocmd == BIO_READ) {
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
2012-09-05 12:24:50 +00:00
|
|
|
* NOTE: for reads, m->dirty will probably be
|
2000-03-26 15:20:23 +00:00
|
|
|
* overridden by the original caller of getpages so
|
1999-01-21 08:29:12 +00:00
|
|
|
* we cannot set them in order to free the underlying
|
|
|
|
* swap in a low-swap situation. I don't think we'd
|
|
|
|
* want to do that anyway, but it was an optimization
|
|
|
|
* that existed in the old swapper for a time before
|
|
|
|
* it got ripped out due to precisely this problem.
|
|
|
|
*/
|
2009-04-25 02:59:06 +00:00
|
|
|
KASSERT(!pmap_page_is_mapped(m),
|
|
|
|
("swp_pager_async_iodone: page %p is mapped", m));
|
|
|
|
KASSERT(m->dirty == 0,
|
|
|
|
("swp_pager_async_iodone: page %p is dirty", m));
|
2016-08-30 05:56:21 +00:00
|
|
|
|
A change to KPI of vm_pager_get_pages() and underlying VOP_GETPAGES().
o With new KPI consumers can request contiguous ranges of pages, and
unlike before, all pages will be kept busied on return, like it was
done before with the 'reqpage' only. Now the reqpage goes away. With
new interface it is easier to implement code protected from race
conditions.
Such arrayed requests for now should be preceeded by a call to
vm_pager_haspage() to make sure that request is possible. This
could be improved later, making vm_pager_haspage() obsolete.
Strenghtening the promises on the business of the array of pages
allows us to remove such hacks as swp_pager_free_nrpage() and
vm_pager_free_nonreq().
o New KPI accepts two integer pointers that may optionally point at
values for read ahead and read behind, that a pager may do, if it
can. These pages are completely owned by pager, and not controlled
by the caller.
This shifts the UFS-specific readahead logic from vm_fault.c, which
should be file system agnostic, into vnode_pager.c. It also removes
one VOP_BMAP() request per hard fault.
Discussed with: kib, alc, jeff, scottl
Sponsored by: Nginx, Inc.
Sponsored by: Netflix
2015-12-16 21:30:45 +00:00
|
|
|
m->valid = VM_PAGE_BITS_ALL;
|
2016-08-30 05:56:21 +00:00
|
|
|
if (i < bp->b_pgbefore ||
|
|
|
|
i >= bp->b_npages - bp->b_pgafter)
|
|
|
|
vm_page_readahead_finish(m);
|
1999-01-21 08:29:12 +00:00
|
|
|
} else {
|
|
|
|
/*
|
2009-04-25 02:59:06 +00:00
|
|
|
* For write success, clear the dirty
|
2012-09-05 12:24:50 +00:00
|
|
|
* status, then finish the I/O ( which decrements the
|
1999-01-21 08:29:12 +00:00
|
|
|
* busy count and possibly wakes waiter's up ).
|
Introduce a new page queue, PQ_LAUNDRY, for storing unreferenced, dirty
pages, specificially, dirty pages that have passed once through the inactive
queue. A new, dedicated thread is responsible for both deciding when to
launder pages and actually laundering them. The new policy uses the
relative sizes of the inactive and laundry queues to determine whether to
launder pages at a given point in time. In general, this leads to more
intelligent swapping behavior, since the laundry thread will avoid pageouts
when the marginal benefit of doing so is low. Previously, without a
dedicated queue for dirty pages, the page daemon didn't have the information
to determine whether pageout provides any benefit to the system. Thus, the
previous policy often resulted in small but steadily increasing amounts of
swap usage when the system is under memory pressure, even when the inactive
queue consisted mostly of clean pages. This change addresses that issue,
and also paves the way for some future virtual memory system improvements by
removing the last source of object-cached clean pages, i.e., PG_CACHE pages.
The new laundry thread sleeps while waiting for a request from the page
daemon thread(s). A request is raised by setting the variable
vm_laundry_request and waking the laundry thread. We request launderings
for two reasons: to try and balance the inactive and laundry queue sizes
("background laundering"), and to quickly make up for a shortage of free
pages and clean inactive pages ("shortfall laundering"). When background
laundering is requested, the laundry thread computes the number of page
daemon wakeups that have taken place since the last laundering. If this
number is large enough relative to the ratio of the laundry and (global)
inactive queue sizes, we will launder vm_background_launder_target pages at
vm_background_launder_rate KB/s. Otherwise, the laundry thread goes back
to sleep without doing any work. When scanning the laundry queue during
background laundering, reactivated pages are counted towards the laundry
thread's target.
In contrast, shortfall laundering is requested when an inactive queue scan
fails to meet its target. In this case, the laundry thread attempts to
launder enough pages to meet v_free_target within 0.5s, which is the
inactive queue scan period.
A laundry request can be latched while another is currently being
serviced. In particular, a shortfall request will immediately preempt a
background laundering.
This change also redefines the meaning of vm_cnt.v_reactivated and removes
the functions vm_page_cache() and vm_page_try_to_cache(). The new meaning
of vm_cnt.v_reactivated now better reflects its name. It represents the
number of inactive or laundry pages that are returned to the active queue
on account of a reference.
In collaboration with: markj
Reviewed by: kib
Tested by: pho
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D8302
2016-11-09 18:48:37 +00:00
|
|
|
* A page is only written to swap after a period of
|
|
|
|
* inactivity. Therefore, we do not expect it to be
|
|
|
|
* reused.
|
1999-01-21 08:29:12 +00:00
|
|
|
*/
|
2012-06-16 18:56:19 +00:00
|
|
|
KASSERT(!pmap_page_is_write_mapped(m),
|
2009-04-25 02:59:06 +00:00
|
|
|
("swp_pager_async_iodone: page %p is not write"
|
|
|
|
" protected", m));
|
1999-08-17 05:56:00 +00:00
|
|
|
vm_page_undirty(m);
|
Introduce a new page queue, PQ_LAUNDRY, for storing unreferenced, dirty
pages, specificially, dirty pages that have passed once through the inactive
queue. A new, dedicated thread is responsible for both deciding when to
launder pages and actually laundering them. The new policy uses the
relative sizes of the inactive and laundry queues to determine whether to
launder pages at a given point in time. In general, this leads to more
intelligent swapping behavior, since the laundry thread will avoid pageouts
when the marginal benefit of doing so is low. Previously, without a
dedicated queue for dirty pages, the page daemon didn't have the information
to determine whether pageout provides any benefit to the system. Thus, the
previous policy often resulted in small but steadily increasing amounts of
swap usage when the system is under memory pressure, even when the inactive
queue consisted mostly of clean pages. This change addresses that issue,
and also paves the way for some future virtual memory system improvements by
removing the last source of object-cached clean pages, i.e., PG_CACHE pages.
The new laundry thread sleeps while waiting for a request from the page
daemon thread(s). A request is raised by setting the variable
vm_laundry_request and waking the laundry thread. We request launderings
for two reasons: to try and balance the inactive and laundry queue sizes
("background laundering"), and to quickly make up for a shortage of free
pages and clean inactive pages ("shortfall laundering"). When background
laundering is requested, the laundry thread computes the number of page
daemon wakeups that have taken place since the last laundering. If this
number is large enough relative to the ratio of the laundry and (global)
inactive queue sizes, we will launder vm_background_launder_target pages at
vm_background_launder_rate KB/s. Otherwise, the laundry thread goes back
to sleep without doing any work. When scanning the laundry queue during
background laundering, reactivated pages are counted towards the laundry
thread's target.
In contrast, shortfall laundering is requested when an inactive queue scan
fails to meet its target. In this case, the laundry thread attempts to
launder enough pages to meet v_free_target within 0.5s, which is the
inactive queue scan period.
A laundry request can be latched while another is currently being
serviced. In particular, a shortfall request will immediately preempt a
background laundering.
This change also redefines the meaning of vm_cnt.v_reactivated and removes
the functions vm_page_cache() and vm_page_try_to_cache(). The new meaning
of vm_cnt.v_reactivated now better reflects its name. It represents the
number of inactive or laundry pages that are returned to the active queue
on account of a reference.
In collaboration with: markj
Reviewed by: kib
Tested by: pho
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D8302
2016-11-09 18:48:37 +00:00
|
|
|
vm_page_lock(m);
|
|
|
|
vm_page_deactivate_noreuse(m);
|
|
|
|
vm_page_unlock(m);
|
2013-08-09 11:11:11 +00:00
|
|
|
vm_page_sunbusy(m);
|
1994-05-25 09:21:21 +00:00
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
1994-05-25 09:21:21 +00:00
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
|
|
|
* adjust pip. NOTE: the original parent may still have its own
|
|
|
|
* pip refs on the object.
|
|
|
|
*/
|
2003-04-19 21:15:44 +00:00
|
|
|
if (object != NULL) {
|
1999-01-21 08:29:12 +00:00
|
|
|
vm_object_pip_wakeupn(object, bp->b_npages);
|
2013-03-09 02:32:23 +00:00
|
|
|
VM_OBJECT_WUNLOCK(object);
|
2003-04-19 21:15:44 +00:00
|
|
|
}
|
1999-01-21 08:29:12 +00:00
|
|
|
|
2012-09-05 12:24:50 +00:00
|
|
|
/*
|
|
|
|
* swapdev_strategy() manually sets b_vp and b_bufobj before calling
|
2006-01-27 21:11:50 +00:00
|
|
|
* bstrategy(). Set them back to NULL now we're done with it, or we'll
|
|
|
|
* trigger a KASSERT in relpbuf().
|
|
|
|
*/
|
|
|
|
if (bp->b_vp) {
|
|
|
|
bp->b_vp = NULL;
|
|
|
|
bp->b_bufobj = NULL;
|
|
|
|
}
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
|
|
|
* release the physical I/O buffer
|
|
|
|
*/
|
1999-02-18 19:57:33 +00:00
|
|
|
relpbuf(
|
2012-09-05 12:24:50 +00:00
|
|
|
bp,
|
|
|
|
((bp->b_iocmd == BIO_READ) ? &nsw_rcount :
|
|
|
|
((bp->b_flags & B_ASYNC) ?
|
|
|
|
&nsw_wcount_async :
|
1999-02-18 19:57:33 +00:00
|
|
|
&nsw_wcount_sync
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
2002-12-15 19:17:57 +00:00
|
|
|
/*
|
|
|
|
* swap_pager_isswapped:
|
|
|
|
*
|
|
|
|
* Return 1 if at least one page in the given object is paged
|
|
|
|
* out to the given swap device.
|
|
|
|
*
|
2011-08-22 20:44:18 +00:00
|
|
|
* This routine may not sleep.
|
2002-12-15 19:17:57 +00:00
|
|
|
*/
|
2003-08-03 13:35:31 +00:00
|
|
|
int
|
|
|
|
swap_pager_isswapped(vm_object_t object, struct swdevt *sp)
|
|
|
|
{
|
2002-12-15 19:17:57 +00:00
|
|
|
daddr_t index = 0;
|
|
|
|
int bcount;
|
|
|
|
int i;
|
|
|
|
|
2013-03-09 02:32:23 +00:00
|
|
|
VM_OBJECT_ASSERT_WLOCKED(object);
|
2004-09-24 16:04:20 +00:00
|
|
|
if (object->type != OBJT_SWAP)
|
|
|
|
return (0);
|
|
|
|
|
Close a race in swapoff(). Here are the gory details:
In order to avoid livelock, swapoff() skips over objects with a
nonzero pip count and makes another pass if necessary. Since it is
impossible to know which objects we care about, it would choose an
arbitrary object with a nonzero pip count and wait for it before
making another pass, the theory being that this object would finish
paging about as quickly as the ones we care about. Unfortunately,
we may have slept since we acquired a reference to this object.
Hack around this problem by tsleep()ing on the pointer anyway, but
timeout after a fixed interval. More elegant solutions are possible,
but the ones I considered unnecessarily complicate this rare case.
Also, kill some nits that seem to have crept into the swapoff() code
in the last 75 revisions or so:
- Don't pass both sp and sp->sw_used to swap_pager_swapoff(), since
the latter can be derived from the former.
- Replace swp_pager_find_dev() with something simpler. There's no
need to iterate over the entire list of swap devices just to determine
if a given block is assigned to the one we're interested in.
- Expand the scope of the swhash_mtx in a couple of places so that it
isn't released and reacquired once for every hash bucket.
- Don't drop the swhash_mtx while holding a reference to an object.
We need to lock the object first. Unfortunately, doing so would
violate the established lock order, so use VM_OBJECT_TRYLOCK() and
try again on a subsequent pass if the object is already locked.
- Refactor swp_pager_force_pagein() and swap_pager_swapoff() a bit.
2004-11-05 05:36:56 +00:00
|
|
|
mtx_lock(&swhash_mtx);
|
2002-12-15 19:17:57 +00:00
|
|
|
for (bcount = 0; bcount < object->un_pager.swp.swp_bcount; bcount++) {
|
|
|
|
struct swblock *swap;
|
|
|
|
|
|
|
|
if ((swap = *swp_pager_hash(object, index)) != NULL) {
|
|
|
|
for (i = 0; i < SWAP_META_PAGES; ++i) {
|
Close a race in swapoff(). Here are the gory details:
In order to avoid livelock, swapoff() skips over objects with a
nonzero pip count and makes another pass if necessary. Since it is
impossible to know which objects we care about, it would choose an
arbitrary object with a nonzero pip count and wait for it before
making another pass, the theory being that this object would finish
paging about as quickly as the ones we care about. Unfortunately,
we may have slept since we acquired a reference to this object.
Hack around this problem by tsleep()ing on the pointer anyway, but
timeout after a fixed interval. More elegant solutions are possible,
but the ones I considered unnecessarily complicate this rare case.
Also, kill some nits that seem to have crept into the swapoff() code
in the last 75 revisions or so:
- Don't pass both sp and sp->sw_used to swap_pager_swapoff(), since
the latter can be derived from the former.
- Replace swp_pager_find_dev() with something simpler. There's no
need to iterate over the entire list of swap devices just to determine
if a given block is assigned to the one we're interested in.
- Expand the scope of the swhash_mtx in a couple of places so that it
isn't released and reacquired once for every hash bucket.
- Don't drop the swhash_mtx while holding a reference to an object.
We need to lock the object first. Unfortunately, doing so would
violate the established lock order, so use VM_OBJECT_TRYLOCK() and
try again on a subsequent pass if the object is already locked.
- Refactor swp_pager_force_pagein() and swap_pager_swapoff() a bit.
2004-11-05 05:36:56 +00:00
|
|
|
if (swp_pager_isondev(swap->swb_pages[i], sp)) {
|
2003-10-26 19:55:35 +00:00
|
|
|
mtx_unlock(&swhash_mtx);
|
Close a race in swapoff(). Here are the gory details:
In order to avoid livelock, swapoff() skips over objects with a
nonzero pip count and makes another pass if necessary. Since it is
impossible to know which objects we care about, it would choose an
arbitrary object with a nonzero pip count and wait for it before
making another pass, the theory being that this object would finish
paging about as quickly as the ones we care about. Unfortunately,
we may have slept since we acquired a reference to this object.
Hack around this problem by tsleep()ing on the pointer anyway, but
timeout after a fixed interval. More elegant solutions are possible,
but the ones I considered unnecessarily complicate this rare case.
Also, kill some nits that seem to have crept into the swapoff() code
in the last 75 revisions or so:
- Don't pass both sp and sp->sw_used to swap_pager_swapoff(), since
the latter can be derived from the former.
- Replace swp_pager_find_dev() with something simpler. There's no
need to iterate over the entire list of swap devices just to determine
if a given block is assigned to the one we're interested in.
- Expand the scope of the swhash_mtx in a couple of places so that it
isn't released and reacquired once for every hash bucket.
- Don't drop the swhash_mtx while holding a reference to an object.
We need to lock the object first. Unfortunately, doing so would
violate the established lock order, so use VM_OBJECT_TRYLOCK() and
try again on a subsequent pass if the object is already locked.
- Refactor swp_pager_force_pagein() and swap_pager_swapoff() a bit.
2004-11-05 05:36:56 +00:00
|
|
|
return (1);
|
2003-10-26 19:55:35 +00:00
|
|
|
}
|
2002-12-15 19:17:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
index += SWAP_META_PAGES;
|
|
|
|
}
|
Close a race in swapoff(). Here are the gory details:
In order to avoid livelock, swapoff() skips over objects with a
nonzero pip count and makes another pass if necessary. Since it is
impossible to know which objects we care about, it would choose an
arbitrary object with a nonzero pip count and wait for it before
making another pass, the theory being that this object would finish
paging about as quickly as the ones we care about. Unfortunately,
we may have slept since we acquired a reference to this object.
Hack around this problem by tsleep()ing on the pointer anyway, but
timeout after a fixed interval. More elegant solutions are possible,
but the ones I considered unnecessarily complicate this rare case.
Also, kill some nits that seem to have crept into the swapoff() code
in the last 75 revisions or so:
- Don't pass both sp and sp->sw_used to swap_pager_swapoff(), since
the latter can be derived from the former.
- Replace swp_pager_find_dev() with something simpler. There's no
need to iterate over the entire list of swap devices just to determine
if a given block is assigned to the one we're interested in.
- Expand the scope of the swhash_mtx in a couple of places so that it
isn't released and reacquired once for every hash bucket.
- Don't drop the swhash_mtx while holding a reference to an object.
We need to lock the object first. Unfortunately, doing so would
violate the established lock order, so use VM_OBJECT_TRYLOCK() and
try again on a subsequent pass if the object is already locked.
- Refactor swp_pager_force_pagein() and swap_pager_swapoff() a bit.
2004-11-05 05:36:56 +00:00
|
|
|
mtx_unlock(&swhash_mtx);
|
|
|
|
return (0);
|
2002-12-15 19:17:57 +00:00
|
|
|
}
|
|
|
|
|
2017-01-03 00:05:44 +00:00
|
|
|
int
|
|
|
|
swap_pager_nswapdev(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (nswapdev);
|
|
|
|
}
|
|
|
|
|
2002-12-15 19:17:57 +00:00
|
|
|
/*
|
|
|
|
* SWP_PAGER_FORCE_PAGEIN() - force a swap block to be paged in
|
|
|
|
*
|
Introduce a new page queue, PQ_LAUNDRY, for storing unreferenced, dirty
pages, specificially, dirty pages that have passed once through the inactive
queue. A new, dedicated thread is responsible for both deciding when to
launder pages and actually laundering them. The new policy uses the
relative sizes of the inactive and laundry queues to determine whether to
launder pages at a given point in time. In general, this leads to more
intelligent swapping behavior, since the laundry thread will avoid pageouts
when the marginal benefit of doing so is low. Previously, without a
dedicated queue for dirty pages, the page daemon didn't have the information
to determine whether pageout provides any benefit to the system. Thus, the
previous policy often resulted in small but steadily increasing amounts of
swap usage when the system is under memory pressure, even when the inactive
queue consisted mostly of clean pages. This change addresses that issue,
and also paves the way for some future virtual memory system improvements by
removing the last source of object-cached clean pages, i.e., PG_CACHE pages.
The new laundry thread sleeps while waiting for a request from the page
daemon thread(s). A request is raised by setting the variable
vm_laundry_request and waking the laundry thread. We request launderings
for two reasons: to try and balance the inactive and laundry queue sizes
("background laundering"), and to quickly make up for a shortage of free
pages and clean inactive pages ("shortfall laundering"). When background
laundering is requested, the laundry thread computes the number of page
daemon wakeups that have taken place since the last laundering. If this
number is large enough relative to the ratio of the laundry and (global)
inactive queue sizes, we will launder vm_background_launder_target pages at
vm_background_launder_rate KB/s. Otherwise, the laundry thread goes back
to sleep without doing any work. When scanning the laundry queue during
background laundering, reactivated pages are counted towards the laundry
thread's target.
In contrast, shortfall laundering is requested when an inactive queue scan
fails to meet its target. In this case, the laundry thread attempts to
launder enough pages to meet v_free_target within 0.5s, which is the
inactive queue scan period.
A laundry request can be latched while another is currently being
serviced. In particular, a shortfall request will immediately preempt a
background laundering.
This change also redefines the meaning of vm_cnt.v_reactivated and removes
the functions vm_page_cache() and vm_page_try_to_cache(). The new meaning
of vm_cnt.v_reactivated now better reflects its name. It represents the
number of inactive or laundry pages that are returned to the active queue
on account of a reference.
In collaboration with: markj
Reviewed by: kib
Tested by: pho
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D8302
2016-11-09 18:48:37 +00:00
|
|
|
* This routine dissociates the page at the given index within an object
|
|
|
|
* from its backing store, paging it in if it does not reside in memory.
|
|
|
|
* If the page is paged in, it is marked dirty and placed in the laundry
|
|
|
|
* queue. The page is marked dirty because it no longer has backing
|
|
|
|
* store. It is placed in the laundry queue because it has not been
|
|
|
|
* accessed recently. Otherwise, it would already reside in memory.
|
|
|
|
*
|
|
|
|
* We also attempt to swap in all other pages in the swap block.
|
|
|
|
* However, we only guarantee that the one at the specified index is
|
2002-12-15 19:17:57 +00:00
|
|
|
* paged in.
|
|
|
|
*
|
|
|
|
* XXX - The code to page the whole block in doesn't work, so we
|
|
|
|
* revert to the one-by-one behavior for now. Sigh.
|
|
|
|
*/
|
2006-03-08 06:31:46 +00:00
|
|
|
static inline void
|
Close a race in swapoff(). Here are the gory details:
In order to avoid livelock, swapoff() skips over objects with a
nonzero pip count and makes another pass if necessary. Since it is
impossible to know which objects we care about, it would choose an
arbitrary object with a nonzero pip count and wait for it before
making another pass, the theory being that this object would finish
paging about as quickly as the ones we care about. Unfortunately,
we may have slept since we acquired a reference to this object.
Hack around this problem by tsleep()ing on the pointer anyway, but
timeout after a fixed interval. More elegant solutions are possible,
but the ones I considered unnecessarily complicate this rare case.
Also, kill some nits that seem to have crept into the swapoff() code
in the last 75 revisions or so:
- Don't pass both sp and sp->sw_used to swap_pager_swapoff(), since
the latter can be derived from the former.
- Replace swp_pager_find_dev() with something simpler. There's no
need to iterate over the entire list of swap devices just to determine
if a given block is assigned to the one we're interested in.
- Expand the scope of the swhash_mtx in a couple of places so that it
isn't released and reacquired once for every hash bucket.
- Don't drop the swhash_mtx while holding a reference to an object.
We need to lock the object first. Unfortunately, doing so would
violate the established lock order, so use VM_OBJECT_TRYLOCK() and
try again on a subsequent pass if the object is already locked.
- Refactor swp_pager_force_pagein() and swap_pager_swapoff() a bit.
2004-11-05 05:36:56 +00:00
|
|
|
swp_pager_force_pagein(vm_object_t object, vm_pindex_t pindex)
|
2002-12-15 19:17:57 +00:00
|
|
|
{
|
|
|
|
vm_page_t m;
|
|
|
|
|
|
|
|
vm_object_pip_add(object, 1);
|
2013-08-22 07:39:53 +00:00
|
|
|
m = vm_page_grab(object, pindex, VM_ALLOC_NORMAL);
|
2002-12-15 19:17:57 +00:00
|
|
|
if (m->valid == VM_PAGE_BITS_ALL) {
|
2014-03-19 01:13:42 +00:00
|
|
|
vm_object_pip_wakeup(object);
|
2010-05-09 00:32:52 +00:00
|
|
|
vm_page_dirty(m);
|
2010-04-30 00:46:43 +00:00
|
|
|
vm_page_lock(m);
|
2002-12-15 19:17:57 +00:00
|
|
|
vm_page_activate(m);
|
2010-04-30 00:46:43 +00:00
|
|
|
vm_page_unlock(m);
|
2013-08-09 11:11:11 +00:00
|
|
|
vm_page_xunbusy(m);
|
2002-12-15 19:17:57 +00:00
|
|
|
vm_pager_page_unswapped(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
A change to KPI of vm_pager_get_pages() and underlying VOP_GETPAGES().
o With new KPI consumers can request contiguous ranges of pages, and
unlike before, all pages will be kept busied on return, like it was
done before with the 'reqpage' only. Now the reqpage goes away. With
new interface it is easier to implement code protected from race
conditions.
Such arrayed requests for now should be preceeded by a call to
vm_pager_haspage() to make sure that request is possible. This
could be improved later, making vm_pager_haspage() obsolete.
Strenghtening the promises on the business of the array of pages
allows us to remove such hacks as swp_pager_free_nrpage() and
vm_pager_free_nonreq().
o New KPI accepts two integer pointers that may optionally point at
values for read ahead and read behind, that a pager may do, if it
can. These pages are completely owned by pager, and not controlled
by the caller.
This shifts the UFS-specific readahead logic from vm_fault.c, which
should be file system agnostic, into vnode_pager.c. It also removes
one VOP_BMAP() request per hard fault.
Discussed with: kib, alc, jeff, scottl
Sponsored by: Nginx, Inc.
Sponsored by: Netflix
2015-12-16 21:30:45 +00:00
|
|
|
if (swap_pager_getpages(object, &m, 1, NULL, NULL) != VM_PAGER_OK)
|
2002-12-15 19:17:57 +00:00
|
|
|
panic("swap_pager_force_pagein: read from swap failed");/*XXX*/
|
2014-03-19 01:13:42 +00:00
|
|
|
vm_object_pip_wakeup(object);
|
2002-12-15 19:17:57 +00:00
|
|
|
vm_page_dirty(m);
|
2010-05-09 16:27:42 +00:00
|
|
|
vm_page_lock(m);
|
Introduce a new page queue, PQ_LAUNDRY, for storing unreferenced, dirty
pages, specificially, dirty pages that have passed once through the inactive
queue. A new, dedicated thread is responsible for both deciding when to
launder pages and actually laundering them. The new policy uses the
relative sizes of the inactive and laundry queues to determine whether to
launder pages at a given point in time. In general, this leads to more
intelligent swapping behavior, since the laundry thread will avoid pageouts
when the marginal benefit of doing so is low. Previously, without a
dedicated queue for dirty pages, the page daemon didn't have the information
to determine whether pageout provides any benefit to the system. Thus, the
previous policy often resulted in small but steadily increasing amounts of
swap usage when the system is under memory pressure, even when the inactive
queue consisted mostly of clean pages. This change addresses that issue,
and also paves the way for some future virtual memory system improvements by
removing the last source of object-cached clean pages, i.e., PG_CACHE pages.
The new laundry thread sleeps while waiting for a request from the page
daemon thread(s). A request is raised by setting the variable
vm_laundry_request and waking the laundry thread. We request launderings
for two reasons: to try and balance the inactive and laundry queue sizes
("background laundering"), and to quickly make up for a shortage of free
pages and clean inactive pages ("shortfall laundering"). When background
laundering is requested, the laundry thread computes the number of page
daemon wakeups that have taken place since the last laundering. If this
number is large enough relative to the ratio of the laundry and (global)
inactive queue sizes, we will launder vm_background_launder_target pages at
vm_background_launder_rate KB/s. Otherwise, the laundry thread goes back
to sleep without doing any work. When scanning the laundry queue during
background laundering, reactivated pages are counted towards the laundry
thread's target.
In contrast, shortfall laundering is requested when an inactive queue scan
fails to meet its target. In this case, the laundry thread attempts to
launder enough pages to meet v_free_target within 0.5s, which is the
inactive queue scan period.
A laundry request can be latched while another is currently being
serviced. In particular, a shortfall request will immediately preempt a
background laundering.
This change also redefines the meaning of vm_cnt.v_reactivated and removes
the functions vm_page_cache() and vm_page_try_to_cache(). The new meaning
of vm_cnt.v_reactivated now better reflects its name. It represents the
number of inactive or laundry pages that are returned to the active queue
on account of a reference.
In collaboration with: markj
Reviewed by: kib
Tested by: pho
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D8302
2016-11-09 18:48:37 +00:00
|
|
|
vm_page_launder(m);
|
2010-04-30 00:46:43 +00:00
|
|
|
vm_page_unlock(m);
|
2013-08-09 11:11:11 +00:00
|
|
|
vm_page_xunbusy(m);
|
2002-12-15 19:17:57 +00:00
|
|
|
vm_pager_page_unswapped(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* swap_pager_swapoff:
|
|
|
|
*
|
|
|
|
* Page in all of the pages that have been paged out to the
|
|
|
|
* given device. The corresponding blocks in the bitmap must be
|
|
|
|
* marked as allocated and the device must be flagged SW_CLOSING.
|
|
|
|
* There may be no processes swapped out to the device.
|
|
|
|
*
|
|
|
|
* This routine may block.
|
|
|
|
*/
|
2003-07-18 10:02:44 +00:00
|
|
|
static void
|
Close a race in swapoff(). Here are the gory details:
In order to avoid livelock, swapoff() skips over objects with a
nonzero pip count and makes another pass if necessary. Since it is
impossible to know which objects we care about, it would choose an
arbitrary object with a nonzero pip count and wait for it before
making another pass, the theory being that this object would finish
paging about as quickly as the ones we care about. Unfortunately,
we may have slept since we acquired a reference to this object.
Hack around this problem by tsleep()ing on the pointer anyway, but
timeout after a fixed interval. More elegant solutions are possible,
but the ones I considered unnecessarily complicate this rare case.
Also, kill some nits that seem to have crept into the swapoff() code
in the last 75 revisions or so:
- Don't pass both sp and sp->sw_used to swap_pager_swapoff(), since
the latter can be derived from the former.
- Replace swp_pager_find_dev() with something simpler. There's no
need to iterate over the entire list of swap devices just to determine
if a given block is assigned to the one we're interested in.
- Expand the scope of the swhash_mtx in a couple of places so that it
isn't released and reacquired once for every hash bucket.
- Don't drop the swhash_mtx while holding a reference to an object.
We need to lock the object first. Unfortunately, doing so would
violate the established lock order, so use VM_OBJECT_TRYLOCK() and
try again on a subsequent pass if the object is already locked.
- Refactor swp_pager_force_pagein() and swap_pager_swapoff() a bit.
2004-11-05 05:36:56 +00:00
|
|
|
swap_pager_swapoff(struct swdevt *sp)
|
2002-12-15 19:17:57 +00:00
|
|
|
{
|
|
|
|
struct swblock *swap;
|
2016-08-31 14:49:58 +00:00
|
|
|
vm_object_t locked_obj, object;
|
|
|
|
vm_pindex_t pindex;
|
2004-11-06 07:17:50 +00:00
|
|
|
int i, j, retries;
|
2002-12-15 19:17:57 +00:00
|
|
|
|
2016-05-22 23:25:01 +00:00
|
|
|
sx_assert(&swdev_syscall_lock, SA_XLOCKED);
|
2002-12-15 19:17:57 +00:00
|
|
|
|
2004-11-06 07:17:50 +00:00
|
|
|
retries = 0;
|
2016-08-31 14:49:58 +00:00
|
|
|
locked_obj = NULL;
|
2002-12-15 19:17:57 +00:00
|
|
|
full_rescan:
|
Close a race in swapoff(). Here are the gory details:
In order to avoid livelock, swapoff() skips over objects with a
nonzero pip count and makes another pass if necessary. Since it is
impossible to know which objects we care about, it would choose an
arbitrary object with a nonzero pip count and wait for it before
making another pass, the theory being that this object would finish
paging about as quickly as the ones we care about. Unfortunately,
we may have slept since we acquired a reference to this object.
Hack around this problem by tsleep()ing on the pointer anyway, but
timeout after a fixed interval. More elegant solutions are possible,
but the ones I considered unnecessarily complicate this rare case.
Also, kill some nits that seem to have crept into the swapoff() code
in the last 75 revisions or so:
- Don't pass both sp and sp->sw_used to swap_pager_swapoff(), since
the latter can be derived from the former.
- Replace swp_pager_find_dev() with something simpler. There's no
need to iterate over the entire list of swap devices just to determine
if a given block is assigned to the one we're interested in.
- Expand the scope of the swhash_mtx in a couple of places so that it
isn't released and reacquired once for every hash bucket.
- Don't drop the swhash_mtx while holding a reference to an object.
We need to lock the object first. Unfortunately, doing so would
violate the established lock order, so use VM_OBJECT_TRYLOCK() and
try again on a subsequent pass if the object is already locked.
- Refactor swp_pager_force_pagein() and swap_pager_swapoff() a bit.
2004-11-05 05:36:56 +00:00
|
|
|
mtx_lock(&swhash_mtx);
|
2002-12-15 19:17:57 +00:00
|
|
|
for (i = 0; i <= swhash_mask; i++) { /* '<=' is correct here */
|
|
|
|
restart:
|
Close a race in swapoff(). Here are the gory details:
In order to avoid livelock, swapoff() skips over objects with a
nonzero pip count and makes another pass if necessary. Since it is
impossible to know which objects we care about, it would choose an
arbitrary object with a nonzero pip count and wait for it before
making another pass, the theory being that this object would finish
paging about as quickly as the ones we care about. Unfortunately,
we may have slept since we acquired a reference to this object.
Hack around this problem by tsleep()ing on the pointer anyway, but
timeout after a fixed interval. More elegant solutions are possible,
but the ones I considered unnecessarily complicate this rare case.
Also, kill some nits that seem to have crept into the swapoff() code
in the last 75 revisions or so:
- Don't pass both sp and sp->sw_used to swap_pager_swapoff(), since
the latter can be derived from the former.
- Replace swp_pager_find_dev() with something simpler. There's no
need to iterate over the entire list of swap devices just to determine
if a given block is assigned to the one we're interested in.
- Expand the scope of the swhash_mtx in a couple of places so that it
isn't released and reacquired once for every hash bucket.
- Don't drop the swhash_mtx while holding a reference to an object.
We need to lock the object first. Unfortunately, doing so would
violate the established lock order, so use VM_OBJECT_TRYLOCK() and
try again on a subsequent pass if the object is already locked.
- Refactor swp_pager_force_pagein() and swap_pager_swapoff() a bit.
2004-11-05 05:36:56 +00:00
|
|
|
for (swap = swhash[i]; swap != NULL; swap = swap->swb_hnext) {
|
2016-08-31 14:49:58 +00:00
|
|
|
object = swap->swb_object;
|
|
|
|
pindex = swap->swb_index;
|
2012-09-05 12:24:50 +00:00
|
|
|
for (j = 0; j < SWAP_META_PAGES; ++j) {
|
2016-08-31 14:49:58 +00:00
|
|
|
if (!swp_pager_isondev(swap->swb_pages[j], sp))
|
|
|
|
continue;
|
|
|
|
if (locked_obj != object) {
|
|
|
|
if (locked_obj != NULL)
|
|
|
|
VM_OBJECT_WUNLOCK(locked_obj);
|
|
|
|
locked_obj = object;
|
2013-03-09 02:32:23 +00:00
|
|
|
if (!VM_OBJECT_TRYWLOCK(object)) {
|
Close a race in swapoff(). Here are the gory details:
In order to avoid livelock, swapoff() skips over objects with a
nonzero pip count and makes another pass if necessary. Since it is
impossible to know which objects we care about, it would choose an
arbitrary object with a nonzero pip count and wait for it before
making another pass, the theory being that this object would finish
paging about as quickly as the ones we care about. Unfortunately,
we may have slept since we acquired a reference to this object.
Hack around this problem by tsleep()ing on the pointer anyway, but
timeout after a fixed interval. More elegant solutions are possible,
but the ones I considered unnecessarily complicate this rare case.
Also, kill some nits that seem to have crept into the swapoff() code
in the last 75 revisions or so:
- Don't pass both sp and sp->sw_used to swap_pager_swapoff(), since
the latter can be derived from the former.
- Replace swp_pager_find_dev() with something simpler. There's no
need to iterate over the entire list of swap devices just to determine
if a given block is assigned to the one we're interested in.
- Expand the scope of the swhash_mtx in a couple of places so that it
isn't released and reacquired once for every hash bucket.
- Don't drop the swhash_mtx while holding a reference to an object.
We need to lock the object first. Unfortunately, doing so would
violate the established lock order, so use VM_OBJECT_TRYLOCK() and
try again on a subsequent pass if the object is already locked.
- Refactor swp_pager_force_pagein() and swap_pager_swapoff() a bit.
2004-11-05 05:36:56 +00:00
|
|
|
mtx_unlock(&swhash_mtx);
|
2016-08-31 14:49:58 +00:00
|
|
|
/* Depends on type-stability. */
|
|
|
|
VM_OBJECT_WLOCK(object);
|
Close a race in swapoff(). Here are the gory details:
In order to avoid livelock, swapoff() skips over objects with a
nonzero pip count and makes another pass if necessary. Since it is
impossible to know which objects we care about, it would choose an
arbitrary object with a nonzero pip count and wait for it before
making another pass, the theory being that this object would finish
paging about as quickly as the ones we care about. Unfortunately,
we may have slept since we acquired a reference to this object.
Hack around this problem by tsleep()ing on the pointer anyway, but
timeout after a fixed interval. More elegant solutions are possible,
but the ones I considered unnecessarily complicate this rare case.
Also, kill some nits that seem to have crept into the swapoff() code
in the last 75 revisions or so:
- Don't pass both sp and sp->sw_used to swap_pager_swapoff(), since
the latter can be derived from the former.
- Replace swp_pager_find_dev() with something simpler. There's no
need to iterate over the entire list of swap devices just to determine
if a given block is assigned to the one we're interested in.
- Expand the scope of the swhash_mtx in a couple of places so that it
isn't released and reacquired once for every hash bucket.
- Don't drop the swhash_mtx while holding a reference to an object.
We need to lock the object first. Unfortunately, doing so would
violate the established lock order, so use VM_OBJECT_TRYLOCK() and
try again on a subsequent pass if the object is already locked.
- Refactor swp_pager_force_pagein() and swap_pager_swapoff() a bit.
2004-11-05 05:36:56 +00:00
|
|
|
mtx_lock(&swhash_mtx);
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
}
|
2016-08-31 14:49:58 +00:00
|
|
|
MPASS(locked_obj == object);
|
|
|
|
mtx_unlock(&swhash_mtx);
|
|
|
|
swp_pager_force_pagein(object, pindex + j);
|
|
|
|
mtx_lock(&swhash_mtx);
|
|
|
|
goto restart;
|
2012-09-05 12:24:50 +00:00
|
|
|
}
|
2002-12-15 19:17:57 +00:00
|
|
|
}
|
|
|
|
}
|
Close a race in swapoff(). Here are the gory details:
In order to avoid livelock, swapoff() skips over objects with a
nonzero pip count and makes another pass if necessary. Since it is
impossible to know which objects we care about, it would choose an
arbitrary object with a nonzero pip count and wait for it before
making another pass, the theory being that this object would finish
paging about as quickly as the ones we care about. Unfortunately,
we may have slept since we acquired a reference to this object.
Hack around this problem by tsleep()ing on the pointer anyway, but
timeout after a fixed interval. More elegant solutions are possible,
but the ones I considered unnecessarily complicate this rare case.
Also, kill some nits that seem to have crept into the swapoff() code
in the last 75 revisions or so:
- Don't pass both sp and sp->sw_used to swap_pager_swapoff(), since
the latter can be derived from the former.
- Replace swp_pager_find_dev() with something simpler. There's no
need to iterate over the entire list of swap devices just to determine
if a given block is assigned to the one we're interested in.
- Expand the scope of the swhash_mtx in a couple of places so that it
isn't released and reacquired once for every hash bucket.
- Don't drop the swhash_mtx while holding a reference to an object.
We need to lock the object first. Unfortunately, doing so would
violate the established lock order, so use VM_OBJECT_TRYLOCK() and
try again on a subsequent pass if the object is already locked.
- Refactor swp_pager_force_pagein() and swap_pager_swapoff() a bit.
2004-11-05 05:36:56 +00:00
|
|
|
mtx_unlock(&swhash_mtx);
|
2016-08-31 14:49:58 +00:00
|
|
|
if (locked_obj != NULL) {
|
|
|
|
VM_OBJECT_WUNLOCK(locked_obj);
|
|
|
|
locked_obj = NULL;
|
|
|
|
}
|
2004-11-06 07:17:50 +00:00
|
|
|
if (sp->sw_used) {
|
Close a race in swapoff(). Here are the gory details:
In order to avoid livelock, swapoff() skips over objects with a
nonzero pip count and makes another pass if necessary. Since it is
impossible to know which objects we care about, it would choose an
arbitrary object with a nonzero pip count and wait for it before
making another pass, the theory being that this object would finish
paging about as quickly as the ones we care about. Unfortunately,
we may have slept since we acquired a reference to this object.
Hack around this problem by tsleep()ing on the pointer anyway, but
timeout after a fixed interval. More elegant solutions are possible,
but the ones I considered unnecessarily complicate this rare case.
Also, kill some nits that seem to have crept into the swapoff() code
in the last 75 revisions or so:
- Don't pass both sp and sp->sw_used to swap_pager_swapoff(), since
the latter can be derived from the former.
- Replace swp_pager_find_dev() with something simpler. There's no
need to iterate over the entire list of swap devices just to determine
if a given block is assigned to the one we're interested in.
- Expand the scope of the swhash_mtx in a couple of places so that it
isn't released and reacquired once for every hash bucket.
- Don't drop the swhash_mtx while holding a reference to an object.
We need to lock the object first. Unfortunately, doing so would
violate the established lock order, so use VM_OBJECT_TRYLOCK() and
try again on a subsequent pass if the object is already locked.
- Refactor swp_pager_force_pagein() and swap_pager_swapoff() a bit.
2004-11-05 05:36:56 +00:00
|
|
|
/*
|
2004-11-06 07:17:50 +00:00
|
|
|
* Objects may be locked or paging to the device being
|
|
|
|
* removed, so we will miss their pages and need to
|
|
|
|
* make another pass. We have marked this device as
|
|
|
|
* SW_CLOSING, so the activity should finish soon.
|
Close a race in swapoff(). Here are the gory details:
In order to avoid livelock, swapoff() skips over objects with a
nonzero pip count and makes another pass if necessary. Since it is
impossible to know which objects we care about, it would choose an
arbitrary object with a nonzero pip count and wait for it before
making another pass, the theory being that this object would finish
paging about as quickly as the ones we care about. Unfortunately,
we may have slept since we acquired a reference to this object.
Hack around this problem by tsleep()ing on the pointer anyway, but
timeout after a fixed interval. More elegant solutions are possible,
but the ones I considered unnecessarily complicate this rare case.
Also, kill some nits that seem to have crept into the swapoff() code
in the last 75 revisions or so:
- Don't pass both sp and sp->sw_used to swap_pager_swapoff(), since
the latter can be derived from the former.
- Replace swp_pager_find_dev() with something simpler. There's no
need to iterate over the entire list of swap devices just to determine
if a given block is assigned to the one we're interested in.
- Expand the scope of the swhash_mtx in a couple of places so that it
isn't released and reacquired once for every hash bucket.
- Don't drop the swhash_mtx while holding a reference to an object.
We need to lock the object first. Unfortunately, doing so would
violate the established lock order, so use VM_OBJECT_TRYLOCK() and
try again on a subsequent pass if the object is already locked.
- Refactor swp_pager_force_pagein() and swap_pager_swapoff() a bit.
2004-11-05 05:36:56 +00:00
|
|
|
*/
|
2004-11-06 07:17:50 +00:00
|
|
|
retries++;
|
|
|
|
if (retries > 100) {
|
|
|
|
panic("swapoff: failed to locate %d swap blocks",
|
|
|
|
sp->sw_used);
|
|
|
|
}
|
2007-02-27 17:23:29 +00:00
|
|
|
pause("swpoff", hz / 20);
|
Close a race in swapoff(). Here are the gory details:
In order to avoid livelock, swapoff() skips over objects with a
nonzero pip count and makes another pass if necessary. Since it is
impossible to know which objects we care about, it would choose an
arbitrary object with a nonzero pip count and wait for it before
making another pass, the theory being that this object would finish
paging about as quickly as the ones we care about. Unfortunately,
we may have slept since we acquired a reference to this object.
Hack around this problem by tsleep()ing on the pointer anyway, but
timeout after a fixed interval. More elegant solutions are possible,
but the ones I considered unnecessarily complicate this rare case.
Also, kill some nits that seem to have crept into the swapoff() code
in the last 75 revisions or so:
- Don't pass both sp and sp->sw_used to swap_pager_swapoff(), since
the latter can be derived from the former.
- Replace swp_pager_find_dev() with something simpler. There's no
need to iterate over the entire list of swap devices just to determine
if a given block is assigned to the one we're interested in.
- Expand the scope of the swhash_mtx in a couple of places so that it
isn't released and reacquired once for every hash bucket.
- Don't drop the swhash_mtx while holding a reference to an object.
We need to lock the object first. Unfortunately, doing so would
violate the established lock order, so use VM_OBJECT_TRYLOCK() and
try again on a subsequent pass if the object is already locked.
- Refactor swp_pager_force_pagein() and swap_pager_swapoff() a bit.
2004-11-05 05:36:56 +00:00
|
|
|
goto full_rescan;
|
2002-12-15 19:17:57 +00:00
|
|
|
}
|
2017-01-03 00:05:44 +00:00
|
|
|
EVENTHANDLER_INVOKE(swapoff, sp);
|
2002-12-15 19:17:57 +00:00
|
|
|
}
|
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
/************************************************************************
|
|
|
|
* SWAP META DATA *
|
|
|
|
************************************************************************
|
|
|
|
*
|
2012-09-05 12:24:50 +00:00
|
|
|
* These routines manipulate the swap metadata stored in the
|
2011-04-26 22:18:53 +00:00
|
|
|
* OBJT_SWAP object.
|
1999-01-21 08:29:12 +00:00
|
|
|
*
|
1999-09-17 05:09:24 +00:00
|
|
|
* Swap metadata is implemented with a global hash and not directly
|
|
|
|
* linked into the object. Instead the object simply contains
|
|
|
|
* appropriate tracking counters.
|
1999-01-21 08:29:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SWP_PAGER_META_BUILD() - add swap block to swap meta data for object
|
|
|
|
*
|
|
|
|
* We first convert the object to a swap object if it is a default
|
|
|
|
* object.
|
|
|
|
*
|
|
|
|
* The specified swapblk is added to the object's swap metadata. If
|
|
|
|
* the swapblk is not valid, it is freed instead. Any previously
|
|
|
|
* assigned swapblk is freed.
|
|
|
|
*/
|
1998-04-15 17:47:40 +00:00
|
|
|
static void
|
2003-08-30 08:32:42 +00:00
|
|
|
swp_pager_meta_build(vm_object_t object, vm_pindex_t pindex, daddr_t swapblk)
|
|
|
|
{
|
2012-08-16 08:29:49 +00:00
|
|
|
static volatile int exhausted;
|
1999-01-21 08:29:12 +00:00
|
|
|
struct swblock *swap;
|
|
|
|
struct swblock **pswap;
|
2002-06-26 20:32:51 +00:00
|
|
|
int idx;
|
1994-05-25 09:21:21 +00:00
|
|
|
|
2013-03-09 02:32:23 +00:00
|
|
|
VM_OBJECT_ASSERT_WLOCKED(object);
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
|
|
|
* Convert default object to swap object if necessary
|
|
|
|
*/
|
|
|
|
if (object->type != OBJT_SWAP) {
|
|
|
|
object->type = OBJT_SWAP;
|
|
|
|
object->un_pager.swp.swp_bcount = 0;
|
2016-06-13 03:42:46 +00:00
|
|
|
KASSERT(object->handle == NULL, ("default pager with handle"));
|
1999-01-21 08:29:12 +00:00
|
|
|
}
|
2012-09-05 12:24:50 +00:00
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
|
|
|
* Locate hash entry. If not found create, but if we aren't adding
|
1999-09-17 05:09:24 +00:00
|
|
|
* anything just return. If we run out of space in the map we wait
|
|
|
|
* and, since the hash table may have changed, retry.
|
1999-01-21 08:29:12 +00:00
|
|
|
*/
|
1999-09-17 05:09:24 +00:00
|
|
|
retry:
|
2003-10-26 19:55:35 +00:00
|
|
|
mtx_lock(&swhash_mtx);
|
2002-06-26 20:32:51 +00:00
|
|
|
pswap = swp_pager_hash(object, pindex);
|
1999-01-21 08:29:12 +00:00
|
|
|
|
|
|
|
if ((swap = *pswap) == NULL) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (swapblk == SWAPBLK_NONE)
|
2003-10-26 19:55:35 +00:00
|
|
|
goto done;
|
1999-01-21 08:29:12 +00:00
|
|
|
|
2013-07-11 20:33:57 +00:00
|
|
|
swap = *pswap = uma_zalloc(swap_zone, M_NOWAIT |
|
|
|
|
(curproc == pageproc ? M_USE_RESERVE : 0));
|
1999-09-17 05:09:24 +00:00
|
|
|
if (swap == NULL) {
|
2003-10-26 19:55:35 +00:00
|
|
|
mtx_unlock(&swhash_mtx);
|
2013-03-09 02:32:23 +00:00
|
|
|
VM_OBJECT_WUNLOCK(object);
|
2008-09-29 19:45:12 +00:00
|
|
|
if (uma_zone_exhausted(swap_zone)) {
|
2012-09-04 22:19:33 +00:00
|
|
|
if (atomic_cmpset_int(&exhausted, 0, 1))
|
2012-08-16 08:29:49 +00:00
|
|
|
printf("swap zone exhausted, "
|
|
|
|
"increase kern.maxswzone\n");
|
2008-09-29 19:45:12 +00:00
|
|
|
vm_pageout_oom(VM_OOM_SWAPZ);
|
|
|
|
pause("swzonex", 10);
|
|
|
|
} else
|
|
|
|
VM_WAIT;
|
2013-03-09 02:32:23 +00:00
|
|
|
VM_OBJECT_WLOCK(object);
|
1999-09-17 05:09:24 +00:00
|
|
|
goto retry;
|
|
|
|
}
|
2002-03-20 04:02:59 +00:00
|
|
|
|
2012-09-04 22:19:33 +00:00
|
|
|
if (atomic_cmpset_int(&exhausted, 1, 0))
|
2012-08-16 08:29:49 +00:00
|
|
|
printf("swap zone ok\n");
|
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
swap->swb_hnext = NULL;
|
|
|
|
swap->swb_object = object;
|
2002-06-26 20:32:51 +00:00
|
|
|
swap->swb_index = pindex & ~(vm_pindex_t)SWAP_META_MASK;
|
1999-01-21 08:29:12 +00:00
|
|
|
swap->swb_count = 0;
|
|
|
|
|
|
|
|
++object->un_pager.swp.swp_bcount;
|
|
|
|
|
|
|
|
for (i = 0; i < SWAP_META_PAGES; ++i)
|
|
|
|
swap->swb_pages[i] = SWAPBLK_NONE;
|
1994-05-25 09:21:21 +00:00
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
|
|
|
* Delete prior contents of metadata
|
|
|
|
*/
|
2002-06-26 20:32:51 +00:00
|
|
|
idx = pindex & SWAP_META_MASK;
|
1999-01-21 08:29:12 +00:00
|
|
|
|
2002-06-26 20:32:51 +00:00
|
|
|
if (swap->swb_pages[idx] != SWAPBLK_NONE) {
|
|
|
|
swp_pager_freeswapspace(swap->swb_pages[idx], 1);
|
1999-01-21 08:29:12 +00:00
|
|
|
--swap->swb_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enter block into metadata
|
|
|
|
*/
|
2002-06-26 20:32:51 +00:00
|
|
|
swap->swb_pages[idx] = swapblk;
|
1999-09-17 05:09:24 +00:00
|
|
|
if (swapblk != SWAPBLK_NONE)
|
|
|
|
++swap->swb_count;
|
2003-10-26 19:55:35 +00:00
|
|
|
done:
|
|
|
|
mtx_unlock(&swhash_mtx);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
1994-05-25 09:21:21 +00:00
|
|
|
/*
|
1999-01-21 08:29:12 +00:00
|
|
|
* SWP_PAGER_META_FREE() - free a range of blocks in the object's swap metadata
|
|
|
|
*
|
2012-09-05 12:24:50 +00:00
|
|
|
* The requested range of blocks is freed, with any associated swap
|
1999-01-21 08:29:12 +00:00
|
|
|
* returned to the swap bitmap.
|
|
|
|
*
|
2012-09-05 12:24:50 +00:00
|
|
|
* This routine will free swap metadata structures as they are cleaned
|
1999-01-21 08:29:12 +00:00
|
|
|
* out. This routine does *NOT* operate on swap metadata associated
|
|
|
|
* with resident pages.
|
1994-05-25 09:21:21 +00:00
|
|
|
*/
|
1995-11-14 20:53:20 +00:00
|
|
|
static void
|
2016-12-24 09:57:31 +00:00
|
|
|
swp_pager_meta_free(vm_object_t object, vm_pindex_t index, vm_pindex_t count)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2016-12-24 09:57:31 +00:00
|
|
|
struct swblock **pswap, *swap;
|
|
|
|
vm_pindex_t c;
|
|
|
|
daddr_t v;
|
|
|
|
int n, sidx;
|
2003-10-31 05:18:45 +00:00
|
|
|
|
2013-05-28 22:07:23 +00:00
|
|
|
VM_OBJECT_ASSERT_LOCKED(object);
|
2016-12-24 09:57:31 +00:00
|
|
|
if (object->type != OBJT_SWAP || count == 0)
|
1999-01-21 08:29:12 +00:00
|
|
|
return;
|
1998-03-01 04:18:54 +00:00
|
|
|
|
2016-12-24 09:57:31 +00:00
|
|
|
mtx_lock(&swhash_mtx);
|
|
|
|
for (c = 0; c < count;) {
|
1999-01-21 08:29:12 +00:00
|
|
|
pswap = swp_pager_hash(object, index);
|
2016-12-24 09:57:31 +00:00
|
|
|
sidx = index & SWAP_META_MASK;
|
|
|
|
n = SWAP_META_PAGES - sidx;
|
|
|
|
index += n;
|
|
|
|
if ((swap = *pswap) == NULL) {
|
|
|
|
c += n;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (; c < count && sidx < SWAP_META_PAGES; ++c, ++sidx) {
|
|
|
|
if ((v = swap->swb_pages[sidx]) == SWAPBLK_NONE)
|
|
|
|
continue;
|
|
|
|
swp_pager_freeswapspace(v, 1);
|
|
|
|
swap->swb_pages[sidx] = SWAPBLK_NONE;
|
|
|
|
if (--swap->swb_count == 0) {
|
|
|
|
*pswap = swap->swb_hnext;
|
|
|
|
uma_zfree(swap_zone, swap);
|
|
|
|
--object->un_pager.swp.swp_bcount;
|
|
|
|
c += SWAP_META_PAGES - sidx;
|
|
|
|
break;
|
1999-01-21 08:29:12 +00:00
|
|
|
}
|
1998-03-01 04:18:54 +00:00
|
|
|
}
|
1994-05-25 09:21:21 +00:00
|
|
|
}
|
2016-12-24 09:57:31 +00:00
|
|
|
mtx_unlock(&swhash_mtx);
|
1999-01-21 08:29:12 +00:00
|
|
|
}
|
These changes embody the support of the fully coherent merged VM buffer cache,
much higher filesystem I/O performance, and much better paging performance. It
represents the culmination of over 6 months of R&D.
The majority of the merged VM/cache work is by John Dyson.
The following highlights the most significant changes. Additionally, there are
(mostly minor) changes to the various filesystem modules (nfs, msdosfs, etc) to
support the new VM/buffer scheme.
vfs_bio.c:
Significant rewrite of most of vfs_bio to support the merged VM buffer cache
scheme. The scheme is almost fully compatible with the old filesystem
interface. Significant improvement in the number of opportunities for write
clustering.
vfs_cluster.c, vfs_subr.c
Upgrade and performance enhancements in vfs layer code to support merged
VM/buffer cache. Fixup of vfs_cluster to eliminate the bogus pagemove stuff.
vm_object.c:
Yet more improvements in the collapse code. Elimination of some windows that
can cause list corruption.
vm_pageout.c:
Fixed it, it really works better now. Somehow in 2.0, some "enhancements"
broke the code. This code has been reworked from the ground-up.
vm_fault.c, vm_page.c, pmap.c, vm_object.c
Support for small-block filesystems with merged VM/buffer cache scheme.
pmap.c vm_map.c
Dynamic kernel VM size, now we dont have to pre-allocate excessive numbers of
kernel PTs.
vm_glue.c
Much simpler and more effective swapping code. No more gratuitous swapping.
proc.h
Fixed the problem that the p_lock flag was not being cleared on a fork.
swap_pager.c, vnode_pager.c
Removal of old vfs_bio cruft to support the past pseudo-coherency. Now the
code doesn't need it anymore.
machdep.c
Changes to better support the parameter values for the merged VM/buffer cache
scheme.
machdep.c, kern_exec.c, vm_glue.c
Implemented a seperate submap for temporary exec string space and another one
to contain process upages. This eliminates all map fragmentation problems
that previously existed.
ffs_inode.c, ufs_inode.c, ufs_readwrite.c
Changes for merged VM/buffer cache. Add "bypass" support for sneaking in on
busy buffers.
Submitted by: John Dyson and David Greenman
1995-01-09 16:06:02 +00:00
|
|
|
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
|
|
|
* SWP_PAGER_META_FREE_ALL() - destroy all swap metadata associated with object
|
|
|
|
*
|
|
|
|
* This routine locates and destroys all swap metadata associated with
|
|
|
|
* an object.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
swp_pager_meta_free_all(vm_object_t object)
|
|
|
|
{
|
2016-12-16 23:33:37 +00:00
|
|
|
struct swblock **pswap, *swap;
|
|
|
|
vm_pindex_t index;
|
|
|
|
daddr_t v;
|
|
|
|
int i;
|
1994-05-25 09:21:21 +00:00
|
|
|
|
2013-03-09 02:32:23 +00:00
|
|
|
VM_OBJECT_ASSERT_WLOCKED(object);
|
1999-01-21 08:29:12 +00:00
|
|
|
if (object->type != OBJT_SWAP)
|
|
|
|
return;
|
|
|
|
|
2016-12-16 23:33:37 +00:00
|
|
|
index = 0;
|
|
|
|
while (object->un_pager.swp.swp_bcount != 0) {
|
2003-10-26 19:55:35 +00:00
|
|
|
mtx_lock(&swhash_mtx);
|
1999-01-21 08:29:12 +00:00
|
|
|
pswap = swp_pager_hash(object, index);
|
|
|
|
if ((swap = *pswap) != NULL) {
|
|
|
|
for (i = 0; i < SWAP_META_PAGES; ++i) {
|
2016-12-16 23:33:37 +00:00
|
|
|
v = swap->swb_pages[i];
|
1999-01-21 08:29:12 +00:00
|
|
|
if (v != SWAPBLK_NONE) {
|
|
|
|
--swap->swb_count;
|
1999-09-17 05:09:24 +00:00
|
|
|
swp_pager_freeswapspace(v, 1);
|
1999-01-21 08:29:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (swap->swb_count != 0)
|
2016-12-16 23:33:37 +00:00
|
|
|
panic(
|
|
|
|
"swap_pager_meta_free_all: swb_count != 0");
|
1999-01-21 08:29:12 +00:00
|
|
|
*pswap = swap->swb_hnext;
|
2002-03-20 04:02:59 +00:00
|
|
|
uma_zfree(swap_zone, swap);
|
1999-01-21 08:29:12 +00:00
|
|
|
--object->un_pager.swp.swp_bcount;
|
|
|
|
}
|
2003-10-26 19:55:35 +00:00
|
|
|
mtx_unlock(&swhash_mtx);
|
1999-01-21 08:29:12 +00:00
|
|
|
index += SWAP_META_PAGES;
|
1994-05-25 09:21:21 +00:00
|
|
|
}
|
1999-01-21 08:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SWP_PAGER_METACTL() - misc control of swap and vm_page_t meta data.
|
|
|
|
*
|
|
|
|
* This routine is capable of looking up, popping, or freeing
|
|
|
|
* swapblk assignments in the swap meta data or in the vm_page_t.
|
|
|
|
* The routine typically returns the swapblk being looked-up, or popped,
|
|
|
|
* or SWAPBLK_NONE if the block was freed, or SWAPBLK_NONE if the block
|
2012-09-05 12:24:50 +00:00
|
|
|
* was invalid. This routine will automatically free any invalid
|
1999-01-21 08:29:12 +00:00
|
|
|
* meta-data swapblks.
|
|
|
|
*
|
|
|
|
* It is not possible to store invalid swapblks in the swap meta data
|
|
|
|
* (other then a literal 'SWAPBLK_NONE'), so we don't bother checking.
|
|
|
|
*
|
2012-09-05 12:24:50 +00:00
|
|
|
* When acting on a busy resident page and paging is in progress, we
|
|
|
|
* have to wait until paging is complete but otherwise can act on the
|
1999-01-21 08:29:12 +00:00
|
|
|
* busy page.
|
|
|
|
*
|
1999-09-17 05:09:24 +00:00
|
|
|
* SWM_FREE remove and free swap block from metadata
|
1999-01-21 08:29:12 +00:00
|
|
|
* SWM_POP remove from meta data but do not free.. pop it out
|
|
|
|
*/
|
|
|
|
static daddr_t
|
2003-08-30 08:32:42 +00:00
|
|
|
swp_pager_meta_ctl(vm_object_t object, vm_pindex_t pindex, int flags)
|
|
|
|
{
|
1999-09-17 05:09:24 +00:00
|
|
|
struct swblock **pswap;
|
|
|
|
struct swblock *swap;
|
|
|
|
daddr_t r1;
|
2002-06-26 20:32:51 +00:00
|
|
|
int idx;
|
1999-09-17 05:09:24 +00:00
|
|
|
|
2013-05-28 22:07:23 +00:00
|
|
|
VM_OBJECT_ASSERT_LOCKED(object);
|
1999-01-21 08:29:12 +00:00
|
|
|
/*
|
2012-09-05 12:24:50 +00:00
|
|
|
* The meta data only exists of the object is OBJT_SWAP
|
1999-01-21 08:29:12 +00:00
|
|
|
* and even then might not be allocated yet.
|
|
|
|
*/
|
1999-09-17 05:09:24 +00:00
|
|
|
if (object->type != OBJT_SWAP)
|
2002-03-10 21:52:48 +00:00
|
|
|
return (SWAPBLK_NONE);
|
1998-02-23 08:22:48 +00:00
|
|
|
|
1999-09-17 05:09:24 +00:00
|
|
|
r1 = SWAPBLK_NONE;
|
2003-10-26 19:55:35 +00:00
|
|
|
mtx_lock(&swhash_mtx);
|
2002-06-26 20:32:51 +00:00
|
|
|
pswap = swp_pager_hash(object, pindex);
|
1999-01-21 08:29:12 +00:00
|
|
|
|
1999-09-17 05:09:24 +00:00
|
|
|
if ((swap = *pswap) != NULL) {
|
2002-06-26 20:32:51 +00:00
|
|
|
idx = pindex & SWAP_META_MASK;
|
|
|
|
r1 = swap->swb_pages[idx];
|
1999-01-21 08:29:12 +00:00
|
|
|
|
1999-09-17 05:09:24 +00:00
|
|
|
if (r1 != SWAPBLK_NONE) {
|
|
|
|
if (flags & SWM_FREE) {
|
|
|
|
swp_pager_freeswapspace(r1, 1);
|
|
|
|
r1 = SWAPBLK_NONE;
|
|
|
|
}
|
|
|
|
if (flags & (SWM_FREE|SWM_POP)) {
|
2002-06-26 20:32:51 +00:00
|
|
|
swap->swb_pages[idx] = SWAPBLK_NONE;
|
1999-09-17 05:09:24 +00:00
|
|
|
if (--swap->swb_count == 0) {
|
|
|
|
*pswap = swap->swb_hnext;
|
2002-03-20 04:02:59 +00:00
|
|
|
uma_zfree(swap_zone, swap);
|
1999-09-17 05:09:24 +00:00
|
|
|
--object->un_pager.swp.swp_bcount;
|
1999-01-21 08:29:12 +00:00
|
|
|
}
|
2012-09-05 12:24:50 +00:00
|
|
|
}
|
1999-01-21 08:29:12 +00:00
|
|
|
}
|
|
|
|
}
|
2003-10-26 19:55:35 +00:00
|
|
|
mtx_unlock(&swhash_mtx);
|
2002-03-10 21:52:48 +00:00
|
|
|
return (r1);
|
1994-05-25 09:21:21 +00:00
|
|
|
}
|
1999-01-21 08:29:12 +00:00
|
|
|
|
2016-12-18 20:56:14 +00:00
|
|
|
/*
|
|
|
|
* Returns the least page index which is greater than or equal to the
|
|
|
|
* parameter pindex and for which there is a swap block allocated.
|
|
|
|
* Returns object's size if the object's type is not swap or if there
|
|
|
|
* are no allocated swap blocks for the object after the requested
|
|
|
|
* pindex.
|
|
|
|
*/
|
|
|
|
vm_pindex_t
|
|
|
|
swap_pager_find_least(vm_object_t object, vm_pindex_t pindex)
|
|
|
|
{
|
|
|
|
struct swblock **pswap, *swap;
|
|
|
|
vm_pindex_t i, j, lim;
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
VM_OBJECT_ASSERT_LOCKED(object);
|
|
|
|
if (object->type != OBJT_SWAP || object->un_pager.swp.swp_bcount == 0)
|
|
|
|
return (object->size);
|
|
|
|
|
|
|
|
mtx_lock(&swhash_mtx);
|
|
|
|
for (j = pindex; j < object->size; j = lim) {
|
|
|
|
pswap = swp_pager_hash(object, j);
|
|
|
|
lim = rounddown2(j + SWAP_META_PAGES, SWAP_META_PAGES);
|
|
|
|
if (lim > object->size)
|
|
|
|
lim = object->size;
|
|
|
|
if ((swap = *pswap) != NULL) {
|
|
|
|
for (idx = j & SWAP_META_MASK, i = j; i < lim;
|
|
|
|
i++, idx++) {
|
|
|
|
if (swap->swb_pages[idx] != SWAPBLK_NONE)
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i = object->size;
|
|
|
|
found:
|
|
|
|
mtx_unlock(&swhash_mtx);
|
|
|
|
return (i);
|
|
|
|
}
|
|
|
|
|
2003-07-18 10:02:44 +00:00
|
|
|
/*
|
|
|
|
* System call swapon(name) enables swapping on device name,
|
|
|
|
* which must be in the swdevsw. Return EBUSY
|
|
|
|
* if already swapping on this device.
|
|
|
|
*/
|
|
|
|
#ifndef _SYS_SYSPROTO_H_
|
|
|
|
struct swapon_args {
|
|
|
|
char *name;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2012-09-05 12:24:50 +00:00
|
|
|
/*
|
2003-07-18 10:02:44 +00:00
|
|
|
* MPSAFE
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys_swapon(struct thread *td, struct swapon_args *uap)
|
2003-07-18 10:02:44 +00:00
|
|
|
{
|
|
|
|
struct vattr attr;
|
|
|
|
struct vnode *vp;
|
|
|
|
struct nameidata nd;
|
|
|
|
int error;
|
|
|
|
|
2006-11-06 13:42:10 +00:00
|
|
|
error = priv_check(td, PRIV_SWAPON);
|
2003-07-18 10:02:44 +00:00
|
|
|
if (error)
|
2006-11-06 13:42:10 +00:00
|
|
|
return (error);
|
2003-07-18 10:02:44 +00:00
|
|
|
|
2016-05-22 23:25:01 +00:00
|
|
|
sx_xlock(&swdev_syscall_lock);
|
2003-07-18 10:02:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Swap metadata may not fit in the KVM if we have physical
|
|
|
|
* memory of >1GB.
|
|
|
|
*/
|
|
|
|
if (swap_zone == NULL) {
|
|
|
|
error = ENOMEM;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2007-04-23 14:41:34 +00:00
|
|
|
NDINIT(&nd, LOOKUP, ISOPEN | FOLLOW | AUDITVNODE1, UIO_USERSPACE,
|
|
|
|
uap->name, td);
|
2003-07-18 10:02:44 +00:00
|
|
|
error = namei(&nd);
|
|
|
|
if (error)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
NDFREE(&nd, NDF_ONLY_PNBUF);
|
|
|
|
vp = nd.ni_vp;
|
|
|
|
|
2003-08-30 16:10:28 +00:00
|
|
|
if (vn_isdisk(vp, &error)) {
|
2016-07-28 15:57:01 +00:00
|
|
|
error = swapongeom(vp);
|
2003-08-30 16:10:28 +00:00
|
|
|
} else if (vp->v_type == VREG &&
|
2003-07-18 10:02:44 +00:00
|
|
|
(vp->v_mount->mnt_vfc->vfc_flags & VFCF_NETWORK) != 0 &&
|
2008-08-28 15:23:18 +00:00
|
|
|
(error = VOP_GETATTR(vp, &attr, td->td_ucred)) == 0) {
|
2003-07-18 10:02:44 +00:00
|
|
|
/*
|
|
|
|
* Allow direct swapping to NFS regular files in the same
|
|
|
|
* way that nfs_mountroot() sets up diskless swapping.
|
|
|
|
*/
|
2003-08-30 11:33:25 +00:00
|
|
|
error = swaponvp(td, vp, attr.va_size / DEV_BSIZE);
|
2003-07-18 10:02:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
vrele(vp);
|
|
|
|
done:
|
2016-05-22 23:25:01 +00:00
|
|
|
sx_xunlock(&swdev_syscall_lock);
|
2003-07-18 10:02:44 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2012-08-16 08:29:49 +00:00
|
|
|
/*
|
|
|
|
* Check that the total amount of swap currently configured does not
|
|
|
|
* exceed half the theoretical maximum. If it does, print a warning
|
|
|
|
* message and return -1; otherwise, return 0.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
swapon_check_swzone(unsigned long npages)
|
|
|
|
{
|
|
|
|
unsigned long maxpages;
|
|
|
|
|
|
|
|
/* absolute maximum we can handle assuming 100% efficiency */
|
|
|
|
maxpages = uma_zone_get_max(swap_zone) * SWAP_META_PAGES;
|
|
|
|
|
|
|
|
/* recommend using no more than half that amount */
|
|
|
|
if (npages > maxpages / 2) {
|
|
|
|
printf("warning: total configured swap (%lu pages) "
|
|
|
|
"exceeds maximum recommended amount (%lu pages).\n",
|
2012-08-27 10:59:49 +00:00
|
|
|
npages, maxpages / 2);
|
2012-08-16 08:29:49 +00:00
|
|
|
printf("warning: increase kern.maxswzone "
|
|
|
|
"or reduce amount of swap.\n");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2003-08-30 11:33:25 +00:00
|
|
|
static void
|
2013-03-19 14:39:27 +00:00
|
|
|
swaponsomething(struct vnode *vp, void *id, u_long nblks,
|
|
|
|
sw_strategy_t *strategy, sw_close_t *close, dev_t dev, int flags)
|
2003-07-18 10:02:44 +00:00
|
|
|
{
|
2003-10-29 05:42:28 +00:00
|
|
|
struct swdevt *sp, *tsp;
|
2003-07-18 10:02:44 +00:00
|
|
|
swblk_t dvbase;
|
2003-08-03 13:35:31 +00:00
|
|
|
u_long mblocks;
|
2003-07-18 10:02:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* nblks is in DEV_BSIZE'd chunks, convert to PAGE_SIZE'd chunks.
|
|
|
|
* First chop nblks off to page-align it, then convert.
|
2012-09-05 12:24:50 +00:00
|
|
|
*
|
2003-07-18 10:02:44 +00:00
|
|
|
* sw->sw_nblks is in page-sized chunks now too.
|
|
|
|
*/
|
|
|
|
nblks &= ~(ctodb(1) - 1);
|
|
|
|
nblks = dbtoc(nblks);
|
|
|
|
|
2011-08-22 11:18:47 +00:00
|
|
|
/*
|
|
|
|
* If we go beyond this, we get overflows in the radix
|
|
|
|
* tree bitmap code.
|
|
|
|
*/
|
|
|
|
mblocks = 0x40000000 / BLIST_META_RADIX;
|
|
|
|
if (nblks > mblocks) {
|
|
|
|
printf(
|
|
|
|
"WARNING: reducing swap size to maximum of %luMB per unit\n",
|
|
|
|
mblocks / 1024 / 1024 * PAGE_SIZE);
|
|
|
|
nblks = mblocks;
|
|
|
|
}
|
|
|
|
|
2003-08-03 13:35:31 +00:00
|
|
|
sp = malloc(sizeof *sp, M_VMPGDATA, M_WAITOK | M_ZERO);
|
2003-08-30 16:44:26 +00:00
|
|
|
sp->sw_vp = vp;
|
|
|
|
sp->sw_id = id;
|
2004-06-17 17:16:53 +00:00
|
|
|
sp->sw_dev = dev;
|
2003-07-31 22:19:28 +00:00
|
|
|
sp->sw_flags = 0;
|
2003-07-18 10:02:44 +00:00
|
|
|
sp->sw_nblks = nblks;
|
|
|
|
sp->sw_used = 0;
|
2003-08-30 11:33:25 +00:00
|
|
|
sp->sw_strategy = strategy;
|
2003-08-30 16:44:26 +00:00
|
|
|
sp->sw_close = close;
|
2013-03-19 14:39:27 +00:00
|
|
|
sp->sw_flags = flags;
|
2003-07-18 10:02:44 +00:00
|
|
|
|
2008-05-05 19:48:54 +00:00
|
|
|
sp->sw_blist = blist_create(nblks, M_WAITOK);
|
2003-07-18 10:02:44 +00:00
|
|
|
/*
|
2003-08-06 14:13:38 +00:00
|
|
|
* Do not free the first two block in order to avoid overwriting
|
2003-08-03 13:35:31 +00:00
|
|
|
* any bsd label at the front of the partition
|
2003-07-18 10:02:44 +00:00
|
|
|
*/
|
2003-08-06 14:13:38 +00:00
|
|
|
blist_free(sp->sw_blist, 2, nblks - 2);
|
2003-07-18 10:02:44 +00:00
|
|
|
|
2003-10-29 05:42:28 +00:00
|
|
|
dvbase = 0;
|
2003-08-30 16:10:28 +00:00
|
|
|
mtx_lock(&sw_dev_mtx);
|
2003-10-29 05:42:28 +00:00
|
|
|
TAILQ_FOREACH(tsp, &swtailq, sw_list) {
|
|
|
|
if (tsp->sw_end >= dvbase) {
|
|
|
|
/*
|
|
|
|
* We put one uncovered page between the devices
|
|
|
|
* in order to definitively prevent any cross-device
|
|
|
|
* I/O requests
|
|
|
|
*/
|
|
|
|
dvbase = tsp->sw_end + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sp->sw_first = dvbase;
|
|
|
|
sp->sw_end = dvbase + nblks;
|
2003-08-03 13:35:31 +00:00
|
|
|
TAILQ_INSERT_TAIL(&swtailq, sp, sw_list);
|
|
|
|
nswapdev++;
|
|
|
|
swap_pager_avail += nblks;
|
Implement global and per-uid accounting of the anonymous memory. Add
rlimit RLIMIT_SWAP that limits the amount of swap that may be reserved
for the uid.
The accounting information (charge) is associated with either map entry,
or vm object backing the entry, assuming the object is the first one
in the shadow chain and entry does not require COW. Charge is moved
from entry to object on allocation of the object, e.g. during the mmap,
assuming the object is allocated, or on the first page fault on the
entry. It moves back to the entry on forks due to COW setup.
The per-entry granularity of accounting makes the charge process fair
for processes that change uid during lifetime, and decrements charge
for proper uid when region is unmapped.
The interface of vm_pager_allocate(9) is extended by adding struct ucred *,
that is used to charge appropriate uid when allocation if performed by
kernel, e.g. md(4).
Several syscalls, among them is fork(2), may now return ENOMEM when
global or per-uid limits are enforced.
In collaboration with: pho
Reviewed by: alc
Approved by: re (kensmith)
2009-06-23 20:45:22 +00:00
|
|
|
swap_total += (vm_ooffset_t)nblks * PAGE_SIZE;
|
2012-08-16 08:29:49 +00:00
|
|
|
swapon_check_swzone(swap_total / PAGE_SIZE);
|
2003-10-30 07:11:06 +00:00
|
|
|
swp_sizecheck();
|
|
|
|
mtx_unlock(&sw_dev_mtx);
|
2017-01-03 00:05:44 +00:00
|
|
|
EVENTHANDLER_INVOKE(swapon, sp);
|
2003-08-30 11:33:25 +00:00
|
|
|
}
|
|
|
|
|
2003-07-18 10:02:44 +00:00
|
|
|
/*
|
|
|
|
* SYSCALL: swapoff(devname)
|
|
|
|
*
|
|
|
|
* Disable swapping on the given device.
|
2003-08-30 16:44:26 +00:00
|
|
|
*
|
|
|
|
* XXX: Badly designed system call: it should use a device index
|
|
|
|
* rather than filename as specification. We keep sw_vp around
|
|
|
|
* only to make this work.
|
2003-07-18 10:02:44 +00:00
|
|
|
*/
|
|
|
|
#ifndef _SYS_SYSPROTO_H_
|
|
|
|
struct swapoff_args {
|
|
|
|
char *name;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MPSAFE
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys_swapoff(struct thread *td, struct swapoff_args *uap)
|
2003-07-18 10:02:44 +00:00
|
|
|
{
|
|
|
|
struct vnode *vp;
|
|
|
|
struct nameidata nd;
|
|
|
|
struct swdevt *sp;
|
2003-08-03 13:35:31 +00:00
|
|
|
int error;
|
2003-07-18 10:02:44 +00:00
|
|
|
|
2006-11-06 13:42:10 +00:00
|
|
|
error = priv_check(td, PRIV_SWAPOFF);
|
2003-07-18 10:02:44 +00:00
|
|
|
if (error)
|
2006-04-10 10:03:41 +00:00
|
|
|
return (error);
|
2003-07-18 10:02:44 +00:00
|
|
|
|
2016-05-22 23:25:01 +00:00
|
|
|
sx_xlock(&swdev_syscall_lock);
|
2003-07-18 10:02:44 +00:00
|
|
|
|
2007-04-23 14:41:34 +00:00
|
|
|
NDINIT(&nd, LOOKUP, FOLLOW | AUDITVNODE1, UIO_USERSPACE, uap->name,
|
|
|
|
td);
|
2003-07-18 10:02:44 +00:00
|
|
|
error = namei(&nd);
|
|
|
|
if (error)
|
|
|
|
goto done;
|
|
|
|
NDFREE(&nd, NDF_ONLY_PNBUF);
|
|
|
|
vp = nd.ni_vp;
|
|
|
|
|
2003-08-30 16:10:28 +00:00
|
|
|
mtx_lock(&sw_dev_mtx);
|
2003-08-03 13:35:31 +00:00
|
|
|
TAILQ_FOREACH(sp, &swtailq, sw_list) {
|
2003-08-30 16:44:26 +00:00
|
|
|
if (sp->sw_vp == vp)
|
2006-04-10 10:03:41 +00:00
|
|
|
break;
|
2003-07-18 10:02:44 +00:00
|
|
|
}
|
2003-08-30 16:10:28 +00:00
|
|
|
mtx_unlock(&sw_dev_mtx);
|
2006-04-10 10:03:41 +00:00
|
|
|
if (sp == NULL) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto done;
|
|
|
|
}
|
2008-01-08 14:58:41 +00:00
|
|
|
error = swapoff_one(sp, td->td_ucred);
|
2006-04-10 10:03:41 +00:00
|
|
|
done:
|
2016-05-22 23:25:01 +00:00
|
|
|
sx_xunlock(&swdev_syscall_lock);
|
2006-04-10 10:03:41 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-01-08 14:58:41 +00:00
|
|
|
swapoff_one(struct swdevt *sp, struct ucred *cred)
|
2006-04-10 10:03:41 +00:00
|
|
|
{
|
|
|
|
u_long nblks, dvbase;
|
|
|
|
#ifdef MAC
|
|
|
|
int error;
|
|
|
|
#endif
|
|
|
|
|
2016-05-22 23:25:01 +00:00
|
|
|
sx_assert(&swdev_syscall_lock, SA_XLOCKED);
|
2003-07-18 10:02:44 +00:00
|
|
|
#ifdef MAC
|
2008-01-10 01:10:58 +00:00
|
|
|
(void) vn_lock(sp->sw_vp, LK_EXCLUSIVE | LK_RETRY);
|
2008-01-08 14:58:41 +00:00
|
|
|
error = mac_system_check_swapoff(cred, sp->sw_vp);
|
2008-01-13 14:44:15 +00:00
|
|
|
(void) VOP_UNLOCK(sp->sw_vp, 0);
|
2003-07-18 10:02:44 +00:00
|
|
|
if (error != 0)
|
2006-04-10 10:03:41 +00:00
|
|
|
return (error);
|
2003-07-18 10:02:44 +00:00
|
|
|
#endif
|
|
|
|
nblks = sp->sw_nblks;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We can turn off this swap device safely only if the
|
|
|
|
* available virtual memory in the system will fit the amount
|
|
|
|
* of data we will have to page back in, plus an epsilon so
|
|
|
|
* the system doesn't become critically low on swap space.
|
|
|
|
*/
|
2016-11-22 18:13:46 +00:00
|
|
|
if (vm_cnt.v_free_count + swap_pager_avail < nblks + nswap_lowat)
|
2006-04-10 10:03:41 +00:00
|
|
|
return (ENOMEM);
|
2003-07-18 10:02:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Prevent further allocations on this device.
|
|
|
|
*/
|
2003-10-31 05:18:45 +00:00
|
|
|
mtx_lock(&sw_dev_mtx);
|
2003-07-18 10:02:44 +00:00
|
|
|
sp->sw_flags |= SW_CLOSING;
|
2003-08-03 13:35:31 +00:00
|
|
|
for (dvbase = 0; dvbase < sp->sw_end; dvbase += dmmax) {
|
|
|
|
swap_pager_avail -= blist_fill(sp->sw_blist,
|
|
|
|
dvbase, dmmax);
|
2003-07-18 10:02:44 +00:00
|
|
|
}
|
Implement global and per-uid accounting of the anonymous memory. Add
rlimit RLIMIT_SWAP that limits the amount of swap that may be reserved
for the uid.
The accounting information (charge) is associated with either map entry,
or vm object backing the entry, assuming the object is the first one
in the shadow chain and entry does not require COW. Charge is moved
from entry to object on allocation of the object, e.g. during the mmap,
assuming the object is allocated, or on the first page fault on the
entry. It moves back to the entry on forks due to COW setup.
The per-entry granularity of accounting makes the charge process fair
for processes that change uid during lifetime, and decrements charge
for proper uid when region is unmapped.
The interface of vm_pager_allocate(9) is extended by adding struct ucred *,
that is used to charge appropriate uid when allocation if performed by
kernel, e.g. md(4).
Several syscalls, among them is fork(2), may now return ENOMEM when
global or per-uid limits are enforced.
In collaboration with: pho
Reviewed by: alc
Approved by: re (kensmith)
2009-06-23 20:45:22 +00:00
|
|
|
swap_total -= (vm_ooffset_t)nblks * PAGE_SIZE;
|
2003-10-31 05:18:45 +00:00
|
|
|
mtx_unlock(&sw_dev_mtx);
|
2003-07-18 10:02:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Page in the contents of the device and close it.
|
|
|
|
*/
|
Close a race in swapoff(). Here are the gory details:
In order to avoid livelock, swapoff() skips over objects with a
nonzero pip count and makes another pass if necessary. Since it is
impossible to know which objects we care about, it would choose an
arbitrary object with a nonzero pip count and wait for it before
making another pass, the theory being that this object would finish
paging about as quickly as the ones we care about. Unfortunately,
we may have slept since we acquired a reference to this object.
Hack around this problem by tsleep()ing on the pointer anyway, but
timeout after a fixed interval. More elegant solutions are possible,
but the ones I considered unnecessarily complicate this rare case.
Also, kill some nits that seem to have crept into the swapoff() code
in the last 75 revisions or so:
- Don't pass both sp and sp->sw_used to swap_pager_swapoff(), since
the latter can be derived from the former.
- Replace swp_pager_find_dev() with something simpler. There's no
need to iterate over the entire list of swap devices just to determine
if a given block is assigned to the one we're interested in.
- Expand the scope of the swhash_mtx in a couple of places so that it
isn't released and reacquired once for every hash bucket.
- Don't drop the swhash_mtx while holding a reference to an object.
We need to lock the object first. Unfortunately, doing so would
violate the established lock order, so use VM_OBJECT_TRYLOCK() and
try again on a subsequent pass if the object is already locked.
- Refactor swp_pager_force_pagein() and swap_pager_swapoff() a bit.
2004-11-05 05:36:56 +00:00
|
|
|
swap_pager_swapoff(sp);
|
2003-07-18 10:02:44 +00:00
|
|
|
|
2008-01-08 14:58:41 +00:00
|
|
|
sp->sw_close(curthread, sp);
|
2003-08-30 16:10:28 +00:00
|
|
|
mtx_lock(&sw_dev_mtx);
|
2015-09-08 17:47:56 +00:00
|
|
|
sp->sw_id = NULL;
|
2003-08-03 13:35:31 +00:00
|
|
|
TAILQ_REMOVE(&swtailq, sp, sw_list);
|
2003-10-29 07:51:41 +00:00
|
|
|
nswapdev--;
|
2004-01-24 21:31:06 +00:00
|
|
|
if (nswapdev == 0) {
|
|
|
|
swap_pager_full = 2;
|
|
|
|
swap_pager_almost_full = 1;
|
|
|
|
}
|
2003-08-03 13:35:31 +00:00
|
|
|
if (swdevhd == sp)
|
|
|
|
swdevhd = NULL;
|
2003-10-30 07:11:06 +00:00
|
|
|
mtx_unlock(&sw_dev_mtx);
|
2003-08-03 13:35:31 +00:00
|
|
|
blist_destroy(sp->sw_blist);
|
|
|
|
free(sp, M_VMPGDATA);
|
2006-04-10 10:03:41 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2003-07-18 10:02:44 +00:00
|
|
|
|
2006-04-10 10:03:41 +00:00
|
|
|
void
|
|
|
|
swapoff_all(void)
|
|
|
|
{
|
|
|
|
struct swdevt *sp, *spt;
|
|
|
|
const char *devname;
|
|
|
|
int error;
|
2012-09-05 12:24:50 +00:00
|
|
|
|
2016-05-22 23:25:01 +00:00
|
|
|
sx_xlock(&swdev_syscall_lock);
|
2012-09-05 12:24:50 +00:00
|
|
|
|
2006-04-10 10:03:41 +00:00
|
|
|
mtx_lock(&sw_dev_mtx);
|
|
|
|
TAILQ_FOREACH_SAFE(sp, &swtailq, sw_list, spt) {
|
|
|
|
mtx_unlock(&sw_dev_mtx);
|
|
|
|
if (vn_isdisk(sp->sw_vp, NULL))
|
2012-02-10 12:35:57 +00:00
|
|
|
devname = devtoname(sp->sw_vp->v_rdev);
|
2006-04-10 10:03:41 +00:00
|
|
|
else
|
|
|
|
devname = "[file]";
|
2008-01-08 14:58:41 +00:00
|
|
|
error = swapoff_one(sp, thread0.td_ucred);
|
2006-04-10 10:03:41 +00:00
|
|
|
if (error != 0) {
|
|
|
|
printf("Cannot remove swap device %s (error=%d), "
|
|
|
|
"skipping.\n", devname, error);
|
|
|
|
} else if (bootverbose) {
|
|
|
|
printf("Swap device %s removed.\n", devname);
|
|
|
|
}
|
|
|
|
mtx_lock(&sw_dev_mtx);
|
|
|
|
}
|
|
|
|
mtx_unlock(&sw_dev_mtx);
|
2012-09-05 12:24:50 +00:00
|
|
|
|
2016-05-22 23:25:01 +00:00
|
|
|
sx_xunlock(&swdev_syscall_lock);
|
2003-07-18 10:02:44 +00:00
|
|
|
}
|
|
|
|
|
2003-07-18 10:26:09 +00:00
|
|
|
void
|
|
|
|
swap_pager_status(int *total, int *used)
|
|
|
|
{
|
|
|
|
struct swdevt *sp;
|
|
|
|
|
|
|
|
*total = 0;
|
|
|
|
*used = 0;
|
2003-08-30 16:10:28 +00:00
|
|
|
mtx_lock(&sw_dev_mtx);
|
2003-08-03 13:35:31 +00:00
|
|
|
TAILQ_FOREACH(sp, &swtailq, sw_list) {
|
2003-07-18 10:26:09 +00:00
|
|
|
*total += sp->sw_nblks;
|
|
|
|
*used += sp->sw_used;
|
|
|
|
}
|
2003-08-30 16:10:28 +00:00
|
|
|
mtx_unlock(&sw_dev_mtx);
|
2003-07-18 10:26:09 +00:00
|
|
|
}
|
|
|
|
|
2011-08-01 19:12:15 +00:00
|
|
|
int
|
|
|
|
swap_dev_info(int name, struct xswdev *xs, char *devname, size_t len)
|
2003-07-18 10:02:44 +00:00
|
|
|
{
|
|
|
|
struct swdevt *sp;
|
2012-02-10 12:35:57 +00:00
|
|
|
const char *tmp_devname;
|
2011-08-01 19:12:15 +00:00
|
|
|
int error, n;
|
2003-07-18 10:02:44 +00:00
|
|
|
|
2003-08-03 13:35:31 +00:00
|
|
|
n = 0;
|
2011-08-01 19:12:15 +00:00
|
|
|
error = ENOENT;
|
2003-08-30 16:10:28 +00:00
|
|
|
mtx_lock(&sw_dev_mtx);
|
2003-08-03 13:35:31 +00:00
|
|
|
TAILQ_FOREACH(sp, &swtailq, sw_list) {
|
2011-08-01 19:12:15 +00:00
|
|
|
if (n != name) {
|
|
|
|
n++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
xs->xsw_version = XSWDEV_VERSION;
|
|
|
|
xs->xsw_dev = sp->sw_dev;
|
|
|
|
xs->xsw_flags = sp->sw_flags;
|
|
|
|
xs->xsw_nblks = sp->sw_nblks;
|
|
|
|
xs->xsw_used = sp->sw_used;
|
|
|
|
if (devname != NULL) {
|
|
|
|
if (vn_isdisk(sp->sw_vp, NULL))
|
2012-02-10 12:35:57 +00:00
|
|
|
tmp_devname = devtoname(sp->sw_vp->v_rdev);
|
2011-08-01 19:12:15 +00:00
|
|
|
else
|
|
|
|
tmp_devname = "[file]";
|
|
|
|
strncpy(devname, tmp_devname, len);
|
2003-07-18 10:02:44 +00:00
|
|
|
}
|
2011-08-01 19:12:15 +00:00
|
|
|
error = 0;
|
|
|
|
break;
|
2003-07-18 10:02:44 +00:00
|
|
|
}
|
2003-08-30 16:10:28 +00:00
|
|
|
mtx_unlock(&sw_dev_mtx);
|
2011-08-01 19:12:15 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sysctl_vm_swap_info(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
struct xswdev xs;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (arg2 != 1) /* name length */
|
|
|
|
return (EINVAL);
|
|
|
|
error = swap_dev_info(*(int *)arg1, &xs, NULL, 0);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
error = SYSCTL_OUT(req, &xs, sizeof(xs));
|
|
|
|
return (error);
|
2003-07-18 10:02:44 +00:00
|
|
|
}
|
|
|
|
|
2003-08-03 13:35:31 +00:00
|
|
|
SYSCTL_INT(_vm, OID_AUTO, nswapdev, CTLFLAG_RD, &nswapdev, 0,
|
2003-07-18 10:02:44 +00:00
|
|
|
"Number of swap devices");
|
2016-05-22 23:28:23 +00:00
|
|
|
SYSCTL_NODE(_vm, OID_AUTO, swap_info, CTLFLAG_RD | CTLFLAG_MPSAFE,
|
|
|
|
sysctl_vm_swap_info,
|
2003-07-18 10:02:44 +00:00
|
|
|
"Swap statistics by device");
|
2003-07-18 10:47:58 +00:00
|
|
|
|
|
|
|
/*
|
2009-04-28 11:43:35 +00:00
|
|
|
* vmspace_swap_count() - count the approximate swap usage in pages for a
|
2003-07-18 10:47:58 +00:00
|
|
|
* vmspace.
|
|
|
|
*
|
|
|
|
* The map must be locked.
|
|
|
|
*
|
2009-04-28 11:43:35 +00:00
|
|
|
* Swap usage is determined by taking the proportional swap used by
|
2003-07-18 10:47:58 +00:00
|
|
|
* VM objects backing the VM map. To make up for fractional losses,
|
|
|
|
* if the VM object has any swap use at all the associated map entries
|
|
|
|
* count for at least 1 swap page.
|
|
|
|
*/
|
2011-03-01 11:04:30 +00:00
|
|
|
long
|
2003-07-18 10:47:58 +00:00
|
|
|
vmspace_swap_count(struct vmspace *vmspace)
|
|
|
|
{
|
2011-02-23 10:28:37 +00:00
|
|
|
vm_map_t map;
|
2003-07-18 10:47:58 +00:00
|
|
|
vm_map_entry_t cur;
|
2011-02-23 10:28:37 +00:00
|
|
|
vm_object_t object;
|
2011-03-01 11:04:30 +00:00
|
|
|
long count, n;
|
2003-07-18 10:47:58 +00:00
|
|
|
|
2011-02-23 10:28:37 +00:00
|
|
|
map = &vmspace->vm_map;
|
|
|
|
count = 0;
|
2003-07-18 10:47:58 +00:00
|
|
|
|
2011-02-23 10:28:37 +00:00
|
|
|
for (cur = map->header.next; cur != &map->header; cur = cur->next) {
|
2003-07-18 10:47:58 +00:00
|
|
|
if ((cur->eflags & MAP_ENTRY_IS_SUB_MAP) == 0 &&
|
|
|
|
(object = cur->object.vm_object) != NULL) {
|
2013-03-09 02:32:23 +00:00
|
|
|
VM_OBJECT_WLOCK(object);
|
2003-07-18 10:47:58 +00:00
|
|
|
if (object->type == OBJT_SWAP &&
|
|
|
|
object->un_pager.swp.swp_bcount != 0) {
|
2011-02-23 10:28:37 +00:00
|
|
|
n = (cur->end - cur->start) / PAGE_SIZE;
|
2003-07-18 10:47:58 +00:00
|
|
|
count += object->un_pager.swp.swp_bcount *
|
|
|
|
SWAP_META_PAGES * n / object->size + 1;
|
|
|
|
}
|
2013-03-09 02:32:23 +00:00
|
|
|
VM_OBJECT_WUNLOCK(object);
|
2003-07-18 10:47:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return (count);
|
|
|
|
}
|
2003-08-30 16:44:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* GEOM backend
|
|
|
|
*
|
|
|
|
* Swapping onto disk devices.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2004-08-08 07:57:53 +00:00
|
|
|
static g_orphan_t swapgeom_orphan;
|
|
|
|
|
2003-08-30 16:44:26 +00:00
|
|
|
static struct g_class g_swap_class = {
|
|
|
|
.name = "SWAP",
|
2004-08-08 07:57:53 +00:00
|
|
|
.version = G_VERSION,
|
|
|
|
.orphan = swapgeom_orphan,
|
2003-08-30 16:44:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DECLARE_GEOM_CLASS(g_swap_class, g_class);
|
|
|
|
|
|
|
|
|
2015-03-26 17:21:12 +00:00
|
|
|
static void
|
|
|
|
swapgeom_close_ev(void *arg, int flags)
|
|
|
|
{
|
|
|
|
struct g_consumer *cp;
|
|
|
|
|
|
|
|
cp = arg;
|
|
|
|
g_access(cp, -1, -1, 0);
|
|
|
|
g_detach(cp);
|
|
|
|
g_destroy_consumer(cp);
|
|
|
|
}
|
|
|
|
|
2015-09-08 17:47:56 +00:00
|
|
|
/*
|
|
|
|
* Add a reference to the g_consumer for an inflight transaction.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
swapgeom_acquire(struct g_consumer *cp)
|
|
|
|
{
|
|
|
|
|
|
|
|
mtx_assert(&sw_dev_mtx, MA_OWNED);
|
|
|
|
cp->index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2016-08-03 07:11:19 +00:00
|
|
|
* Remove a reference from the g_consumer. Post a close event if all
|
|
|
|
* references go away, since the function might be called from the
|
|
|
|
* biodone context.
|
2015-09-08 17:47:56 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
swapgeom_release(struct g_consumer *cp, struct swdevt *sp)
|
|
|
|
{
|
|
|
|
|
|
|
|
mtx_assert(&sw_dev_mtx, MA_OWNED);
|
|
|
|
cp->index--;
|
|
|
|
if (cp->index == 0) {
|
|
|
|
if (g_post_event(swapgeom_close_ev, cp, M_NOWAIT, NULL) == 0)
|
|
|
|
sp->sw_id = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-30 16:44:26 +00:00
|
|
|
static void
|
|
|
|
swapgeom_done(struct bio *bp2)
|
|
|
|
{
|
2015-03-26 17:21:12 +00:00
|
|
|
struct swdevt *sp;
|
2003-08-30 16:44:26 +00:00
|
|
|
struct buf *bp;
|
2015-03-26 17:21:12 +00:00
|
|
|
struct g_consumer *cp;
|
2003-08-30 16:44:26 +00:00
|
|
|
|
|
|
|
bp = bp2->bio_caller2;
|
2015-03-26 17:21:12 +00:00
|
|
|
cp = bp2->bio_from;
|
2004-11-04 08:38:07 +00:00
|
|
|
bp->b_ioflags = bp2->bio_flags;
|
2003-08-30 16:44:26 +00:00
|
|
|
if (bp2->bio_error)
|
|
|
|
bp->b_ioflags |= BIO_ERROR;
|
2004-11-04 08:38:07 +00:00
|
|
|
bp->b_resid = bp->b_bcount - bp2->bio_completed;
|
|
|
|
bp->b_error = bp2->bio_error;
|
2003-08-30 16:44:26 +00:00
|
|
|
bufdone(bp);
|
2015-09-08 17:47:56 +00:00
|
|
|
sp = bp2->bio_caller1;
|
2015-03-26 17:21:12 +00:00
|
|
|
mtx_lock(&sw_dev_mtx);
|
2015-09-08 17:47:56 +00:00
|
|
|
swapgeom_release(cp, sp);
|
2015-03-26 17:21:12 +00:00
|
|
|
mtx_unlock(&sw_dev_mtx);
|
2003-08-30 16:44:26 +00:00
|
|
|
g_destroy_bio(bp2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
swapgeom_strategy(struct buf *bp, struct swdevt *sp)
|
|
|
|
{
|
|
|
|
struct bio *bio;
|
|
|
|
struct g_consumer *cp;
|
|
|
|
|
2015-03-26 17:21:12 +00:00
|
|
|
mtx_lock(&sw_dev_mtx);
|
2003-08-30 16:44:26 +00:00
|
|
|
cp = sp->sw_id;
|
|
|
|
if (cp == NULL) {
|
2015-03-26 17:21:12 +00:00
|
|
|
mtx_unlock(&sw_dev_mtx);
|
2003-08-30 16:44:26 +00:00
|
|
|
bp->b_error = ENXIO;
|
|
|
|
bp->b_ioflags |= BIO_ERROR;
|
|
|
|
bufdone(bp);
|
|
|
|
return;
|
|
|
|
}
|
2015-09-08 17:47:56 +00:00
|
|
|
swapgeom_acquire(cp);
|
2015-03-26 17:21:12 +00:00
|
|
|
mtx_unlock(&sw_dev_mtx);
|
2008-07-11 11:27:42 +00:00
|
|
|
if (bp->b_iocmd == BIO_WRITE)
|
|
|
|
bio = g_new_bio();
|
|
|
|
else
|
|
|
|
bio = g_alloc_bio();
|
2004-02-02 13:08:03 +00:00
|
|
|
if (bio == NULL) {
|
2015-09-08 17:47:56 +00:00
|
|
|
mtx_lock(&sw_dev_mtx);
|
|
|
|
swapgeom_release(cp, sp);
|
|
|
|
mtx_unlock(&sw_dev_mtx);
|
2004-02-02 13:08:03 +00:00
|
|
|
bp->b_error = ENOMEM;
|
|
|
|
bp->b_ioflags |= BIO_ERROR;
|
|
|
|
bufdone(bp);
|
|
|
|
return;
|
|
|
|
}
|
2008-07-11 11:27:42 +00:00
|
|
|
|
2015-03-26 17:21:12 +00:00
|
|
|
bio->bio_caller1 = sp;
|
2003-08-30 16:44:26 +00:00
|
|
|
bio->bio_caller2 = bp;
|
2004-11-04 08:38:07 +00:00
|
|
|
bio->bio_cmd = bp->b_iocmd;
|
2003-08-30 16:44:26 +00:00
|
|
|
bio->bio_offset = (bp->b_blkno - sp->sw_first) * PAGE_SIZE;
|
|
|
|
bio->bio_length = bp->b_bcount;
|
|
|
|
bio->bio_done = swapgeom_done;
|
2015-07-23 19:13:41 +00:00
|
|
|
if (!buf_mapped(bp)) {
|
2013-03-19 14:39:27 +00:00
|
|
|
bio->bio_ma = bp->b_pages;
|
|
|
|
bio->bio_data = unmapped_buf;
|
|
|
|
bio->bio_ma_offset = (vm_offset_t)bp->b_offset & PAGE_MASK;
|
|
|
|
bio->bio_ma_n = bp->b_npages;
|
|
|
|
bio->bio_flags |= BIO_UNMAPPED;
|
|
|
|
} else {
|
|
|
|
bio->bio_data = bp->b_data;
|
|
|
|
bio->bio_ma = NULL;
|
|
|
|
}
|
2003-08-30 16:44:26 +00:00
|
|
|
g_io_request(bio, cp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
swapgeom_orphan(struct g_consumer *cp)
|
|
|
|
{
|
|
|
|
struct swdevt *sp;
|
2015-03-26 17:21:12 +00:00
|
|
|
int destroy;
|
2003-08-30 16:44:26 +00:00
|
|
|
|
|
|
|
mtx_lock(&sw_dev_mtx);
|
2015-03-26 17:21:12 +00:00
|
|
|
TAILQ_FOREACH(sp, &swtailq, sw_list) {
|
|
|
|
if (sp->sw_id == cp) {
|
2012-02-01 20:12:44 +00:00
|
|
|
sp->sw_flags |= SW_CLOSING;
|
2015-03-26 17:21:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-09-08 17:47:56 +00:00
|
|
|
/*
|
|
|
|
* Drop reference we were created with. Do directly since we're in a
|
|
|
|
* special context where we don't have to queue the call to
|
|
|
|
* swapgeom_close_ev().
|
|
|
|
*/
|
|
|
|
cp->index--;
|
2015-03-26 17:21:12 +00:00
|
|
|
destroy = ((sp != NULL) && (cp->index == 0));
|
|
|
|
if (destroy)
|
|
|
|
sp->sw_id = NULL;
|
2003-08-30 16:44:26 +00:00
|
|
|
mtx_unlock(&sw_dev_mtx);
|
2015-03-26 17:21:12 +00:00
|
|
|
if (destroy)
|
|
|
|
swapgeom_close_ev(cp, 0);
|
2003-08-30 16:44:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
swapgeom_close(struct thread *td, struct swdevt *sw)
|
|
|
|
{
|
2015-03-26 17:21:12 +00:00
|
|
|
struct g_consumer *cp;
|
2003-08-30 16:44:26 +00:00
|
|
|
|
2015-03-26 17:21:12 +00:00
|
|
|
mtx_lock(&sw_dev_mtx);
|
|
|
|
cp = sw->sw_id;
|
|
|
|
sw->sw_id = NULL;
|
|
|
|
mtx_unlock(&sw_dev_mtx);
|
2016-08-03 07:11:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* swapgeom_close() may be called from the biodone context,
|
|
|
|
* where we cannot perform topology changes. Delegate the
|
|
|
|
* work to the events thread.
|
|
|
|
*/
|
2015-03-26 17:21:12 +00:00
|
|
|
if (cp != NULL)
|
|
|
|
g_waitfor_event(swapgeom_close_ev, cp, M_WAITOK, NULL);
|
2003-08-30 16:44:26 +00:00
|
|
|
}
|
|
|
|
|
2016-07-28 15:57:01 +00:00
|
|
|
static int
|
|
|
|
swapongeom_locked(struct cdev *dev, struct vnode *vp)
|
2003-08-30 16:44:26 +00:00
|
|
|
{
|
|
|
|
struct g_provider *pp;
|
|
|
|
struct g_consumer *cp;
|
|
|
|
static struct g_geom *gp;
|
|
|
|
struct swdevt *sp;
|
|
|
|
u_long nblks;
|
|
|
|
int error;
|
|
|
|
|
2016-07-28 15:57:01 +00:00
|
|
|
pp = g_dev_getprovider(dev);
|
|
|
|
if (pp == NULL)
|
|
|
|
return (ENODEV);
|
2003-08-30 16:44:26 +00:00
|
|
|
mtx_lock(&sw_dev_mtx);
|
|
|
|
TAILQ_FOREACH(sp, &swtailq, sw_list) {
|
|
|
|
cp = sp->sw_id;
|
|
|
|
if (cp != NULL && cp->provider == pp) {
|
|
|
|
mtx_unlock(&sw_dev_mtx);
|
2016-07-28 15:57:01 +00:00
|
|
|
return (EBUSY);
|
2003-08-30 16:44:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mtx_unlock(&sw_dev_mtx);
|
2004-08-08 07:57:53 +00:00
|
|
|
if (gp == NULL)
|
2012-11-20 12:32:18 +00:00
|
|
|
gp = g_new_geomf(&g_swap_class, "swap");
|
2003-08-30 16:44:26 +00:00
|
|
|
cp = g_new_consumer(gp);
|
2016-07-28 15:49:51 +00:00
|
|
|
cp->index = 1; /* Number of active I/Os, plus one for being active. */
|
2015-09-08 17:47:56 +00:00
|
|
|
cp->flags |= G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE;
|
2003-08-30 16:44:26 +00:00
|
|
|
g_attach(cp, pp);
|
2003-09-02 05:53:44 +00:00
|
|
|
/*
|
2016-05-02 20:16:29 +00:00
|
|
|
* XXX: Every time you think you can improve the margin for
|
2003-09-02 05:53:44 +00:00
|
|
|
* footshooting, somebody depends on the ability to do so:
|
|
|
|
* savecore(8) wants to write to our swapdev so we cannot
|
|
|
|
* set an exclusive count :-(
|
|
|
|
*/
|
2004-02-12 22:42:11 +00:00
|
|
|
error = g_access(cp, 1, 1, 0);
|
2016-07-28 15:57:01 +00:00
|
|
|
if (error != 0) {
|
2003-08-30 16:44:26 +00:00
|
|
|
g_detach(cp);
|
|
|
|
g_destroy_consumer(cp);
|
2016-07-28 15:57:01 +00:00
|
|
|
return (error);
|
2003-08-30 16:44:26 +00:00
|
|
|
}
|
|
|
|
nblks = pp->mediasize / DEV_BSIZE;
|
2016-07-28 15:57:01 +00:00
|
|
|
swaponsomething(vp, cp, nblks, swapgeom_strategy,
|
|
|
|
swapgeom_close, dev2udev(dev),
|
2013-03-19 14:39:27 +00:00
|
|
|
(pp->flags & G_PF_ACCEPT_UNMAPPED) != 0 ? SW_UNMAPPED : 0);
|
2016-07-28 15:57:01 +00:00
|
|
|
return (0);
|
2003-08-30 16:44:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-07-28 15:57:01 +00:00
|
|
|
swapongeom(struct vnode *vp)
|
2003-08-30 16:44:26 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2008-01-10 01:10:58 +00:00
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
2016-07-28 15:57:01 +00:00
|
|
|
if (vp->v_type != VCHR || (vp->v_iflag & VI_DOOMED) != 0) {
|
|
|
|
error = ENOENT;
|
|
|
|
} else {
|
|
|
|
g_topology_lock();
|
|
|
|
error = swapongeom_locked(vp->v_rdev, vp);
|
|
|
|
g_topology_unlock();
|
|
|
|
}
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(vp, 0);
|
2003-08-30 16:44:26 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* VNODE backend
|
|
|
|
*
|
|
|
|
* This is used mainly for network filesystem (read: probably only tested
|
|
|
|
* with NFS) swapfiles.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
swapdev_strategy(struct buf *bp, struct swdevt *sp)
|
|
|
|
{
|
2004-10-22 08:47:20 +00:00
|
|
|
struct vnode *vp2;
|
2003-08-30 16:44:26 +00:00
|
|
|
|
|
|
|
bp->b_blkno = ctodb(bp->b_blkno - sp->sw_first);
|
|
|
|
|
|
|
|
vp2 = sp->sw_id;
|
|
|
|
vhold(vp2);
|
|
|
|
if (bp->b_iocmd == BIO_WRITE) {
|
2005-09-21 15:01:09 +00:00
|
|
|
if (bp->b_bufobj)
|
2004-10-22 08:47:20 +00:00
|
|
|
bufobj_wdrop(bp->b_bufobj);
|
2004-10-21 15:53:54 +00:00
|
|
|
bufobj_wref(&vp2->v_bufobj);
|
2003-08-30 16:44:26 +00:00
|
|
|
}
|
2005-09-21 15:01:09 +00:00
|
|
|
if (bp->b_bufobj != &vp2->v_bufobj)
|
|
|
|
bp->b_bufobj = &vp2->v_bufobj;
|
2003-08-30 16:44:26 +00:00
|
|
|
bp->b_vp = vp2;
|
2003-10-18 14:10:28 +00:00
|
|
|
bp->b_iooffset = dbtob(bp->b_blkno);
|
2004-10-24 20:03:41 +00:00
|
|
|
bstrategy(bp);
|
2003-08-30 16:44:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
swapdev_close(struct thread *td, struct swdevt *sp)
|
|
|
|
{
|
|
|
|
|
|
|
|
VOP_CLOSE(sp->sw_vp, FREAD | FWRITE, td->td_ucred, td);
|
|
|
|
vrele(sp->sw_vp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
swaponvp(struct thread *td, struct vnode *vp, u_long nblks)
|
|
|
|
{
|
|
|
|
struct swdevt *sp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (nblks == 0)
|
|
|
|
return (ENXIO);
|
|
|
|
mtx_lock(&sw_dev_mtx);
|
|
|
|
TAILQ_FOREACH(sp, &swtailq, sw_list) {
|
|
|
|
if (sp->sw_id == vp) {
|
|
|
|
mtx_unlock(&sw_dev_mtx);
|
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mtx_unlock(&sw_dev_mtx);
|
2012-09-05 12:24:50 +00:00
|
|
|
|
2008-01-10 01:10:58 +00:00
|
|
|
(void) vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
2003-08-30 16:44:26 +00:00
|
|
|
#ifdef MAC
|
2007-10-24 19:04:04 +00:00
|
|
|
error = mac_system_check_swapon(td->td_ucred, vp);
|
2003-08-30 16:44:26 +00:00
|
|
|
if (error == 0)
|
|
|
|
#endif
|
2007-05-31 11:51:53 +00:00
|
|
|
error = VOP_OPEN(vp, FREAD | FWRITE, td->td_ucred, td, NULL);
|
2008-01-13 14:44:15 +00:00
|
|
|
(void) VOP_UNLOCK(vp, 0);
|
2003-08-30 16:44:26 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
swaponsomething(vp, vp, nblks, swapdev_strategy, swapdev_close,
|
2013-03-19 14:39:27 +00:00
|
|
|
NODEV, 0);
|
2003-08-30 16:44:26 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2015-05-02 20:27:37 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
sysctl_swap_async_max(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
int error, new, n;
|
|
|
|
|
|
|
|
new = nsw_wcount_async_max;
|
|
|
|
error = sysctl_handle_int(oidp, &new, 0, req);
|
|
|
|
if (error != 0 || req->newptr == NULL)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
if (new > nswbuf / 2 || new < 1)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
mtx_lock(&pbuf_mtx);
|
|
|
|
while (nsw_wcount_async_max != new) {
|
|
|
|
/*
|
|
|
|
* Adjust difference. If the current async count is too low,
|
|
|
|
* we will need to sqeeze our update slowly in. Sleep with a
|
|
|
|
* higher priority than getpbuf() to finish faster.
|
|
|
|
*/
|
|
|
|
n = new - nsw_wcount_async_max;
|
|
|
|
if (nsw_wcount_async + n >= 0) {
|
|
|
|
nsw_wcount_async += n;
|
|
|
|
nsw_wcount_async_max += n;
|
|
|
|
wakeup(&nsw_wcount_async);
|
|
|
|
} else {
|
|
|
|
nsw_wcount_async_max -= nsw_wcount_async;
|
|
|
|
nsw_wcount_async = 0;
|
|
|
|
msleep(&nsw_wcount_async, &pbuf_mtx, PSWP,
|
|
|
|
"swpsysctl", 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mtx_unlock(&pbuf_mtx);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|