NetBSD/sys/uvm/uvm_pdaemon.c

961 lines
22 KiB
C
Raw Normal View History

/* $NetBSD: uvm_pdaemon.c,v 1.82 2006/12/27 17:59:08 alc Exp $ */
2001-05-25 08:06:11 +04:00
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
2001-05-25 08:06:11 +04:00
* Copyright (c) 1991, 1993, The Regents of the University of California.
*
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* The Mach Operating System project at Carnegie-Mellon University.
*
* 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
* must display the following acknowledgement:
* This product includes software developed by Charles D. Cranor,
2001-05-25 08:06:11 +04:00
* Washington University, 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.
*
* @(#)vm_pageout.c 8.5 (Berkeley) 2/14/94
1998-02-07 14:07:38 +03:00
* from: Id: uvm_pdaemon.c,v 1.1.2.32 1998/02/06 05:26:30 chs Exp
*
*
* Copyright (c) 1987, 1990 Carnegie-Mellon University.
* All rights reserved.
2001-05-25 08:06:11 +04:00
*
* Permission to use, copy, modify and distribute this software and
* its documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
2001-05-25 08:06:11 +04:00
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
2001-05-25 08:06:11 +04:00
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
*/
/*
* uvm_pdaemon.c: the page daemon
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: uvm_pdaemon.c,v 1.82 2006/12/27 17:59:08 alc Exp $");
#include "opt_uvmhist.h"
2005-11-29 18:45:28 +03:00
#include "opt_readahead.h"
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/systm.h>
#include <sys/kernel.h>
1998-07-24 00:36:09 +04:00
#include <sys/pool.h>
#include <sys/buf.h>
#include <uvm/uvm.h>
#include <uvm/uvm_pdpolicy.h>
/*
2002-01-21 17:42:26 +03:00
* UVMPD_NUMDIRTYREACTS is how many dirty pages the pagedaemon will reactivate
* in a pass thru the inactive list when swap is full. the value should be
* "small"... if it's too large we'll cycle the active pages thru the inactive
* queue too quickly to for them to be referenced and avoid being freed.
*/
#define UVMPD_NUMDIRTYREACTS 16
/*
* local prototypes
*/
2005-06-27 06:19:48 +04:00
static void uvmpd_scan(void);
static void uvmpd_scan_queue(void);
2005-06-27 06:19:48 +04:00
static void uvmpd_tune(void);
/*
* XXX hack to avoid hangs when large processes fork.
*/
int uvm_extrapages;
/*
* uvm_wait: wait (sleep) for the page daemon to free some pages
*
* => should be called with all locks released
* => should _not_ be called by the page daemon (to avoid deadlock)
*/
1999-11-05 00:51:42 +03:00
void
2005-06-27 06:19:48 +04:00
uvm_wait(const char *wmsg)
1998-03-09 03:58:55 +03:00
{
int timo = 0;
int s = splbio();
1998-03-09 03:58:55 +03:00
/*
* check for page daemon going to sleep (waiting for itself)
*/
a whole bunch of changes to improve performance and robustness under load: - remove special treatment of pager_map mappings in pmaps. this is required now, since I've removed the globals that expose the address range. pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's no longer any need to special-case it. - eliminate struct uvm_vnode by moving its fields into struct vnode. - rewrite the pageout path. the pager is now responsible for handling the high-level requests instead of only getting control after a bunch of work has already been done on its behalf. this will allow us to UBCify LFS, which needs tighter control over its pages than other filesystems do. writing a page to disk no longer requires making it read-only, which allows us to write wired pages without causing all kinds of havoc. - use a new PG_PAGEOUT flag to indicate that a page should be freed on behalf of the pagedaemon when it's unlocked. this flag is very similar to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the pageout fails due to eg. an indirect-block buffer being locked. this allows us to remove the "version" field from struct vm_page, and together with shrinking "loan_count" from 32 bits to 16, struct vm_page is now 4 bytes smaller. - no longer use PG_RELEASED for swap-backed pages. if the page is busy because it's being paged out, we can't release the swap slot to be reallocated until that write is complete, but unlike with vnodes we don't keep a count of in-progress writes so there's no good way to know when the write is done. instead, when we need to free a busy swap-backed page, just sleep until we can get it busy ourselves. - implement a fast-path for extending writes which allows us to avoid zeroing new pages. this substantially reduces cpu usage. - encapsulate the data used by the genfs code in a struct genfs_node, which must be the first element of the filesystem-specific vnode data for filesystems which use genfs_{get,put}pages(). - eliminate many of the UVM pagerops, since they aren't needed anymore now that the pager "put" operation is a higher-level operation. - enhance the genfs code to allow NFS to use the genfs_{get,put}pages instead of a modified copy. - clean up struct vnode by removing all the fields that used to be used by the vfs_cluster.c code (which we don't use anymore with UBC). - remove kmem_object and mb_object since they were useless. instead of allocating pages to these objects, we now just allocate pages with no object. such pages are mapped in the kernel until they are freed, so we can use the mapping to find the page to free it. this allows us to remove splvm() protection in several places. The sum of all these changes improves write throughput on my decstation 5000/200 to within 1% of the rate of NetBSD 1.5 and reduces the elapsed time for "make release" of a NetBSD 1.5 source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
if (curproc == uvm.pagedaemon_proc && uvmexp.paging == 0) {
1998-03-09 03:58:55 +03:00
/*
* now we have a problem: the pagedaemon wants to go to
* sleep until it frees more memory. but how can it
* free more memory if it is asleep? that is a deadlock.
* we have two options:
* [1] panic now
* [2] put a timeout on the sleep, thus causing the
* pagedaemon to only pause (rather than sleep forever)
*
* note that option [2] will only help us if we get lucky
* and some other process on the system breaks the deadlock
* by exiting or freeing memory (thus allowing the pagedaemon
* to continue). for now we panic if DEBUG is defined,
* otherwise we hope for the best with option [2] (better
* yet, this should never happen in the first place!).
*/
printf("pagedaemon: deadlock detected!\n");
timo = hz >> 3; /* set timeout */
#if defined(DEBUG)
1998-03-09 03:58:55 +03:00
/* DEBUG: panic so we can debug it */
panic("pagedaemon deadlock");
#endif
1998-03-09 03:58:55 +03:00
}
1998-03-09 03:58:55 +03:00
simple_lock(&uvm.pagedaemon_lock);
wakeup(&uvm.pagedaemon); /* wake the daemon! */
1998-03-09 03:58:55 +03:00
UVM_UNLOCK_AND_WAIT(&uvmexp.free, &uvm.pagedaemon_lock, FALSE, wmsg,
timo);
1998-03-09 03:58:55 +03:00
splx(s);
}
/*
* uvm_kick_pdaemon: perform checks to determine if we need to
* give the pagedaemon a nudge, and do so if necessary.
*/
void
uvm_kick_pdaemon(void)
{
if (uvmexp.free + uvmexp.paging < uvmexp.freemin ||
(uvmexp.free + uvmexp.paging < uvmexp.freetarg &&
uvmpdpol_needsscan_p())) {
wakeup(&uvm.pagedaemon);
}
}
/*
* uvmpd_tune: tune paging parameters
*
* => called when ever memory is added (or removed?) to the system
* => caller must call with page queues locked
*/
2005-06-27 06:19:48 +04:00
static void
a whole bunch of changes to improve performance and robustness under load: - remove special treatment of pager_map mappings in pmaps. this is required now, since I've removed the globals that expose the address range. pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's no longer any need to special-case it. - eliminate struct uvm_vnode by moving its fields into struct vnode. - rewrite the pageout path. the pager is now responsible for handling the high-level requests instead of only getting control after a bunch of work has already been done on its behalf. this will allow us to UBCify LFS, which needs tighter control over its pages than other filesystems do. writing a page to disk no longer requires making it read-only, which allows us to write wired pages without causing all kinds of havoc. - use a new PG_PAGEOUT flag to indicate that a page should be freed on behalf of the pagedaemon when it's unlocked. this flag is very similar to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the pageout fails due to eg. an indirect-block buffer being locked. this allows us to remove the "version" field from struct vm_page, and together with shrinking "loan_count" from 32 bits to 16, struct vm_page is now 4 bytes smaller. - no longer use PG_RELEASED for swap-backed pages. if the page is busy because it's being paged out, we can't release the swap slot to be reallocated until that write is complete, but unlike with vnodes we don't keep a count of in-progress writes so there's no good way to know when the write is done. instead, when we need to free a busy swap-backed page, just sleep until we can get it busy ourselves. - implement a fast-path for extending writes which allows us to avoid zeroing new pages. this substantially reduces cpu usage. - encapsulate the data used by the genfs code in a struct genfs_node, which must be the first element of the filesystem-specific vnode data for filesystems which use genfs_{get,put}pages(). - eliminate many of the UVM pagerops, since they aren't needed anymore now that the pager "put" operation is a higher-level operation. - enhance the genfs code to allow NFS to use the genfs_{get,put}pages instead of a modified copy. - clean up struct vnode by removing all the fields that used to be used by the vfs_cluster.c code (which we don't use anymore with UBC). - remove kmem_object and mb_object since they were useless. instead of allocating pages to these objects, we now just allocate pages with no object. such pages are mapped in the kernel until they are freed, so we can use the mapping to find the page to free it. this allows us to remove splvm() protection in several places. The sum of all these changes improves write throughput on my decstation 5000/200 to within 1% of the rate of NetBSD 1.5 and reduces the elapsed time for "make release" of a NetBSD 1.5 source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
uvmpd_tune(void)
{
1998-03-09 03:58:55 +03:00
UVMHIST_FUNC("uvmpd_tune"); UVMHIST_CALLED(pdhist);
uvmexp.freemin = uvmexp.npages / 20;
1998-03-09 03:58:55 +03:00
/* between 16k and 256k */
/* XXX: what are these values good for? */
a whole bunch of changes to improve performance and robustness under load: - remove special treatment of pager_map mappings in pmaps. this is required now, since I've removed the globals that expose the address range. pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's no longer any need to special-case it. - eliminate struct uvm_vnode by moving its fields into struct vnode. - rewrite the pageout path. the pager is now responsible for handling the high-level requests instead of only getting control after a bunch of work has already been done on its behalf. this will allow us to UBCify LFS, which needs tighter control over its pages than other filesystems do. writing a page to disk no longer requires making it read-only, which allows us to write wired pages without causing all kinds of havoc. - use a new PG_PAGEOUT flag to indicate that a page should be freed on behalf of the pagedaemon when it's unlocked. this flag is very similar to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the pageout fails due to eg. an indirect-block buffer being locked. this allows us to remove the "version" field from struct vm_page, and together with shrinking "loan_count" from 32 bits to 16, struct vm_page is now 4 bytes smaller. - no longer use PG_RELEASED for swap-backed pages. if the page is busy because it's being paged out, we can't release the swap slot to be reallocated until that write is complete, but unlike with vnodes we don't keep a count of in-progress writes so there's no good way to know when the write is done. instead, when we need to free a busy swap-backed page, just sleep until we can get it busy ourselves. - implement a fast-path for extending writes which allows us to avoid zeroing new pages. this substantially reduces cpu usage. - encapsulate the data used by the genfs code in a struct genfs_node, which must be the first element of the filesystem-specific vnode data for filesystems which use genfs_{get,put}pages(). - eliminate many of the UVM pagerops, since they aren't needed anymore now that the pager "put" operation is a higher-level operation. - enhance the genfs code to allow NFS to use the genfs_{get,put}pages instead of a modified copy. - clean up struct vnode by removing all the fields that used to be used by the vfs_cluster.c code (which we don't use anymore with UBC). - remove kmem_object and mb_object since they were useless. instead of allocating pages to these objects, we now just allocate pages with no object. such pages are mapped in the kernel until they are freed, so we can use the mapping to find the page to free it. this allows us to remove splvm() protection in several places. The sum of all these changes improves write throughput on my decstation 5000/200 to within 1% of the rate of NetBSD 1.5 and reduces the elapsed time for "make release" of a NetBSD 1.5 source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
uvmexp.freemin = MAX(uvmexp.freemin, (16*1024) >> PAGE_SHIFT);
uvmexp.freemin = MIN(uvmexp.freemin, (256*1024) >> PAGE_SHIFT);
/* Make sure there's always a user page free. */
if (uvmexp.freemin < uvmexp.reserve_kernel + 1)
uvmexp.freemin = uvmexp.reserve_kernel + 1;
1998-03-09 03:58:55 +03:00
uvmexp.freetarg = (uvmexp.freemin * 4) / 3;
if (uvmexp.freetarg <= uvmexp.freemin)
uvmexp.freetarg = uvmexp.freemin + 1;
uvmexp.freetarg += uvm_extrapages;
uvm_extrapages = 0;
1998-03-09 03:58:55 +03:00
uvmexp.wiredmax = uvmexp.npages / 3;
UVMHIST_LOG(pdhist, "<- done, freemin=%d, freetarg=%d, wiredmax=%d",
uvmexp.freemin, uvmexp.freetarg, uvmexp.wiredmax, 0);
}
/*
* uvm_pageout: the main loop for the pagedaemon
*/
1998-03-09 03:58:55 +03:00
void
uvm_pageout(void *arg)
{
int bufcnt, npages = 0;
int extrapages = 0;
1998-03-09 03:58:55 +03:00
UVMHIST_FUNC("uvm_pageout"); UVMHIST_CALLED(pdhist);
1998-03-09 03:58:55 +03:00
UVMHIST_LOG(pdhist,"<starting uvm pagedaemon>", 0, 0, 0, 0);
/*
* ensure correct priority and set paging parameters...
*/
uvm.pagedaemon_proc = curproc;
uvm_lock_pageq();
npages = uvmexp.npages;
uvmpd_tune();
uvm_unlock_pageq();
/*
* main loop
*/
for (;;) {
1998-03-09 03:58:55 +03:00
simple_lock(&uvm.pagedaemon_lock);
UVMHIST_LOG(pdhist," <<SLEEPING>>",0,0,0,0);
UVM_UNLOCK_AND_WAIT(&uvm.pagedaemon,
&uvm.pagedaemon_lock, FALSE, "pgdaemon", 0);
uvmexp.pdwoke++;
UVMHIST_LOG(pdhist," <<WOKE UP>>",0,0,0,0);
1998-03-09 03:58:55 +03:00
/*
* now lock page queues and recompute inactive count
*/
uvm_lock_pageq();
if (npages != uvmexp.npages || extrapages != uvm_extrapages) {
1998-03-09 03:58:55 +03:00
npages = uvmexp.npages;
extrapages = uvm_extrapages;
1998-03-09 03:58:55 +03:00
uvmpd_tune();
}
uvmpdpol_tune();
1998-03-09 03:58:55 +03:00
/*
* Estimate a hint. Note that bufmem are returned to
* system only when entire pool page is empty.
*/
bufcnt = uvmexp.freetarg - uvmexp.free;
if (bufcnt < 0)
bufcnt = 0;
UVMHIST_LOG(pdhist," free/ftarg=%d/%d",
uvmexp.free, uvmexp.freetarg, 0,0);
1998-03-09 03:58:55 +03:00
/*
* scan if needed
*/
if (uvmexp.free + uvmexp.paging < uvmexp.freetarg ||
uvmpdpol_needsscan_p()) {
1998-03-09 03:58:55 +03:00
uvmpd_scan();
}
/*
* if there's any free memory to be had,
* wake up any waiters.
*/
if (uvmexp.free > uvmexp.reserve_kernel ||
uvmexp.paging == 0) {
wakeup(&uvmexp.free);
}
1998-03-09 03:58:55 +03:00
/*
* scan done. unlock page queues (the only lock we are holding)
1998-03-09 03:58:55 +03:00
*/
1998-03-09 03:58:55 +03:00
uvm_unlock_pageq();
buf_drain(bufcnt << PAGE_SHIFT);
/*
* drain pool resources now that we're not holding any locks
*/
pool_drain(0);
/*
* free any cached u-areas we don't need
*/
uvm_uarea_drain(TRUE);
}
/*NOTREACHED*/
}
/*
* uvm_aiodone_worker: a workqueue callback for the aiodone daemon.
*/
void
uvm_aiodone_worker(struct work *wk, void *dummy)
{
int s, free;
struct buf *bp = (void *)wk;
KASSERT(&bp->b_work == wk);
/*
* process an i/o that's done.
*/
free = uvmexp.free;
(*bp->b_iodone)(bp);
if (free <= uvmexp.reserve_kernel) {
s = uvm_lock_fpageq();
wakeup(&uvm.pagedaemon);
uvm_unlock_fpageq(s);
} else {
simple_lock(&uvm.pagedaemon_lock);
wakeup(&uvmexp.free);
simple_unlock(&uvm.pagedaemon_lock);
1998-03-09 03:58:55 +03:00
}
}
/*
* uvmpd_trylockowner: trylock the page's owner.
*
* => called with pageq locked.
* => resolve orphaned O->A loaned page.
* => return the locked simplelock on success. otherwise, return NULL.
*/
struct simplelock *
uvmpd_trylockowner(struct vm_page *pg)
{
struct uvm_object *uobj = pg->uobject;
struct simplelock *slock;
UVM_LOCK_ASSERT_PAGEQ();
if (uobj != NULL) {
slock = &uobj->vmobjlock;
} else {
struct vm_anon *anon = pg->uanon;
KASSERT(anon != NULL);
slock = &anon->an_lock;
}
if (!simple_lock_try(slock)) {
return NULL;
}
if (uobj == NULL) {
/*
* set PQ_ANON if it isn't set already.
*/
if ((pg->pqflags & PQ_ANON) == 0) {
KASSERT(pg->loan_count > 0);
pg->loan_count--;
pg->pqflags |= PQ_ANON;
/* anon now owns it */
}
}
return slock;
}
2006-02-12 12:19:59 +03:00
#if defined(VMSWAP)
struct swapcluster {
int swc_slot;
int swc_nallocated;
int swc_nused;
struct vm_page *swc_pages[howmany(MAXPHYS, MIN_PAGE_SIZE)];
2006-02-12 12:19:59 +03:00
};
static void
swapcluster_init(struct swapcluster *swc)
{
swc->swc_slot = 0;
}
static int
swapcluster_allocslots(struct swapcluster *swc)
{
int slot;
int npages;
if (swc->swc_slot != 0) {
return 0;
}
/* Even with strange MAXPHYS, the shift
implicitly rounds down to a page. */
npages = MAXPHYS >> PAGE_SHIFT;
slot = uvm_swap_alloc(&npages, TRUE);
if (slot == 0) {
return ENOMEM;
}
swc->swc_slot = slot;
swc->swc_nallocated = npages;
swc->swc_nused = 0;
return 0;
}
static int
swapcluster_add(struct swapcluster *swc, struct vm_page *pg)
{
int slot;
struct uvm_object *uobj;
KASSERT(swc->swc_slot != 0);
KASSERT(swc->swc_nused < swc->swc_nallocated);
KASSERT((pg->pqflags & PQ_SWAPBACKED) != 0);
slot = swc->swc_slot + swc->swc_nused;
uobj = pg->uobject;
if (uobj == NULL) {
LOCK_ASSERT(simple_lock_held(&pg->uanon->an_lock));
pg->uanon->an_swslot = slot;
} else {
int result;
LOCK_ASSERT(simple_lock_held(&uobj->vmobjlock));
result = uao_set_swslot(uobj, pg->offset >> PAGE_SHIFT, slot);
if (result == -1) {
return ENOMEM;
}
}
swc->swc_pages[swc->swc_nused] = pg;
swc->swc_nused++;
return 0;
}
static void
swapcluster_flush(struct swapcluster *swc, boolean_t now)
{
int slot;
int nused;
int nallocated;
int error;
if (swc->swc_slot == 0) {
return;
}
KASSERT(swc->swc_nused <= swc->swc_nallocated);
slot = swc->swc_slot;
nused = swc->swc_nused;
nallocated = swc->swc_nallocated;
/*
* if this is the final pageout we could have a few
* unused swap blocks. if so, free them now.
*/
if (nused < nallocated) {
if (!now) {
return;
}
uvm_swap_free(slot + nused, nallocated - nused);
}
/*
* now start the pageout.
*/
uvmexp.pdpageouts++;
error = uvm_swap_put(slot, swc->swc_pages, nused, 0);
KASSERT(error == 0);
/*
* zero swslot to indicate that we are
* no longer building a swap-backed cluster.
*/
swc->swc_slot = 0;
}
/*
* uvmpd_dropswap: free any swap allocated to this page.
*
* => called with owner locked.
* => return TRUE if a page had an associated slot.
*/
static boolean_t
uvmpd_dropswap(struct vm_page *pg)
{
boolean_t result = FALSE;
struct vm_anon *anon = pg->uanon;
if ((pg->pqflags & PQ_ANON) && anon->an_swslot) {
uvm_swap_free(anon->an_swslot, 1);
anon->an_swslot = 0;
pg->flags &= ~PG_CLEAN;
result = TRUE;
} else if (pg->pqflags & PQ_AOBJ) {
int slot = uao_set_swslot(pg->uobject,
pg->offset >> PAGE_SHIFT, 0);
if (slot) {
uvm_swap_free(slot, 1);
pg->flags &= ~PG_CLEAN;
result = TRUE;
}
}
return result;
}
/*
* uvmpd_trydropswap: try to free any swap allocated to this page.
*
* => return TRUE if a slot is successfully freed.
*/
boolean_t
uvmpd_trydropswap(struct vm_page *pg)
{
struct simplelock *slock;
boolean_t result;
if ((pg->flags & PG_BUSY) != 0) {
return FALSE;
}
/*
* lock the page's owner.
*/
slock = uvmpd_trylockowner(pg);
if (slock == NULL) {
return FALSE;
}
/*
* skip this page if it's busy.
*/
if ((pg->flags & PG_BUSY) != 0) {
simple_unlock(slock);
return FALSE;
}
result = uvmpd_dropswap(pg);
simple_unlock(slock);
return result;
}
2006-02-12 12:19:59 +03:00
#endif /* defined(VMSWAP) */
/*
* uvmpd_scan_queue: scan an replace candidate list for pages
* to clean or free.
*
* => called with page queues locked
* => we work on meeting our free target by converting inactive pages
* into free pages.
* => we handle the building of swap-backed clusters
*/
2005-06-27 06:19:48 +04:00
static void
uvmpd_scan_queue(void)
1998-03-09 03:58:55 +03:00
{
struct vm_page *p;
1998-03-09 03:58:55 +03:00
struct uvm_object *uobj;
struct vm_anon *anon;
#if defined(VMSWAP)
2006-02-12 12:19:59 +03:00
struct swapcluster swc;
#endif /* defined(VMSWAP) */
int dirtyreacts;
a whole bunch of changes to improve performance and robustness under load: - remove special treatment of pager_map mappings in pmaps. this is required now, since I've removed the globals that expose the address range. pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's no longer any need to special-case it. - eliminate struct uvm_vnode by moving its fields into struct vnode. - rewrite the pageout path. the pager is now responsible for handling the high-level requests instead of only getting control after a bunch of work has already been done on its behalf. this will allow us to UBCify LFS, which needs tighter control over its pages than other filesystems do. writing a page to disk no longer requires making it read-only, which allows us to write wired pages without causing all kinds of havoc. - use a new PG_PAGEOUT flag to indicate that a page should be freed on behalf of the pagedaemon when it's unlocked. this flag is very similar to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the pageout fails due to eg. an indirect-block buffer being locked. this allows us to remove the "version" field from struct vm_page, and together with shrinking "loan_count" from 32 bits to 16, struct vm_page is now 4 bytes smaller. - no longer use PG_RELEASED for swap-backed pages. if the page is busy because it's being paged out, we can't release the swap slot to be reallocated until that write is complete, but unlike with vnodes we don't keep a count of in-progress writes so there's no good way to know when the write is done. instead, when we need to free a busy swap-backed page, just sleep until we can get it busy ourselves. - implement a fast-path for extending writes which allows us to avoid zeroing new pages. this substantially reduces cpu usage. - encapsulate the data used by the genfs code in a struct genfs_node, which must be the first element of the filesystem-specific vnode data for filesystems which use genfs_{get,put}pages(). - eliminate many of the UVM pagerops, since they aren't needed anymore now that the pager "put" operation is a higher-level operation. - enhance the genfs code to allow NFS to use the genfs_{get,put}pages instead of a modified copy. - clean up struct vnode by removing all the fields that used to be used by the vfs_cluster.c code (which we don't use anymore with UBC). - remove kmem_object and mb_object since they were useless. instead of allocating pages to these objects, we now just allocate pages with no object. such pages are mapped in the kernel until they are freed, so we can use the mapping to find the page to free it. this allows us to remove splvm() protection in several places. The sum of all these changes improves write throughput on my decstation 5000/200 to within 1% of the rate of NetBSD 1.5 and reduces the elapsed time for "make release" of a NetBSD 1.5 source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
struct simplelock *slock;
UVMHIST_FUNC("uvmpd_scan_queue"); UVMHIST_CALLED(pdhist);
1998-03-09 03:58:55 +03:00
/*
* swslot is non-zero if we are building a swap cluster. we want
* to stay in the loop while we have a page to scan or we have
1998-03-09 03:58:55 +03:00
* a swap-cluster to build.
*/
2006-02-12 12:19:59 +03:00
#if defined(VMSWAP)
swapcluster_init(&swc);
#endif /* defined(VMSWAP) */
dirtyreacts = 0;
uvmpdpol_scaninit();
while (/* CONSTCOND */ 1) {
2006-02-12 12:19:59 +03:00
/*
* see if we've met the free target.
*/
2006-02-12 12:19:59 +03:00
if (uvmexp.free + uvmexp.paging >= uvmexp.freetarg << 2 ||
dirtyreacts == UVMPD_NUMDIRTYREACTS) {
UVMHIST_LOG(pdhist," met free target: "
"exit loop", 0, 0, 0, 0);
break;
}
p = uvmpdpol_selectvictim();
if (p == NULL) {
break;
}
KASSERT(uvmpdpol_pageisqueued_p(p));
KASSERT(p->wire_count == 0);
2006-02-12 12:19:59 +03:00
/*
* we are below target and have a new page to consider.
2006-02-12 12:19:59 +03:00
*/
a whole bunch of changes to improve performance and robustness under load: - remove special treatment of pager_map mappings in pmaps. this is required now, since I've removed the globals that expose the address range. pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's no longer any need to special-case it. - eliminate struct uvm_vnode by moving its fields into struct vnode. - rewrite the pageout path. the pager is now responsible for handling the high-level requests instead of only getting control after a bunch of work has already been done on its behalf. this will allow us to UBCify LFS, which needs tighter control over its pages than other filesystems do. writing a page to disk no longer requires making it read-only, which allows us to write wired pages without causing all kinds of havoc. - use a new PG_PAGEOUT flag to indicate that a page should be freed on behalf of the pagedaemon when it's unlocked. this flag is very similar to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the pageout fails due to eg. an indirect-block buffer being locked. this allows us to remove the "version" field from struct vm_page, and together with shrinking "loan_count" from 32 bits to 16, struct vm_page is now 4 bytes smaller. - no longer use PG_RELEASED for swap-backed pages. if the page is busy because it's being paged out, we can't release the swap slot to be reallocated until that write is complete, but unlike with vnodes we don't keep a count of in-progress writes so there's no good way to know when the write is done. instead, when we need to free a busy swap-backed page, just sleep until we can get it busy ourselves. - implement a fast-path for extending writes which allows us to avoid zeroing new pages. this substantially reduces cpu usage. - encapsulate the data used by the genfs code in a struct genfs_node, which must be the first element of the filesystem-specific vnode data for filesystems which use genfs_{get,put}pages(). - eliminate many of the UVM pagerops, since they aren't needed anymore now that the pager "put" operation is a higher-level operation. - enhance the genfs code to allow NFS to use the genfs_{get,put}pages instead of a modified copy. - clean up struct vnode by removing all the fields that used to be used by the vfs_cluster.c code (which we don't use anymore with UBC). - remove kmem_object and mb_object since they were useless. instead of allocating pages to these objects, we now just allocate pages with no object. such pages are mapped in the kernel until they are freed, so we can use the mapping to find the page to free it. this allows us to remove splvm() protection in several places. The sum of all these changes improves write throughput on my decstation 5000/200 to within 1% of the rate of NetBSD 1.5 and reduces the elapsed time for "make release" of a NetBSD 1.5 source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
2006-02-12 12:19:59 +03:00
anon = p->uanon;
uobj = p->uobject;
1998-03-09 03:58:55 +03:00
2006-02-12 12:19:59 +03:00
/*
* first we attempt to lock the object that this page
* belongs to. if our attempt fails we skip on to
* the next page (no harm done). it is important to
* "try" locking the object as we are locking in the
* wrong order (pageq -> object) and we don't want to
* deadlock.
*
* the only time we expect to see an ownerless page
* (i.e. a page with no uobject and !PQ_ANON) is if an
* anon has loaned a page from a uvm_object and the
* uvm_object has dropped the ownership. in that
* case, the anon can "take over" the loaned page
* and make it its own.
*/
slock = uvmpd_trylockowner(p);
if (slock == NULL) {
continue;
}
if (p->flags & PG_BUSY) {
simple_unlock(slock);
uvmexp.pdbusy++;
continue;
}
2006-02-12 12:19:59 +03:00
/* does the page belong to an object? */
if (uobj != NULL) {
uvmexp.pdobscan++;
} else {
#if defined(VMSWAP)
KASSERT(anon != NULL);
uvmexp.pdanscan++;
#else /* defined(VMSWAP) */
2006-02-12 12:19:59 +03:00
panic("%s: anon", __func__);
#endif /* defined(VMSWAP) */
2006-02-12 12:19:59 +03:00
}
1998-03-09 03:58:55 +03:00
a whole bunch of changes to improve performance and robustness under load: - remove special treatment of pager_map mappings in pmaps. this is required now, since I've removed the globals that expose the address range. pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's no longer any need to special-case it. - eliminate struct uvm_vnode by moving its fields into struct vnode. - rewrite the pageout path. the pager is now responsible for handling the high-level requests instead of only getting control after a bunch of work has already been done on its behalf. this will allow us to UBCify LFS, which needs tighter control over its pages than other filesystems do. writing a page to disk no longer requires making it read-only, which allows us to write wired pages without causing all kinds of havoc. - use a new PG_PAGEOUT flag to indicate that a page should be freed on behalf of the pagedaemon when it's unlocked. this flag is very similar to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the pageout fails due to eg. an indirect-block buffer being locked. this allows us to remove the "version" field from struct vm_page, and together with shrinking "loan_count" from 32 bits to 16, struct vm_page is now 4 bytes smaller. - no longer use PG_RELEASED for swap-backed pages. if the page is busy because it's being paged out, we can't release the swap slot to be reallocated until that write is complete, but unlike with vnodes we don't keep a count of in-progress writes so there's no good way to know when the write is done. instead, when we need to free a busy swap-backed page, just sleep until we can get it busy ourselves. - implement a fast-path for extending writes which allows us to avoid zeroing new pages. this substantially reduces cpu usage. - encapsulate the data used by the genfs code in a struct genfs_node, which must be the first element of the filesystem-specific vnode data for filesystems which use genfs_{get,put}pages(). - eliminate many of the UVM pagerops, since they aren't needed anymore now that the pager "put" operation is a higher-level operation. - enhance the genfs code to allow NFS to use the genfs_{get,put}pages instead of a modified copy. - clean up struct vnode by removing all the fields that used to be used by the vfs_cluster.c code (which we don't use anymore with UBC). - remove kmem_object and mb_object since they were useless. instead of allocating pages to these objects, we now just allocate pages with no object. such pages are mapped in the kernel until they are freed, so we can use the mapping to find the page to free it. this allows us to remove splvm() protection in several places. The sum of all these changes improves write throughput on my decstation 5000/200 to within 1% of the rate of NetBSD 1.5 and reduces the elapsed time for "make release" of a NetBSD 1.5 source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
2006-02-12 12:19:59 +03:00
/*
* we now have the object and the page queues locked.
* if the page is not swap-backed, call the object's
* pager to flush and free the page.
*/
a whole bunch of changes to improve performance and robustness under load: - remove special treatment of pager_map mappings in pmaps. this is required now, since I've removed the globals that expose the address range. pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's no longer any need to special-case it. - eliminate struct uvm_vnode by moving its fields into struct vnode. - rewrite the pageout path. the pager is now responsible for handling the high-level requests instead of only getting control after a bunch of work has already been done on its behalf. this will allow us to UBCify LFS, which needs tighter control over its pages than other filesystems do. writing a page to disk no longer requires making it read-only, which allows us to write wired pages without causing all kinds of havoc. - use a new PG_PAGEOUT flag to indicate that a page should be freed on behalf of the pagedaemon when it's unlocked. this flag is very similar to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the pageout fails due to eg. an indirect-block buffer being locked. this allows us to remove the "version" field from struct vm_page, and together with shrinking "loan_count" from 32 bits to 16, struct vm_page is now 4 bytes smaller. - no longer use PG_RELEASED for swap-backed pages. if the page is busy because it's being paged out, we can't release the swap slot to be reallocated until that write is complete, but unlike with vnodes we don't keep a count of in-progress writes so there's no good way to know when the write is done. instead, when we need to free a busy swap-backed page, just sleep until we can get it busy ourselves. - implement a fast-path for extending writes which allows us to avoid zeroing new pages. this substantially reduces cpu usage. - encapsulate the data used by the genfs code in a struct genfs_node, which must be the first element of the filesystem-specific vnode data for filesystems which use genfs_{get,put}pages(). - eliminate many of the UVM pagerops, since they aren't needed anymore now that the pager "put" operation is a higher-level operation. - enhance the genfs code to allow NFS to use the genfs_{get,put}pages instead of a modified copy. - clean up struct vnode by removing all the fields that used to be used by the vfs_cluster.c code (which we don't use anymore with UBC). - remove kmem_object and mb_object since they were useless. instead of allocating pages to these objects, we now just allocate pages with no object. such pages are mapped in the kernel until they are freed, so we can use the mapping to find the page to free it. this allows us to remove splvm() protection in several places. The sum of all these changes improves write throughput on my decstation 5000/200 to within 1% of the rate of NetBSD 1.5 and reduces the elapsed time for "make release" of a NetBSD 1.5 source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
2005-11-29 18:45:28 +03:00
#if defined(READAHEAD_STATS)
if ((p->pqflags & PQ_READAHEAD) != 0) {
p->pqflags &= ~PQ_READAHEAD;
2006-02-12 12:19:59 +03:00
uvm_ra_miss.ev_count++;
}
2005-11-29 18:45:28 +03:00
#endif /* defined(READAHEAD_STATS) */
2006-02-12 12:19:59 +03:00
if ((p->pqflags & PQ_SWAPBACKED) == 0) {
KASSERT(uobj != NULL);
2006-02-12 12:19:59 +03:00
uvm_unlock_pageq();
(void) (uobj->pgops->pgo_put)(uobj, p->offset,
p->offset + PAGE_SIZE, PGO_CLEANIT|PGO_FREE);
uvm_lock_pageq();
continue;
}
a whole bunch of changes to improve performance and robustness under load: - remove special treatment of pager_map mappings in pmaps. this is required now, since I've removed the globals that expose the address range. pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's no longer any need to special-case it. - eliminate struct uvm_vnode by moving its fields into struct vnode. - rewrite the pageout path. the pager is now responsible for handling the high-level requests instead of only getting control after a bunch of work has already been done on its behalf. this will allow us to UBCify LFS, which needs tighter control over its pages than other filesystems do. writing a page to disk no longer requires making it read-only, which allows us to write wired pages without causing all kinds of havoc. - use a new PG_PAGEOUT flag to indicate that a page should be freed on behalf of the pagedaemon when it's unlocked. this flag is very similar to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the pageout fails due to eg. an indirect-block buffer being locked. this allows us to remove the "version" field from struct vm_page, and together with shrinking "loan_count" from 32 bits to 16, struct vm_page is now 4 bytes smaller. - no longer use PG_RELEASED for swap-backed pages. if the page is busy because it's being paged out, we can't release the swap slot to be reallocated until that write is complete, but unlike with vnodes we don't keep a count of in-progress writes so there's no good way to know when the write is done. instead, when we need to free a busy swap-backed page, just sleep until we can get it busy ourselves. - implement a fast-path for extending writes which allows us to avoid zeroing new pages. this substantially reduces cpu usage. - encapsulate the data used by the genfs code in a struct genfs_node, which must be the first element of the filesystem-specific vnode data for filesystems which use genfs_{get,put}pages(). - eliminate many of the UVM pagerops, since they aren't needed anymore now that the pager "put" operation is a higher-level operation. - enhance the genfs code to allow NFS to use the genfs_{get,put}pages instead of a modified copy. - clean up struct vnode by removing all the fields that used to be used by the vfs_cluster.c code (which we don't use anymore with UBC). - remove kmem_object and mb_object since they were useless. instead of allocating pages to these objects, we now just allocate pages with no object. such pages are mapped in the kernel until they are freed, so we can use the mapping to find the page to free it. this allows us to remove splvm() protection in several places. The sum of all these changes improves write throughput on my decstation 5000/200 to within 1% of the rate of NetBSD 1.5 and reduces the elapsed time for "make release" of a NetBSD 1.5 source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
2006-02-12 12:19:59 +03:00
/*
* the page is swap-backed. remove all the permissions
* from the page so we can sync the modified info
* without any race conditions. if the page is clean
* we can free it now and continue.
*/
2006-02-12 12:19:59 +03:00
pmap_page_protect(p, VM_PROT_NONE);
if ((p->flags & PG_CLEAN) && pmap_clear_modify(p)) {
p->flags &= ~(PG_CLEAN);
}
if (p->flags & PG_CLEAN) {
int slot;
int pageidx;
2006-02-12 12:19:59 +03:00
pageidx = p->offset >> PAGE_SHIFT;
uvm_pagefree(p);
uvmexp.pdfreed++;
a whole bunch of changes to improve performance and robustness under load: - remove special treatment of pager_map mappings in pmaps. this is required now, since I've removed the globals that expose the address range. pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's no longer any need to special-case it. - eliminate struct uvm_vnode by moving its fields into struct vnode. - rewrite the pageout path. the pager is now responsible for handling the high-level requests instead of only getting control after a bunch of work has already been done on its behalf. this will allow us to UBCify LFS, which needs tighter control over its pages than other filesystems do. writing a page to disk no longer requires making it read-only, which allows us to write wired pages without causing all kinds of havoc. - use a new PG_PAGEOUT flag to indicate that a page should be freed on behalf of the pagedaemon when it's unlocked. this flag is very similar to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the pageout fails due to eg. an indirect-block buffer being locked. this allows us to remove the "version" field from struct vm_page, and together with shrinking "loan_count" from 32 bits to 16, struct vm_page is now 4 bytes smaller. - no longer use PG_RELEASED for swap-backed pages. if the page is busy because it's being paged out, we can't release the swap slot to be reallocated until that write is complete, but unlike with vnodes we don't keep a count of in-progress writes so there's no good way to know when the write is done. instead, when we need to free a busy swap-backed page, just sleep until we can get it busy ourselves. - implement a fast-path for extending writes which allows us to avoid zeroing new pages. this substantially reduces cpu usage. - encapsulate the data used by the genfs code in a struct genfs_node, which must be the first element of the filesystem-specific vnode data for filesystems which use genfs_{get,put}pages(). - eliminate many of the UVM pagerops, since they aren't needed anymore now that the pager "put" operation is a higher-level operation. - enhance the genfs code to allow NFS to use the genfs_{get,put}pages instead of a modified copy. - clean up struct vnode by removing all the fields that used to be used by the vfs_cluster.c code (which we don't use anymore with UBC). - remove kmem_object and mb_object since they were useless. instead of allocating pages to these objects, we now just allocate pages with no object. such pages are mapped in the kernel until they are freed, so we can use the mapping to find the page to free it. this allows us to remove splvm() protection in several places. The sum of all these changes improves write throughput on my decstation 5000/200 to within 1% of the rate of NetBSD 1.5 and reduces the elapsed time for "make release" of a NetBSD 1.5 source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
/*
2006-02-12 12:19:59 +03:00
* for anons, we need to remove the page
* from the anon ourselves. for aobjs,
* pagefree did that for us.
*/
2006-02-12 12:19:59 +03:00
if (anon) {
KASSERT(anon->an_swslot != 0);
anon->an_page = NULL;
slot = anon->an_swslot;
} else {
slot = uao_find_swslot(uobj, pageidx);
1998-03-09 03:58:55 +03:00
}
2006-02-12 12:19:59 +03:00
simple_unlock(slock);
if (slot > 0) {
/* this page is now only in swap. */
simple_lock(&uvm.swap_data_lock);
KASSERT(uvmexp.swpgonly < uvmexp.swpginuse);
uvmexp.swpgonly++;
simple_unlock(&uvm.swap_data_lock);
}
2006-02-12 12:19:59 +03:00
continue;
}
#if defined(VMSWAP)
2006-02-12 12:19:59 +03:00
/*
* this page is dirty, skip it if we'll have met our
* free target when all the current pageouts complete.
*/
1998-03-09 03:58:55 +03:00
2006-02-12 12:19:59 +03:00
if (uvmexp.free + uvmexp.paging > uvmexp.freetarg << 2) {
simple_unlock(slock);
continue;
}
2006-02-12 12:19:59 +03:00
/*
* free any swap space allocated to the page since
* we'll have to write it again with its new data.
*/
1998-03-09 03:58:55 +03:00
uvmpd_dropswap(p);
2006-02-12 12:19:59 +03:00
/*
* if all pages in swap are only in swap,
* the swap space is full and we can't page out
* any more swap-backed pages. reactivate this page
* so that we eventually cycle all pages through
* the inactive queue.
*/
2006-02-12 12:19:59 +03:00
if (uvm_swapisfull()) {
dirtyreacts++;
uvm_pageactivate(p);
simple_unlock(slock);
continue;
1998-03-09 03:58:55 +03:00
}
/*
2006-02-12 12:19:59 +03:00
* start new swap pageout cluster (if necessary).
1998-03-09 03:58:55 +03:00
*/
2006-02-12 12:19:59 +03:00
if (swapcluster_allocslots(&swc)) {
simple_unlock(slock);
dirtyreacts++; /* XXX */
2006-02-12 12:19:59 +03:00
continue;
1998-03-09 03:58:55 +03:00
}
/*
2006-02-12 12:19:59 +03:00
* at this point, we're definitely going reuse this
* page. mark the page busy and delayed-free.
* we should remove the page from the page queues
* so we don't ever look at it again.
* adjust counters and such.
1998-03-09 03:58:55 +03:00
*/
2006-02-12 12:19:59 +03:00
p->flags |= PG_BUSY;
UVM_PAGE_OWN(p, "scan_queue");
2006-02-12 12:19:59 +03:00
p->flags |= PG_PAGEOUT;
uvmexp.paging++;
uvm_pagedequeue(p);
uvmexp.pgswapout++;
a whole bunch of changes to improve performance and robustness under load: - remove special treatment of pager_map mappings in pmaps. this is required now, since I've removed the globals that expose the address range. pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's no longer any need to special-case it. - eliminate struct uvm_vnode by moving its fields into struct vnode. - rewrite the pageout path. the pager is now responsible for handling the high-level requests instead of only getting control after a bunch of work has already been done on its behalf. this will allow us to UBCify LFS, which needs tighter control over its pages than other filesystems do. writing a page to disk no longer requires making it read-only, which allows us to write wired pages without causing all kinds of havoc. - use a new PG_PAGEOUT flag to indicate that a page should be freed on behalf of the pagedaemon when it's unlocked. this flag is very similar to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the pageout fails due to eg. an indirect-block buffer being locked. this allows us to remove the "version" field from struct vm_page, and together with shrinking "loan_count" from 32 bits to 16, struct vm_page is now 4 bytes smaller. - no longer use PG_RELEASED for swap-backed pages. if the page is busy because it's being paged out, we can't release the swap slot to be reallocated until that write is complete, but unlike with vnodes we don't keep a count of in-progress writes so there's no good way to know when the write is done. instead, when we need to free a busy swap-backed page, just sleep until we can get it busy ourselves. - implement a fast-path for extending writes which allows us to avoid zeroing new pages. this substantially reduces cpu usage. - encapsulate the data used by the genfs code in a struct genfs_node, which must be the first element of the filesystem-specific vnode data for filesystems which use genfs_{get,put}pages(). - eliminate many of the UVM pagerops, since they aren't needed anymore now that the pager "put" operation is a higher-level operation. - enhance the genfs code to allow NFS to use the genfs_{get,put}pages instead of a modified copy. - clean up struct vnode by removing all the fields that used to be used by the vfs_cluster.c code (which we don't use anymore with UBC). - remove kmem_object and mb_object since they were useless. instead of allocating pages to these objects, we now just allocate pages with no object. such pages are mapped in the kernel until they are freed, so we can use the mapping to find the page to free it. this allows us to remove splvm() protection in several places. The sum of all these changes improves write throughput on my decstation 5000/200 to within 1% of the rate of NetBSD 1.5 and reduces the elapsed time for "make release" of a NetBSD 1.5 source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
uvm_unlock_pageq();
1998-03-09 03:58:55 +03:00
/*
2006-02-12 12:19:59 +03:00
* add the new page to the cluster.
1998-03-09 03:58:55 +03:00
*/
2006-02-12 12:19:59 +03:00
if (swapcluster_add(&swc, p)) {
p->flags &= ~(PG_BUSY|PG_PAGEOUT);
UVM_PAGE_OWN(p, NULL);
uvm_lock_pageq();
uvmexp.paging--;
dirtyreacts++;
2006-02-12 12:19:59 +03:00
uvm_pageactivate(p);
simple_unlock(slock);
continue;
}
simple_unlock(slock);
swapcluster_flush(&swc, FALSE);
uvm_lock_pageq();
1998-03-09 03:58:55 +03:00
/*
* the pageout is in progress. bump counters and set up
* for the next loop.
1998-03-09 03:58:55 +03:00
*/
uvmexp.pdpending++;
#else /* defined(VMSWAP) */
uvm_pageactivate(p);
simple_unlock(slock);
#endif /* defined(VMSWAP) */
}
2006-02-12 12:19:59 +03:00
#if defined(VMSWAP)
uvm_unlock_pageq();
swapcluster_flush(&swc, TRUE);
uvm_lock_pageq();
#endif /* defined(VMSWAP) */
}
/*
* uvmpd_scan: scan the page queues and attempt to meet our targets.
*
* => called with pageq's locked
*/
2005-06-27 06:19:48 +04:00
static void
a whole bunch of changes to improve performance and robustness under load: - remove special treatment of pager_map mappings in pmaps. this is required now, since I've removed the globals that expose the address range. pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's no longer any need to special-case it. - eliminate struct uvm_vnode by moving its fields into struct vnode. - rewrite the pageout path. the pager is now responsible for handling the high-level requests instead of only getting control after a bunch of work has already been done on its behalf. this will allow us to UBCify LFS, which needs tighter control over its pages than other filesystems do. writing a page to disk no longer requires making it read-only, which allows us to write wired pages without causing all kinds of havoc. - use a new PG_PAGEOUT flag to indicate that a page should be freed on behalf of the pagedaemon when it's unlocked. this flag is very similar to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the pageout fails due to eg. an indirect-block buffer being locked. this allows us to remove the "version" field from struct vm_page, and together with shrinking "loan_count" from 32 bits to 16, struct vm_page is now 4 bytes smaller. - no longer use PG_RELEASED for swap-backed pages. if the page is busy because it's being paged out, we can't release the swap slot to be reallocated until that write is complete, but unlike with vnodes we don't keep a count of in-progress writes so there's no good way to know when the write is done. instead, when we need to free a busy swap-backed page, just sleep until we can get it busy ourselves. - implement a fast-path for extending writes which allows us to avoid zeroing new pages. this substantially reduces cpu usage. - encapsulate the data used by the genfs code in a struct genfs_node, which must be the first element of the filesystem-specific vnode data for filesystems which use genfs_{get,put}pages(). - eliminate many of the UVM pagerops, since they aren't needed anymore now that the pager "put" operation is a higher-level operation. - enhance the genfs code to allow NFS to use the genfs_{get,put}pages instead of a modified copy. - clean up struct vnode by removing all the fields that used to be used by the vfs_cluster.c code (which we don't use anymore with UBC). - remove kmem_object and mb_object since they were useless. instead of allocating pages to these objects, we now just allocate pages with no object. such pages are mapped in the kernel until they are freed, so we can use the mapping to find the page to free it. this allows us to remove splvm() protection in several places. The sum of all these changes improves write throughput on my decstation 5000/200 to within 1% of the rate of NetBSD 1.5 and reduces the elapsed time for "make release" of a NetBSD 1.5 source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
uvmpd_scan(void)
{
int swap_shortage, pages_freed;
1998-03-09 03:58:55 +03:00
UVMHIST_FUNC("uvmpd_scan"); UVMHIST_CALLED(pdhist);
a whole bunch of changes to improve performance and robustness under load: - remove special treatment of pager_map mappings in pmaps. this is required now, since I've removed the globals that expose the address range. pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's no longer any need to special-case it. - eliminate struct uvm_vnode by moving its fields into struct vnode. - rewrite the pageout path. the pager is now responsible for handling the high-level requests instead of only getting control after a bunch of work has already been done on its behalf. this will allow us to UBCify LFS, which needs tighter control over its pages than other filesystems do. writing a page to disk no longer requires making it read-only, which allows us to write wired pages without causing all kinds of havoc. - use a new PG_PAGEOUT flag to indicate that a page should be freed on behalf of the pagedaemon when it's unlocked. this flag is very similar to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the pageout fails due to eg. an indirect-block buffer being locked. this allows us to remove the "version" field from struct vm_page, and together with shrinking "loan_count" from 32 bits to 16, struct vm_page is now 4 bytes smaller. - no longer use PG_RELEASED for swap-backed pages. if the page is busy because it's being paged out, we can't release the swap slot to be reallocated until that write is complete, but unlike with vnodes we don't keep a count of in-progress writes so there's no good way to know when the write is done. instead, when we need to free a busy swap-backed page, just sleep until we can get it busy ourselves. - implement a fast-path for extending writes which allows us to avoid zeroing new pages. this substantially reduces cpu usage. - encapsulate the data used by the genfs code in a struct genfs_node, which must be the first element of the filesystem-specific vnode data for filesystems which use genfs_{get,put}pages(). - eliminate many of the UVM pagerops, since they aren't needed anymore now that the pager "put" operation is a higher-level operation. - enhance the genfs code to allow NFS to use the genfs_{get,put}pages instead of a modified copy. - clean up struct vnode by removing all the fields that used to be used by the vfs_cluster.c code (which we don't use anymore with UBC). - remove kmem_object and mb_object since they were useless. instead of allocating pages to these objects, we now just allocate pages with no object. such pages are mapped in the kernel until they are freed, so we can use the mapping to find the page to free it. this allows us to remove splvm() protection in several places. The sum of all these changes improves write throughput on my decstation 5000/200 to within 1% of the rate of NetBSD 1.5 and reduces the elapsed time for "make release" of a NetBSD 1.5 source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
uvmexp.pdrevs++;
#ifndef __SWAP_BROKEN
1998-03-09 03:58:55 +03:00
/*
* swap out some processes if we are below our free target.
* we need to unlock the page queues for this.
*/
if (uvmexp.free < uvmexp.freetarg && uvmexp.nswapdev != 0) {
1998-03-09 03:58:55 +03:00
uvmexp.pdswout++;
a whole bunch of changes to improve performance and robustness under load: - remove special treatment of pager_map mappings in pmaps. this is required now, since I've removed the globals that expose the address range. pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's no longer any need to special-case it. - eliminate struct uvm_vnode by moving its fields into struct vnode. - rewrite the pageout path. the pager is now responsible for handling the high-level requests instead of only getting control after a bunch of work has already been done on its behalf. this will allow us to UBCify LFS, which needs tighter control over its pages than other filesystems do. writing a page to disk no longer requires making it read-only, which allows us to write wired pages without causing all kinds of havoc. - use a new PG_PAGEOUT flag to indicate that a page should be freed on behalf of the pagedaemon when it's unlocked. this flag is very similar to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the pageout fails due to eg. an indirect-block buffer being locked. this allows us to remove the "version" field from struct vm_page, and together with shrinking "loan_count" from 32 bits to 16, struct vm_page is now 4 bytes smaller. - no longer use PG_RELEASED for swap-backed pages. if the page is busy because it's being paged out, we can't release the swap slot to be reallocated until that write is complete, but unlike with vnodes we don't keep a count of in-progress writes so there's no good way to know when the write is done. instead, when we need to free a busy swap-backed page, just sleep until we can get it busy ourselves. - implement a fast-path for extending writes which allows us to avoid zeroing new pages. this substantially reduces cpu usage. - encapsulate the data used by the genfs code in a struct genfs_node, which must be the first element of the filesystem-specific vnode data for filesystems which use genfs_{get,put}pages(). - eliminate many of the UVM pagerops, since they aren't needed anymore now that the pager "put" operation is a higher-level operation. - enhance the genfs code to allow NFS to use the genfs_{get,put}pages instead of a modified copy. - clean up struct vnode by removing all the fields that used to be used by the vfs_cluster.c code (which we don't use anymore with UBC). - remove kmem_object and mb_object since they were useless. instead of allocating pages to these objects, we now just allocate pages with no object. such pages are mapped in the kernel until they are freed, so we can use the mapping to find the page to free it. this allows us to remove splvm() protection in several places. The sum of all these changes improves write throughput on my decstation 5000/200 to within 1% of the rate of NetBSD 1.5 and reduces the elapsed time for "make release" of a NetBSD 1.5 source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
UVMHIST_LOG(pdhist," free %d < target %d: swapout",
uvmexp.free, uvmexp.freetarg, 0, 0);
1998-03-09 03:58:55 +03:00
uvm_unlock_pageq();
uvm_swapout_threads();
uvm_lock_pageq();
}
#endif
1998-03-09 03:58:55 +03:00
/*
* now we want to work on meeting our targets. first we work on our
* free target by converting inactive pages into free pages. then
* we work on meeting our inactive target by converting active pages
* to inactive ones.
*/
UVMHIST_LOG(pdhist, " starting 'free' loop",0,0,0,0);
pages_freed = uvmexp.pdfreed;
uvmpd_scan_queue();
pages_freed = uvmexp.pdfreed - pages_freed;
1998-03-09 03:58:55 +03:00
/*
* detect if we're not going to be able to page anything out
* until we free some swap resources from active pages.
*/
swap_shortage = 0;
if (uvmexp.free < uvmexp.freetarg &&
uvmexp.swpginuse >= uvmexp.swpgavail &&
!uvm_swapisfull() &&
pages_freed == 0) {
swap_shortage = uvmexp.freetarg - uvmexp.free;
}
uvmpdpol_balancequeue(swap_shortage);
}
/*
* uvm_reclaimable: decide whether to wait for pagedaemon.
*
* => return TRUE if it seems to be worth to do uvm_wait.
*
* XXX should be tunable.
* XXX should consider pools, etc?
*/
boolean_t
uvm_reclaimable(void)
{
int filepages;
int active, inactive;
/*
* if swap is not full, no problem.
*/
if (!uvm_swapisfull()) {
return TRUE;
}
/*
* file-backed pages can be reclaimed even when swap is full.
* if we have more than 1/16 of pageable memory or 5MB, try to reclaim.
*
* XXX assume the worst case, ie. all wired pages are file-backed.
2005-05-05 03:23:28 +04:00
*
* XXX should consider about other reclaimable memory.
* XXX ie. pools, traditional buffer cache.
*/
filepages = uvmexp.filepages + uvmexp.execpages - uvmexp.wired;
uvm_estimatepageable(&active, &inactive);
if (filepages >= MIN((active + inactive) >> 4,
5 * 1024 * 1024 >> PAGE_SHIFT)) {
return TRUE;
}
/*
* kill the process, fail allocation, etc..
*/
return FALSE;
}
void
uvm_estimatepageable(int *active, int *inactive)
{
uvmpdpol_estimatepageable(active, inactive);
}