2001-11-10 10:36:59 +03:00
|
|
|
/* $NetBSD: uvm_km.c,v 1.55 2001/11/10 07:37:00 lukem Exp $ */
|
1998-02-05 09:25:08 +03:00
|
|
|
|
2001-05-25 08:06:11 +04:00
|
|
|
/*
|
1998-02-05 09:25:08 +03: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.
|
1998-02-05 09:25:08 +03:00
|
|
|
*
|
|
|
|
* 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
|
1998-02-05 09:25:08 +03:00
|
|
|
* 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_kern.c 8.3 (Berkeley) 1/12/94
|
1998-02-07 14:07:38 +03:00
|
|
|
* from: Id: uvm_km.c,v 1.1.2.14 1998/02/06 05:19:27 chs Exp
|
1998-02-05 09:25:08 +03:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (c) 1987, 1990 Carnegie-Mellon University.
|
|
|
|
* All rights reserved.
|
2001-05-25 08:06:11 +04:00
|
|
|
*
|
1998-02-05 09:25:08 +03: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
|
1998-02-05 09:25:08 +03:00
|
|
|
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
2001-05-25 08:06:11 +04:00
|
|
|
*
|
1998-02-05 09:25:08 +03: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_km.c: handle kernel memory allocation and management
|
|
|
|
*/
|
|
|
|
|
1998-02-24 18:58:09 +03:00
|
|
|
/*
|
|
|
|
* overview of kernel memory management:
|
|
|
|
*
|
|
|
|
* the kernel virtual address space is mapped by "kernel_map." kernel_map
|
|
|
|
* starts at VM_MIN_KERNEL_ADDRESS and goes to VM_MAX_KERNEL_ADDRESS.
|
|
|
|
* note that VM_MIN_KERNEL_ADDRESS is equal to vm_map_min(kernel_map).
|
|
|
|
*
|
2001-05-25 08:06:11 +04:00
|
|
|
* the kernel_map has several "submaps." submaps can only appear in
|
1998-02-24 18:58:09 +03:00
|
|
|
* the kernel_map (user processes can't use them). submaps "take over"
|
|
|
|
* the management of a sub-range of the kernel's address space. submaps
|
|
|
|
* are typically allocated at boot time and are never released. kernel
|
2001-05-25 08:06:11 +04:00
|
|
|
* virtual address space that is mapped by a submap is locked by the
|
1998-02-24 18:58:09 +03:00
|
|
|
* submap's lock -- not the kernel_map's lock.
|
|
|
|
*
|
|
|
|
* thus, the useful feature of submaps is that they allow us to break
|
|
|
|
* up the locking and protection of the kernel address space into smaller
|
|
|
|
* chunks.
|
|
|
|
*
|
|
|
|
* the vm system has several standard kernel submaps, including:
|
|
|
|
* kmem_map => contains only wired kernel memory for the kernel
|
|
|
|
* malloc. *** access to kmem_map must be protected
|
2001-01-14 05:10:01 +03:00
|
|
|
* by splvm() because we are allowed to call malloc()
|
1998-02-24 18:58:09 +03:00
|
|
|
* at interrupt time ***
|
2001-01-14 05:10:01 +03:00
|
|
|
* mb_map => memory for large mbufs, *** protected by splvm ***
|
1998-02-24 18:58:09 +03:00
|
|
|
* pager_map => used to map "buf" structures into kernel space
|
|
|
|
* exec_map => used during exec to handle exec args
|
|
|
|
* etc...
|
|
|
|
*
|
|
|
|
* the kernel allocates its private memory out of special uvm_objects whose
|
|
|
|
* reference count is set to UVM_OBJ_KERN (thus indicating that the objects
|
|
|
|
* are "special" and never die). all kernel objects should be thought of
|
2001-05-25 08:06:11 +04:00
|
|
|
* as large, fixed-sized, sparsely populated uvm_objects. each kernel
|
1998-02-24 18:58:09 +03:00
|
|
|
* object is equal to the size of kernel virtual address space (i.e. the
|
|
|
|
* value "VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS").
|
|
|
|
*
|
|
|
|
* most kernel private memory lives in kernel_object. the only exception
|
|
|
|
* to this is for memory that belongs to submaps that must be protected
|
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
|
|
|
* by splvm(). pages in these submaps are not assigned to an object.
|
1998-02-24 18:58:09 +03:00
|
|
|
*
|
|
|
|
* note that just because a kernel object spans the entire kernel virutal
|
|
|
|
* address space doesn't mean that it has to be mapped into the entire space.
|
2001-05-25 08:06:11 +04:00
|
|
|
* large chunks of a kernel object's space go unused either because
|
|
|
|
* that area of kernel VM is unmapped, or there is some other type of
|
1998-02-24 18:58:09 +03:00
|
|
|
* object mapped into that range (e.g. a vnode). for submap's kernel
|
|
|
|
* objects, the only part of the object that can ever be populated is the
|
|
|
|
* offsets that are managed by the submap.
|
|
|
|
*
|
|
|
|
* note that the "offset" in a kernel object is always the kernel virtual
|
|
|
|
* address minus the VM_MIN_KERNEL_ADDRESS (aka vm_map_min(kernel_map)).
|
|
|
|
* example:
|
|
|
|
* suppose VM_MIN_KERNEL_ADDRESS is 0xf8000000 and the kernel does a
|
|
|
|
* uvm_km_alloc(kernel_map, PAGE_SIZE) [allocate 1 wired down page in the
|
|
|
|
* kernel map]. if uvm_km_alloc returns virtual address 0xf8235000,
|
|
|
|
* then that means that the page at offset 0x235000 in kernel_object is
|
2001-05-25 08:06:11 +04:00
|
|
|
* mapped at 0xf8235000.
|
1998-02-24 18:58:09 +03:00
|
|
|
*
|
|
|
|
* kernel object have one other special property: when the kernel virtual
|
|
|
|
* memory mapping them is unmapped, the backing memory in the object is
|
|
|
|
* freed right away. this is done with the uvm_km_pgremove() function.
|
|
|
|
* this has to be done because there is no backing store for kernel pages
|
|
|
|
* and no need to save them after they are no longer referenced.
|
|
|
|
*/
|
|
|
|
|
2001-11-10 10:36:59 +03:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__KERNEL_RCSID(0, "$NetBSD: uvm_km.c,v 1.55 2001/11/10 07:37:00 lukem Exp $");
|
|
|
|
|
|
|
|
#include "opt_uvmhist.h"
|
|
|
|
|
1998-02-05 09:25:08 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
|
|
|
|
#include <uvm/uvm.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* global data structures
|
|
|
|
*/
|
|
|
|
|
2001-06-02 22:09:08 +04:00
|
|
|
struct vm_map *kernel_map = NULL;
|
1998-02-05 09:25:08 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* local data structues
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct vm_map kernel_map_store;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* uvm_km_init: init kernel maps and objects to reflect reality (i.e.
|
|
|
|
* KVM already allocated for text, data, bss, and static data structures).
|
|
|
|
*
|
|
|
|
* => KVM is defined by VM_MIN_KERNEL_ADDRESS/VM_MAX_KERNEL_ADDRESS.
|
|
|
|
* we assume that [min -> start] has already been allocated and that
|
|
|
|
* "end" is the end.
|
|
|
|
*/
|
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
void
|
|
|
|
uvm_km_init(start, end)
|
1998-08-13 06:10:37 +04:00
|
|
|
vaddr_t start, end;
|
1998-02-05 09:25:08 +03:00
|
|
|
{
|
1998-08-13 06:10:37 +04:00
|
|
|
vaddr_t base = VM_MIN_KERNEL_ADDRESS;
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1999-06-05 03:38:41 +04:00
|
|
|
/*
|
|
|
|
* next, init kernel memory objects.
|
1998-03-09 03:58:55 +03:00
|
|
|
*/
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/* kernel_object: for pageable anonymous kernel memory */
|
2000-01-11 09:57:49 +03:00
|
|
|
uao_init();
|
1998-03-09 03:58:55 +03:00
|
|
|
uvm.kernel_object = uao_create(VM_MAX_KERNEL_ADDRESS -
|
1998-02-07 05:29:21 +03:00
|
|
|
VM_MIN_KERNEL_ADDRESS, UAO_FLAG_KERNOBJ);
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
2001-11-06 11:07:49 +03:00
|
|
|
* init the map and reserve already allocated kernel space
|
1998-03-09 03:58:55 +03:00
|
|
|
* before installing.
|
|
|
|
*/
|
|
|
|
|
1999-05-26 23:16:28 +04:00
|
|
|
uvm_map_setup(&kernel_map_store, base, end, VM_MAP_PAGEABLE);
|
1998-03-09 03:58:55 +03:00
|
|
|
kernel_map_store.pmap = pmap_kernel();
|
|
|
|
if (uvm_map(&kernel_map_store, &base, start - base, NULL,
|
2000-09-13 19:00:15 +04:00
|
|
|
UVM_UNKNOWN_OFFSET, 0, UVM_MAPFLAG(UVM_PROT_ALL, UVM_PROT_ALL,
|
2001-03-15 09:10:32 +03:00
|
|
|
UVM_INH_NONE, UVM_ADV_RANDOM,UVM_FLAG_FIXED)) != 0)
|
1998-03-09 03:58:55 +03:00
|
|
|
panic("uvm_km_init: could not reserve space for kernel");
|
2001-05-25 08:06:11 +04:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* install!
|
|
|
|
*/
|
|
|
|
|
|
|
|
kernel_map = &kernel_map_store;
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* uvm_km_suballoc: allocate a submap in the kernel map. once a submap
|
|
|
|
* is allocated all references to that area of VM must go through it. this
|
|
|
|
* allows the locking of VAs in kernel_map to be broken up into regions.
|
|
|
|
*
|
1998-02-08 09:15:53 +03:00
|
|
|
* => if `fixed' is true, *min specifies where the region described
|
|
|
|
* by the submap must start
|
1998-02-05 09:25:08 +03:00
|
|
|
* => if submap is non NULL we use that as the submap, otherwise we
|
|
|
|
* alloc a new map
|
|
|
|
*/
|
1998-03-09 03:58:55 +03:00
|
|
|
struct vm_map *
|
1999-05-26 23:16:28 +04:00
|
|
|
uvm_km_suballoc(map, min, max, size, flags, fixed, submap)
|
1998-03-09 03:58:55 +03:00
|
|
|
struct vm_map *map;
|
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
|
|
|
vaddr_t *min, *max; /* IN/OUT, OUT */
|
1998-08-13 06:10:37 +04:00
|
|
|
vsize_t size;
|
1999-05-26 23:16:28 +04:00
|
|
|
int flags;
|
1998-03-09 03:58:55 +03:00
|
|
|
boolean_t fixed;
|
|
|
|
struct vm_map *submap;
|
|
|
|
{
|
|
|
|
int mapflags = UVM_FLAG_NOMERGE | (fixed ? UVM_FLAG_FIXED : 0);
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
size = round_page(size); /* round up to pagesize */
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* first allocate a blank spot in the parent map
|
|
|
|
*/
|
1998-02-05 09:25:08 +03:00
|
|
|
|
2000-09-13 19:00:15 +04:00
|
|
|
if (uvm_map(map, min, size, NULL, UVM_UNKNOWN_OFFSET, 0,
|
1998-03-09 03:58:55 +03:00
|
|
|
UVM_MAPFLAG(UVM_PROT_ALL, UVM_PROT_ALL, UVM_INH_NONE,
|
2001-03-15 09:10:32 +03:00
|
|
|
UVM_ADV_RANDOM, mapflags)) != 0) {
|
1998-03-09 03:58:55 +03:00
|
|
|
panic("uvm_km_suballoc: unable to allocate space in parent map");
|
|
|
|
}
|
1998-02-08 09:15:53 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* set VM bounds (min is filled in by uvm_map)
|
|
|
|
*/
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
*max = *min + size;
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* add references to pmap and create or init the submap
|
|
|
|
*/
|
|
|
|
|
|
|
|
pmap_reference(vm_map_pmap(map));
|
|
|
|
if (submap == NULL) {
|
1999-05-26 23:16:28 +04:00
|
|
|
submap = uvm_map_create(vm_map_pmap(map), *min, *max, flags);
|
1998-03-09 03:58:55 +03:00
|
|
|
if (submap == NULL)
|
|
|
|
panic("uvm_km_suballoc: unable to create submap");
|
|
|
|
} else {
|
1999-05-26 23:16:28 +04:00
|
|
|
uvm_map_setup(submap, *min, *max, flags);
|
1998-03-09 03:58:55 +03:00
|
|
|
submap->pmap = vm_map_pmap(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* now let uvm_map_submap plug in it...
|
|
|
|
*/
|
|
|
|
|
2001-03-15 09:10:32 +03:00
|
|
|
if (uvm_map_submap(map, *min, *max, submap) != 0)
|
1998-03-09 03:58:55 +03:00
|
|
|
panic("uvm_km_suballoc: submap allocation failed");
|
|
|
|
|
|
|
|
return(submap);
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* uvm_km_pgremove: remove pages from a kernel uvm_object.
|
|
|
|
*
|
|
|
|
* => when you unmap a part of anonymous kernel memory you want to toss
|
|
|
|
* the pages right away. (this gets called from uvm_unmap_...).
|
|
|
|
*/
|
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
void
|
|
|
|
uvm_km_pgremove(uobj, start, end)
|
|
|
|
struct uvm_object *uobj;
|
1998-08-13 06:10:37 +04:00
|
|
|
vaddr_t start, end;
|
1998-02-05 09:25:08 +03:00
|
|
|
{
|
2001-11-06 11:07:49 +03:00
|
|
|
struct vm_page *pg;
|
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
|
|
|
voff_t curoff, nextoff;
|
2001-11-06 11:07:49 +03:00
|
|
|
int swpgonlydelta = 0;
|
1998-03-09 03:58:55 +03:00
|
|
|
UVMHIST_FUNC("uvm_km_pgremove"); UVMHIST_CALLED(maphist);
|
1998-02-05 09:25:08 +03:00
|
|
|
|
2000-11-24 10:07:27 +03:00
|
|
|
KASSERT(uobj->pgops == &aobj_pager);
|
|
|
|
simple_lock(&uobj->vmobjlock);
|
1998-02-07 05:29:21 +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
|
|
|
for (curoff = start; curoff < end; curoff = nextoff) {
|
|
|
|
nextoff = curoff + PAGE_SIZE;
|
|
|
|
pg = uvm_pagelookup(uobj, curoff);
|
2001-11-06 11:07:49 +03:00
|
|
|
if (pg != NULL && pg->flags & PG_BUSY) {
|
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
|
|
|
pg->flags |= PG_WANTED;
|
|
|
|
UVM_UNLOCK_AND_WAIT(pg, &uobj->vmobjlock, 0,
|
|
|
|
"km_pgrm", 0);
|
|
|
|
simple_lock(&uobj->vmobjlock);
|
|
|
|
nextoff = curoff;
|
|
|
|
continue;
|
|
|
|
}
|
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
|
|
|
/*
|
|
|
|
* free the swap slot, then the page.
|
|
|
|
*/
|
1999-05-26 00:30:08 +04:00
|
|
|
|
2001-11-06 11:07:49 +03:00
|
|
|
if (pg == NULL &&
|
|
|
|
uao_find_swslot(uobj, curoff >> PAGE_SHIFT) != 0) {
|
|
|
|
swpgonlydelta++;
|
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
|
|
|
}
|
2001-11-06 11:07:49 +03:00
|
|
|
uao_dropswap(uobj, curoff >> PAGE_SHIFT);
|
|
|
|
if (pg != NULL) {
|
|
|
|
uvm_lock_pageq();
|
|
|
|
uvm_pagefree(pg);
|
|
|
|
uvm_unlock_pageq();
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
1999-05-26 00:30:08 +04:00
|
|
|
}
|
|
|
|
simple_unlock(&uobj->vmobjlock);
|
2001-11-06 11:07:49 +03:00
|
|
|
|
2001-11-07 11:43:32 +03:00
|
|
|
if (swpgonlydelta > 0) {
|
|
|
|
simple_lock(&uvm.swap_data_lock);
|
|
|
|
KASSERT(uvmexp.swpgonly >= swpgonlydelta);
|
|
|
|
uvmexp.swpgonly -= swpgonlydelta;
|
|
|
|
simple_unlock(&uvm.swap_data_lock);
|
|
|
|
}
|
1999-05-26 00:30:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* uvm_km_pgremove_intrsafe: like uvm_km_pgremove(), but for "intrsafe"
|
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
|
|
|
* maps
|
1999-05-26 00:30:08 +04:00
|
|
|
*
|
|
|
|
* => when you unmap a part of anonymous kernel memory you want to toss
|
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
|
|
|
* the pages right away. (this is called from uvm_unmap_...).
|
1999-05-26 00:30:08 +04:00
|
|
|
* => none of the pages will ever be busy, and none of them will ever
|
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
|
|
|
* be on the active or inactive queues (because they have no object).
|
1999-05-26 00:30:08 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
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
|
|
|
uvm_km_pgremove_intrsafe(start, end)
|
1999-05-26 00:30:08 +04:00
|
|
|
vaddr_t start, end;
|
|
|
|
{
|
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;
|
|
|
|
paddr_t pa;
|
1999-05-26 00:30:08 +04:00
|
|
|
UVMHIST_FUNC("uvm_km_pgremove_intrsafe"); UVMHIST_CALLED(maphist);
|
|
|
|
|
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
|
|
|
for (; start < end; start += PAGE_SIZE) {
|
|
|
|
if (!pmap_extract(pmap_kernel(), start, &pa)) {
|
1999-05-26 00:30:08 +04:00
|
|
|
continue;
|
2000-11-24 10:07:27 +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
|
|
|
pg = PHYS_TO_VM_PAGE(pa);
|
|
|
|
KASSERT(pg);
|
|
|
|
KASSERT(pg->uobject == NULL && pg->uanon == NULL);
|
|
|
|
uvm_pagefree(pg);
|
1999-05-26 00:30:08 +04:00
|
|
|
}
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* uvm_km_kmemalloc: lower level kernel memory allocator for malloc()
|
|
|
|
*
|
|
|
|
* => we map wired memory into the specified map using the obj passed in
|
|
|
|
* => NOTE: we can return NULL even if we can wait if there is not enough
|
|
|
|
* free VM space in the map... caller should be prepared to handle
|
|
|
|
* this case.
|
|
|
|
* => we return KVA of memory allocated
|
|
|
|
* => flags: NOWAIT, VALLOC - just allocate VA, TRYLOCK - fail if we can't
|
|
|
|
* lock the map
|
|
|
|
*/
|
|
|
|
|
1998-08-13 06:10:37 +04:00
|
|
|
vaddr_t
|
1998-03-09 03:58:55 +03:00
|
|
|
uvm_km_kmemalloc(map, obj, size, flags)
|
2001-06-02 22:09:08 +04:00
|
|
|
struct vm_map *map;
|
1998-03-09 03:58:55 +03:00
|
|
|
struct uvm_object *obj;
|
1998-08-13 06:10:37 +04:00
|
|
|
vsize_t size;
|
1998-03-09 03:58:55 +03:00
|
|
|
int flags;
|
1998-02-05 09:25:08 +03:00
|
|
|
{
|
1998-08-13 06:10:37 +04:00
|
|
|
vaddr_t kva, loopva;
|
|
|
|
vaddr_t offset;
|
2001-04-13 01:08:25 +04:00
|
|
|
vsize_t loopsize;
|
1998-03-09 03:58:55 +03:00
|
|
|
struct vm_page *pg;
|
|
|
|
UVMHIST_FUNC("uvm_km_kmemalloc"); UVMHIST_CALLED(maphist);
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
UVMHIST_LOG(maphist," (map=0x%x, obj=0x%x, size=0x%x, flags=%d)",
|
2000-11-24 10:07:27 +03:00
|
|
|
map, obj, size, flags);
|
|
|
|
KASSERT(vm_map_pmap(map) == pmap_kernel());
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* setup for call
|
|
|
|
*/
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
size = round_page(size);
|
|
|
|
kva = vm_map_min(map); /* hint */
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* allocate some virtual space
|
|
|
|
*/
|
1998-02-05 09:25:08 +03:00
|
|
|
|
2000-05-09 03:10:20 +04:00
|
|
|
if (__predict_false(uvm_map(map, &kva, size, obj, UVM_UNKNOWN_OFFSET,
|
2000-09-13 19:00:15 +04:00
|
|
|
0, UVM_MAPFLAG(UVM_PROT_ALL, UVM_PROT_ALL, UVM_INH_NONE,
|
2001-05-25 08:06:11 +04:00
|
|
|
UVM_ADV_RANDOM, (flags & UVM_KMF_TRYLOCK)))
|
2001-03-15 09:10:32 +03:00
|
|
|
!= 0)) {
|
1998-03-09 03:58:55 +03:00
|
|
|
UVMHIST_LOG(maphist, "<- done (no VM)",0,0,0,0);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if all we wanted was VA, return now
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (flags & UVM_KMF_VALLOC) {
|
|
|
|
UVMHIST_LOG(maphist,"<- done valloc (kva=0x%x)", kva,0,0,0);
|
|
|
|
return(kva);
|
|
|
|
}
|
2000-11-24 10:07:27 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* recover object offset from virtual address
|
|
|
|
*/
|
|
|
|
|
|
|
|
offset = kva - vm_map_min(kernel_map);
|
|
|
|
UVMHIST_LOG(maphist, " kva=0x%x, offset=0x%x", kva, offset,0,0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* now allocate and map in the memory... note that we are the only ones
|
|
|
|
* whom should ever get a handle on this area of VM.
|
|
|
|
*/
|
|
|
|
|
|
|
|
loopva = kva;
|
2001-04-13 01:08:25 +04:00
|
|
|
loopsize = size;
|
|
|
|
while (loopsize) {
|
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 (obj) {
|
|
|
|
simple_lock(&obj->vmobjlock);
|
|
|
|
}
|
|
|
|
pg = uvm_pagealloc(obj, offset, NULL, UVM_PGA_USERESERVE);
|
2001-04-13 01:11:47 +04:00
|
|
|
if (__predict_true(pg != NULL)) {
|
1998-03-09 03:58:55 +03:00
|
|
|
pg->flags &= ~PG_BUSY; /* new page */
|
|
|
|
UVM_PAGE_OWN(pg, NULL);
|
|
|
|
}
|
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 (obj) {
|
|
|
|
simple_unlock(&obj->vmobjlock);
|
|
|
|
}
|
2001-05-25 08:06:11 +04:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* out of memory?
|
|
|
|
*/
|
|
|
|
|
2000-05-09 03:10:20 +04:00
|
|
|
if (__predict_false(pg == NULL)) {
|
1998-03-09 03:58:55 +03:00
|
|
|
if (flags & UVM_KMF_NOWAIT) {
|
|
|
|
/* free everything! */
|
1998-10-12 03:18:20 +04:00
|
|
|
uvm_unmap(map, kva, kva + size);
|
1998-03-09 03:58:55 +03:00
|
|
|
return(0);
|
|
|
|
} else {
|
|
|
|
uvm_wait("km_getwait2"); /* sleep here */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2001-05-25 08:06:11 +04: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
|
|
|
* map it in
|
1998-03-09 03:58:55 +03:00
|
|
|
*/
|
2000-11-24 10:07:27 +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
|
|
|
if (obj == NULL) {
|
1999-05-26 00:30:08 +04:00
|
|
|
pmap_kenter_pa(loopva, VM_PAGE_TO_PHYS(pg),
|
|
|
|
VM_PROT_ALL);
|
|
|
|
} else {
|
|
|
|
pmap_enter(map->pmap, loopva, VM_PAGE_TO_PHYS(pg),
|
1999-11-13 03:24:38 +03:00
|
|
|
UVM_PROT_ALL,
|
|
|
|
PMAP_WIRED | VM_PROT_READ | VM_PROT_WRITE);
|
1999-05-26 00:30:08 +04:00
|
|
|
}
|
1998-03-09 03:58:55 +03:00
|
|
|
loopva += PAGE_SIZE;
|
|
|
|
offset += PAGE_SIZE;
|
2001-04-13 01:08:25 +04:00
|
|
|
loopsize -= PAGE_SIZE;
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
2001-09-11 01:19:08 +04:00
|
|
|
|
|
|
|
pmap_update(pmap_kernel());
|
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
UVMHIST_LOG(maphist,"<- done (kva=0x%x)", kva,0,0,0);
|
|
|
|
return(kva);
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* uvm_km_free: free an area of kernel memory
|
|
|
|
*/
|
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
void
|
|
|
|
uvm_km_free(map, addr, size)
|
2001-06-02 22:09:08 +04:00
|
|
|
struct vm_map *map;
|
1998-08-13 06:10:37 +04:00
|
|
|
vaddr_t addr;
|
|
|
|
vsize_t size;
|
1998-02-05 09:25:08 +03:00
|
|
|
{
|
1998-10-12 03:18:20 +04:00
|
|
|
uvm_unmap(map, trunc_page(addr), round_page(addr+size));
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* uvm_km_free_wakeup: free an area of kernel memory and wake up
|
|
|
|
* anyone waiting for vm space.
|
|
|
|
*
|
|
|
|
* => XXX: "wanted" bit + unlock&wait on other end?
|
|
|
|
*/
|
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
void
|
|
|
|
uvm_km_free_wakeup(map, addr, size)
|
2001-06-02 22:09:08 +04:00
|
|
|
struct vm_map *map;
|
1998-08-13 06:10:37 +04:00
|
|
|
vaddr_t addr;
|
|
|
|
vsize_t size;
|
1998-02-05 09:25:08 +03:00
|
|
|
{
|
2001-06-02 22:09:08 +04:00
|
|
|
struct vm_map_entry *dead_entries;
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
vm_map_lock(map);
|
2001-05-25 08:06:11 +04:00
|
|
|
uvm_unmap_remove(map, trunc_page(addr), round_page(addr + size),
|
2001-03-15 09:10:32 +03:00
|
|
|
&dead_entries);
|
1999-07-23 02:58:38 +04:00
|
|
|
wakeup(map);
|
1998-03-09 03:58:55 +03:00
|
|
|
vm_map_unlock(map);
|
|
|
|
if (dead_entries != NULL)
|
|
|
|
uvm_unmap_detach(dead_entries, 0);
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* uvm_km_alloc1: allocate wired down memory in the kernel map.
|
|
|
|
*
|
|
|
|
* => we can sleep if needed
|
|
|
|
*/
|
|
|
|
|
1998-08-13 06:10:37 +04:00
|
|
|
vaddr_t
|
1998-03-09 03:58:55 +03:00
|
|
|
uvm_km_alloc1(map, size, zeroit)
|
2001-06-02 22:09:08 +04:00
|
|
|
struct vm_map *map;
|
1998-08-13 06:10:37 +04:00
|
|
|
vsize_t size;
|
1998-03-09 03:58:55 +03:00
|
|
|
boolean_t zeroit;
|
1998-02-05 09:25:08 +03:00
|
|
|
{
|
1998-08-13 06:10:37 +04:00
|
|
|
vaddr_t kva, loopva, offset;
|
1998-03-09 03:58:55 +03:00
|
|
|
struct vm_page *pg;
|
|
|
|
UVMHIST_FUNC("uvm_km_alloc1"); UVMHIST_CALLED(maphist);
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
UVMHIST_LOG(maphist,"(map=0x%x, size=0x%x)", map, size,0,0);
|
2000-11-24 10:07:27 +03:00
|
|
|
KASSERT(vm_map_pmap(map) == pmap_kernel());
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
size = round_page(size);
|
|
|
|
kva = vm_map_min(map); /* hint */
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* allocate some virtual space
|
|
|
|
*/
|
1998-02-05 09:25:08 +03:00
|
|
|
|
2000-05-09 03:10:20 +04:00
|
|
|
if (__predict_false(uvm_map(map, &kva, size, uvm.kernel_object,
|
2000-09-13 19:00:15 +04:00
|
|
|
UVM_UNKNOWN_OFFSET, 0, UVM_MAPFLAG(UVM_PROT_ALL, UVM_PROT_ALL,
|
2000-05-09 03:10:20 +04:00
|
|
|
UVM_INH_NONE, UVM_ADV_RANDOM,
|
2001-03-15 09:10:32 +03:00
|
|
|
0)) != 0)) {
|
1998-03-09 03:58:55 +03:00
|
|
|
UVMHIST_LOG(maphist,"<- done (no VM)",0,0,0,0);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* recover object offset from virtual address
|
|
|
|
*/
|
|
|
|
|
|
|
|
offset = kva - vm_map_min(kernel_map);
|
|
|
|
UVMHIST_LOG(maphist," kva=0x%x, offset=0x%x", kva, offset,0,0);
|
|
|
|
|
|
|
|
/*
|
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
|
|
|
* now allocate the memory.
|
1998-03-09 03:58:55 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
loopva = kva;
|
|
|
|
while (size) {
|
|
|
|
simple_lock(&uvm.kernel_object->vmobjlock);
|
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
|
|
|
KASSERT(uvm_pagelookup(uvm.kernel_object, offset) == NULL);
|
1999-04-11 08:04:04 +04:00
|
|
|
pg = uvm_pagealloc(uvm.kernel_object, offset, NULL, 0);
|
1998-03-09 03:58:55 +03:00
|
|
|
if (pg) {
|
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
|
|
|
pg->flags &= ~PG_BUSY;
|
1998-03-09 03:58:55 +03:00
|
|
|
UVM_PAGE_OWN(pg, NULL);
|
|
|
|
}
|
|
|
|
simple_unlock(&uvm.kernel_object->vmobjlock);
|
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 (pg == NULL) {
|
|
|
|
uvm_wait("km_alloc1w");
|
1998-03-09 03:58:55 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pmap_enter(map->pmap, loopva, VM_PAGE_TO_PHYS(pg),
|
1999-11-13 03:24:38 +03:00
|
|
|
UVM_PROT_ALL, PMAP_WIRED | VM_PROT_READ | VM_PROT_WRITE);
|
1998-03-09 03:58:55 +03:00
|
|
|
loopva += PAGE_SIZE;
|
|
|
|
offset += PAGE_SIZE;
|
|
|
|
size -= PAGE_SIZE;
|
|
|
|
}
|
2001-09-11 01:19:08 +04:00
|
|
|
pmap_update(map->pmap);
|
2001-04-24 08:30:50 +04:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* zero on request (note that "size" is now zero due to the above loop
|
|
|
|
* so we need to subtract kva from loopva to reconstruct the size).
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (zeroit)
|
1998-08-10 02:36:37 +04:00
|
|
|
memset((caddr_t)kva, 0, loopva - kva);
|
1998-03-09 03:58:55 +03:00
|
|
|
UVMHIST_LOG(maphist,"<- done (kva=0x%x)", kva,0,0,0);
|
|
|
|
return(kva);
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* uvm_km_valloc: allocate zero-fill memory in the kernel's address space
|
|
|
|
*
|
|
|
|
* => memory is not allocated until fault time
|
|
|
|
*/
|
|
|
|
|
1998-08-13 06:10:37 +04:00
|
|
|
vaddr_t
|
1998-03-09 03:58:55 +03:00
|
|
|
uvm_km_valloc(map, size)
|
2001-06-02 22:09:08 +04:00
|
|
|
struct vm_map *map;
|
1998-08-13 06:10:37 +04:00
|
|
|
vsize_t size;
|
2000-11-27 07:36:40 +03:00
|
|
|
{
|
|
|
|
return(uvm_km_valloc_align(map, size, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
vaddr_t
|
|
|
|
uvm_km_valloc_align(map, size, align)
|
2001-06-02 22:09:08 +04:00
|
|
|
struct vm_map *map;
|
2000-11-27 07:36:40 +03:00
|
|
|
vsize_t size;
|
|
|
|
vsize_t align;
|
1998-02-05 09:25:08 +03:00
|
|
|
{
|
1998-08-13 06:10:37 +04:00
|
|
|
vaddr_t kva;
|
1998-03-09 03:58:55 +03:00
|
|
|
UVMHIST_FUNC("uvm_km_valloc"); UVMHIST_CALLED(maphist);
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
UVMHIST_LOG(maphist, "(map=0x%x, size=0x%x)", map, size, 0,0);
|
2000-11-24 10:07:27 +03:00
|
|
|
KASSERT(vm_map_pmap(map) == pmap_kernel());
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
size = round_page(size);
|
|
|
|
kva = vm_map_min(map); /* hint */
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* allocate some virtual space. will be demand filled by kernel_object.
|
|
|
|
*/
|
1998-02-05 09:25:08 +03:00
|
|
|
|
2000-05-09 03:10:20 +04:00
|
|
|
if (__predict_false(uvm_map(map, &kva, size, uvm.kernel_object,
|
2000-11-27 07:36:40 +03:00
|
|
|
UVM_UNKNOWN_OFFSET, align, UVM_MAPFLAG(UVM_PROT_ALL, UVM_PROT_ALL,
|
2000-05-09 03:10:20 +04:00
|
|
|
UVM_INH_NONE, UVM_ADV_RANDOM,
|
2001-03-15 09:10:32 +03:00
|
|
|
0)) != 0)) {
|
1998-03-09 03:58:55 +03:00
|
|
|
UVMHIST_LOG(maphist, "<- done (no VM)", 0,0,0,0);
|
|
|
|
return(0);
|
|
|
|
}
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
UVMHIST_LOG(maphist, "<- done (kva=0x%x)", kva,0,0,0);
|
|
|
|
return(kva);
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* uvm_km_valloc_wait: allocate zero-fill memory in the kernel's address space
|
|
|
|
*
|
|
|
|
* => memory is not allocated until fault time
|
|
|
|
* => if no room in map, wait for space to free, unless requested size
|
|
|
|
* is larger than map (in which case we return 0)
|
|
|
|
*/
|
|
|
|
|
1998-08-13 06:10:37 +04:00
|
|
|
vaddr_t
|
2000-07-25 00:10:51 +04:00
|
|
|
uvm_km_valloc_prefer_wait(map, size, prefer)
|
2001-06-02 22:09:08 +04:00
|
|
|
struct vm_map *map;
|
1998-08-13 06:10:37 +04:00
|
|
|
vsize_t size;
|
2000-07-25 00:10:51 +04:00
|
|
|
voff_t prefer;
|
1998-02-05 09:25:08 +03:00
|
|
|
{
|
1998-08-13 06:10:37 +04:00
|
|
|
vaddr_t kva;
|
2000-07-25 00:10:51 +04:00
|
|
|
UVMHIST_FUNC("uvm_km_valloc_prefer_wait"); UVMHIST_CALLED(maphist);
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
UVMHIST_LOG(maphist, "(map=0x%x, size=0x%x)", map, size, 0,0);
|
2000-11-24 10:07:27 +03:00
|
|
|
KASSERT(vm_map_pmap(map) == pmap_kernel());
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
size = round_page(size);
|
|
|
|
if (size > vm_map_max(map) - vm_map_min(map))
|
|
|
|
return(0);
|
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
|
|
|
for (;;) {
|
1998-03-09 03:58:55 +03:00
|
|
|
kva = vm_map_min(map); /* hint */
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* allocate some virtual space. will be demand filled
|
|
|
|
* by kernel_object.
|
|
|
|
*/
|
1998-02-05 09:25:08 +03:00
|
|
|
|
2000-05-09 03:10:20 +04:00
|
|
|
if (__predict_true(uvm_map(map, &kva, size, uvm.kernel_object,
|
2000-09-13 19:00:15 +04:00
|
|
|
prefer, 0, UVM_MAPFLAG(UVM_PROT_ALL,
|
1998-03-09 03:58:55 +03:00
|
|
|
UVM_PROT_ALL, UVM_INH_NONE, UVM_ADV_RANDOM, 0))
|
2001-03-15 09:10:32 +03:00
|
|
|
== 0)) {
|
1998-03-09 03:58:55 +03:00
|
|
|
UVMHIST_LOG(maphist,"<- done (kva=0x%x)", kva,0,0,0);
|
|
|
|
return(kva);
|
|
|
|
}
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* failed. sleep for a while (on map)
|
|
|
|
*/
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
UVMHIST_LOG(maphist,"<<<sleeping>>>",0,0,0,0);
|
|
|
|
tsleep((caddr_t)map, PVM, "vallocwait", 0);
|
|
|
|
}
|
|
|
|
/*NOTREACHED*/
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|
1998-07-25 00:28:48 +04:00
|
|
|
|
2000-07-25 00:10:51 +04:00
|
|
|
vaddr_t
|
|
|
|
uvm_km_valloc_wait(map, size)
|
2001-06-02 22:09:08 +04:00
|
|
|
struct vm_map *map;
|
2000-07-25 00:10:51 +04:00
|
|
|
vsize_t size;
|
|
|
|
{
|
|
|
|
return uvm_km_valloc_prefer_wait(map, size, UVM_UNKNOWN_OFFSET);
|
|
|
|
}
|
|
|
|
|
1998-07-25 00:28:48 +04:00
|
|
|
/* Sanity; must specify both or none. */
|
|
|
|
#if (defined(PMAP_MAP_POOLPAGE) || defined(PMAP_UNMAP_POOLPAGE)) && \
|
|
|
|
(!defined(PMAP_MAP_POOLPAGE) || !defined(PMAP_UNMAP_POOLPAGE))
|
|
|
|
#error Must specify MAP and UNMAP together.
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* uvm_km_alloc_poolpage: allocate a page for the pool allocator
|
|
|
|
*
|
|
|
|
* => if the pmap specifies an alternate mapping method, we use it.
|
|
|
|
*/
|
|
|
|
|
1998-08-01 00:46:36 +04:00
|
|
|
/* ARGSUSED */
|
1998-08-13 06:10:37 +04:00
|
|
|
vaddr_t
|
1998-08-29 00:05:48 +04:00
|
|
|
uvm_km_alloc_poolpage1(map, obj, waitok)
|
2001-06-02 22:09:08 +04:00
|
|
|
struct vm_map *map;
|
1998-08-01 05:39:03 +04:00
|
|
|
struct uvm_object *obj;
|
1998-08-29 00:05:48 +04:00
|
|
|
boolean_t waitok;
|
1998-07-25 00:28:48 +04:00
|
|
|
{
|
|
|
|
#if defined(PMAP_MAP_POOLPAGE)
|
|
|
|
struct vm_page *pg;
|
1998-08-13 06:10:37 +04:00
|
|
|
vaddr_t va;
|
1998-07-25 00:28:48 +04:00
|
|
|
|
1998-08-29 00:05:48 +04:00
|
|
|
again:
|
1999-07-19 02:55:30 +04:00
|
|
|
pg = uvm_pagealloc(NULL, 0, NULL, UVM_PGA_USERESERVE);
|
2000-05-09 03:10:20 +04:00
|
|
|
if (__predict_false(pg == NULL)) {
|
1998-08-29 00:05:48 +04:00
|
|
|
if (waitok) {
|
|
|
|
uvm_wait("plpg");
|
|
|
|
goto again;
|
|
|
|
} else
|
|
|
|
return (0);
|
|
|
|
}
|
1998-07-25 00:28:48 +04:00
|
|
|
va = PMAP_MAP_POOLPAGE(VM_PAGE_TO_PHYS(pg));
|
2000-05-09 03:10:20 +04:00
|
|
|
if (__predict_false(va == 0))
|
1998-07-25 00:28:48 +04:00
|
|
|
uvm_pagefree(pg);
|
|
|
|
return (va);
|
|
|
|
#else
|
1998-08-13 06:10:37 +04:00
|
|
|
vaddr_t va;
|
1998-07-25 00:28:48 +04:00
|
|
|
int s;
|
|
|
|
|
1998-08-29 01:16:23 +04:00
|
|
|
/*
|
2001-01-14 05:10:01 +03:00
|
|
|
* NOTE: We may be called with a map that doens't require splvm
|
1998-08-29 01:16:23 +04:00
|
|
|
* protection (e.g. kernel_map). However, it does not hurt to
|
2001-01-14 05:10:01 +03:00
|
|
|
* go to splvm in this case (since unprocted maps will never be
|
1998-08-29 01:16:23 +04:00
|
|
|
* accessed in interrupt context).
|
|
|
|
*
|
|
|
|
* XXX We may want to consider changing the interface to this
|
|
|
|
* XXX function.
|
|
|
|
*/
|
|
|
|
|
2001-01-14 05:10:01 +03:00
|
|
|
s = splvm();
|
1998-08-29 00:05:48 +04:00
|
|
|
va = uvm_km_kmemalloc(map, obj, PAGE_SIZE, waitok ? 0 : UVM_KMF_NOWAIT);
|
1998-07-25 00:28:48 +04:00
|
|
|
splx(s);
|
|
|
|
return (va);
|
|
|
|
#endif /* PMAP_MAP_POOLPAGE */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* uvm_km_free_poolpage: free a previously allocated pool page
|
|
|
|
*
|
|
|
|
* => if the pmap specifies an alternate unmapping method, we use it.
|
|
|
|
*/
|
|
|
|
|
1998-08-01 00:46:36 +04:00
|
|
|
/* ARGSUSED */
|
1998-07-25 00:28:48 +04:00
|
|
|
void
|
1998-08-01 00:46:36 +04:00
|
|
|
uvm_km_free_poolpage1(map, addr)
|
2001-06-02 22:09:08 +04:00
|
|
|
struct vm_map *map;
|
1998-08-13 06:10:37 +04:00
|
|
|
vaddr_t addr;
|
1998-07-25 00:28:48 +04:00
|
|
|
{
|
|
|
|
#if defined(PMAP_UNMAP_POOLPAGE)
|
1998-08-13 06:10:37 +04:00
|
|
|
paddr_t pa;
|
1998-07-25 00:28:48 +04:00
|
|
|
|
|
|
|
pa = PMAP_UNMAP_POOLPAGE(addr);
|
|
|
|
uvm_pagefree(PHYS_TO_VM_PAGE(pa));
|
|
|
|
#else
|
|
|
|
int s;
|
|
|
|
|
1998-08-29 01:16:23 +04:00
|
|
|
/*
|
2001-01-14 05:10:01 +03:00
|
|
|
* NOTE: We may be called with a map that doens't require splvm
|
1998-08-29 01:16:23 +04:00
|
|
|
* protection (e.g. kernel_map). However, it does not hurt to
|
2001-01-14 05:10:01 +03:00
|
|
|
* go to splvm in this case (since unprocted maps will never be
|
1998-08-29 01:16:23 +04:00
|
|
|
* accessed in interrupt context).
|
|
|
|
*
|
|
|
|
* XXX We may want to consider changing the interface to this
|
|
|
|
* XXX function.
|
|
|
|
*/
|
|
|
|
|
2001-01-14 05:10:01 +03:00
|
|
|
s = splvm();
|
1998-08-01 00:46:36 +04:00
|
|
|
uvm_km_free(map, addr, PAGE_SIZE);
|
1998-07-25 00:28:48 +04:00
|
|
|
splx(s);
|
|
|
|
#endif /* PMAP_UNMAP_POOLPAGE */
|
|
|
|
}
|