2002-06-18 19:49:48 +04:00
|
|
|
/* $NetBSD: uvm_pglist.c,v 1.22 2002/06/18 15:49:48 drochner Exp $ */
|
1998-02-07 01:26:13 +03:00
|
|
|
|
1998-02-05 09:25:08 +03:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1997 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
2001-05-25 08:06:11 +04:00
|
|
|
*
|
1998-02-05 09:25:08 +03:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
|
2001-05-25 08:06:11 +04:00
|
|
|
* NASA Ames Research Center.
|
1998-02-05 09:25:08 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
2001-05-25 08:06:11 +04:00
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
1998-02-05 09:25:08 +03:00
|
|
|
* 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 the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
2001-05-25 08:06:11 +04:00
|
|
|
*
|
1998-02-05 09:25:08 +03:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* uvm_pglist.c: pglist functions
|
|
|
|
*/
|
|
|
|
|
2001-11-10 10:36:59 +03:00
|
|
|
#include <sys/cdefs.h>
|
2002-06-18 19:49:48 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: uvm_pglist.c,v 1.22 2002/06/18 15:49:48 drochner Exp $");
|
2001-11-10 10:36:59 +03:00
|
|
|
|
1998-02-05 09:25:08 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
|
|
|
|
#include <uvm/uvm.h>
|
|
|
|
|
|
|
|
#ifdef VM_PAGE_ALLOC_MEMORY_STATS
|
|
|
|
#define STAT_INCR(v) (v)++
|
|
|
|
#define STAT_DECR(v) do { \
|
|
|
|
if ((v) == 0) \
|
|
|
|
printf("%s:%d -- Already 0!\n", __FILE__, __LINE__); \
|
|
|
|
else \
|
|
|
|
(v)--; \
|
|
|
|
} while (0)
|
|
|
|
u_long uvm_pglistalloc_npages;
|
|
|
|
#else
|
|
|
|
#define STAT_INCR(v)
|
|
|
|
#define STAT_DECR(v)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* uvm_pglistalloc: allocate a list of pages
|
|
|
|
*
|
|
|
|
* => allocated pages are placed at the tail of rlist. rlist is
|
|
|
|
* assumed to be properly initialized by caller.
|
|
|
|
* => returns 0 on success or errno on failure
|
|
|
|
* => XXX: implementation allocates only a single segment, also
|
|
|
|
* might be able to better advantage of vm_physeg[].
|
|
|
|
* => doesn't take into account clean non-busy pages on inactive list
|
|
|
|
* that could be used(?)
|
|
|
|
* => params:
|
|
|
|
* size the size of the allocation, rounded to page size.
|
|
|
|
* low the low address of the allowed allocation range.
|
|
|
|
* high the high address of the allowed allocation range.
|
|
|
|
* alignment memory must be aligned to this power-of-two boundary.
|
2001-05-25 08:06:11 +04:00
|
|
|
* boundary no segment in the allocation may cross this
|
1998-02-05 09:25:08 +03:00
|
|
|
* power-of-two boundary (relative to zero).
|
|
|
|
*/
|
|
|
|
|
2002-05-29 23:20:11 +04:00
|
|
|
static void uvm_pglist_add(struct vm_page *, struct pglist *);
|
2002-06-18 19:49:48 +04:00
|
|
|
static int uvm_pglistalloc_c_ps(int, psize_t, paddr_t, paddr_t,
|
|
|
|
paddr_t, paddr_t, struct pglist *);
|
2002-05-29 23:20:11 +04:00
|
|
|
static int uvm_pglistalloc_contig(psize_t, paddr_t, paddr_t, paddr_t, paddr_t,
|
|
|
|
struct pglist *);
|
2002-06-18 19:49:48 +04:00
|
|
|
static void uvm_pglistalloc_s_ps(int, paddr_t, paddr_t,
|
|
|
|
struct pglist *, int *);
|
2002-05-29 23:20:11 +04:00
|
|
|
static int uvm_pglistalloc_simple(psize_t, paddr_t, paddr_t,
|
|
|
|
struct pglist *, int);
|
|
|
|
|
|
|
|
static void
|
|
|
|
uvm_pglist_add(pg, rlist)
|
|
|
|
struct vm_page *pg;
|
1998-03-09 03:58:55 +03:00
|
|
|
struct pglist *rlist;
|
1998-02-05 09:25:08 +03:00
|
|
|
{
|
2002-05-29 23:20:11 +04:00
|
|
|
int free_list, color, pgflidx;
|
1998-02-05 09:25:08 +03:00
|
|
|
#ifdef DEBUG
|
2001-05-27 01:27:10 +04:00
|
|
|
struct vm_page *tp;
|
1998-02-05 09:25:08 +03:00
|
|
|
#endif
|
|
|
|
|
2002-05-29 23:20:11 +04:00
|
|
|
#if PGFL_NQUEUES != 2
|
|
|
|
#error uvm_pglistalloc needs to be updated
|
|
|
|
#endif
|
2001-05-25 08:06:11 +04:00
|
|
|
|
2002-05-29 23:20:11 +04:00
|
|
|
free_list = uvm_page_lookup_freelist(pg);
|
|
|
|
color = VM_PGCOLOR_BUCKET(pg);
|
|
|
|
pgflidx = (pg->flags & PG_ZERO) ? PGFL_ZEROS : PGFL_UNKNOWN;
|
|
|
|
#ifdef DEBUG
|
|
|
|
for (tp = TAILQ_FIRST(&uvm.page_free[
|
|
|
|
free_list].pgfl_buckets[color].pgfl_queues[pgflidx]);
|
|
|
|
tp != NULL;
|
|
|
|
tp = TAILQ_NEXT(tp, pageq)) {
|
|
|
|
if (tp == pg)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (tp == NULL)
|
|
|
|
panic("uvm_pglistalloc: page not on freelist");
|
|
|
|
#endif
|
|
|
|
TAILQ_REMOVE(&uvm.page_free[free_list].pgfl_buckets[
|
|
|
|
color].pgfl_queues[pgflidx], pg, pageq);
|
|
|
|
uvmexp.free--;
|
|
|
|
if (pg->flags & PG_ZERO)
|
|
|
|
uvmexp.zeropages--;
|
|
|
|
pg->flags = PG_CLEAN;
|
|
|
|
pg->pqflags = 0;
|
|
|
|
pg->uobject = NULL;
|
|
|
|
pg->uanon = NULL;
|
|
|
|
TAILQ_INSERT_TAIL(rlist, pg, pageq);
|
|
|
|
STAT_INCR(uvm_pglistalloc_npages);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-06-18 19:49:48 +04:00
|
|
|
uvm_pglistalloc_c_ps(psi, size, low, high, alignment, boundary, rlist)
|
|
|
|
int psi;
|
2002-05-29 23:20:11 +04:00
|
|
|
psize_t size;
|
|
|
|
paddr_t low, high, alignment, boundary;
|
|
|
|
struct pglist *rlist;
|
|
|
|
{
|
2002-06-18 19:49:48 +04:00
|
|
|
int try, limit, tryidx, end, idx;
|
2002-05-29 23:20:11 +04:00
|
|
|
struct vm_page *pgs;
|
2002-06-18 19:49:48 +04:00
|
|
|
paddr_t idxpa, lastidxpa;
|
2002-05-29 23:20:11 +04:00
|
|
|
u_long pagemask;
|
2002-06-18 19:49:48 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
int cidx;
|
|
|
|
#endif
|
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
|
|
|
|
2002-06-18 19:49:48 +04:00
|
|
|
limit = min(atop(high), vm_physmem[psi].avail_end);
|
1998-03-09 03:58:55 +03:00
|
|
|
pagemask = ~(boundary - 1);
|
|
|
|
|
2002-06-18 19:49:48 +04:00
|
|
|
for (try = roundup(max(atop(low), vm_physmem[psi].avail_start),
|
|
|
|
atop(alignment));; try += atop(alignment)) {
|
|
|
|
if (try + atop(size) >= limit) {
|
2000-11-25 09:27:59 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* We've run past the allowable range.
|
|
|
|
*/
|
2000-11-25 09:27:59 +03:00
|
|
|
|
2002-06-18 19:49:48 +04:00
|
|
|
return (0); /* FAIL */
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
2002-06-18 19:49:48 +04:00
|
|
|
#ifdef DEBUG
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* Make sure this is a managed physical page.
|
|
|
|
*/
|
|
|
|
|
2002-06-18 19:49:48 +04:00
|
|
|
if (vm_physseg_find(try, &cidx) != psi)
|
|
|
|
panic("pgalloc contig: botch1");
|
|
|
|
if (cidx != try - vm_physmem[psi].start)
|
|
|
|
panic("pgalloc contig: botch2");
|
|
|
|
if (vm_physseg_find(try + atop(size), &cidx) != psi)
|
|
|
|
panic("pgalloc contig: botch3");
|
|
|
|
if (cidx != try - vm_physmem[psi].start + atop(size))
|
|
|
|
panic("pgalloc contig: botch4");
|
|
|
|
#endif
|
|
|
|
tryidx = try - vm_physmem[psi].start;
|
|
|
|
end = tryidx + (size / PAGE_SIZE);
|
1998-03-09 03:58:55 +03:00
|
|
|
pgs = vm_physmem[psi].pgs;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Found a suitable starting page. See of the range is free.
|
|
|
|
*/
|
2000-11-25 09:27:59 +03:00
|
|
|
|
2002-06-18 19:49:48 +04:00
|
|
|
for (idx = tryidx; idx < end; idx++) {
|
1998-03-09 03:58:55 +03:00
|
|
|
if (VM_PAGE_IS_FREE(&pgs[idx]) == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
idxpa = VM_PAGE_TO_PHYS(&pgs[idx]);
|
|
|
|
if (idx > tryidx) {
|
|
|
|
lastidxpa = VM_PAGE_TO_PHYS(&pgs[idx - 1]);
|
|
|
|
if ((lastidxpa + PAGE_SIZE) != idxpa) {
|
2000-11-25 09:27:59 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* Region not contiguous.
|
|
|
|
*/
|
2000-11-25 09:27:59 +03:00
|
|
|
|
2002-06-18 19:49:48 +04:00
|
|
|
panic("pgalloc contig: botch5");
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
|
|
|
if (boundary != 0 &&
|
|
|
|
((lastidxpa ^ idxpa) & pagemask) != 0) {
|
2000-11-25 09:27:59 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* Region crosses boundary.
|
|
|
|
*/
|
2000-11-25 09:27:59 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (idx == end) {
|
|
|
|
break;
|
|
|
|
}
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|
1998-03-09 03:58:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* we have a chunk of memory that conforms to the requested constraints.
|
|
|
|
*/
|
|
|
|
idx = tryidx;
|
|
|
|
while (idx < end) {
|
2002-05-29 23:20:11 +04:00
|
|
|
uvm_pglist_add(&pgs[idx++], rlist);
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
2002-06-18 19:49:48 +04:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
uvm_pglistalloc_contig(size, low, high, alignment, boundary, rlist)
|
|
|
|
psize_t size;
|
|
|
|
paddr_t low, high, alignment, boundary;
|
|
|
|
struct pglist *rlist;
|
|
|
|
{
|
|
|
|
int fl, psi;
|
|
|
|
int s, error;
|
|
|
|
|
|
|
|
if (boundary != 0 && boundary < size)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
/* Default to "lose". */
|
|
|
|
error = ENOMEM;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Block all memory allocation and lock the free list.
|
|
|
|
*/
|
|
|
|
|
|
|
|
s = uvm_lock_fpageq();
|
|
|
|
|
|
|
|
/* Are there even any free pages? */
|
|
|
|
if (uvmexp.free <= (uvmexp.reserve_pagedaemon + uvmexp.reserve_kernel))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
for (fl = 0; fl < VM_NFREELIST; fl++) {
|
|
|
|
#if (VM_PHYSSEG_STRAT == VM_PSTRAT_BIGFIRST)
|
|
|
|
for (psi = vm_nphysseg - 1 ; psi >= 0 ; psi--)
|
|
|
|
#else
|
|
|
|
for (psi = 0 ; psi < vm_nphysseg ; psi++)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if (vm_physmem[psi].free_list != fl)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (uvm_pglistalloc_c_ps(psi, size, low, high,
|
|
|
|
alignment, boundary, rlist)) {
|
|
|
|
#if 0
|
|
|
|
printf("pgalloc: %lx-%lx\n",
|
|
|
|
TAILQ_FIRST(rlist)->phys_addr,
|
|
|
|
TAILQ_LAST(rlist, pglist)->phys_addr);
|
|
|
|
#endif
|
|
|
|
error = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-02-05 09:25:08 +03:00
|
|
|
|
|
|
|
out:
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* check to see if we need to generate some free pages waking
|
|
|
|
* the pagedaemon.
|
|
|
|
*/
|
2001-05-25 08:06:11 +04:00
|
|
|
|
2001-06-28 01:18:34 +04:00
|
|
|
UVM_KICK_PDAEMON();
|
2000-11-25 09:27:59 +03:00
|
|
|
uvm_unlock_fpageq(s);
|
1998-03-09 03:58:55 +03:00
|
|
|
return (error);
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|
|
|
|
|
2002-06-18 19:49:48 +04:00
|
|
|
static void
|
|
|
|
uvm_pglistalloc_s_ps(psi, low, high, rlist, todo)
|
|
|
|
int psi;
|
|
|
|
paddr_t low, high;
|
|
|
|
struct pglist *rlist;
|
|
|
|
int *todo;
|
|
|
|
{
|
|
|
|
int limit, try;
|
|
|
|
struct vm_page *pg;
|
|
|
|
#ifdef DEBUG
|
|
|
|
int cidx;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
limit = min(atop(high), vm_physmem[psi].avail_end);
|
|
|
|
|
|
|
|
for (try = max(atop(low), vm_physmem[psi].avail_start);
|
|
|
|
try < limit; try ++) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (vm_physseg_find(try, &cidx) != psi)
|
|
|
|
panic("pgalloc simple: botch1");
|
|
|
|
if (cidx != (try - vm_physmem[psi].start))
|
|
|
|
panic("pgalloc simple: botch2");
|
|
|
|
#endif
|
|
|
|
pg = &vm_physmem[psi].pgs[try - vm_physmem[psi].start];
|
|
|
|
if (VM_PAGE_IS_FREE(pg) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
uvm_pglist_add(pg, rlist);
|
|
|
|
if (--(*todo) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-29 23:20:11 +04:00
|
|
|
static int
|
|
|
|
uvm_pglistalloc_simple(size, low, high, rlist, waitok)
|
|
|
|
psize_t size;
|
|
|
|
paddr_t low, high;
|
|
|
|
struct pglist *rlist;
|
|
|
|
int waitok;
|
|
|
|
{
|
2002-06-18 19:49:48 +04:00
|
|
|
int fl, psi, s, todo, error;
|
2002-05-29 23:20:11 +04:00
|
|
|
|
|
|
|
/* Default to "lose". */
|
|
|
|
error = ENOMEM;
|
|
|
|
|
|
|
|
todo = size / PAGE_SIZE;
|
|
|
|
|
|
|
|
again:
|
|
|
|
/*
|
|
|
|
* Block all memory allocation and lock the free list.
|
|
|
|
*/
|
|
|
|
|
|
|
|
s = uvm_lock_fpageq();
|
|
|
|
|
|
|
|
/* Are there even any free pages? */
|
|
|
|
if (uvmexp.free <= (uvmexp.reserve_pagedaemon + uvmexp.reserve_kernel))
|
|
|
|
goto out;
|
|
|
|
|
2002-06-18 19:49:48 +04:00
|
|
|
for (fl = 0; fl < VM_NFREELIST; fl++) {
|
|
|
|
#if (VM_PHYSSEG_STRAT == VM_PSTRAT_BIGFIRST)
|
|
|
|
for (psi = vm_nphysseg - 1 ; psi >= 0 ; psi--)
|
|
|
|
#else
|
|
|
|
for (psi = 0 ; psi < vm_nphysseg ; psi++)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if (vm_physmem[psi].free_list != fl)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
uvm_pglistalloc_s_ps(psi, low, high, rlist, &todo);
|
|
|
|
if (todo == 0) {
|
|
|
|
error = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-29 23:20:11 +04:00
|
|
|
}
|
2002-06-18 19:49:48 +04:00
|
|
|
|
2002-05-29 23:20:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
/*
|
|
|
|
* check to see if we need to generate some free pages waking
|
|
|
|
* the pagedaemon.
|
|
|
|
*/
|
|
|
|
|
|
|
|
UVM_KICK_PDAEMON();
|
|
|
|
uvm_unlock_fpageq(s);
|
|
|
|
if (error) {
|
|
|
|
if (waitok) {
|
|
|
|
/* XXX perhaps some time limitation? */
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("pglistalloc waiting\n");
|
|
|
|
#endif
|
|
|
|
uvm_wait("pglalloc");
|
|
|
|
goto again;
|
|
|
|
} else
|
|
|
|
uvm_pglistfree(rlist);
|
|
|
|
}
|
2002-06-18 19:49:48 +04:00
|
|
|
#if 0
|
|
|
|
if (!error)
|
|
|
|
printf("pgalloc: %lx..%lx\n",
|
|
|
|
TAILQ_FIRST(rlist)->phys_addr,
|
|
|
|
TAILQ_LAST(rlist, pglist)->phys_addr);
|
|
|
|
#endif
|
2002-05-29 23:20:11 +04:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
uvm_pglistalloc(size, low, high, alignment, boundary, rlist, nsegs, waitok)
|
|
|
|
psize_t size;
|
|
|
|
paddr_t low, high, alignment, boundary;
|
|
|
|
struct pglist *rlist;
|
|
|
|
int nsegs, waitok;
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
|
|
|
|
KASSERT((alignment & (alignment - 1)) == 0);
|
|
|
|
KASSERT((boundary & (boundary - 1)) == 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Our allocations are always page granularity, so our alignment
|
|
|
|
* must be, too.
|
|
|
|
*/
|
|
|
|
if (alignment < PAGE_SIZE)
|
|
|
|
alignment = PAGE_SIZE;
|
|
|
|
size = round_page(size);
|
|
|
|
low = roundup(low, alignment);
|
|
|
|
|
2002-06-02 18:44:35 +04:00
|
|
|
TAILQ_INIT(rlist);
|
|
|
|
|
2002-05-29 23:20:11 +04:00
|
|
|
if ((nsegs < size / PAGE_SIZE) || (alignment != PAGE_SIZE)
|
|
|
|
|| (boundary != 0))
|
|
|
|
res = uvm_pglistalloc_contig(size, low, high, alignment,
|
|
|
|
boundary, rlist);
|
|
|
|
else
|
|
|
|
res = uvm_pglistalloc_simple(size, low, high, rlist, waitok);
|
|
|
|
|
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
1998-02-05 09:25:08 +03:00
|
|
|
/*
|
|
|
|
* uvm_pglistfree: free a list of pages
|
|
|
|
*
|
|
|
|
* => pages should already be unmapped
|
|
|
|
*/
|
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
void
|
|
|
|
uvm_pglistfree(list)
|
|
|
|
struct pglist *list;
|
1998-02-05 09:25:08 +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
|
|
|
struct vm_page *pg;
|
1998-03-09 03:58:55 +03:00
|
|
|
int s;
|
1998-02-05 09:25:08 +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
|
|
|
* Lock the free list and free each page.
|
1998-03-09 03:58:55 +03:00
|
|
|
*/
|
1998-02-05 09:25:08 +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
|
|
|
s = uvm_lock_fpageq();
|
|
|
|
while ((pg = TAILQ_FIRST(list)) != NULL) {
|
|
|
|
KASSERT((pg->pqflags & (PQ_ACTIVE|PQ_INACTIVE)) == 0);
|
|
|
|
TAILQ_REMOVE(list, pg, pageq);
|
|
|
|
pg->pqflags = PQ_FREE;
|
|
|
|
TAILQ_INSERT_TAIL(&uvm.page_free[uvm_page_lookup_freelist(pg)].
|
|
|
|
pgfl_buckets[VM_PGCOLOR_BUCKET(pg)].
|
|
|
|
pgfl_queues[PGFL_UNKNOWN], pg, pageq);
|
1998-03-09 03:58:55 +03:00
|
|
|
uvmexp.free++;
|
2000-04-24 21:12:00 +04:00
|
|
|
if (uvmexp.zeropages < UVM_PAGEZERO_TARGET)
|
|
|
|
uvm.page_idle_zero = vm_page_zero_enable;
|
1998-03-09 03:58:55 +03:00
|
|
|
STAT_DECR(uvm_pglistalloc_npages);
|
|
|
|
}
|
1999-05-24 23:10:57 +04:00
|
|
|
uvm_unlock_fpageq(s);
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|