2005-01-07 02:29:27 +00:00
|
|
|
/*-
|
1994-05-24 10:09:53 +00:00
|
|
|
* Copyright (c) 1991, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* The Mach Operating System project at Carnegie-Mellon University.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 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.
|
|
|
|
*
|
1994-08-02 07:55:43 +00:00
|
|
|
* from: @(#)vm_init.c 8.1 (Berkeley) 6/11/93
|
1994-05-24 10:09:53 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (c) 1987, 1990 Carnegie-Mellon University.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Authors: Avadis Tevanian, Jr., Michael Wayne Young
|
These changes embody the support of the fully coherent merged VM buffer cache,
much higher filesystem I/O performance, and much better paging performance. It
represents the culmination of over 6 months of R&D.
The majority of the merged VM/cache work is by John Dyson.
The following highlights the most significant changes. Additionally, there are
(mostly minor) changes to the various filesystem modules (nfs, msdosfs, etc) to
support the new VM/buffer scheme.
vfs_bio.c:
Significant rewrite of most of vfs_bio to support the merged VM buffer cache
scheme. The scheme is almost fully compatible with the old filesystem
interface. Significant improvement in the number of opportunities for write
clustering.
vfs_cluster.c, vfs_subr.c
Upgrade and performance enhancements in vfs layer code to support merged
VM/buffer cache. Fixup of vfs_cluster to eliminate the bogus pagemove stuff.
vm_object.c:
Yet more improvements in the collapse code. Elimination of some windows that
can cause list corruption.
vm_pageout.c:
Fixed it, it really works better now. Somehow in 2.0, some "enhancements"
broke the code. This code has been reworked from the ground-up.
vm_fault.c, vm_page.c, pmap.c, vm_object.c
Support for small-block filesystems with merged VM/buffer cache scheme.
pmap.c vm_map.c
Dynamic kernel VM size, now we dont have to pre-allocate excessive numbers of
kernel PTs.
vm_glue.c
Much simpler and more effective swapping code. No more gratuitous swapping.
proc.h
Fixed the problem that the p_lock flag was not being cleared on a fork.
swap_pager.c, vnode_pager.c
Removal of old vfs_bio cruft to support the past pseudo-coherency. Now the
code doesn't need it anymore.
machdep.c
Changes to better support the parameter values for the merged VM/buffer cache
scheme.
machdep.c, kern_exec.c, vm_glue.c
Implemented a seperate submap for temporary exec string space and another one
to contain process upages. This eliminates all map fragmentation problems
that previously existed.
ffs_inode.c, ufs_inode.c, ufs_readwrite.c
Changes for merged VM/buffer cache. Add "bypass" support for sneaking in on
busy buffers.
Submitted by: John Dyson and David Greenman
1995-01-09 16:06:02 +00:00
|
|
|
*
|
1994-05-24 10:09:53 +00:00
|
|
|
* 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.
|
These changes embody the support of the fully coherent merged VM buffer cache,
much higher filesystem I/O performance, and much better paging performance. It
represents the culmination of over 6 months of R&D.
The majority of the merged VM/cache work is by John Dyson.
The following highlights the most significant changes. Additionally, there are
(mostly minor) changes to the various filesystem modules (nfs, msdosfs, etc) to
support the new VM/buffer scheme.
vfs_bio.c:
Significant rewrite of most of vfs_bio to support the merged VM buffer cache
scheme. The scheme is almost fully compatible with the old filesystem
interface. Significant improvement in the number of opportunities for write
clustering.
vfs_cluster.c, vfs_subr.c
Upgrade and performance enhancements in vfs layer code to support merged
VM/buffer cache. Fixup of vfs_cluster to eliminate the bogus pagemove stuff.
vm_object.c:
Yet more improvements in the collapse code. Elimination of some windows that
can cause list corruption.
vm_pageout.c:
Fixed it, it really works better now. Somehow in 2.0, some "enhancements"
broke the code. This code has been reworked from the ground-up.
vm_fault.c, vm_page.c, pmap.c, vm_object.c
Support for small-block filesystems with merged VM/buffer cache scheme.
pmap.c vm_map.c
Dynamic kernel VM size, now we dont have to pre-allocate excessive numbers of
kernel PTs.
vm_glue.c
Much simpler and more effective swapping code. No more gratuitous swapping.
proc.h
Fixed the problem that the p_lock flag was not being cleared on a fork.
swap_pager.c, vnode_pager.c
Removal of old vfs_bio cruft to support the past pseudo-coherency. Now the
code doesn't need it anymore.
machdep.c
Changes to better support the parameter values for the merged VM/buffer cache
scheme.
machdep.c, kern_exec.c, vm_glue.c
Implemented a seperate submap for temporary exec string space and another one
to contain process upages. This eliminates all map fragmentation problems
that previously existed.
ffs_inode.c, ufs_inode.c, ufs_readwrite.c
Changes for merged VM/buffer cache. Add "bypass" support for sneaking in on
busy buffers.
Submitted by: John Dyson and David Greenman
1995-01-09 16:06:02 +00:00
|
|
|
*
|
|
|
|
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
|
|
|
|
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
|
1994-05-24 10:09:53 +00:00
|
|
|
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
These changes embody the support of the fully coherent merged VM buffer cache,
much higher filesystem I/O performance, and much better paging performance. It
represents the culmination of over 6 months of R&D.
The majority of the merged VM/cache work is by John Dyson.
The following highlights the most significant changes. Additionally, there are
(mostly minor) changes to the various filesystem modules (nfs, msdosfs, etc) to
support the new VM/buffer scheme.
vfs_bio.c:
Significant rewrite of most of vfs_bio to support the merged VM buffer cache
scheme. The scheme is almost fully compatible with the old filesystem
interface. Significant improvement in the number of opportunities for write
clustering.
vfs_cluster.c, vfs_subr.c
Upgrade and performance enhancements in vfs layer code to support merged
VM/buffer cache. Fixup of vfs_cluster to eliminate the bogus pagemove stuff.
vm_object.c:
Yet more improvements in the collapse code. Elimination of some windows that
can cause list corruption.
vm_pageout.c:
Fixed it, it really works better now. Somehow in 2.0, some "enhancements"
broke the code. This code has been reworked from the ground-up.
vm_fault.c, vm_page.c, pmap.c, vm_object.c
Support for small-block filesystems with merged VM/buffer cache scheme.
pmap.c vm_map.c
Dynamic kernel VM size, now we dont have to pre-allocate excessive numbers of
kernel PTs.
vm_glue.c
Much simpler and more effective swapping code. No more gratuitous swapping.
proc.h
Fixed the problem that the p_lock flag was not being cleared on a fork.
swap_pager.c, vnode_pager.c
Removal of old vfs_bio cruft to support the past pseudo-coherency. Now the
code doesn't need it anymore.
machdep.c
Changes to better support the parameter values for the merged VM/buffer cache
scheme.
machdep.c, kern_exec.c, vm_glue.c
Implemented a seperate submap for temporary exec string space and another one
to contain process upages. This eliminates all map fragmentation problems
that previously existed.
ffs_inode.c, ufs_inode.c, ufs_readwrite.c
Changes for merged VM/buffer cache. Add "bypass" support for sneaking in on
busy buffers.
Submitted by: John Dyson and David Greenman
1995-01-09 16:06:02 +00:00
|
|
|
*
|
1994-05-24 10:09:53 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the Virtual Memory subsystem.
|
|
|
|
*/
|
|
|
|
|
2003-06-11 23:50:51 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/param.h>
|
1995-08-28 09:19:25 +00:00
|
|
|
#include <sys/kernel.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/proc.h>
|
2013-03-09 02:32:23 +00:00
|
|
|
#include <sys/rwlock.h>
|
2013-08-07 06:21:20 +00:00
|
|
|
#include <sys/malloc.h>
|
2005-04-25 19:22:05 +00:00
|
|
|
#include <sys/sysctl.h>
|
1994-10-09 01:52:19 +00:00
|
|
|
#include <sys/systm.h>
|
2003-08-11 05:51:51 +00:00
|
|
|
#include <sys/selinfo.h>
|
2015-10-14 02:10:07 +00:00
|
|
|
#include <sys/smp.h>
|
2003-08-11 05:51:51 +00:00
|
|
|
#include <sys/pipe.h>
|
2001-08-22 04:07:27 +00:00
|
|
|
#include <sys/bio.h>
|
|
|
|
#include <sys/buf.h>
|
2013-06-28 03:51:20 +00:00
|
|
|
#include <sys/vmem.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
#include <vm/vm.h>
|
2001-08-22 04:07:27 +00:00
|
|
|
#include <vm/vm_param.h>
|
|
|
|
#include <vm/vm_kern.h>
|
1995-12-07 12:48:31 +00:00
|
|
|
#include <vm/vm_object.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <vm/vm_page.h>
|
1995-12-07 12:48:31 +00:00
|
|
|
#include <vm/vm_map.h>
|
NOTE: libkvm, w, ps, 'top', and any other utility which depends on struct
proc or any VM system structure will have to be rebuilt!!!
Much needed overhaul of the VM system. Included in this first round of
changes:
1) Improved pager interfaces: init, alloc, dealloc, getpages, putpages,
haspage, and sync operations are supported. The haspage interface now
provides information about clusterability. All pager routines now take
struct vm_object's instead of "pagers".
2) Improved data structures. In the previous paradigm, there is constant
confusion caused by pagers being both a data structure ("allocate a
pager") and a collection of routines. The idea of a pager structure has
escentially been eliminated. Objects now have types, and this type is
used to index the appropriate pager. In most cases, items in the pager
structure were duplicated in the object data structure and thus were
unnecessary. In the few cases that remained, a un_pager structure union
was created in the object to contain these items.
3) Because of the cleanup of #1 & #2, a lot of unnecessary layering can now
be removed. For instance, vm_object_enter(), vm_object_lookup(),
vm_object_remove(), and the associated object hash list were some of the
things that were removed.
4) simple_lock's removed. Discussion with several people reveals that the
SMP locking primitives used in the VM system aren't likely the mechanism
that we'll be adopting. Even if it were, the locking that was in the code
was very inadequate and would have to be mostly re-done anyway. The
locking in a uni-processor kernel was a no-op but went a long way toward
making the code difficult to read and debug.
5) Places that attempted to kludge-up the fact that we don't have kernel
thread support have been fixed to reflect the reality that we are really
dealing with processes, not threads. The VM system didn't have complete
thread support, so the comments and mis-named routines were just wrong.
We now use tsleep and wakeup directly in the lock routines, for instance.
6) Where appropriate, the pagers have been improved, especially in the
pager_alloc routines. Most of the pager_allocs have been rewritten and
are now faster and easier to maintain.
7) The pagedaemon pageout clustering algorithm has been rewritten and
now tries harder to output an even number of pages before and after
the requested page. This is sort of the reverse of the ideal pagein
algorithm and should provide better overall performance.
8) Unnecessary (incorrect) casts to caddr_t in calls to tsleep & wakeup
have been removed. Some other unnecessary casts have also been removed.
9) Some almost useless debugging code removed.
10) Terminology of shadow objects vs. backing objects straightened out.
The fact that the vm_object data structure escentially had this
backwards really confused things. The use of "shadow" and "backing
object" throughout the code is now internally consistent and correct
in the Mach terminology.
11) Several minor bug fixes, including one in the vm daemon that caused
0 RSS objects to not get purged as intended.
12) A "default pager" has now been created which cleans up the transition
of objects to the "swap" type. The previous checks throughout the code
for swp->pg_data != NULL were really ugly. This change also provides
the rudiments for future backing of "anonymous" memory by something
other than the swap pager (via the vnode pager, for example), and it
allows the decision about which of these pagers to use to be made
dynamically (although will need some additional decision code to do
this, of course).
13) (dyson) MAP_COPY has been deprecated and the corresponding "copy
object" code has been removed. MAP_COPY was undocumented and non-
standard. It was furthermore broken in several ways which caused its
behavior to degrade to MAP_PRIVATE. Binaries that use MAP_COPY will
continue to work correctly, but via the slightly different semantics
of MAP_PRIVATE.
14) (dyson) Sharing maps have been removed. It's marginal usefulness in a
threads design can be worked around in other ways. Both #12 and #13
were done to simplify the code and improve readability and maintain-
ability. (As were most all of these changes)
TODO:
1) Rewrite most of the vnode pager to use VOP_GETPAGES/PUTPAGES. Doing
this will reduce the vnode pager to a mere fraction of its current size.
2) Rewrite vm_fault and the swap/vnode pagers to use the clustering
information provided by the new haspage pager interface. This will
substantially reduce the overhead by eliminating a large number of
VOP_BMAP() calls. The VOP_BMAP() filesystem interface should be
improved to provide both a "behind" and "ahead" indication of
contiguousness.
3) Implement the extended features of pager_haspage in swap_pager_haspage().
It currently just says 0 pages ahead/behind.
4) Re-implement the swap device (swstrategy) in a more elegant way, perhaps
via a much more general mechanism that could also be used for disk
striping of regular filesystems.
5) Do something to improve the architecture of vm_object_collapse(). The
fact that it makes calls into the swap pager and knows too much about
how the swap pager operates really bothers me. It also doesn't allow
for collapsing of non-swap pager objects ("unnamed" objects backed by
other pagers).
1995-07-13 08:48:48 +00:00
|
|
|
#include <vm/vm_pager.h>
|
1995-12-07 12:48:31 +00:00
|
|
|
#include <vm/vm_extern.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2002-11-07 23:57:17 +00:00
|
|
|
long physmem;
|
|
|
|
|
2005-04-25 19:22:05 +00:00
|
|
|
static int exec_map_entries = 16;
|
2014-06-28 03:56:17 +00:00
|
|
|
SYSCTL_INT(_vm, OID_AUTO, exec_map_entries, CTLFLAG_RDTUN, &exec_map_entries, 0,
|
2005-04-25 19:22:05 +00:00
|
|
|
"Maximum number of simultaneous execs");
|
|
|
|
|
1995-08-28 09:19:25 +00:00
|
|
|
/*
|
|
|
|
* System initialization
|
|
|
|
*/
|
2002-03-19 22:20:14 +00:00
|
|
|
static void vm_mem_init(void *);
|
2008-03-16 10:58:09 +00:00
|
|
|
SYSINIT(vm_mem, SI_SUB_VM, SI_ORDER_FIRST, vm_mem_init, NULL);
|
1995-08-28 09:19:25 +00:00
|
|
|
|
2013-08-07 06:21:20 +00:00
|
|
|
/*
|
|
|
|
* Import kva into the kernel arena.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
kva_import(void *unused, vmem_size_t size, int flags, vmem_addr_t *addrp)
|
|
|
|
{
|
|
|
|
vm_offset_t addr;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
addr = vm_map_min(kernel_map);
|
2013-09-09 18:11:59 +00:00
|
|
|
result = vm_map_find(kernel_map, NULL, 0, &addr, size, 0,
|
2013-08-16 21:13:55 +00:00
|
|
|
VMFS_SUPER_SPACE, VM_PROT_ALL, VM_PROT_ALL, MAP_NOFAULT);
|
2013-08-07 06:21:20 +00:00
|
|
|
if (result != KERN_SUCCESS)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
|
|
|
*addrp = addr;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* vm_init initializes the virtual memory system.
|
|
|
|
* This is done only by the first cpu up.
|
|
|
|
*
|
|
|
|
* The start and end address of physical memory is passed in.
|
|
|
|
*/
|
1995-08-28 09:19:25 +00:00
|
|
|
/* ARGSUSED*/
|
|
|
|
static void
|
1995-12-02 17:11:20 +00:00
|
|
|
vm_mem_init(dummy)
|
|
|
|
void *dummy;
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2013-08-07 06:21:20 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
These changes embody the support of the fully coherent merged VM buffer cache,
much higher filesystem I/O performance, and much better paging performance. It
represents the culmination of over 6 months of R&D.
The majority of the merged VM/cache work is by John Dyson.
The following highlights the most significant changes. Additionally, there are
(mostly minor) changes to the various filesystem modules (nfs, msdosfs, etc) to
support the new VM/buffer scheme.
vfs_bio.c:
Significant rewrite of most of vfs_bio to support the merged VM buffer cache
scheme. The scheme is almost fully compatible with the old filesystem
interface. Significant improvement in the number of opportunities for write
clustering.
vfs_cluster.c, vfs_subr.c
Upgrade and performance enhancements in vfs layer code to support merged
VM/buffer cache. Fixup of vfs_cluster to eliminate the bogus pagemove stuff.
vm_object.c:
Yet more improvements in the collapse code. Elimination of some windows that
can cause list corruption.
vm_pageout.c:
Fixed it, it really works better now. Somehow in 2.0, some "enhancements"
broke the code. This code has been reworked from the ground-up.
vm_fault.c, vm_page.c, pmap.c, vm_object.c
Support for small-block filesystems with merged VM/buffer cache scheme.
pmap.c vm_map.c
Dynamic kernel VM size, now we dont have to pre-allocate excessive numbers of
kernel PTs.
vm_glue.c
Much simpler and more effective swapping code. No more gratuitous swapping.
proc.h
Fixed the problem that the p_lock flag was not being cleared on a fork.
swap_pager.c, vnode_pager.c
Removal of old vfs_bio cruft to support the past pseudo-coherency. Now the
code doesn't need it anymore.
machdep.c
Changes to better support the parameter values for the merged VM/buffer cache
scheme.
machdep.c, kern_exec.c, vm_glue.c
Implemented a seperate submap for temporary exec string space and another one
to contain process upages. This eliminates all map fragmentation problems
that previously existed.
ffs_inode.c, ufs_inode.c, ufs_readwrite.c
Changes for merged VM/buffer cache. Add "bypass" support for sneaking in on
busy buffers.
Submitted by: John Dyson and David Greenman
1995-01-09 16:06:02 +00:00
|
|
|
* Initializes resident memory structures. From here on, all physical
|
|
|
|
* memory is accounted for, and we use only virtual addresses.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
1994-05-25 09:21:21 +00:00
|
|
|
vm_set_page_size();
|
2004-04-04 23:33:36 +00:00
|
|
|
virtual_avail = vm_page_startup(virtual_avail);
|
2001-01-22 07:02:42 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Initialize other VM packages
|
|
|
|
*/
|
2013-06-28 03:51:20 +00:00
|
|
|
vmem_startup();
|
1995-12-11 04:58:34 +00:00
|
|
|
vm_object_init();
|
1994-05-24 10:09:53 +00:00
|
|
|
vm_map_startup();
|
|
|
|
kmem_init(virtual_avail, virtual_end);
|
2013-08-07 06:21:20 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the kernel_arena. This can grow on demand.
|
|
|
|
*/
|
|
|
|
vmem_init(kernel_arena, "kernel arena", 0, 0, PAGE_SIZE, 0, 0);
|
|
|
|
vmem_set_import(kernel_arena, kva_import, NULL, NULL,
|
|
|
|
#if VM_NRESERVLEVEL > 0
|
|
|
|
1 << (VM_LEVEL_0_ORDER + PAGE_SHIFT));
|
|
|
|
#else
|
2013-08-19 23:02:39 +00:00
|
|
|
/* On non-superpage architectures want large import sizes. */
|
|
|
|
PAGE_SIZE * 1024);
|
2013-08-07 06:21:20 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
kmem_init_zero_region();
|
2004-04-05 00:37:50 +00:00
|
|
|
pmap_init();
|
1994-05-24 10:09:53 +00:00
|
|
|
vm_pager_init();
|
|
|
|
}
|
2001-08-22 04:07:27 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
vm_ksubmap_init(struct kva_md_info *kmi)
|
|
|
|
{
|
|
|
|
vm_offset_t firstaddr;
|
|
|
|
caddr_t v;
|
|
|
|
vm_size_t size = 0;
|
2002-08-30 04:04:37 +00:00
|
|
|
long physmem_est;
|
2001-08-22 04:07:27 +00:00
|
|
|
vm_offset_t minaddr;
|
|
|
|
vm_offset_t maxaddr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate space for system data structures.
|
|
|
|
* The first available kernel virtual address is in "v".
|
|
|
|
* As pages of kernel virtual memory are allocated, "v" is incremented.
|
|
|
|
* As pages of memory are allocated and cleared,
|
|
|
|
* "firstaddr" is incremented.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make two passes. The first pass calculates how much memory is
|
|
|
|
* needed and allocates it. The second pass assigns virtual
|
|
|
|
* addresses to the various data structures.
|
|
|
|
*/
|
|
|
|
firstaddr = 0;
|
|
|
|
again:
|
|
|
|
v = (caddr_t)firstaddr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Discount the physical memory larger than the size of kernel_map
|
|
|
|
* to avoid eating up all of KVA space.
|
|
|
|
*/
|
2004-08-07 05:58:31 +00:00
|
|
|
physmem_est = lmin(physmem, btoc(kernel_map->max_offset -
|
|
|
|
kernel_map->min_offset));
|
2001-08-22 04:07:27 +00:00
|
|
|
|
|
|
|
v = kern_vfs_bio_buffer_alloc(v, physmem_est);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* End of first pass, size has been calculated so allocate memory
|
|
|
|
*/
|
|
|
|
if (firstaddr == 0) {
|
2003-07-13 21:02:11 +00:00
|
|
|
size = (vm_size_t)v;
|
2013-08-07 06:21:20 +00:00
|
|
|
firstaddr = kmem_malloc(kernel_arena, round_page(size),
|
|
|
|
M_ZERO | M_WAITOK);
|
2001-08-22 04:07:27 +00:00
|
|
|
if (firstaddr == 0)
|
|
|
|
panic("startup: no room for tables");
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* End of second pass, addresses have been assigned
|
|
|
|
*/
|
|
|
|
if ((vm_size_t)((char *)v - firstaddr) != size)
|
|
|
|
panic("startup: table size inconsistency");
|
|
|
|
|
2013-08-07 06:21:20 +00:00
|
|
|
/*
|
|
|
|
* Allocate the clean map to hold all of the paging and I/O virtual
|
|
|
|
* memory.
|
|
|
|
*/
|
2013-06-28 03:51:20 +00:00
|
|
|
size = (long)nbuf * BKVASIZE + (long)nswbuf * MAXPHYS +
|
|
|
|
(long)bio_transient_maxcnt * MAXPHYS;
|
2013-08-07 06:21:20 +00:00
|
|
|
kmi->clean_sva = firstaddr = kva_alloc(size);
|
|
|
|
kmi->clean_eva = firstaddr + size;
|
2013-06-28 03:51:20 +00:00
|
|
|
|
2013-08-07 06:21:20 +00:00
|
|
|
/*
|
|
|
|
* Allocate the buffer arena.
|
2015-10-14 02:10:07 +00:00
|
|
|
*
|
|
|
|
* Enable the quantum cache if we have more than 4 cpus. This
|
|
|
|
* avoids lock contention at the expense of some fragmentation.
|
2013-08-07 06:21:20 +00:00
|
|
|
*/
|
2013-06-28 03:51:20 +00:00
|
|
|
size = (long)nbuf * BKVASIZE;
|
2013-08-07 06:21:20 +00:00
|
|
|
kmi->buffer_sva = firstaddr;
|
2013-06-28 03:51:20 +00:00
|
|
|
kmi->buffer_eva = kmi->buffer_sva + size;
|
|
|
|
vmem_init(buffer_arena, "buffer arena", kmi->buffer_sva, size,
|
2015-10-14 02:10:07 +00:00
|
|
|
PAGE_SIZE, (mp_ncpus > 4) ? BKVASIZE * 8 : 0, 0);
|
2013-08-07 06:21:20 +00:00
|
|
|
firstaddr += size;
|
2013-06-28 03:51:20 +00:00
|
|
|
|
2013-08-07 06:21:20 +00:00
|
|
|
/*
|
|
|
|
* Now swap kva.
|
|
|
|
*/
|
|
|
|
swapbkva = firstaddr;
|
2013-06-28 03:51:20 +00:00
|
|
|
size = (long)nswbuf * MAXPHYS;
|
2013-08-07 06:21:20 +00:00
|
|
|
firstaddr += size;
|
2013-06-28 03:51:20 +00:00
|
|
|
|
2013-08-07 06:21:20 +00:00
|
|
|
/*
|
|
|
|
* And optionally transient bio space.
|
|
|
|
*/
|
2013-03-21 07:28:15 +00:00
|
|
|
if (bio_transient_maxcnt != 0) {
|
2013-06-28 03:51:20 +00:00
|
|
|
size = (long)bio_transient_maxcnt * MAXPHYS;
|
|
|
|
vmem_init(transient_arena, "transient arena",
|
2013-08-07 06:21:20 +00:00
|
|
|
firstaddr, size, PAGE_SIZE, 0, 0);
|
|
|
|
firstaddr += size;
|
2013-03-21 07:28:15 +00:00
|
|
|
}
|
2013-08-07 06:21:20 +00:00
|
|
|
if (firstaddr != kmi->clean_eva)
|
|
|
|
panic("Clean map calculation incorrect");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate the pageable submaps.
|
|
|
|
*/
|
2001-08-22 04:07:27 +00:00
|
|
|
exec_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr,
|
2010-07-27 17:31:03 +00:00
|
|
|
exec_map_entries * round_page(PATH_MAX + ARG_MAX), FALSE);
|
2008-05-10 21:46:20 +00:00
|
|
|
pipe_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr, maxpipekva,
|
|
|
|
FALSE);
|
2001-08-22 04:07:27 +00:00
|
|
|
}
|