netbsd dirent.h, import sys/sys *.h, mfs cleanup

. add all sys/sys headers not already present to help compiling
	. take netbsd dirent.h and struct dirent; main result is
	  introducing d_type and d_namlen that have to be set by getdents()
	  in all FS code implementing it
	. d_off is gone
	. alignment of the struct has become 8 bytes instead of 4
	. remove _MAX_BLOCK_SIZE, _MIN_BLOCK_SIZE, _STATIC_BLOCK_SIZE
	. libminlib: cleanup unused yet duplicate code
	. mfs: throw out the long-broken v1, v2 support
	. new test for dirent contents filled by getdents()

Change-Id: I1459755c7ba5e5d1c9396d3a587ce6e63ddc283e
This commit is contained in:
Ben Gras
2013-09-16 22:52:36 +02:00
committed by Lionel Sambuc
parent 664b726cd3
commit 6c8f7fc3ba
260 changed files with 37541 additions and 529 deletions

13
sys/uvm/Makefile Normal file
View File

@@ -0,0 +1,13 @@
# $NetBSD: Makefile,v 1.9 2006/02/11 12:45:07 yamt Exp $
INCSDIR= /usr/include/uvm
INCS= uvm.h uvm_amap.h uvm_anon.h uvm_aobj.h uvm_device.h \
uvm_extern.h uvm_fault.h uvm_fault_i.h uvm_glue.h \
uvm_km.h uvm_loan.h \
uvm_map.h uvm_object.h uvm_page.h \
uvm_pager.h uvm_param.h uvm_pdaemon.h uvm_pglist.h \
uvm_pmap.h uvm_prot.h uvm_stat.h \
uvm_swap.h
.include <bsd.kinc.mk>

47
sys/uvm/files.uvm Normal file
View File

@@ -0,0 +1,47 @@
# $NetBSD: files.uvm,v 1.20 2011/05/17 05:32:31 mrg Exp $
#
# UVM options
#
defflag opt_uvmhist.h UVMHIST UVMHIST_PRINT: KERNHIST
defflag opt_uvm.h USE_TOPDOWN_VM UVMMAP_COUNTERS
defflag opt_vmswap.h VMSWAP
defflag opt_readahead.h READAHEAD_STATS
defflag opt_ubc.h UBC_STATS
defparam opt_pagermap.h PAGER_MAP_SIZE
defflag PDPOLICY_CLOCKPRO
defparam USER_VA0_DISABLE_DEFAULT
defflag opt_uvm_page_trkown.h UVM_PAGE_TRKOWN
file uvm/uvm_amap.c
file uvm/uvm_anon.c
file uvm/uvm_aobj.c
file uvm/uvm_bio.c
file uvm/uvm_coredump.c coredump
file uvm/uvm_device.c
file uvm/uvm_emap.c
file uvm/uvm_fault.c
file uvm/uvm_glue.c
file uvm/uvm_init.c
file uvm/uvm_io.c
file uvm/uvm_km.c
file uvm/uvm_kmguard.c debug
file uvm/uvm_loan.c
file uvm/uvm_map.c
file uvm/uvm_meter.c
file uvm/uvm_mmap.c
file uvm/uvm_mremap.c
file uvm/uvm_object.c
file uvm/uvm_page.c
file uvm/uvm_pager.c
file uvm/uvm_pdaemon.c
file uvm/uvm_pdpolicy_clock.c !pdpolicy_clockpro
file uvm/uvm_pdpolicy_clockpro.c pdpolicy_clockpro
file uvm/uvm_pglist.c
file uvm/uvm_readahead.c
file uvm/uvm_stat.c
file uvm/uvm_swap.c vmswap
file uvm/uvm_swapstub.c !vmswap
file uvm/uvm_unix.c
file uvm/uvm_user.c
file uvm/uvm_vnode.c

271
sys/uvm/pmap/pmap.h Normal file
View File

@@ -0,0 +1,271 @@
/* $NetBSD: pmap.h,v 1.1 2012/10/03 00:51:46 christos Exp $ */
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Ralph Campbell.
*
* 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. 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.
*
* @(#)pmap.h 8.1 (Berkeley) 6/10/93
*/
/*
* Copyright (c) 1987 Carnegie-Mellon University
*
* This code is derived from software contributed to Berkeley by
* Ralph Campbell.
*
* 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 the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)pmap.h 8.1 (Berkeley) 6/10/93
*/
#ifndef _COMMON_PMAP_H_
#define _COMMON_PMAP_H_
#include <uvm/uvm_stat.h>
#ifdef UVMHIST
UVMHIST_DECL(pmapexechist);
UVMHIST_DECL(pmaphist);
#endif
/*
* The user address space is mapped using a two level structure where
* virtual address bits 31..22 are used to index into a segment table which
* points to a page worth of PTEs (4096 page can hold 1024 PTEs).
* Bits 21..12 are then used to index a PTE which describes a page within
* a segment.
*/
#define pmap_trunc_seg(x) ((vaddr_t)(x) & ~SEGOFSET)
#define pmap_round_seg(x) (((vaddr_t)(x) + SEGOFSET) & ~SEGOFSET)
/*
* Each seg_tab point an array of pt_entry [NPTEPG]
*/
typedef union pmap_segtab {
union pmap_segtab * seg_seg[PMAP_SEGTABSIZE];
pt_entry_t * seg_tab[PMAP_SEGTABSIZE];
} pmap_segtab_t;
#ifdef _KERNEL
struct pmap;
typedef bool (*pte_callback_t)(struct pmap *, vaddr_t, vaddr_t,
pt_entry_t *, uintptr_t);
pt_entry_t *pmap_pte_lookup(struct pmap *, vaddr_t);
pt_entry_t *pmap_pte_reserve(struct pmap *, vaddr_t, int);
void pmap_pte_process(struct pmap *, vaddr_t, vaddr_t, pte_callback_t,
uintptr_t);
void pmap_segtab_activate(struct pmap *, struct lwp *);
void pmap_segtab_init(struct pmap *);
void pmap_segtab_destroy(struct pmap *, pte_callback_t, uintptr_t);
extern kmutex_t pmap_segtab_lock;
#endif /* _KERNEL */
/*
* Per TLB (normally same as CPU) asid info
*/
struct pmap_asid_info {
LIST_ENTRY(pmap_asid_info) pai_link;
uint32_t pai_asid; /* TLB address space tag */
};
#define TLBINFO_LOCK(ti) mutex_spin_enter((ti)->ti_lock)
#define TLBINFO_UNLOCK(ti) mutex_spin_exit((ti)->ti_lock)
#define PMAP_PAI_ASIDVALID_P(pai, ti) ((pai)->pai_asid != 0)
#define PMAP_PAI(pmap, ti) (&(pmap)->pm_pai[tlbinfo_index(ti)])
#define PAI_PMAP(pai, ti) \
((pmap_t)((intptr_t)(pai) \
- offsetof(struct pmap, pm_pai[tlbinfo_index(ti)])))
/*
* Machine dependent pmap structure.
*/
struct pmap {
#ifdef MULTIPROCESSOR
__cpuset_t pm_active; /* pmap was active on ... */
__cpuset_t pm_onproc; /* pmap is active on ... */
volatile u_int pm_shootdown_pending;
#endif
pmap_segtab_t * pm_segtab; /* pointers to pages of PTEs */
u_int pm_count; /* pmap reference count */
u_int pm_flags;
#define PMAP_DEFERRED_ACTIVATE 0x0001
struct pmap_statistics pm_stats; /* pmap statistics */
vaddr_t pm_minaddr;
vaddr_t pm_maxaddr;
struct pmap_asid_info pm_pai[1];
};
enum tlb_invalidate_op {
TLBINV_NOBODY=0,
TLBINV_ONE=1,
TLBINV_ALLUSER=2,
TLBINV_ALLKERNEL=3,
TLBINV_ALL=4
};
struct pmap_tlb_info {
char ti_name[8];
uint32_t ti_asid_hint; /* probable next ASID to use */
uint32_t ti_asids_free; /* # of ASIDs free */
#define tlbinfo_noasids_p(ti) ((ti)->ti_asids_free == 0)
kmutex_t *ti_lock;
u_int ti_wired; /* # of wired TLB entries */
uint32_t ti_asid_max;
LIST_HEAD(, pmap_asid_info) ti_pais; /* list of active ASIDs */
#ifdef MULTIPROCESSOR
pmap_t ti_victim;
uint32_t ti_synci_page_bitmap; /* page indices needing a syncicache */
__cpuset_t ti_cpu_mask; /* bitmask of CPUs sharing this TLB */
enum tlb_invalidate_op ti_tlbinvop;
u_int ti_index;
#define tlbinfo_index(ti) ((ti)->ti_index)
struct evcnt ti_evcnt_synci_asts;
struct evcnt ti_evcnt_synci_all;
struct evcnt ti_evcnt_synci_pages;
struct evcnt ti_evcnt_synci_deferred;
struct evcnt ti_evcnt_synci_desired;
struct evcnt ti_evcnt_synci_duplicate;
#else
#define tlbinfo_index(ti) (0)
#endif
struct evcnt ti_evcnt_asid_reinits;
u_long ti_asid_bitmap[256 / (sizeof(u_long) * 8)];
};
#ifdef _KERNEL
struct pmap_kernel {
struct pmap kernel_pmap;
#ifdef MULTIPROCESSOR
struct pmap_asid_info kernel_pai[MAXCPUS-1];
#endif
};
struct pmap_limits {
paddr_t avail_start;
paddr_t avail_end;
vaddr_t virtual_end;
};
/*
* The pools from which pmap structures and sub-structures are allocated.
*/
extern struct pool pmap_pmap_pool;
extern struct pool pmap_pv_pool;
extern struct pool_allocator pmap_pv_page_allocator;
extern struct pmap_kernel kernel_pmap_store;
extern struct pmap_tlb_info pmap_tlb0_info;
#ifdef MULTIPROCESSOR
extern struct pmap_tlb_info *pmap_tlbs[MAXCPUS];
extern u_int pmap_ntlbs;
#endif
extern struct pmap_limits pmap_limits;
#define pmap_wired_count(pmap) ((pmap)->pm_stats.wired_count)
#define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count)
/*
* Bootstrap the system enough to run with virtual memory.
*/
void pmap_remove_all(pmap_t);
void pmap_set_modified(paddr_t);
bool pmap_page_clear_attributes(struct vm_page_md *, u_int);
void pmap_page_set_attributes(struct vm_page_md *, u_int);
void pmap_pvlist_lock_init(size_t);
#define PMAP_WB 0
#define PMAP_WBINV 1
#define PMAP_INV 2
#ifdef MULTIPROCESSOR
void pmap_tlb_shootdown_process(void);
bool pmap_tlb_shootdown_bystanders(pmap_t pmap);
void pmap_tlb_info_attach(struct pmap_tlb_info *, struct cpu_info *);
void pmap_md_tlb_info_attach(struct pmap_tlb_info *, struct cpu_info *);
void pmap_syncicache_ast(struct cpu_info *);
void pmap_syncicache_wanted(struct cpu_info *);
void pmap_syncicache(vaddr_t, uint32_t);
#endif
void pmap_tlb_info_init(struct pmap_tlb_info *);
void pmap_tlb_info_evcnt_attach(struct pmap_tlb_info *);
void pmap_tlb_asid_acquire(pmap_t, struct lwp *l);
void pmap_tlb_asid_deactivate(pmap_t);
void pmap_tlb_asid_release_all(pmap_t);
int pmap_tlb_update_addr(pmap_t, vaddr_t, uint32_t, u_int);
#define PMAP_TLB_NEED_IPI 0x01
#define PMAP_TLB_INSERT 0x02
void pmap_tlb_invalidate_addr(pmap_t, vaddr_t);
void pmap_tlb_check(pmap_t, bool (*)(void *, vaddr_t, tlb_asid_t, pt_entry_t));
void pmap_tlb_asid_check(void);
uint16_t pmap_pvlist_lock(struct vm_page_md *, bool);
#define PMAP_STEAL_MEMORY /* enable pmap_steal_memory() */
#define PMAP_GROWKERNEL /* enable pmap_growkernel() */
/*
* Alternate mapping hooks for pool pages. Avoids thrashing the TLB.
*/
vaddr_t pmap_map_poolpage(paddr_t);
paddr_t pmap_unmap_poolpage(vaddr_t);
struct vm_page *pmap_md_alloc_poolpage(int);
#define PMAP_ALLOC_POOLPAGE(flags) pmap_md_alloc_poolpage(flags)
#define PMAP_MAP_POOLPAGE(pa) pmap_map_poolpage(pa)
#define PMAP_UNMAP_POOLPAGE(va) pmap_unmap_poolpage(va)
#endif /* _KERNEL */
#endif /* _COMMON_PMAP_H_ */

71
sys/uvm/pmap/tlb.h Normal file
View File

@@ -0,0 +1,71 @@
/* $NetBSD: tlb.h,v 1.1 2012/10/03 00:51:47 christos Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _COMMON_PMAP_TLB_TLB_H_
#define _COMMON_PMAP_TLB_TLB_H_
#if defined(_KERNEL) || defined(_KMEMUSER)
struct tlbmask;
struct tlb_md_ops {
void (*md_tlb_set_asid)(tlb_asid_t);
tlb_asid_t
(*md_tlb_get_asid)(void);
void (*md_tlb_invalidate_all)(void);
void (*md_tlb_invalidate_globals)(void);
void (*md_tlb_invalidate_asids)(tlb_asid_t, tlb_asid_t);
void (*md_tlb_invalidate_addr)(vaddr_t, tlb_asid_t);
bool (*md_tlb_update_addr)(vaddr_t, tlb_asid_t, pt_entry_t, bool);
void (*md_tlb_read_entry)(size_t, struct tlbmask *);
void (*md_tlb_write_entry)(size_t, const struct tlbmask *);
u_int (*md_tlb_record_asids)(u_long *);
void (*md_tlb_dump)(void (*)(const char *, ...));
void (*md_tlb_walk)(void *, bool (*)(void *, vaddr_t, tlb_asid_t,
pt_entry_t));
};
tlb_asid_t
tlb_get_asid(void);
void tlb_set_asid(tlb_asid_t);
void tlb_invalidate_all(void);
void tlb_invalidate_globals(void);
void tlb_invalidate_asids(tlb_asid_t, tlb_asid_t);
void tlb_invalidate_addr(vaddr_t, tlb_asid_t);
bool tlb_update_addr(vaddr_t, tlb_asid_t, pt_entry_t, bool);
u_int tlb_record_asids(u_long *);
void tlb_enter_addr(size_t, const struct tlbmask *);
void tlb_read_entry(size_t, struct tlbmask *);
void tlb_write_entry(size_t, const struct tlbmask *);
void tlb_walk(void *, bool (*)(void *, vaddr_t, tlb_asid_t, pt_entry_t));
void tlb_dump(void (*)(const char *, ...));
#endif /* _KERNEL || _KMEMUSER */
#endif /* !_COMMON_PMAP_TLB_TLB_H_ */

112
sys/uvm/pmap/vmpagemd.h Normal file
View File

@@ -0,0 +1,112 @@
/* $NetBSD: vmpagemd.h,v 1.1 2012/10/03 00:51:47 christos Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Raytheon BBN Technologies Corp and Defense Advanced Research Projects
* Agency and which was developed by Matt Thomas of 3am Software Foundry.
*
* This material is based upon work supported by the Defense Advanced Research
* Projects Agency and Space and Naval Warfare Systems Center, Pacific, under
* Contract No. N66001-09-C-2073.
* Approved for Public Release, Distribution Unlimited
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _COMMON_PMAP_TLB_VMPAGEMD_H_
#define _COMMON_PMAP_TLB_VMPAGEMD_H_
#ifdef _LOCORE
#error use assym.h instead
#endif
#ifdef _MODULE
#error this file should not be included by loadable kernel modules
#endif
#include "opt_modular.h"
#include "opt_multiprocessor.h"
#include <sys/mutex.h>
#define __HAVE_VM_PAGE_MD
typedef struct pv_entry {
struct pv_entry *pv_next;
struct pmap *pv_pmap;
vaddr_t pv_va;
} *pv_entry_t;
#define VM_PAGEMD_REFERENCED 0x0001 /* page has been recently referenced */
#define VM_PAGEMD_MODIFIED 0x0002 /* page has been modified */
#define VM_PAGEMD_POOLPAGE 0x0004 /* page is used as a poolpage */
#define VM_PAGEMD_EXECPAGE 0x0008 /* page is exec mapped */
#ifdef __PMAP_VIRTUAL_CACHE_ALIASES
#define VM_PAGEMD_UNCACHED 0x0010 /* page is mapped uncached */
#endif
#ifdef __PMAP_VIRTUAL_CACHE_ALIASES
#define VM_PAGEMD_CACHED_P(mdpg) (((mdpg)->mdpg_attrs & VM_PAGEMD_UNCACHED) == 0)
#define VM_PAGEMD_UNCACHED_P(mdpg) (((mdpg)->mdpg_attrs & VM_PAGEMD_UNCACHED) != 0)
#endif
#define VM_PAGEMD_MODIFIED_P(mdpg) (((mdpg)->mdpg_attrs & VM_PAGEMD_MODIFIED) != 0)
#define VM_PAGEMD_REFERENCED_P(mdpg) (((mdpg)->mdpg_attrs & VM_PAGEMD_REFERENCED) != 0)
#define VM_PAGEMD_POOLPAGE_P(mdpg) (((mdpg)->mdpg_attrs & VM_PAGEMD_POOLPAGE) != 0)
#define VM_PAGEMD_EXECPAGE_P(mdpg) (((mdpg)->mdpg_attrs & VM_PAGEMD_EXECPAGE) != 0)
struct vm_page_md {
volatile u_int mdpg_attrs; /* page attributes */
struct pv_entry mdpg_first; /* pv_entry first */
#if defined(MULTIPROCESSOR) || defined(MODULAR)
kmutex_t *mdpg_lock; /* pv list lock */
#define VM_PAGEMD_PVLIST_LOCK_INIT(mdpg) \
(mdpg)->mdpg_lock = NULL
#define VM_PAGEMD_PVLIST_LOCK(pg, list_change) \
pmap_pvlist_lock(mdpg, list_change)
#define VM_PAGEMD_PVLIST_UNLOCK(mdpg) \
mutex_spin_exit((mdpg)->mdpg_lock)
#define VM_PAGEMD_PVLIST_LOCKED_P(mdpg) \
mutex_owner((mdpg)->mdpg_lock)
#define VM_PAGEMD_PVLIST_GEN(mdpg) \
((uint16_t)((mdpg)->mdpg_attrs >> 16))
#else
#define VM_PAGEMD_PVLIST_LOCK_INIT(mdpg) do { } while (/*CONSTCOND*/ 0)
#define VM_PAGEMD_PVLIST_LOCK(mdpg, lc) (mutex_spin_enter(&pmap_pvlist_mutex), 0)
#define VM_PAGEMD_PVLIST_UNLOCK(mdpg) mutex_spin_exit(&pmap_pvlist_mutex)
#define VM_PAGEMD_PVLIST_LOCKED_P(mdpg) true
#define VM_PAGEMD_PVLIST_GEN(mdpg) (0)
#endif /* MULTIPROCESSOR || MODULAR */
};
#define VM_MDPAGE_INIT(pg) \
do { \
(pg)->mdpage.mdpg_first.pv_next = NULL; \
(pg)->mdpage.mdpg_first.pv_pmap = NULL; \
(pg)->mdpage.mdpg_first.pv_va = (pg)->phys_addr; \
(pg)->mdpage.mdpg_attrs = 0; \
VM_PAGEMD_PVLIST_LOCK_INIT(&(pg)->mdpage); \
} while (/* CONSTCOND */ 0)
#endif /* __COMMON_PMAP_TLB_VMPAGEMD_H_ */

197
sys/uvm/uvm.h Normal file
View File

@@ -0,0 +1,197 @@
/* $NetBSD: uvm.h,v 1.63 2012/02/02 19:43:08 tls Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
* from: Id: uvm.h,v 1.1.2.14 1998/02/02 20:07:19 chuck Exp
*/
#ifndef _UVM_UVM_H_
#define _UVM_UVM_H_
#if defined(_KERNEL_OPT)
#include "opt_lockdebug.h"
#include "opt_multiprocessor.h"
#include "opt_uvmhist.h"
#include "opt_uvm_page_trkown.h"
#endif
#include <uvm/uvm_extern.h>
#ifdef _KERNEL
#include <uvm/uvm_stat.h>
#endif
/*
* pull in prototypes
*/
#include <uvm/uvm_amap.h>
#include <uvm/uvm_aobj.h>
#include <uvm/uvm_fault.h>
#include <uvm/uvm_glue.h>
#include <uvm/uvm_km.h>
#include <uvm/uvm_loan.h>
#include <uvm/uvm_map.h>
#include <uvm/uvm_object.h>
#include <uvm/uvm_page.h>
#include <uvm/uvm_pager.h>
#include <uvm/uvm_pdaemon.h>
#include <uvm/uvm_swap.h>
#include <sys/rnd.h>
#ifdef _KERNEL
/*
* pull in VM_NFREELIST
*/
#include <machine/vmparam.h>
struct workqueue;
/*
* per-cpu data
*/
struct uvm_cpu {
struct pgfreelist page_free[VM_NFREELIST]; /* unallocated pages */
int page_free_nextcolor; /* next color to allocate from */
int page_idlezero_next; /* which color to zero next */
bool page_idle_zero; /* TRUE if we should try to zero
pages in the idle loop */
int pages[PGFL_NQUEUES]; /* total of pages in page_free */
u_int emap_gen; /* emap generation number */
uintptr_t last_fltaddr; /* last faulted address */
uintptr_t last_delta; /* difference of last two flt addrs */
uintptr_t last_delta2; /* difference of differences */
krndsource_t rs; /* entropy source */
};
/*
* uvm structure (vm global state: collected in one structure for ease
* of reference...)
*/
struct uvm {
/* vm_page related parameters */
/* vm_page queues */
struct pgfreelist page_free[VM_NFREELIST]; /* unallocated pages */
bool page_init_done; /* TRUE if uvm_page_init() finished */
/* page daemon trigger */
int pagedaemon; /* daemon sleeps on this */
struct lwp *pagedaemon_lwp; /* daemon's lid */
/* aiodone daemon */
struct workqueue *aiodone_queue;
/* aio_done is locked by uvm.pagedaemon_lock and splbio! */
TAILQ_HEAD(, buf) aio_done; /* done async i/o reqs */
/* per-cpu data */
struct uvm_cpu *cpus[MAXCPUS];
};
/*
* kernel object: to support anonymous pageable kernel memory
*/
extern struct uvm_object *uvm_kernel_object;
/*
* locks (made globals for lockstat).
*/
extern kmutex_t uvm_pageqlock; /* lock for active/inactive page q */
extern kmutex_t uvm_fpageqlock; /* lock for free page q */
extern kmutex_t uvm_kentry_lock;
extern kmutex_t uvm_swap_data_lock;
#endif /* _KERNEL */
/*
* vm_map_entry etype bits:
*/
#define UVM_ET_OBJ 0x01 /* it is a uvm_object */
#define UVM_ET_SUBMAP 0x02 /* it is a vm_map submap */
#define UVM_ET_COPYONWRITE 0x04 /* copy_on_write */
#define UVM_ET_NEEDSCOPY 0x08 /* needs_copy */
#define UVM_ET_ISOBJ(E) (((E)->etype & UVM_ET_OBJ) != 0)
#define UVM_ET_ISSUBMAP(E) (((E)->etype & UVM_ET_SUBMAP) != 0)
#define UVM_ET_ISCOPYONWRITE(E) (((E)->etype & UVM_ET_COPYONWRITE) != 0)
#define UVM_ET_ISNEEDSCOPY(E) (((E)->etype & UVM_ET_NEEDSCOPY) != 0)
#ifdef _KERNEL
/*
* holds all the internal UVM data
*/
extern struct uvm uvm;
/*
* historys
*/
#ifdef UVMHIST
UVMHIST_DECL(maphist);
UVMHIST_DECL(pdhist);
UVMHIST_DECL(ubchist);
UVMHIST_DECL(loanhist);
#endif
extern struct evcnt uvm_ra_total;
extern struct evcnt uvm_ra_hit;
extern struct evcnt uvm_ra_miss;
/*
* UVM_UNLOCK_AND_WAIT: atomic unlock+wait... wrapper around the
* interlocked tsleep() function.
*/
#define UVM_UNLOCK_AND_WAIT(event, slock, intr, msg, timo) \
do { \
(void) mtsleep(event, PVM | PNORELOCK | (intr ? PCATCH : 0), \
msg, timo, slock); \
} while (/*CONSTCOND*/ 0)
void uvm_kick_pdaemon(void);
/*
* UVM_PAGE_OWN: track page ownership (only if UVM_PAGE_TRKOWN)
*/
#if defined(UVM_PAGE_TRKOWN)
#define UVM_PAGE_OWN(PG, TAG) uvm_page_own(PG, TAG)
#else
#define UVM_PAGE_OWN(PG, TAG) /* nothing */
#endif /* UVM_PAGE_TRKOWN */
#include <uvm/uvm_fault_i.h>
#endif /* _KERNEL */
#endif /* _UVM_UVM_H_ */

279
sys/uvm/uvm_amap.h Normal file
View File

@@ -0,0 +1,279 @@
/* $NetBSD: uvm_amap.h,v 1.37 2011/06/12 03:36:02 rmind Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
#ifndef _UVM_UVM_AMAP_H_
#define _UVM_UVM_AMAP_H_
/*
* uvm_amap.h: general amap interface and amap implementation-specific info
*/
/*
* an amap structure contains pointers to a set of anons that are
* mapped together in virtual memory (an anon is a single page of
* anonymous virtual memory -- see uvm_anon.h). in uvm we hide the
* details of the implementation of amaps behind a general amap
* interface. this allows us to change the amap implementation
* without having to touch the rest of the code. this file is divided
* into two parts: the definition of the uvm amap interface and the
* amap implementation-specific definitions.
*/
#ifdef _KERNEL
/*
* part 1: amap interface
*/
void uvm_amap_init(void);
/*
* forward definition of vm_amap structure. only amap
* implementation-specific code should directly access the fields of
* this structure.
*/
struct vm_amap;
/*
* prototypes for the amap interface
*/
void amap_add /* add an anon to an amap */
(struct vm_aref *, vaddr_t,
struct vm_anon *, bool);
struct vm_amap *amap_alloc /* allocate a new amap */
(vaddr_t, vaddr_t, int);
void amap_copy /* clear amap needs-copy flag */
(struct vm_map *, struct vm_map_entry *, int,
vaddr_t, vaddr_t);
void amap_cow_now /* resolve all COW faults now */
(struct vm_map *, struct vm_map_entry *);
int amap_extend /* make amap larger */
(struct vm_map_entry *, vsize_t, int);
int amap_flags /* get amap's flags */
(struct vm_amap *);
void amap_free /* free amap */
(struct vm_amap *);
void amap_lock /* lock amap */
(struct vm_amap *);
struct vm_anon *amap_lookup /* lookup an anon @ offset in amap */
(struct vm_aref *, vaddr_t);
void amap_lookups /* lookup multiple anons */
(struct vm_aref *, vaddr_t,
struct vm_anon **, int);
void amap_ref /* add a reference to an amap */
(struct vm_amap *, vaddr_t, vsize_t, int);
int amap_refs /* get number of references of amap */
(struct vm_amap *);
void amap_share_protect /* protect pages in a shared amap */
(struct vm_map_entry *, vm_prot_t);
void amap_splitref /* split reference to amap into two */
(struct vm_aref *, struct vm_aref *, vaddr_t);
void amap_unadd /* remove an anon from an amap */
(struct vm_aref *, vaddr_t);
void amap_unlock /* unlock amap */
(struct vm_amap *);
void amap_unref /* drop reference to an amap */
(struct vm_amap *, vaddr_t, vsize_t, bool);
void amap_wipeout /* remove all anons from amap */
(struct vm_amap *);
bool amap_swap_off
(int, int);
/*
* amap flag values
*/
#define AMAP_SHARED 0x1 /* amap is shared */
#define AMAP_REFALL 0x2 /* amap_ref: reference entire amap */
#define AMAP_SWAPOFF 0x4 /* amap_swap_off() is in progress */
/*
* amap_copy flags
*/
#define AMAP_COPY_NOWAIT 0x02 /* not allowed to sleep */
#define AMAP_COPY_NOCHUNK 0x04 /* not allowed to chunk */
#define AMAP_COPY_NOMERGE 0x08 /* not allowed to merge */
/*
* amap_extend flags
*/
#define AMAP_EXTEND_BACKWARDS 0x00 /* add "size" to start of map */
#define AMAP_EXTEND_FORWARDS 0x01 /* add "size" to end of map */
#define AMAP_EXTEND_NOWAIT 0x02 /* not allowed to sleep */
#endif /* _KERNEL */
/**********************************************************************/
/*
* part 2: amap implementation-specific info
*/
/*
* we currently provide an array-based amap implementation. in this
* implementation we provide the option of tracking split references
* so that we don't lose track of references during partial unmaps
* ... this is enabled with the "UVM_AMAP_PPREF" define.
*/
#define UVM_AMAP_PPREF /* track partial references */
/*
* here is the definition of the vm_amap structure for this implementation.
*/
struct vm_amap {
kmutex_t *am_lock; /* lock [locks all vm_amap fields] */
int am_ref; /* reference count */
int am_flags; /* flags */
int am_maxslot; /* max # of slots allocated */
int am_nslot; /* # of slots currently in map ( <= maxslot) */
int am_nused; /* # of slots currently in use */
int *am_slots; /* contig array of active slots */
int *am_bckptr; /* back pointer array to am_slots */
struct vm_anon **am_anon; /* array of anonymous pages */
#ifdef UVM_AMAP_PPREF
int *am_ppref; /* per page reference count (if !NULL) */
#endif
LIST_ENTRY(vm_amap) am_list;
};
/*
* note that am_slots, am_bckptr, and am_anon are arrays. this allows
* fast lookup of pages based on their virual address at the expense of
* some extra memory. in the future we should be smarter about memory
* usage and fall back to a non-array based implementation on systems
* that are short of memory (XXXCDC).
*
* the entries in the array are called slots... for example an amap that
* covers four pages of virtual memory is said to have four slots. here
* is an example of the array usage for a four slot amap. note that only
* slots one and three have anons assigned to them. "D/C" means that we
* "don't care" about the value.
*
* 0 1 2 3
* am_anon: NULL, anon0, NULL, anon1 (actual pointers to anons)
* am_bckptr: D/C, 1, D/C, 0 (points to am_slots entry)
*
* am_slots: 3, 1, D/C, D/C (says slots 3 and 1 are in use)
*
* note that am_bckptr is D/C if the slot in am_anon is set to NULL.
* to find the entry in am_slots for an anon, look at am_bckptr[slot],
* thus the entry for slot 3 in am_slots[] is at am_slots[am_bckptr[3]].
* in general, if am_anon[X] is non-NULL, then the following must be
* true: am_slots[am_bckptr[X]] == X
*
* note that am_slots is always contig-packed.
*/
/*
* defines for handling of large, sparse amaps:
*
* one of the problems of array-based amaps is that if you allocate a
* large, sparsely-used area of virtual memory you end up allocating
* large arrays that, for the most part, don't get used. this is a
* problem for BSD in that the kernel likes to make these types of
* allocations to "reserve" memory for possible future use.
*
* for example, the kernel allocates (reserves) a large chunk of user
* VM for possible stack growth. most of the time only a page or two
* of this VM is actually used. since the stack is anonymous memory
* it makes sense for it to live in an amap, but if we allocated an
* amap for the entire stack range we could end up wasting a large
* amount of allocated KVM.
*
* for example, on the i386 at boot time we allocate two amaps for the stack
* of /sbin/init:
* 1. a 7680 slot amap at protection 0 (reserve space for stack)
* 2. a 512 slot amap at protection 7 (top of stack)
*
* most of the array allocated for the amaps for this is never used.
* the amap interface provides a way for us to avoid this problem by
* allowing amap_copy() to break larger amaps up into smaller sized
* chunks (controlled by the "canchunk" option). we use this feature
* to reduce our memory usage with the BSD stack management. if we
* are asked to create an amap with more than UVM_AMAP_LARGE slots in it,
* we attempt to break it up into a UVM_AMAP_CHUNK sized amap if the
* "canchunk" flag is set.
*
* so, in the i386 example, the 7680 slot area is never referenced so
* nothing gets allocated (amap_copy is never called because the protection
* is zero). the 512 slot area for the top of the stack is referenced.
* the chunking code breaks it up into 16 slot chunks (hopefully a single
* 16 slot chunk is enough to handle the whole stack).
*/
#define UVM_AMAP_LARGE 256 /* # of slots in "large" amap */
#define UVM_AMAP_CHUNK 16 /* # of slots to chunk large amaps in */
#ifdef _KERNEL
/*
* macros
*/
/* AMAP_B2SLOT: convert byte offset to slot */
#define AMAP_B2SLOT(S,B) { \
KASSERT(((B) & (PAGE_SIZE - 1)) == 0); \
(S) = (B) >> PAGE_SHIFT; \
}
/*
* lock/unlock/refs/flags macros
*/
#define amap_flags(AMAP) ((AMAP)->am_flags)
#define amap_lock(AMAP) mutex_enter((AMAP)->am_lock)
#define amap_lock_try(AMAP) mutex_tryenter((AMAP)->am_lock)
#define amap_refs(AMAP) ((AMAP)->am_ref)
#define amap_unlock(AMAP) mutex_exit((AMAP)->am_lock)
/*
* if we enable PPREF, then we have a couple of extra functions that
* we need to prototype here...
*/
#ifdef UVM_AMAP_PPREF
#define PPREF_NONE ((int *) -1) /* not using ppref */
void amap_pp_adjref /* adjust references */
(struct vm_amap *, int, vsize_t, int,
struct vm_anon **);
void amap_pp_establish /* establish ppref */
(struct vm_amap *, vaddr_t);
void amap_wiperange /* wipe part of an amap */
(struct vm_amap *, int, int, struct vm_anon **);
#endif /* UVM_AMAP_PPREF */
#endif /* _KERNEL */
#endif /* _UVM_UVM_AMAP_H_ */

116
sys/uvm/uvm_anon.h Normal file
View File

@@ -0,0 +1,116 @@
/* $NetBSD: uvm_anon.h,v 1.30 2011/08/06 17:25:03 rmind Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
#ifndef _UVM_UVM_ANON_H_
#define _UVM_UVM_ANON_H_
/*
* uvm_anon.h
*/
#if defined(_KERNEL_OPT)
#include "opt_vmswap.h"
#endif
/*
* anonymous memory management
*
* anonymous virtual memory is short term virtual memory that goes away
* when the processes referencing it go away. an anonymous page of
* virtual memory is described by the following data structure:
*/
struct vm_anon {
kmutex_t *an_lock; /* Lock for an_ref */
union {
uintptr_t au_ref; /* Reference count [an_lock] */
struct vm_anon *au_link; /* Link for deferred free */
} an_u;
#define an_ref an_u.au_ref
#define an_link an_u.au_link
struct vm_page *an_page; /* If in RAM [an_lock] */
#if defined(VMSWAP) || 1 /* XXX libkvm */
/*
* Drum swap slot # (if != 0) [an_lock. also, it is ok to read
* an_swslot if we hold an_page PG_BUSY].
*/
int an_swslot;
#endif
};
/*
* for active vm_anon's the data can be in one of the following state:
* [1] in a vm_page with no backing store allocated yet, [2] in a vm_page
* with backing store allocated, or [3] paged out to backing store
* (no vm_page).
*
* for pageout in case [2]: if the page has been modified then we must
* flush it out to backing store, otherwise we can just dump the
* vm_page.
*/
/*
* anons are grouped together in anonymous memory maps, or amaps.
* amaps are defined in uvm_amap.h.
*/
/*
* processes reference anonymous virtual memory maps with an anonymous
* reference structure:
*/
struct vm_aref {
int ar_pageoff; /* page offset into amap we start */
struct vm_amap *ar_amap; /* pointer to amap */
};
/*
* the offset field indicates which part of the amap we are referencing.
* locked by vm_map lock.
*/
#ifdef _KERNEL
/*
* prototypes
*/
struct vm_anon *uvm_analloc(void);
void uvm_anon_free(struct vm_anon *);
void uvm_anon_freelst(struct vm_amap *, struct vm_anon *);
void uvm_anon_init(void);
struct vm_page *uvm_anon_lockloanpg(struct vm_anon *);
#if defined(VMSWAP)
void uvm_anon_dropswap(struct vm_anon *);
#else /* defined(VMSWAP) */
#define uvm_anon_dropswap(a) /* nothing */
#endif /* defined(VMSWAP) */
void uvm_anon_release(struct vm_anon *);
bool uvm_anon_pagein(struct vm_amap *, struct vm_anon *);
#endif /* _KERNEL */
#endif /* _UVM_UVM_ANON_H_ */

71
sys/uvm/uvm_aobj.h Normal file
View File

@@ -0,0 +1,71 @@
/* $NetBSD: uvm_aobj.h,v 1.22 2012/09/14 18:56:15 rmind Exp $ */
/*
* Copyright (c) 1998 Chuck Silvers, Charles D. Cranor and
* Washington University.
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
* from: Id: uvm_aobj.h,v 1.1.2.4 1998/02/06 05:19:28 chs Exp
*/
/*
* uvm_aobj.h: anonymous memory uvm_object pager
*
* author: Chuck Silvers <chuq@chuq.com>
* started: Jan-1998
*
* - design mostly from Chuck Cranor
*/
#ifndef _UVM_UVM_AOBJ_H_
#define _UVM_UVM_AOBJ_H_
/*
* Flags for uao_create: UAO_FLAG_KERNOBJ and UAO_FLAG_KERNSWAP are
* used only once, to initialise UVM.
*/
#define UAO_FLAG_KERNOBJ 0x1 /* create kernel object */
#define UAO_FLAG_KERNSWAP 0x2 /* enable kernel swap */
#define UAO_FLAG_NOSWAP 0x8 /* aobj may not swap */
#ifdef _KERNEL
#if defined(_KERNEL_OPT)
#include "opt_vmswap.h"
#endif
void uao_init(void);
int uao_set_swslot(struct uvm_object *, int, int);
#if defined(VMSWAP)
int uao_find_swslot(struct uvm_object *, int);
void uao_dropswap(struct uvm_object *, int);
bool uao_swap_off(int, int);
void uao_dropswap_range(struct uvm_object *, voff_t, voff_t);
#else
#define uao_find_swslot(obj, off) 0
#define uao_dropswap(obj, off) /* nothing */
#define uao_dropswap_range(obj, lo, hi) /* nothing */
#endif
#endif /* _KERNEL */
#endif /* _UVM_UVM_AOBJ_H_ */

48
sys/uvm/uvm_ddb.h Normal file
View File

@@ -0,0 +1,48 @@
/* $NetBSD: uvm_ddb.h,v 1.15 2011/05/17 04:18:07 mrg Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
* from: Id: uvm_extern.h,v 1.1.2.21 1998/02/07 01:16:53 chs Exp
*/
#ifndef _UVM_UVM_DDB_H_
#define _UVM_UVM_DDB_H_
#ifdef _KERNEL
#if defined(DDB) || defined(DEBUGPRINT)
void uvm_map_printit(struct vm_map *, bool,
void (*)(const char *, ...));
void uvm_object_printit(struct uvm_object *, bool,
void (*)(const char *, ...));
void uvm_page_printit(struct vm_page *, bool,
void (*)(const char *, ...));
void uvm_page_printall(void (*)(const char *, ...));
void uvmexp_print(void (*)(const char *, ...));
#endif /* DDB || DEBUGPRINT */
#endif /* _KERNEL */
#endif /* _UVM_UVM_DDB_H_ */

69
sys/uvm/uvm_device.h Normal file
View File

@@ -0,0 +1,69 @@
/* $NetBSD: uvm_device.h,v 1.12 2011/02/02 15:13:34 chuck Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
* from: Id: uvm_device.h,v 1.1.2.2 1997/10/03 17:39:44 chuck Exp
*/
#ifndef _UVM_UVM_DEVICE_H_
#define _UVM_UVM_DEVICE_H_
/*
* uvm_device.h
*
* device handle into the VM system.
*/
/*
* the uvm_device structure. object is put at the top of the data structure.
* this allows:
* (struct uvm_device *) == (struct uvm_object *)
*/
struct uvm_device {
struct uvm_object u_obj; /* the actual VM object */
int u_flags; /* flags [LOCKED BY UDV_LOCK!] */
dev_t u_device; /* our device */
LIST_ENTRY(uvm_device) u_list; /* list of device objects */
};
/*
* u_flags values
*/
#define UVM_DEVICE_HOLD 0x1 /* someone has a "hold" on it */
#define UVM_DEVICE_WANTED 0x2 /* someone wants to put a "hold" on */
#ifdef _KERNEL
/*
* prototypes
*/
struct uvm_object *udv_attach(void *, vm_prot_t, voff_t, vsize_t);
#endif /* _KERNEL */
#endif /* _UVM_UVM_DEVICE_H_ */

749
sys/uvm/uvm_extern.h Normal file
View File

@@ -0,0 +1,749 @@
/* $NetBSD: uvm_extern.h,v 1.184 2012/09/01 00:26:37 matt Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
* from: Id: uvm_extern.h,v 1.1.2.21 1998/02/07 01:16:53 chs Exp
*/
/*-
* Copyright (c) 1991, 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* 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. 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_extern.h 8.5 (Berkeley) 5/3/95
*/
#ifndef _UVM_UVM_EXTERN_H_
#define _UVM_UVM_EXTERN_H_
/*
* uvm_extern.h: this file defines the external interface to the VM system.
*
* this should be the only file included by non-VM parts of the kernel
* which need access to VM services. if you want to know the interface
* to the MI VM layer without knowing the details, this is the file to
* learn.
*
* NOTE: vm system calls are prototyped in syscallargs.h
*/
/*
* defines
*/
/*
* the following defines are for uvm_map and functions which call it.
*/
/* protections bits */
#define UVM_PROT_MASK 0x07 /* protection mask */
#define UVM_PROT_NONE 0x00 /* protection none */
#define UVM_PROT_ALL 0x07 /* everything */
#define UVM_PROT_READ 0x01 /* read */
#define UVM_PROT_WRITE 0x02 /* write */
#define UVM_PROT_EXEC 0x04 /* exec */
/* protection short codes */
#define UVM_PROT_R 0x01 /* read */
#define UVM_PROT_W 0x02 /* write */
#define UVM_PROT_RW 0x03 /* read-write */
#define UVM_PROT_X 0x04 /* exec */
#define UVM_PROT_RX 0x05 /* read-exec */
#define UVM_PROT_WX 0x06 /* write-exec */
#define UVM_PROT_RWX 0x07 /* read-write-exec */
/* 0x08: not used */
/* inherit codes */
#define UVM_INH_MASK 0x30 /* inherit mask */
#define UVM_INH_SHARE 0x00 /* "share" */
#define UVM_INH_COPY 0x10 /* "copy" */
#define UVM_INH_NONE 0x20 /* "none" */
#define UVM_INH_DONATE 0x30 /* "donate" << not used */
/* 0x40, 0x80: not used */
/* bits 0x700: max protection, 0x800: not used */
/* bits 0x7000: advice, 0x8000: not used */
/* advice: matches MADV_* from sys/mman.h and POSIX_FADV_* from sys/fcntl.h */
#define UVM_ADV_NORMAL 0x0 /* 'normal' */
#define UVM_ADV_RANDOM 0x1 /* 'random' */
#define UVM_ADV_SEQUENTIAL 0x2 /* 'sequential' */
#define UVM_ADV_WILLNEED 0x3 /* pages will be needed */
#define UVM_ADV_DONTNEED 0x4 /* pages won't be needed */
#define UVM_ADV_NOREUSE 0x5 /* pages will be used only once */
#define UVM_ADV_MASK 0x7 /* mask */
/* bits 0xffff0000: mapping flags */
#define UVM_FLAG_FIXED 0x010000 /* find space */
#define UVM_FLAG_OVERLAY 0x020000 /* establish overlay */
#define UVM_FLAG_NOMERGE 0x040000 /* don't merge map entries */
#define UVM_FLAG_COPYONW 0x080000 /* set copy_on_write flag */
#define UVM_FLAG_AMAPPAD 0x100000 /* for bss: pad amap to reduce allocations */
#define UVM_FLAG_TRYLOCK 0x200000 /* fail if we can not lock map */
#define UVM_FLAG_NOWAIT 0x400000 /* not allowed to sleep */
#define UVM_FLAG_WAITVA 0x800000 /* wait for va */
#define UVM_FLAG_VAONLY 0x2000000 /* unmap: no pages are mapped */
#define UVM_FLAG_COLORMATCH 0x4000000 /* match color given in off */
/* macros to extract info */
#define UVM_PROTECTION(X) ((X) & UVM_PROT_MASK)
#define UVM_INHERIT(X) (((X) & UVM_INH_MASK) >> 4)
#define UVM_MAXPROTECTION(X) (((X) >> 8) & UVM_PROT_MASK)
#define UVM_ADVICE(X) (((X) >> 12) & UVM_ADV_MASK)
#define UVM_MAPFLAG(PROT,MAXPROT,INH,ADVICE,FLAGS) \
(((MAXPROT) << 8)|(PROT)|(INH)|((ADVICE) << 12)|(FLAGS))
/* magic offset value: offset not known(obj) or don't care(!obj) */
#define UVM_UNKNOWN_OFFSET ((voff_t) -1)
/*
* the following defines are for uvm_km_alloc/free's flags
*/
#define UVM_KMF_WIRED 0x1 /* allocation type: wired */
#define UVM_KMF_PAGEABLE 0x2 /* allocation type: pageable */
#define UVM_KMF_VAONLY 0x4 /* allocation type: VA only */
#define UVM_KMF_TYPEMASK (UVM_KMF_VAONLY | UVM_KMF_PAGEABLE | UVM_KMF_WIRED)
#define UVM_KMF_CANFAIL 0x8 /* caller handles failure */
#define UVM_KMF_ZERO 0x10 /* want zero filled memory */
#define UVM_KMF_EXEC 0x20 /* need executable mapping */
#define UVM_KMF_TRYLOCK UVM_FLAG_TRYLOCK /* try locking only */
#define UVM_KMF_NOWAIT UVM_FLAG_NOWAIT /* not allowed to sleep */
#define UVM_KMF_WAITVA UVM_FLAG_WAITVA /* sleep for va */
#define UVM_KMF_COLORMATCH UVM_FLAG_COLORMATCH /* start at color in align */
/*
* the following defines the strategies for uvm_pagealloc_strat()
*/
#define UVM_PGA_STRAT_NORMAL 0 /* priority (low id to high) walk */
#define UVM_PGA_STRAT_ONLY 1 /* only specified free list */
#define UVM_PGA_STRAT_FALLBACK 2 /* ONLY falls back on NORMAL */
/*
* flags for uvm_pagealloc_strat()
*/
#define UVM_PGA_USERESERVE 0x0001 /* ok to use reserve pages */
#define UVM_PGA_ZERO 0x0002 /* returned page must be zero'd */
/*
* flags for ubc_alloc()
*/
#define UBC_READ 0x001
#define UBC_WRITE 0x002
#define UBC_FAULTBUSY 0x004
/*
* flags for ubc_release()
*/
#define UBC_UNMAP 0x010
/*
* flags for ubc_uiomve()
*/
#define UBC_PARTIALOK 0x100
/*
* flags for uvn_findpages().
*/
#define UFP_ALL 0x00
#define UFP_NOWAIT 0x01
#define UFP_NOALLOC 0x02
#define UFP_NOCACHE 0x04
#define UFP_NORDONLY 0x08
#define UFP_DIRTYONLY 0x10
#define UFP_BACKWARD 0x20
/*
* lockflags that control the locking behavior of various functions.
*/
#define UVM_LK_ENTER 0x00000001 /* map locked on entry */
#define UVM_LK_EXIT 0x00000002 /* leave map locked on exit */
/*
* Default number of pages to allocate on the stack
*/
#define UBC_MAX_PAGES 8
/*
* Value representing inactive emap.
*/
#define UVM_EMAP_INACTIVE (0)
/*
* structures
*/
struct buf;
struct core;
struct loadavg;
struct mount;
struct pglist;
struct proc;
struct uio;
struct uvm_object;
struct vm_anon;
struct vmspace;
struct pmap;
struct vnode;
struct simplelock;
struct vm_map_entry;
struct vm_map;
struct vm_page;
struct vmtotal;
/*
* uvm_pctparam: parameter to be shown as percentage to user.
*/
#define UVM_PCTPARAM_SHIFT 8
#define UVM_PCTPARAM_SCALE (1 << UVM_PCTPARAM_SHIFT)
#define UVM_PCTPARAM_APPLY(pct, x) \
(((x) * (pct)->pct_scaled) >> UVM_PCTPARAM_SHIFT)
struct uvm_pctparam {
int pct_pct; /* percent [0, 100] */ /* should be the first member */
int pct_scaled;
int (*pct_check)(struct uvm_pctparam *, int);
};
/*
* uvmexp: global data structures that are exported to parts of the kernel
* other than the vm system.
*/
struct uvmexp {
/* vm_page constants */
int pagesize; /* size of a page (PAGE_SIZE): must be power of 2 */
int pagemask; /* page mask */
int pageshift; /* page shift */
/* vm_page counters */
int npages; /* number of pages we manage */
int free; /* number of free pages */
int paging; /* number of pages in the process of being paged out */
int wired; /* number of wired pages */
/*
* Adding anything before this line will break binary compatibility
* with top(1) on NetBSD 1.5.
*/
int ncolors; /* number of page color buckets: must be p-o-2 */
int colormask; /* color bucket mask */
int zeropages; /* number of zero'd pages */
int reserve_pagedaemon; /* number of pages reserved for pagedaemon */
int reserve_kernel; /* number of pages reserved for kernel */
unsigned anonpages; /* number of pages used by anon mappings */
unsigned filepages; /* number of pages used by cached file data */
unsigned execpages; /* number of pages used by cached exec data */
/* pageout params */
int freemin; /* min number of free pages */
int freetarg; /* target number of free pages */
int wiredmax; /* max number of wired pages */
/* swap */
int nswapdev; /* number of configured swap devices in system */
int swpages; /* number of PAGE_SIZE'ed swap pages */
int swpgavail; /* number of swap pages currently available */
int swpginuse; /* number of swap pages in use */
int swpgonly; /* number of swap pages in use, not also in RAM */
int nswget; /* number of times fault calls uvm_swap_get() */
/* stat counters. XXX: should be 64-bit counters */
int _unused_faults; /* page fault count */
int _unused_traps; /* trap count */
int _unused_intrs; /* interrupt count */
int _unused_swtch; /* context switch count */
int _unused_softs; /* software interrupt count */
int _unused_syscalls; /* system calls */
int pageins; /* pagein operation count */
/* pageouts are in pdpageouts below */
int _unused1;
int _unused2;
int pgswapin; /* pages swapped in */
int pgswapout; /* pages swapped out */
int forks; /* forks */
int forks_ppwait; /* forks where parent waits */
int forks_sharevm; /* forks where vmspace is shared */
int pga_zerohit; /* pagealloc where zero wanted and zero
was available */
int pga_zeromiss; /* pagealloc where zero wanted and zero
not available */
int zeroaborts; /* number of times page zeroing was
aborted */
int colorhit; /* pagealloc where we got optimal color */
int colormiss; /* pagealloc where we didn't */
int cpuhit; /* pagealloc where we allocated locally */
int cpumiss; /* pagealloc where we didn't */
/* fault subcounters. XXX: should be 64-bit counters */
int fltnoram; /* number of times fault was out of ram */
int fltnoanon; /* number of times fault was out of anons */
int fltpgwait; /* number of times fault had to wait on a page */
int fltpgrele; /* number of times fault found a released page */
int fltrelck; /* number of times fault relock called */
int fltrelckok; /* number of times fault relock is a success */
int fltanget; /* number of times fault gets anon page */
int fltanretry; /* number of times fault retrys an anon get */
int fltamcopy; /* number of times fault clears "needs copy" */
int fltnamap; /* number of times fault maps a neighbor anon page */
int fltnomap; /* number of times fault maps a neighbor obj page */
int fltlget; /* number of times fault does a locked pgo_get */
int fltget; /* number of times fault does an unlocked get */
int flt_anon; /* number of times fault anon (case 1a) */
int flt_acow; /* number of times fault anon cow (case 1b) */
int flt_obj; /* number of times fault is on object page (2a) */
int flt_prcopy; /* number of times fault promotes with copy (2b) */
int flt_przero; /* number of times fault promotes with zerofill (2b) */
/* daemon counters. XXX: should be 64-bit counters */
int pdwoke; /* number of times daemon woke up */
int pdrevs; /* number of times daemon rev'd clock hand */
int _unused3;
int pdfreed; /* number of pages daemon freed since boot */
int pdscans; /* number of pages daemon scanned since boot */
int pdanscan; /* number of anonymous pages scanned by daemon */
int pdobscan; /* number of object pages scanned by daemon */
int pdreact; /* number of pages daemon reactivated since boot */
int pdbusy; /* number of times daemon found a busy page */
int pdpageouts; /* number of times daemon started a pageout */
int pdpending; /* number of times daemon got a pending pagout */
int pddeact; /* number of pages daemon deactivates */
int pdreanon; /* anon pages reactivated due to thresholds */
int pdrefile; /* file pages reactivated due to thresholds */
int pdreexec; /* executable pages reactivated due to thresholds */
};
/*
* The following structure is 64-bit alignment safe. New elements
* should only be added to the end of this structure so binary
* compatibility can be preserved.
*/
struct uvmexp_sysctl {
int64_t pagesize;
int64_t pagemask;
int64_t pageshift;
int64_t npages;
int64_t free;
int64_t active;
int64_t inactive;
int64_t paging;
int64_t wired;
int64_t zeropages;
int64_t reserve_pagedaemon;
int64_t reserve_kernel;
int64_t freemin;
int64_t freetarg;
int64_t inactarg; /* unused */
int64_t wiredmax;
int64_t nswapdev;
int64_t swpages;
int64_t swpginuse;
int64_t swpgonly;
int64_t nswget;
int64_t unused1; /* unused; was nanon */
int64_t cpuhit;
int64_t cpumiss;
int64_t faults;
int64_t traps;
int64_t intrs;
int64_t swtch;
int64_t softs;
int64_t syscalls;
int64_t pageins;
int64_t swapins; /* unused */
int64_t swapouts; /* unused */
int64_t pgswapin;
int64_t pgswapout;
int64_t forks;
int64_t forks_ppwait;
int64_t forks_sharevm;
int64_t pga_zerohit;
int64_t pga_zeromiss;
int64_t zeroaborts;
int64_t fltnoram;
int64_t fltnoanon;
int64_t fltpgwait;
int64_t fltpgrele;
int64_t fltrelck;
int64_t fltrelckok;
int64_t fltanget;
int64_t fltanretry;
int64_t fltamcopy;
int64_t fltnamap;
int64_t fltnomap;
int64_t fltlget;
int64_t fltget;
int64_t flt_anon;
int64_t flt_acow;
int64_t flt_obj;
int64_t flt_prcopy;
int64_t flt_przero;
int64_t pdwoke;
int64_t pdrevs;
int64_t unused4;
int64_t pdfreed;
int64_t pdscans;
int64_t pdanscan;
int64_t pdobscan;
int64_t pdreact;
int64_t pdbusy;
int64_t pdpageouts;
int64_t pdpending;
int64_t pddeact;
int64_t anonpages;
int64_t filepages;
int64_t execpages;
int64_t colorhit;
int64_t colormiss;
int64_t ncolors;
};
#ifdef _KERNEL
/* we need this before including uvm_page.h on some platforms */
extern struct uvmexp uvmexp;
/* MD code needs this without including <uvm/uvm.h> */
extern bool vm_page_zero_enable;
#endif
/*
* Finally, bring in standard UVM headers.
*/
#include <sys/vmmeter.h>
#include <sys/queue.h>
#include <sys/lock.h>
#ifdef _KERNEL
#include <sys/vmem.h>
#endif
#include <uvm/uvm_param.h>
#include <uvm/uvm_prot.h>
#include <uvm/uvm_pmap.h>
#include <uvm/uvm_map.h>
#include <uvm/uvm_pager.h>
/*
* helpers for calling ubc_release()
*/
#ifdef PMAP_CACHE_VIVT
#define UBC_WANT_UNMAP(vp) (((vp)->v_iflag & VI_TEXT) != 0)
#else
#define UBC_WANT_UNMAP(vp) false
#endif
#define UBC_UNMAP_FLAG(vp) (UBC_WANT_UNMAP(vp) ? UBC_UNMAP : 0)
/*
* Shareable process virtual address space.
* May eventually be merged with vm_map.
* Several fields are temporary (text, data stuff).
*/
struct vmspace {
struct vm_map vm_map; /* VM address map */
int vm_refcnt; /* number of references *
* note: protected by vm_map.ref_lock */
void * vm_shm; /* SYS5 shared memory private data XXX */
/* we copy from vm_startcopy to the end of the structure on fork */
#define vm_startcopy vm_rssize
segsz_t vm_rssize; /* current resident set size in pages */
segsz_t vm_swrss; /* resident set size before last swap */
segsz_t vm_tsize; /* text size (pages) XXX */
segsz_t vm_dsize; /* data size (pages) XXX */
segsz_t vm_ssize; /* stack size (pages) */
segsz_t vm_issize; /* initial unmapped stack size (pages) */
void * vm_taddr; /* user virtual address of text XXX */
void * vm_daddr; /* user virtual address of data XXX */
void *vm_maxsaddr; /* user VA at max stack growth */
void *vm_minsaddr; /* user VA at top of stack */
size_t vm_aslr_delta_mmap; /* mmap() random delta for ASLR */
};
#define VMSPACE_IS_KERNEL_P(vm) VM_MAP_IS_KERNEL(&(vm)->vm_map)
#ifdef _KERNEL
/*
* used to keep state while iterating over the map for a core dump.
*/
struct uvm_coredump_state {
void *cookie; /* opaque for the caller */
vaddr_t start; /* start of region */
vaddr_t realend; /* real end of region */
vaddr_t end; /* virtual end of region */
vm_prot_t prot; /* protection of region */
int flags; /* flags; see below */
};
#define UVM_COREDUMP_STACK 0x01 /* region is user stack */
/*
* the various kernel maps, owned by MD code
*/
extern struct vm_map *kernel_map;
extern struct vm_map *phys_map;
/*
* macros
*/
#define vm_resident_count(vm) (pmap_resident_count((vm)->vm_map.pmap))
/* vm_machdep.c */
int vmapbuf(struct buf *, vsize_t);
void vunmapbuf(struct buf *, vsize_t);
/* uvm_aobj.c */
struct uvm_object *uao_create(vsize_t, int);
void uao_detach(struct uvm_object *);
void uao_reference(struct uvm_object *);
/* uvm_bio.c */
void ubc_init(void);
void * ubc_alloc(struct uvm_object *, voff_t, vsize_t *, int,
int);
void ubc_release(void *, int);
int ubc_uiomove(struct uvm_object *, struct uio *, vsize_t,
int, int);
void ubc_zerorange(struct uvm_object *, off_t, size_t, int);
void ubc_purge(struct uvm_object *);
/* uvm_emap.c */
void uvm_emap_sysinit(void);
#ifdef __HAVE_PMAP_EMAP
void uvm_emap_switch(lwp_t *);
#else
#define uvm_emap_switch(l)
#endif
u_int uvm_emap_gen_return(void);
void uvm_emap_update(u_int);
vaddr_t uvm_emap_alloc(vsize_t, bool);
void uvm_emap_free(vaddr_t, size_t);
void uvm_emap_enter(vaddr_t, struct vm_page **, u_int);
void uvm_emap_remove(vaddr_t, vsize_t);
#ifdef __HAVE_PMAP_EMAP
void uvm_emap_consume(u_int);
u_int uvm_emap_produce(void);
#else
#define uvm_emap_consume(x)
#define uvm_emap_produce() UVM_EMAP_INACTIVE
#endif
/* uvm_fault.c */
#define uvm_fault(m, a, p) uvm_fault_internal(m, a, p, 0)
int uvm_fault_internal(struct vm_map *, vaddr_t, vm_prot_t, int);
/* handle a page fault */
/* uvm_glue.c */
#if defined(KGDB)
void uvm_chgkprot(void *, size_t, int);
#endif
void uvm_proc_fork(struct proc *, struct proc *, bool);
void uvm_lwp_fork(struct lwp *, struct lwp *,
void *, size_t, void (*)(void *), void *);
int uvm_coredump_walkmap(struct proc *,
void *,
int (*)(struct proc *, void *,
struct uvm_coredump_state *), void *);
void uvm_proc_exit(struct proc *);
void uvm_lwp_exit(struct lwp *);
void uvm_init_limits(struct proc *);
bool uvm_kernacc(void *, size_t, vm_prot_t);
__dead void uvm_scheduler(void);
vaddr_t uvm_uarea_alloc(void);
void uvm_uarea_free(vaddr_t);
vaddr_t uvm_uarea_system_alloc(struct cpu_info *);
void uvm_uarea_system_free(vaddr_t);
vaddr_t uvm_lwp_getuarea(lwp_t *);
void uvm_lwp_setuarea(lwp_t *, vaddr_t);
int uvm_vslock(struct vmspace *, void *, size_t, vm_prot_t);
void uvm_vsunlock(struct vmspace *, void *, size_t);
void uvm_cpu_attach(struct cpu_info *);
/* uvm_init.c */
void uvm_init(void);
/* uvm_io.c */
int uvm_io(struct vm_map *, struct uio *);
/* uvm_km.c */
vaddr_t uvm_km_alloc(struct vm_map *, vsize_t, vsize_t,
uvm_flag_t);
void uvm_km_free(struct vm_map *, vaddr_t, vsize_t,
uvm_flag_t);
struct vm_map *uvm_km_suballoc(struct vm_map *, vaddr_t *,
vaddr_t *, vsize_t, int, bool,
struct vm_map *);
#ifdef _KERNEL
int uvm_km_kmem_alloc(vmem_t *, vmem_size_t, vm_flag_t,
vmem_addr_t *);
void uvm_km_kmem_free(vmem_t *, vmem_addr_t, vmem_size_t);
bool uvm_km_va_starved_p(void);
#endif
/* uvm_map.c */
int uvm_map(struct vm_map *, vaddr_t *, vsize_t,
struct uvm_object *, voff_t, vsize_t,
uvm_flag_t);
int uvm_map_pageable(struct vm_map *, vaddr_t,
vaddr_t, bool, int);
int uvm_map_pageable_all(struct vm_map *, int, vsize_t);
bool uvm_map_checkprot(struct vm_map *, vaddr_t,
vaddr_t, vm_prot_t);
int uvm_map_protect(struct vm_map *, vaddr_t,
vaddr_t, vm_prot_t, bool);
struct vmspace *uvmspace_alloc(vaddr_t, vaddr_t);
void uvmspace_init(struct vmspace *, struct pmap *,
vaddr_t, vaddr_t);
void uvmspace_exec(struct lwp *, vaddr_t, vaddr_t);
void uvmspace_spawn(struct lwp *, vaddr_t, vaddr_t);
struct vmspace *uvmspace_fork(struct vmspace *);
void uvmspace_addref(struct vmspace *);
void uvmspace_free(struct vmspace *);
void uvmspace_share(struct proc *, struct proc *);
void uvmspace_unshare(struct lwp *);
void uvm_whatis(uintptr_t, void (*)(const char *, ...));
/* uvm_meter.c */
int uvm_sysctl(int *, u_int, void *, size_t *,
void *, size_t, struct proc *);
int uvm_pctparam_check(struct uvm_pctparam *, int);
void uvm_pctparam_set(struct uvm_pctparam *, int);
int uvm_pctparam_get(struct uvm_pctparam *);
void uvm_pctparam_init(struct uvm_pctparam *, int,
int (*)(struct uvm_pctparam *, int));
int uvm_pctparam_createsysctlnode(struct uvm_pctparam *,
const char *, const char *);
/* uvm_mmap.c */
int uvm_mmap(struct vm_map *, vaddr_t *, vsize_t,
vm_prot_t, vm_prot_t, int,
void *, voff_t, vsize_t);
vaddr_t uvm_default_mapaddr(struct proc *, vaddr_t, vsize_t);
/* uvm_mremap.c */
int uvm_mremap(struct vm_map *, vaddr_t, vsize_t,
struct vm_map *, vaddr_t *, vsize_t,
struct proc *, int);
/* uvm_object.c */
void uvm_obj_init(struct uvm_object *,
const struct uvm_pagerops *, bool, u_int);
void uvm_obj_setlock(struct uvm_object *, kmutex_t *);
void uvm_obj_destroy(struct uvm_object *, bool);
int uvm_obj_wirepages(struct uvm_object *, off_t, off_t,
struct pglist *);
void uvm_obj_unwirepages(struct uvm_object *, off_t, off_t);
/* uvm_page.c */
struct vm_page *uvm_pagealloc_strat(struct uvm_object *,
voff_t, struct vm_anon *, int, int, int);
#define uvm_pagealloc(obj, off, anon, flags) \
uvm_pagealloc_strat((obj), (off), (anon), (flags), \
UVM_PGA_STRAT_NORMAL, 0)
void uvm_pagereplace(struct vm_page *,
struct vm_page *);
void uvm_pagerealloc(struct vm_page *,
struct uvm_object *, voff_t);
/* Actually, uvm_page_physload takes PF#s which need their own type */
void uvm_page_physload(paddr_t, paddr_t, paddr_t,
paddr_t, int);
void uvm_setpagesize(void);
/* uvm_pager.c */
void uvm_aio_biodone(struct buf *);
void uvm_aio_aiodone(struct buf *);
void uvm_aio_aiodone_pages(struct vm_page **, int, bool,
int);
/* uvm_pdaemon.c */
void uvm_pageout(void *);
struct work;
void uvm_aiodone_worker(struct work *, void *);
void uvm_pageout_start(int);
void uvm_pageout_done(int);
void uvm_estimatepageable(int *, int *);
/* uvm_pglist.c */
int uvm_pglistalloc(psize_t, paddr_t, paddr_t,
paddr_t, paddr_t, struct pglist *, int, int);
void uvm_pglistfree(struct pglist *);
/* uvm_swap.c */
void uvm_swap_init(void);
/* uvm_unix.c */
int uvm_grow(struct proc *, vaddr_t);
/* uvm_user.c */
void uvm_deallocate(struct vm_map *, vaddr_t, vsize_t);
/* uvm_vnode.c */
void uvm_vnp_setsize(struct vnode *, voff_t);
void uvm_vnp_setwritesize(struct vnode *, voff_t);
int uvn_findpages(struct uvm_object *, voff_t,
int *, struct vm_page **, int);
bool uvn_text_p(struct uvm_object *);
bool uvn_clean_p(struct uvm_object *);
bool uvn_needs_writefault_p(struct uvm_object *);
/* kern_malloc.c */
void kmeminit_nkmempages(void);
void kmeminit(void);
extern int nkmempages;
#endif /* _KERNEL */
#endif /* _UVM_UVM_EXTERN_H_ */

68
sys/uvm/uvm_fault.h Normal file
View File

@@ -0,0 +1,68 @@
/* $NetBSD: uvm_fault.h,v 1.20 2011/02/02 15:13:34 chuck Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
* from: Id: uvm_fault.h,v 1.1.2.2 1997/12/08 16:07:12 chuck Exp
*/
#ifndef _UVM_UVM_FAULT_H_
#define _UVM_UVM_FAULT_H_
/*
* fault data structures
*/
/*
* uvm_faultinfo: to load one of these fill in all orig_* fields and
* then call uvmfault_lookup on it.
*/
struct uvm_faultinfo {
struct vm_map *orig_map; /* IN: original map */
vaddr_t orig_rvaddr; /* IN: original rounded VA */
vsize_t orig_size; /* IN: original size of interest */
struct vm_map *map; /* map (could be a submap) */
unsigned int mapv; /* map's version number */
struct vm_map_entry *entry; /* map entry (from 'map') */
vsize_t size; /* size of interest */
};
#ifdef _KERNEL
/*
* fault prototypes
*/
int uvmfault_anonget(struct uvm_faultinfo *, struct vm_amap *,
struct vm_anon *);
int uvm_fault_wire(struct vm_map *, vaddr_t, vaddr_t, vm_prot_t, int);
void uvm_fault_unwire(struct vm_map *, vaddr_t, vaddr_t);
void uvm_fault_unwire_locked(struct vm_map *, vaddr_t, vaddr_t);
#endif /* _KERNEL */
#endif /* _UVM_UVM_FAULT_H_ */

198
sys/uvm/uvm_fault_i.h Normal file
View File

@@ -0,0 +1,198 @@
/* $NetBSD: uvm_fault_i.h,v 1.28 2012/02/19 00:05:56 rmind Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
* from: Id: uvm_fault_i.h,v 1.1.6.1 1997/12/08 16:07:12 chuck Exp
*/
#ifndef _UVM_UVM_FAULT_I_H_
#define _UVM_UVM_FAULT_I_H_
/*
* uvm_fault_i.h: fault inline functions
*/
/*
* uvmfault_unlockmaps: unlock the maps
*/
static inline void
uvmfault_unlockmaps(struct uvm_faultinfo *ufi, bool write_locked)
{
/*
* ufi can be NULL when this isn't really a fault,
* but merely paging in anon data.
*/
if (ufi == NULL) {
return;
}
if (write_locked) {
vm_map_unlock(ufi->map);
} else {
vm_map_unlock_read(ufi->map);
}
}
/*
* uvmfault_unlockall: unlock everything passed in.
*
* => maps must be read-locked (not write-locked).
*/
static inline void
uvmfault_unlockall(struct uvm_faultinfo *ufi, struct vm_amap *amap,
struct uvm_object *uobj)
{
if (uobj)
mutex_exit(uobj->vmobjlock);
if (amap)
amap_unlock(amap);
uvmfault_unlockmaps(ufi, false);
}
/*
* uvmfault_lookup: lookup a virtual address in a map
*
* => caller must provide a uvm_faultinfo structure with the IN
* params properly filled in
* => we will lookup the map entry (handling submaps) as we go
* => if the lookup is a success we will return with the maps locked
* => if "write_lock" is true, we write_lock the map, otherwise we only
* get a read lock.
* => note that submaps can only appear in the kernel and they are
* required to use the same virtual addresses as the map they
* are referenced by (thus address translation between the main
* map and the submap is unnecessary).
*/
static inline bool
uvmfault_lookup(struct uvm_faultinfo *ufi, bool write_lock)
{
struct vm_map *tmpmap;
/*
* init ufi values for lookup.
*/
ufi->map = ufi->orig_map;
ufi->size = ufi->orig_size;
/*
* keep going down levels until we are done. note that there can
* only be two levels so we won't loop very long.
*/
for (;;) {
/*
* lock map
*/
if (write_lock) {
vm_map_lock(ufi->map);
} else {
vm_map_lock_read(ufi->map);
}
/*
* lookup
*/
if (!uvm_map_lookup_entry(ufi->map, ufi->orig_rvaddr,
&ufi->entry)) {
uvmfault_unlockmaps(ufi, write_lock);
return(false);
}
/*
* reduce size if necessary
*/
if (ufi->entry->end - ufi->orig_rvaddr < ufi->size)
ufi->size = ufi->entry->end - ufi->orig_rvaddr;
/*
* submap? replace map with the submap and lookup again.
* note: VAs in submaps must match VAs in main map.
*/
if (UVM_ET_ISSUBMAP(ufi->entry)) {
tmpmap = ufi->entry->object.sub_map;
if (write_lock) {
vm_map_unlock(ufi->map);
} else {
vm_map_unlock_read(ufi->map);
}
ufi->map = tmpmap;
continue;
}
/*
* got it!
*/
ufi->mapv = ufi->map->timestamp;
return(true);
} /* while loop */
/*NOTREACHED*/
}
/*
* uvmfault_relock: attempt to relock the same version of the map
*
* => fault data structures should be unlocked before calling.
* => if a success (true) maps will be locked after call.
*/
static inline bool
uvmfault_relock(struct uvm_faultinfo *ufi)
{
/*
* ufi can be NULL when this isn't really a fault,
* but merely paging in anon data.
*/
if (ufi == NULL) {
return true;
}
uvmexp.fltrelck++;
/*
* relock map. fail if version mismatch (in which case nothing
* gets locked).
*/
vm_map_lock_read(ufi->map);
if (ufi->mapv != ufi->map->timestamp) {
vm_map_unlock_read(ufi->map);
return(false);
}
uvmexp.fltrelckok++;
return(true);
}
#endif /* _UVM_UVM_FAULT_I_H_ */

45
sys/uvm/uvm_glue.h Normal file
View File

@@ -0,0 +1,45 @@
/* $NetBSD: uvm_glue.h,v 1.10 2011/02/02 15:13:34 chuck Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
* from: Id: uvm_glue.h,v 1.1.2.1 1997/08/14 19:10:48 chuck Exp
*/
#ifndef _UVM_UVM_GLUE_H_
#define _UVM_UVM_GLUE_H_
#ifdef _KERNEL
/*
* uvm_glue.h
*/
void uvm_swapout_threads(void);
void uvm_uarea_init(void);
#endif /* _KERNEL */
#endif /* _UVM_UVM_GLUE_H_ */

55
sys/uvm/uvm_km.h Normal file
View File

@@ -0,0 +1,55 @@
/* $NetBSD: uvm_km.h,v 1.20 2012/01/27 19:48:41 para Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
* from: Id: uvm_km.h,v 1.1.2.2 1997/12/30 12:03:15 mrg Exp
*/
#ifndef _UVM_UVM_KM_H_
#define _UVM_UVM_KM_H_
/*
* uvm_km.h
*/
#ifdef _KERNEL
/*
* prototypes
*/
void uvm_km_bootstrap(vaddr_t, vaddr_t);
void uvm_km_init(void);
void uvm_km_pgremove(vaddr_t, vaddr_t);
void uvm_km_pgremove_intrsafe(struct vm_map *, vaddr_t, vaddr_t);
#if defined(DEBUG)
void uvm_km_check_empty(struct vm_map *, vaddr_t, vaddr_t);
#else
#define uvm_km_check_empty(a, b, c) /* nothing */
#endif /* defined(DEBUG) */
#endif /* _KERNEL */
#endif /* _UVM_UVM_KM_H_ */

46
sys/uvm/uvm_kmguard.h Normal file
View File

@@ -0,0 +1,46 @@
/* $NetBSD: uvm_kmguard.h,v 1.2 2012/02/05 03:40:07 rmind Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Andrew Doran.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _UVM_KMGUARD_H_
#define _UVM_KMGUARD_H_
struct uvm_kmguard {
u_int kg_depth;
intptr_t * kg_fifo;
u_int kg_rotor;
vmem_t * kg_vmem;
};
void uvm_kmguard_init(struct uvm_kmguard *, u_int *, size_t *, vmem_t *);
void * uvm_kmguard_alloc(struct uvm_kmguard *, size_t, bool);
bool uvm_kmguard_free(struct uvm_kmguard *, size_t, void *);
#endif /* _UVM_KMGUARD_H_ */

56
sys/uvm/uvm_loan.h Normal file
View File

@@ -0,0 +1,56 @@
/* $NetBSD: uvm_loan.h,v 1.17 2011/02/02 15:13:34 chuck Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
* from: Id: uvm_loan.h,v 1.1.4.1 1997/12/08 16:07:14 chuck Exp
*/
#ifndef _UVM_UVM_LOAN_H_
#define _UVM_UVM_LOAN_H_
#ifdef _KERNEL
/*
* flags for uvm_loan()
*/
#define UVM_LOAN_TOANON 0x1 /* loan to anon */
#define UVM_LOAN_TOPAGE 0x2 /* loan to page */
/*
* loan prototypes
*/
void uvm_loan_init(void);
int uvm_loan(struct vm_map *, vaddr_t, vsize_t, void *, int);
void uvm_unloan(void *, int, int);
int uvm_loanuobjpages(struct uvm_object *, voff_t, int,
struct vm_page **);
struct vm_page *uvm_loanbreak(struct vm_page *);
int uvm_loanbreak_anon(struct vm_anon *, struct uvm_object *);
#endif /* _KERNEL */
#endif /* _UVM_UVM_LOAN_H_ */

343
sys/uvm/uvm_map.h Normal file
View File

@@ -0,0 +1,343 @@
/* $NetBSD: uvm_map.h,v 1.71 2012/02/19 00:05:56 rmind Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
* Copyright (c) 1991, 1993, The Regents of the University of California.
*
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* The Mach Operating System project at Carnegie-Mellon University.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. 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_map.h 8.3 (Berkeley) 3/15/94
* from: Id: uvm_map.h,v 1.1.2.3 1998/02/07 01:16:55 chs Exp
*
*
* Copyright (c) 1987, 1990 Carnegie-Mellon University.
* All rights reserved.
*
* 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.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* 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.
*/
#ifndef _UVM_UVM_MAP_H_
#define _UVM_UVM_MAP_H_
/*
* uvm_map.h
*/
#ifdef _KERNEL
/*
* macros
*/
/*
* UVM_MAP_CLIP_START: ensure that the entry begins at or after
* the starting address, if it doesn't we split the entry.
*
* => map must be locked by caller
*/
#define UVM_MAP_CLIP_START(MAP,ENTRY,VA) { \
if ((VA) > (ENTRY)->start && (VA) < (ENTRY)->end) { \
uvm_map_clip_start(MAP,ENTRY,VA); \
} \
}
/*
* UVM_MAP_CLIP_END: ensure that the entry ends at or before
* the ending address, if it does't we split the entry.
*
* => map must be locked by caller
*/
#define UVM_MAP_CLIP_END(MAP,ENTRY,VA) { \
if ((VA) > (ENTRY)->start && (VA) < (ENTRY)->end) { \
uvm_map_clip_end(MAP,ENTRY,VA); \
} \
}
/*
* extract flags
*/
#define UVM_EXTRACT_REMOVE 0x01 /* remove mapping from old map */
#define UVM_EXTRACT_CONTIG 0x02 /* try to keep it contig */
#define UVM_EXTRACT_QREF 0x04 /* use quick refs */
#define UVM_EXTRACT_FIXPROT 0x08 /* set prot to maxprot as we go */
#define UVM_EXTRACT_RESERVED 0x10 /* caller did uvm_map_reserve() */
#endif /* _KERNEL */
#include <sys/rbtree.h>
#include <sys/pool.h>
#include <sys/rwlock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <uvm/uvm_anon.h>
/*
* Address map entries consist of start and end addresses,
* a VM object (or sharing map) and offset into that object,
* and user-exported inheritance and protection information.
* Also included is control information for virtual copy operations.
*/
struct vm_map_entry {
struct rb_node rb_node; /* tree information */
vsize_t gap; /* free space after */
vsize_t maxgap; /* space in subtree */
struct vm_map_entry *prev; /* previous entry */
struct vm_map_entry *next; /* next entry */
vaddr_t start; /* start address */
vaddr_t end; /* end address */
union {
struct uvm_object *uvm_obj; /* uvm object */
struct vm_map *sub_map; /* belongs to another map */
} object; /* object I point to */
voff_t offset; /* offset into object */
int etype; /* entry type */
vm_prot_t protection; /* protection code */
vm_prot_t max_protection; /* maximum protection */
vm_inherit_t inheritance; /* inheritance */
int wired_count; /* can be paged if == 0 */
struct vm_aref aref; /* anonymous overlay */
int advice; /* madvise advice */
uint32_t map_attrib; /* uvm-external map attributes */
#define uvm_map_entry_stop_copy flags
u_int8_t flags; /* flags */
#define UVM_MAP_KERNEL 0x01 /* kernel map entry */
#define UVM_MAP_KMAPENT 0x02 /* contains map entries */
#define UVM_MAP_STATIC 0x04 /* special static entries */
#define UVM_MAP_NOMERGE 0x08 /* this entry is not mergable */
};
#define VM_MAPENT_ISWIRED(entry) ((entry)->wired_count != 0)
/*
* Maps are doubly-linked lists of map entries, kept sorted
* by address. A single hint is provided to start
* searches again from the last successful search,
* insertion, or removal.
*
* LOCKING PROTOCOL NOTES:
* -----------------------
*
* VM map locking is a little complicated. There are both shared
* and exclusive locks on maps. However, it is sometimes required
* to downgrade an exclusive lock to a shared lock, and upgrade to
* an exclusive lock again (to perform error recovery). However,
* another thread *must not* queue itself to receive an exclusive
* lock while before we upgrade back to exclusive, otherwise the
* error recovery becomes extremely difficult, if not impossible.
*
* In order to prevent this scenario, we introduce the notion of
* a `busy' map. A `busy' map is read-locked, but other threads
* attempting to write-lock wait for this flag to clear before
* entering the lock manager. A map may only be marked busy
* when the map is write-locked (and then the map must be downgraded
* to read-locked), and may only be marked unbusy by the thread
* which marked it busy (holding *either* a read-lock or a
* write-lock, the latter being gained by an upgrade).
*
* Access to the map `flags' member is controlled by the `flags_lock'
* simple lock. Note that some flags are static (set once at map
* creation time, and never changed), and thus require no locking
* to check those flags. All flags which are r/w must be set or
* cleared while the `flags_lock' is asserted. Additional locking
* requirements are:
*
* VM_MAP_PAGEABLE r/o static flag; no locking required
*
* VM_MAP_WIREFUTURE r/w; may only be set or cleared when
* map is write-locked. may be tested
* without asserting `flags_lock'.
*
* VM_MAP_DYING r/o; set when a vmspace is being
* destroyed to indicate that updates
* to the pmap can be skipped.
*
* VM_MAP_TOPDOWN r/o; set when the vmspace is
* created if the unspecified map
* allocations are to be arranged in
* a "top down" manner.
*/
struct vm_map {
struct pmap * pmap; /* Physical map */
krwlock_t lock; /* Non-intrsafe lock */
struct lwp * busy; /* LWP holding map busy */
kmutex_t misc_lock; /* Lock for ref_count, cv */
kcondvar_t cv; /* For signalling */
int flags; /* flags */
struct rb_tree rb_tree; /* Tree for entries */
struct vm_map_entry header; /* List of entries */
int nentries; /* Number of entries */
vsize_t size; /* virtual size */
int ref_count; /* Reference count */
struct vm_map_entry * hint; /* hint for quick lookups */
struct vm_map_entry * first_free; /* First free space hint */
unsigned int timestamp; /* Version number */
};
#if defined(_KERNEL)
#include <sys/callback.h>
#endif /* defined(_KERNEL) */
#define VM_MAP_IS_KERNEL(map) (vm_map_pmap(map) == pmap_kernel())
/* vm_map flags */
#define VM_MAP_PAGEABLE 0x01 /* ro: entries are pageable */
#define VM_MAP_WIREFUTURE 0x04 /* rw: wire future mappings */
#define VM_MAP_DYING 0x20 /* rw: map is being destroyed */
#define VM_MAP_TOPDOWN 0x40 /* ro: arrange map top-down */
#define VM_MAP_WANTVA 0x100 /* rw: want va */
#ifdef _KERNEL
struct uvm_map_args {
struct vm_map_entry *uma_prev;
vaddr_t uma_start;
vsize_t uma_size;
struct uvm_object *uma_uobj;
voff_t uma_uoffset;
uvm_flag_t uma_flags;
};
#endif /* _KERNEL */
/*
* globals:
*/
#ifdef _KERNEL
#include <sys/proc.h>
#ifdef PMAP_GROWKERNEL
extern vaddr_t uvm_maxkaddr;
#endif
/*
* protos: the following prototypes define the interface to vm_map
*/
void uvm_map_deallocate(struct vm_map *);
int uvm_map_willneed(struct vm_map *, vaddr_t, vaddr_t);
int uvm_map_clean(struct vm_map *, vaddr_t, vaddr_t, int);
void uvm_map_clip_start(struct vm_map *, struct vm_map_entry *,
vaddr_t);
void uvm_map_clip_end(struct vm_map *, struct vm_map_entry *,
vaddr_t);
int uvm_map_extract(struct vm_map *, vaddr_t, vsize_t,
struct vm_map *, vaddr_t *, int);
struct vm_map_entry *
uvm_map_findspace(struct vm_map *, vaddr_t, vsize_t,
vaddr_t *, struct uvm_object *, voff_t, vsize_t, int);
int uvm_map_inherit(struct vm_map *, vaddr_t, vaddr_t,
vm_inherit_t);
int uvm_map_advice(struct vm_map *, vaddr_t, vaddr_t, int);
void uvm_map_init(void);
void uvm_map_init_caches(void);
bool uvm_map_lookup_entry(struct vm_map *, vaddr_t,
struct vm_map_entry **);
void uvm_map_reference(struct vm_map *);
int uvm_map_reserve(struct vm_map *, vsize_t, vaddr_t, vsize_t,
vaddr_t *, uvm_flag_t);
void uvm_map_setup(struct vm_map *, vaddr_t, vaddr_t, int);
int uvm_map_submap(struct vm_map *, vaddr_t, vaddr_t,
struct vm_map *);
void uvm_unmap1(struct vm_map *, vaddr_t, vaddr_t, int);
#define uvm_unmap(map, s, e) uvm_unmap1((map), (s), (e), 0)
void uvm_unmap_detach(struct vm_map_entry *,int);
void uvm_unmap_remove(struct vm_map *, vaddr_t, vaddr_t,
struct vm_map_entry **, int);
int uvm_map_prepare(struct vm_map *, vaddr_t, vsize_t,
struct uvm_object *, voff_t, vsize_t, uvm_flag_t,
struct uvm_map_args *);
int uvm_map_enter(struct vm_map *, const struct uvm_map_args *,
struct vm_map_entry *);
int uvm_mapent_trymerge(struct vm_map *,
struct vm_map_entry *, int);
#define UVM_MERGE_COPYING 1
bool vm_map_starved_p(struct vm_map *);
/*
* VM map locking operations.
*/
bool vm_map_lock_try(struct vm_map *);
void vm_map_lock(struct vm_map *);
void vm_map_unlock(struct vm_map *);
void vm_map_unbusy(struct vm_map *);
void vm_map_lock_read(struct vm_map *);
void vm_map_unlock_read(struct vm_map *);
void vm_map_busy(struct vm_map *);
bool vm_map_locked_p(struct vm_map *);
void uvm_map_lock_entry(struct vm_map_entry *);
void uvm_map_unlock_entry(struct vm_map_entry *);
#endif /* _KERNEL */
/*
* Functions implemented as macros
*/
#define vm_map_min(map) ((map)->header.end)
#define vm_map_max(map) ((map)->header.start)
#define vm_map_setmin(map, v) ((map)->header.end = (v))
#define vm_map_setmax(map, v) ((map)->header.start = (v))
#define vm_map_pmap(map) ((map)->pmap)
#endif /* _UVM_UVM_MAP_H_ */

119
sys/uvm/uvm_object.h Normal file
View File

@@ -0,0 +1,119 @@
/* $NetBSD: uvm_object.h,v 1.33 2012/09/14 22:20:50 rmind Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
* from: Id: uvm_object.h,v 1.1.2.2 1998/01/04 22:44:51 chuck Exp
*/
#ifndef _UVM_UVM_OBJECT_H_
#define _UVM_UVM_OBJECT_H_
#include <sys/queue.h>
#include <sys/rbtree.h>
#include <uvm/uvm_pglist.h>
/*
* The UVM memory object interface. Notes:
*
* A UVM memory object represents a list of pages, which are managed by
* the object's pager operations (uvm_object::pgops). All pages belonging
* to an object are owned by it and thus protected by the object lock.
*
* The lock (uvm_object::vmobjlock) may be shared amongst the UVM objects.
* By default, the lock is allocated dynamically using mutex_obj(9) cache.
* Lock sharing is normally used when there is an underlying object. For
* example, vnode representing a file may have an underlying node, which
* is the case for tmpfs and layered file systems. In such case, vnode's
* UVM object and the underlying UVM object shares the lock (note that the
* vnode_t::v_interlock points to uvm_object::vmobjlock).
*
* The reference count is managed atomically for the anonymous UVM objects.
* For other objects, it is arbitrary (may use the lock or atomics).
*/
struct uvm_object {
kmutex_t * vmobjlock; /* lock on memq */
const struct uvm_pagerops *pgops; /* pager ops */
struct pglist memq; /* pages in this object */
int uo_npages; /* # of pages in memq */
unsigned uo_refs; /* reference count */
struct rb_tree rb_tree; /* tree of pages */
LIST_HEAD(,ubc_map) uo_ubc; /* ubc mappings */
};
/*
* UVM_OBJ_KERN is a 'special' uo_refs value which indicates that the
* object is a kernel memory object rather than a normal one (kernel
* memory objects don't have reference counts -- they never die).
*
* this value is used to detected kernel object mappings at uvm_unmap()
* time. normally when an object is unmapped its pages eventaully become
* deactivated and then paged out and/or freed. this is not useful
* for kernel objects... when a kernel object is unmapped we always want
* to free the resources associated with the mapping. UVM_OBJ_KERN
* allows us to decide which type of unmapping we want to do.
*/
#define UVM_OBJ_KERN (-2)
#define UVM_OBJ_IS_KERN_OBJECT(uobj) \
((uobj)->uo_refs == UVM_OBJ_KERN)
#ifdef _KERNEL
extern const struct uvm_pagerops uvm_vnodeops;
extern const struct uvm_pagerops uvm_deviceops;
extern const struct uvm_pagerops ubc_pager;
extern const struct uvm_pagerops aobj_pager;
#define UVM_OBJ_IS_VNODE(uobj) \
((uobj)->pgops == &uvm_vnodeops)
#define UVM_OBJ_IS_DEVICE(uobj) \
((uobj)->pgops == &uvm_deviceops)
#define UVM_OBJ_IS_VTEXT(uobj) \
(UVM_OBJ_IS_VNODE(uobj) && uvn_text_p(uobj))
#define UVM_OBJ_IS_CLEAN(uobj) \
(UVM_OBJ_IS_VNODE(uobj) && uvn_clean_p(uobj))
/*
* UVM_OBJ_NEEDS_WRITEFAULT: true if the uobj needs to detect modification.
* (ie. wants to avoid writable user mappings.)
*
* XXX bad name
*/
#define UVM_OBJ_NEEDS_WRITEFAULT(uobj) \
(UVM_OBJ_IS_VNODE(uobj) && uvn_needs_writefault_p(uobj))
#define UVM_OBJ_IS_AOBJ(uobj) \
((uobj)->pgops == &aobj_pager)
extern const rb_tree_ops_t uvm_page_tree_ops;
#endif /* _KERNEL */
#endif /* _UVM_UVM_OBJECT_H_ */

363
sys/uvm/uvm_page.h Normal file
View File

@@ -0,0 +1,363 @@
/* $NetBSD: uvm_page.h,v 1.75 2012/05/05 20:45:35 rmind Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
* Copyright (c) 1991, 1993, The Regents of the University of California.
*
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* The Mach Operating System project at Carnegie-Mellon University.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. 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_page.h 7.3 (Berkeley) 4/21/91
* from: Id: uvm_page.h,v 1.1.2.6 1998/02/04 02:31:42 chuck Exp
*
*
* Copyright (c) 1987, 1990 Carnegie-Mellon University.
* All rights reserved.
*
* 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.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* 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.
*/
#ifndef _UVM_UVM_PAGE_H_
#define _UVM_UVM_PAGE_H_
#include <uvm/uvm_extern.h>
#include <uvm/uvm_pglist.h>
#include <sys/rbtree.h>
/*
* Management of resident (logical) pages.
*
* Each resident page has a vm_page structure, indexed by page number.
* There are several lists in the structure:
*
* - A red-black tree rooted with the containing object is used to
* quickly perform object+offset lookups.
* - A list of all pages for a given object, for a quick deactivation
* at a time of deallocation.
* - An ordered list of pages due for pageout.
*
* In addition, the structure contains the object and offset to which
* this page belongs (for pageout) and sundry status bits.
*
* Note that the page structure has no lock of its own. The page is
* generally protected by its owner's lock (UVM object or amap/anon).
* It should be noted that UVM has to serialize pmap(9) operations on
* the managed pages, e.g. for pmap_enter() calls. Hence, the lock
* order is as follows:
*
* [vmpage-owner-lock] ->
* any pmap locks (e.g. PV hash lock)
*
* Since the kernel is always self-consistent, no serialization is
* required for unmanaged mappings, e.g. for pmap_kenter_pa() calls.
*
* Field markings and the corresponding locks:
*
* o: page owner's lock (UVM object or amap/anon)
* p: lock on the page queues
* o|p: either lock can be acquired
* o&p: both locks are required
* ?: locked by pmap or assumed page owner's lock
*
* UVM and pmap(9) may use uvm_page_locked_p() to assert whether the
* page owner's lock is acquired.
*/
struct vm_page {
struct rb_node rb_node; /* o: tree of pages in obj */
union {
TAILQ_ENTRY(vm_page) queue;
LIST_ENTRY(vm_page) list;
} pageq; /* p: queue info for FIFO
* queue or free list */
union {
TAILQ_ENTRY(vm_page) queue;
LIST_ENTRY(vm_page) list;
} listq; /* o: pages in same object */
struct vm_anon *uanon; /* o,p: anon */
struct uvm_object *uobject; /* o,p: object */
voff_t offset; /* o,p: offset into object */
uint16_t flags; /* o: object flags */
uint16_t loan_count; /* number of active loans
* o|p: for reading
* o&p: for modification */
uint16_t wire_count; /* p: wired down map refs */
uint16_t pqflags; /* p: page queue flags */
paddr_t phys_addr; /* physical address of page */
#ifdef __HAVE_VM_PAGE_MD
struct vm_page_md mdpage; /* ?: pmap-specific data */
#endif
#if defined(UVM_PAGE_TRKOWN)
/* debugging fields to track page ownership */
pid_t owner; /* proc that set PG_BUSY */
lwpid_t lowner; /* lwp that set PG_BUSY */
const char *owner_tag; /* why it was set busy */
#endif
};
/*
* Overview of UVM page flags.
*
* Locking notes:
*
* PG_, struct vm_page::flags => locked by the owner
* PQ_, struct vm_page::pqflags => locked by the page-queue lock
* PQ_FREE => additionally locked by free-queue lock
*
* Flag descriptions:
*
* PG_BUSY:
* Page is long-term locked, usually because of I/O (transfer from the
* page memory to the backing store) is in progress. LWP attempting
* to access the page shall set PG_WANTED and wait.
*
* PG_WANTED:
* Indicates that the page, which is currently PG_BUSY, is wanted by
* some other LWP. The page owner (i.e. LWP which set PG_BUSY) is
* responsible to clear both flags and wake up any waiters once it has
* released the long-term lock (PG_BUSY).
*
* PG_RELEASED:
* Indicates that the page, which is currently PG_BUSY, should be freed
* after the release of long-term lock. It is responsibility of the
* owning LWP (i.e. which set PG_BUSY) to do it.
*
* PG_CLEAN:
* Page has not been modified since it was loaded from the backing
* store. If this flag is not set, page is considered "dirty".
* XXX: Currently it means that the page *might* be clean; will be
* fixed with yamt-pagecache merge.
*
* PG_FAKE:
* Page has been allocated, but not yet initialised. The flag is used
* to avoid overwriting of valid data, e.g. to prevent read from the
* backing store when in-core data is newer.
*
* PG_TABLED:
* Indicates that the page is currently in the object's offset queue,
* and that it should be removed from it once the page is freed. Used
* diagnostic purposes.
*
* PG_PAGEOUT:
* Indicates that the page is being paged-out in preparation for
* being freed.
*
* PG_RDONLY:
* Indicates that the page must be mapped read-only.
*
* PG_ZERO:
* Indicates that the page has been pre-zeroed. This flag is only
* set when the page is not in the queues and is cleared when the
* page is placed on the free list.
*
* PG_MARKER:
* Dummy marker page.
*/
#define PG_BUSY 0x0001
#define PG_WANTED 0x0002
#define PG_TABLED 0x0004
#define PG_CLEAN 0x0008
#define PG_PAGEOUT 0x0010
#define PG_RELEASED 0x0020
#define PG_FAKE 0x0040
#define PG_RDONLY 0x0080
#define PG_ZERO 0x0100
#define PG_MARKER 0x0200
#define PG_PAGER1 0x1000 /* pager-specific flag */
#define UVM_PGFLAGBITS \
"\20\1BUSY\2WANTED\3TABLED\4CLEAN\5PAGEOUT\6RELEASED\7FAKE\10RDONLY" \
"\11ZERO\12MARKER\15PAGER1"
#define PQ_FREE 0x0001 /* page is on free list */
#define PQ_ANON 0x0002 /* page is part of an anon, rather
than an uvm_object */
#define PQ_AOBJ 0x0004 /* page is part of an anonymous
uvm_object */
#define PQ_SWAPBACKED (PQ_ANON|PQ_AOBJ)
#define PQ_READAHEAD 0x0008 /* read-ahead but has not been "hit" yet */
#define PQ_PRIVATE1 0x0100
#define PQ_PRIVATE2 0x0200
#define PQ_PRIVATE3 0x0400
#define PQ_PRIVATE4 0x0800
#define PQ_PRIVATE5 0x1000
#define PQ_PRIVATE6 0x2000
#define PQ_PRIVATE7 0x4000
#define PQ_PRIVATE8 0x8000
#define UVM_PQFLAGBITS \
"\20\1FREE\2ANON\3AOBJ\4READAHEAD" \
"\11PRIVATE1\12PRIVATE2\13PRIVATE3\14PRIVATE4" \
"\15PRIVATE5\16PRIVATE6\17PRIVATE7\20PRIVATE8"
/*
* physical memory layout structure
*
* MD vmparam.h must #define:
* VM_PHYSEG_MAX = max number of physical memory segments we support
* (if this is "1" then we revert to a "contig" case)
* VM_PHYSSEG_STRAT: memory sort/search options (for VM_PHYSEG_MAX > 1)
* - VM_PSTRAT_RANDOM: linear search (random order)
* - VM_PSTRAT_BSEARCH: binary search (sorted by address)
* - VM_PSTRAT_BIGFIRST: linear search (sorted by largest segment first)
* - others?
* XXXCDC: eventually we should purge all left-over global variables...
*/
#define VM_PSTRAT_RANDOM 1
#define VM_PSTRAT_BSEARCH 2
#define VM_PSTRAT_BIGFIRST 3
/*
* vm_physseg: describes one segment of physical memory
*/
struct vm_physseg {
paddr_t start; /* PF# of first page in segment */
paddr_t end; /* (PF# of last page in segment) + 1 */
paddr_t avail_start; /* PF# of first free page in segment */
paddr_t avail_end; /* (PF# of last free page in segment) +1 */
struct vm_page *pgs; /* vm_page structures (from start) */
struct vm_page *lastpg; /* vm_page structure for end */
int free_list; /* which free list they belong on */
u_int start_hint; /* start looking for free pages here */
/* protected by uvm_fpageqlock */
#ifdef __HAVE_PMAP_PHYSSEG
struct pmap_physseg pmseg; /* pmap specific (MD) data */
#endif
};
#ifdef _KERNEL
/*
* globals
*/
extern bool vm_page_zero_enable;
/*
* physical memory config is stored in vm_physmem.
*/
#define VM_PHYSMEM_PTR(i) (&vm_physmem[i])
#define VM_PHYSMEM_PTR_SWAP(i, j) \
do { vm_physmem[(i)] = vm_physmem[(j)]; } while (0)
extern struct vm_physseg vm_physmem[VM_PHYSSEG_MAX];
extern int vm_nphysseg;
/*
* prototypes: the following prototypes define the interface to pages
*/
void uvm_page_init(vaddr_t *, vaddr_t *);
#if defined(UVM_PAGE_TRKOWN)
void uvm_page_own(struct vm_page *, const char *);
#endif
#if !defined(PMAP_STEAL_MEMORY)
bool uvm_page_physget(paddr_t *);
#endif
void uvm_page_recolor(int);
void uvm_pageidlezero(void);
void uvm_pageactivate(struct vm_page *);
vaddr_t uvm_pageboot_alloc(vsize_t);
void uvm_pagecopy(struct vm_page *, struct vm_page *);
void uvm_pagedeactivate(struct vm_page *);
void uvm_pagedequeue(struct vm_page *);
void uvm_pageenqueue(struct vm_page *);
void uvm_pagefree(struct vm_page *);
void uvm_page_unbusy(struct vm_page **, int);
struct vm_page *uvm_pagelookup(struct uvm_object *, voff_t);
void uvm_pageunwire(struct vm_page *);
void uvm_pagewire(struct vm_page *);
void uvm_pagezero(struct vm_page *);
bool uvm_pageismanaged(paddr_t);
bool uvm_page_locked_p(struct vm_page *);
int uvm_page_lookup_freelist(struct vm_page *);
int vm_physseg_find(paddr_t, int *);
struct vm_page *uvm_phys_to_vm_page(paddr_t);
paddr_t uvm_vm_page_to_phys(const struct vm_page *);
/*
* macros
*/
#define UVM_PAGE_TREE_PENALTY 4 /* XXX: a guess */
#define VM_PAGE_TO_PHYS(entry) uvm_vm_page_to_phys(entry)
#ifdef __HAVE_VM_PAGE_MD
#define VM_PAGE_TO_MD(pg) (&(pg)->mdpage)
#endif
/*
* Compute the page color bucket for a given page.
*/
#define VM_PGCOLOR_BUCKET(pg) \
(atop(VM_PAGE_TO_PHYS((pg))) & uvmexp.colormask)
#define PHYS_TO_VM_PAGE(pa) uvm_phys_to_vm_page(pa)
#define VM_PAGE_IS_FREE(entry) ((entry)->pqflags & PQ_FREE)
#define VM_FREE_PAGE_TO_CPU(pg) ((struct uvm_cpu *)((uintptr_t)pg->offset))
#ifdef DEBUG
void uvm_pagezerocheck(struct vm_page *);
#endif /* DEBUG */
#endif /* _KERNEL */
#endif /* _UVM_UVM_PAGE_H_ */

183
sys/uvm/uvm_pager.h Normal file
View File

@@ -0,0 +1,183 @@
/* $NetBSD: uvm_pager.h,v 1.43 2012/04/29 22:54:01 chs Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
* from: Id: uvm_pager.h,v 1.1.2.14 1998/01/13 19:00:50 chuck Exp
*/
/*
* 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 Systems Programming Group of the University of Utah Computer
* Science Department.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. 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_pager.h 8.5 (Berkeley) 7/7/94
*/
/*
* Copyright (c) 1990 University of Utah.
*
* This code is derived from software contributed to Berkeley by
* the Systems Programming Group of the University of Utah Computer
* Science Department.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. 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_pager.h 8.5 (Berkeley) 7/7/94
*/
#ifndef _UVM_UVM_PAGER_H_
#define _UVM_UVM_PAGER_H_
/*
* uvm_pager.h
*/
/*
* forward structure declarations
*/
struct uvm_faultinfo;
/*
* pager ops
*/
struct uvm_pagerops {
/* init pager */
void (*pgo_init)(void);
/* add reference to obj */
void (*pgo_reference)(struct uvm_object *);
/* drop reference to obj */
void (*pgo_detach)(struct uvm_object *);
/* special non-standard fault processing */
int (*pgo_fault)(struct uvm_faultinfo *, vaddr_t, struct vm_page **,
int, int, vm_prot_t, int);
/* get/read pages */
int (*pgo_get)(struct uvm_object *, voff_t, struct vm_page **,
int *, int, vm_prot_t, int, int);
/* put/write pages */
int (*pgo_put)(struct uvm_object *, voff_t, voff_t, int);
};
/* pager flags [mostly for flush] */
#define PGO_CLEANIT 0x001 /* write dirty pages to backing store */
#define PGO_SYNCIO 0x002 /* use sync I/O */
#define PGO_DEACTIVATE 0x004 /* deactivate flushed pages */
#define PGO_FREE 0x008 /* free flushed pages */
/* if PGO_FREE is not set then the pages stay where they are. */
#define PGO_ALLPAGES 0x010 /* flush whole object/get all pages */
#define PGO_JOURNALLOCKED 0x020 /* journal is already locked [put] */
#define PGO_LOCKED 0x040 /* fault data structures are locked [get] */
#define PGO_BUSYFAIL 0x080 /* fail if a page is busy [put] */
#define PGO_OVERWRITE 0x200 /* pages will be overwritten before unlocked */
#define PGO_PASTEOF 0x400 /* allow allocation of pages past EOF */
#define PGO_NOBLOCKALLOC 0x800 /* backing block allocation is not needed */
#define PGO_NOTIMESTAMP 0x1000 /* don't mark object accessed/modified */
#define PGO_RECLAIM 0x2000 /* object is being reclaimed */
#define PGO_GLOCKHELD 0x4000 /* genfs_node's lock is already held */
#define PGO_LAZY 0x8000 /* equivalent of MNT_LAZY / FSYNC_LAZY */
/* page we are not interested in getting */
#define PGO_DONTCARE ((struct vm_page *) -1L) /* [get only] */
#ifdef _KERNEL
/*
* prototypes
*/
void uvm_pager_init(void);
void uvm_pager_realloc_emerg(void);
struct vm_page *uvm_pageratop(vaddr_t);
vaddr_t uvm_pagermapin(struct vm_page **, int, int);
void uvm_pagermapout(vaddr_t, int);
extern size_t pager_map_size;
/* Flags to uvm_pagermapin() */
#define UVMPAGER_MAPIN_WAITOK 0x01 /* it's okay to wait */
#define UVMPAGER_MAPIN_READ 0x02 /* device -> host */
#define UVMPAGER_MAPIN_WRITE 0x00 /* host -> device (pseudo flag) */
#endif /* _KERNEL */
#endif /* _UVM_UVM_PAGER_H_ */

277
sys/uvm/uvm_param.h Normal file
View File

@@ -0,0 +1,277 @@
/* $NetBSD: uvm_param.h,v 1.31 2012/03/19 00:17:08 uebayasi Exp $ */
/*
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* The Mach Operating System project at Carnegie-Mellon University.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. 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_param.h 8.2 (Berkeley) 1/9/95
*
*
* Copyright (c) 1987, 1990 Carnegie-Mellon University.
* All rights reserved.
*
* Authors: Avadis Tevanian, Jr., Michael Wayne Young
*
* 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.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* 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.
*/
/*
* Machine independent virtual memory parameters.
*/
#ifndef _VM_PARAM_
#define _VM_PARAM_
#ifdef _KERNEL_OPT
#include "opt_modular.h"
#include "opt_uvm.h"
#endif
#ifdef _KERNEL
#include <sys/types.h>
#include <machine/vmparam.h>
#include <sys/resourcevar.h>
#endif
#if defined(_KERNEL)
#if defined(PAGE_SIZE)
/*
* If PAGE_SIZE is defined at this stage, it must be a constant.
*/
#if PAGE_SIZE == 0
#error Invalid PAGE_SIZE definition
#endif
/*
* If the platform does not need to support a variable PAGE_SIZE,
* then provide default values for MIN_PAGE_SIZE and MAX_PAGE_SIZE.
*/
#if !defined(MIN_PAGE_SIZE)
#define MIN_PAGE_SIZE PAGE_SIZE
#endif /* ! MIN_PAGE_SIZE */
#if !defined(MAX_PAGE_SIZE)
#define MAX_PAGE_SIZE PAGE_SIZE
#endif /* ! MAX_PAGE_SIZE */
#else /* ! PAGE_SIZE */
/*
* PAGE_SIZE is not a constant; MIN_PAGE_SIZE and MAX_PAGE_SIZE must
* be defined.
*/
#if !defined(MIN_PAGE_SIZE)
#error MIN_PAGE_SIZE not defined
#endif
#if !defined(MAX_PAGE_SIZE)
#error MAX_PAGE_SIZE not defined
#endif
#endif /* PAGE_SIZE */
/*
* MIN_PAGE_SIZE and MAX_PAGE_SIZE must be constants.
*/
#if MIN_PAGE_SIZE == 0
#error Invalid MIN_PAGE_SIZE definition
#endif
#if MAX_PAGE_SIZE == 0
#error Invalid MAX_PAGE_SIZE definition
#endif
/*
* If MIN_PAGE_SIZE and MAX_PAGE_SIZE are not equal, then we must use
* non-constant PAGE_SIZE, et al for LKMs.
*/
#if (MIN_PAGE_SIZE != MAX_PAGE_SIZE)
#define __uvmexp_pagesize
#if defined(_LKM) || defined(_MODULE)
#undef PAGE_SIZE
#undef PAGE_MASK
#undef PAGE_SHIFT
#endif
#endif
/*
* Now provide PAGE_SIZE, PAGE_MASK, and PAGE_SHIFT if we do not
* have ones that are compile-time constants.
*/
#if !defined(PAGE_SIZE)
extern const int *const uvmexp_pagesize;
extern const int *const uvmexp_pagemask;
extern const int *const uvmexp_pageshift;
#define PAGE_SIZE (*uvmexp_pagesize) /* size of page */
#define PAGE_MASK (*uvmexp_pagemask) /* size of page - 1 */
#define PAGE_SHIFT (*uvmexp_pageshift) /* bits to shift for pages */
#endif /* PAGE_SIZE */
#endif /* _KERNEL */
/*
* CTL_VM identifiers
*/
#define VM_METER 1 /* struct vmmeter */
#define VM_LOADAVG 2 /* struct loadavg */
#define VM_UVMEXP 3 /* struct uvmexp */
#define VM_NKMEMPAGES 4 /* kmem_map pages */
#define VM_UVMEXP2 5 /* struct uvmexp_sysctl */
#define VM_ANONMIN 6
#define VM_EXECMIN 7
#define VM_FILEMIN 8
#define VM_MAXSLP 9
#define VM_USPACE 10
#define VM_ANONMAX 11
#define VM_EXECMAX 12
#define VM_FILEMAX 13
#define VM_MAXID 14 /* number of valid vm ids */
#define CTL_VM_NAMES { \
{ 0, 0 }, \
{ "vmmeter", CTLTYPE_STRUCT }, \
{ "loadavg", CTLTYPE_STRUCT }, \
{ "uvmexp", CTLTYPE_STRUCT }, \
{ "nkmempages", CTLTYPE_INT }, \
{ "uvmexp2", CTLTYPE_STRUCT }, \
{ "anonmin", CTLTYPE_INT }, \
{ "execmin", CTLTYPE_INT }, \
{ "filemin", CTLTYPE_INT }, \
{ "maxslp", CTLTYPE_INT }, \
{ "uspace", CTLTYPE_INT }, \
{ "anonmax", CTLTYPE_INT }, \
{ "execmax", CTLTYPE_INT }, \
{ "filemax", CTLTYPE_INT }, \
}
#ifndef ASSEMBLER
/*
* Convert addresses to pages and vice versa.
* No rounding is used.
*/
#ifdef _KERNEL
#define atop(x) (((paddr_t)(x)) >> PAGE_SHIFT)
#define ptoa(x) (((paddr_t)(x)) << PAGE_SHIFT)
/*
* Round off or truncate to the nearest page. These will work
* for either addresses or counts (i.e., 1 byte rounds to 1 page).
*/
#define round_page(x) (((x) + PAGE_MASK) & ~PAGE_MASK)
#define trunc_page(x) ((x) & ~PAGE_MASK)
/*
* Set up the default mapping address (VM_DEFAULT_ADDRESS) according to:
*
* USE_TOPDOWN_VM: a kernel option to enable on a per-kernel basis
* which only be used on ports that define...
* __HAVE_TOPDOWN_VM: a per-port option to offer the topdown option
*
* __USE_TOPDOWN_VM: a per-port option to unconditionally use it
*
* if __USE_TOPDOWN_VM is defined, the port can specify a default vm
* address, or we will use the topdown default from below. If it is
* NOT defined, then the port can offer topdown as an option, but it
* MUST define the VM_DEFAULT_ADDRESS macro itself.
*/
#if defined(USE_TOPDOWN_VM) || defined(__USE_TOPDOWN_VM)
# if !defined(__HAVE_TOPDOWN_VM) && !defined(__USE_TOPDOWN_VM)
# error "Top down memory allocation not enabled for this system"
# else /* !__HAVE_TOPDOWN_VM && !__USE_TOPDOWN_VM */
# define __USING_TOPDOWN_VM
# if !defined(VM_DEFAULT_ADDRESS)
# if !defined(__USE_TOPDOWN_VM)
# error "Top down memory allocation not configured for this system"
# else /* !__USE_TOPDOWN_VM */
# define VM_DEFAULT_ADDRESS(da, sz) \
trunc_page(VM_MAXUSER_ADDRESS - MAXSSIZ - (sz))
# endif /* !__USE_TOPDOWN_VM */
# endif /* !VM_DEFAULT_ADDRESS */
# endif /* !__HAVE_TOPDOWN_VM && !__USE_TOPDOWN_VM */
#endif /* USE_TOPDOWN_VM || __USE_TOPDOWN_VM */
#if !defined(__USING_TOPDOWN_VM)
# if defined(VM_DEFAULT_ADDRESS)
# error "Default vm address should not be defined here"
# else /* VM_DEFAULT_ADDRESS */
# define VM_DEFAULT_ADDRESS(da, sz) round_page((vaddr_t)(da) + (vsize_t)maxdmap)
# endif /* VM_DEFAULT_ADDRESS */
#endif /* !__USING_TOPDOWN_VM */
extern int ubc_nwins; /* number of UBC mapping windows */
extern int ubc_winshift; /* shift for a UBC mapping window */
extern u_int uvm_emap_size; /* size of emap */
#else
/* out-of-kernel versions of round_page and trunc_page */
#define round_page(x) \
((((vaddr_t)(x) + (vm_page_size - 1)) / vm_page_size) * \
vm_page_size)
#define trunc_page(x) \
((((vaddr_t)(x)) / vm_page_size) * vm_page_size)
#endif /* _KERNEL */
/*
* typedefs, necessary for standard UVM headers.
*/
typedef unsigned int uvm_flag_t;
typedef int vm_inherit_t; /* XXX: inheritance codes */
typedef off_t voff_t; /* XXX: offset within a uvm_object */
typedef voff_t pgoff_t; /* XXX: number of pages within a uvm object */
#endif /* ASSEMBLER */
#endif /* _VM_PARAM_ */

89
sys/uvm/uvm_pdaemon.h Normal file
View File

@@ -0,0 +1,89 @@
/* $NetBSD: uvm_pdaemon.h,v 1.17 2011/02/02 15:25:27 chuck Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
* Copyright (c) 1991, 1993, The Regents of the University of California.
*
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* The Mach Operating System project at Carnegie-Mellon University.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)vm_pageout.h 8.2 (Berkeley) 1/12/94
* from: Id: uvm_pdaemon.h,v 1.1.2.4 1998/02/02 20:07:20 chuck Exp
*
*
* Copyright (c) 1987, 1990 Carnegie-Mellon University.
* All rights reserved.
*
* 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.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* 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.
*/
#ifndef _UVM_UVM_PDAEMON_H_
#define _UVM_UVM_PDAEMON_H_
/*
* uvm_pdaemon.h: page daemon hooks
*/
#ifdef _KERNEL
/*
* prototypes
*/
void uvm_wait(const char *);
bool uvm_reclaimable(void);
kmutex_t *uvmpd_trylockowner(struct vm_page *);
#ifdef VMSWAP
bool uvmpd_trydropswap(struct vm_page *);
#else
#define uvmpd_trydropswap(_a_) (/*CONSTCOND*/false)
#endif
#endif /* _KERNEL */
#endif /* _UVM_UVM_PDAEMON_H_ */

59
sys/uvm/uvm_pdpolicy.h Normal file
View File

@@ -0,0 +1,59 @@
/* $NetBSD: uvm_pdpolicy.h,v 1.3 2007/02/21 23:00:14 thorpej Exp $ */
/*-
* Copyright (c)2005, 2006 YAMAMOTO Takashi,
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
*/
#ifndef _UVM_PDPOLICY_H_
#define _UVM_PDPOLICY_H_
struct vm_page;
struct vm_anon;
/*
* these API is for uvm internal use only.
* don't use them directly from outside of /sys/uvm.
*/
void uvmpdpol_init(void);
void uvmpdpol_reinit(void);
void uvmpdpol_estimatepageable(int *, int *);
bool uvmpdpol_needsscan_p(void);
void uvmpdpol_pageactivate(struct vm_page *);
void uvmpdpol_pagedeactivate(struct vm_page *);
void uvmpdpol_pagedequeue(struct vm_page *);
void uvmpdpol_pageenqueue(struct vm_page *);
bool uvmpdpol_pageisqueued_p(struct vm_page *);
void uvmpdpol_anfree(struct vm_anon *);
void uvmpdpol_tune(void);
void uvmpdpol_scaninit(void);
struct vm_page *uvmpdpol_selectvictim(void);
void uvmpdpol_balancequeue(int);
void uvmpdpol_sysctlsetup(void);
#endif /* !_UVM_PDPOLICY_H_ */

View File

@@ -0,0 +1,44 @@
/* $NetBSD: uvm_pdpolicy_impl.h,v 1.2 2006/09/15 15:51:13 yamt Exp $ */
/*-
* Copyright (c)2006 YAMAMOTO Takashi,
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
*/
#ifndef _UVM_PDPOLICY_IMPL_H_
#define _UVM_PDPOLICY_IMPL_H_
/*
* definitions for page replacement policy implementations.
*/
#include <sys/evcnt.h>
#define PDPOL_EVCNT_DEFINE(name) \
struct evcnt pdpol_evcnt_##name = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, \
"pdpolicy", #name); \
EVCNT_ATTACH_STATIC(pdpol_evcnt_##name);
#define PDPOL_EVCNT_INCR(ev) pdpol_evcnt_##ev.ev_count++
#endif /* !_UVM_PDPOLICY_IMPL_H_ */

59
sys/uvm/uvm_pglist.h Normal file
View File

@@ -0,0 +1,59 @@
/* $NetBSD: uvm_pglist.h,v 1.8 2010/11/06 15:48:00 uebayasi Exp $ */
/*-
* Copyright (c) 2000, 2001, 2008 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _UVM_UVM_PGLIST_H_
#define _UVM_UVM_PGLIST_H_
/*
* This defines the type of a page queue, e.g. active list, inactive
* list, etc.
*/
struct vm_page;
TAILQ_HEAD(pglist, vm_page);
LIST_HEAD(pgflist, vm_page);
/*
* A page free list consists of free pages of unknown contents and free
* pages of all zeros.
*/
#define PGFL_UNKNOWN 0
#define PGFL_ZEROS 1
#define PGFL_NQUEUES 2
struct pgflbucket {
struct pgflist pgfl_queues[PGFL_NQUEUES];
};
struct pgfreelist {
struct pgflbucket *pgfl_buckets;
};
#endif /* _UVM_UVM_PGLIST_H_ */

218
sys/uvm/uvm_pmap.h Normal file
View File

@@ -0,0 +1,218 @@
/* $NetBSD: uvm_pmap.h,v 1.37 2011/06/30 00:49:14 matt Exp $ */
/*
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* The Mach Operating System project at Carnegie-Mellon University.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. 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.
*
* @(#)pmap.h 8.1 (Berkeley) 6/11/93
*
*
* Copyright (c) 1987, 1990 Carnegie-Mellon University.
* All rights reserved.
*
* Author: Avadis Tevanian, Jr.
*
* 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.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* 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.
*/
/*
* Machine address mapping definitions -- machine-independent
* section. [For machine-dependent section, see "machine/pmap.h".]
*/
#ifndef _PMAP_VM_
#define _PMAP_VM_
struct lwp; /* for pmap_activate()/pmap_deactivate() proto */
struct pmap;
typedef struct pmap *pmap_t;
/*
* Each machine dependent implementation is expected to
* keep certain statistics. They may do this anyway they
* so choose, but are expected to return the statistics
* in the following structure.
*/
struct pmap_statistics {
long resident_count; /* # of pages mapped (total)*/
long wired_count; /* # of pages wired */
};
typedef struct pmap_statistics *pmap_statistics_t;
#ifdef _KERNEL
extern struct pmap *const kernel_pmap_ptr;
#define pmap_kernel() kernel_pmap_ptr
#endif
/*
* Cache Type Encodings
*/
#define PMAP_CACHE_MASK 0x00000f00
/* All accesses are uncacheable. No speculative accesses. */
#define PMAP_NOCACHE 0x00000100 /* [BOTH] */
/* All accesses are uncacheable. No speculative accesses.
* Writes are combined. */
#define PMAP_WRITE_COMBINE 0x00000200 /* [BOTH] */
/* On reads, cachelines become shared or exclusive if allocated on cache miss.
* On writes, cachelines become modified on a cache miss. */
#define PMAP_WRITE_BACK 0x00000300 /* [BOTH] */
/* = PMAP_NOCACHE but overrideable (e.g. on x86 by MTRRs) */
#define PMAP_NOCACHE_OVR 0x00000400 /* [BOTH] */
#ifdef _KERNEL
#include <machine/pmap.h>
#endif
/*
* Flags passed to pmap_enter(). Note the bottom 3 bits are VM_PROT_*
* bits, used to indicate the access type that was made (to seed modified
* and referenced information).
*
* Flags marked [PA] are for pmap_kenter_pa() only. Flags marked [BOTH]
* apply to pmap_kenter_pa() and pmap_enter(). All other flags are valid
* for pmap_enter() only.
*/
#define PMAP_WIRED 0x00000010 /* wired mapping */
#define PMAP_CANFAIL 0x00000020 /* can fail if resource shortage */
#if defined(PMAP_ENABLE_PMAP_KMPAGE)
#define PMAP_KMPAGE 0x00000040 /* [PA] page used for kernel memory */
#else
#define PMAP_KMPAGE 0x00000000
#endif /* PMAP_ENABLE_PMAP_KMPAGE */
#define PMAP_MD_MASK 0xff000000 /* [BOTH] Machine-dependent bits */
#define PMAP_PROT_MASK 0x0000000f /* [BOTH] VM_PROT_* bit mask */
#ifndef PMAP_EXCLUDE_DECLS /* Used in Sparc port to virtualize pmap mod */
#ifdef _KERNEL
__BEGIN_DECLS
void pmap_activate(struct lwp *);
void pmap_deactivate(struct lwp *);
void pmap_unwire(pmap_t, vaddr_t);
#if !defined(pmap_clear_modify)
bool pmap_clear_modify(struct vm_page *);
#endif
#if !defined(pmap_clear_reference)
bool pmap_clear_reference(struct vm_page *);
#endif
#if !defined(pmap_copy)
void pmap_copy(pmap_t, pmap_t, vaddr_t, vsize_t, vaddr_t);
#endif
#if !defined(pmap_copy_page)
void pmap_copy_page(paddr_t, paddr_t);
#endif
struct pmap *pmap_create(void);
void pmap_destroy(pmap_t);
int pmap_enter(pmap_t, vaddr_t, paddr_t, vm_prot_t, u_int);
bool pmap_extract(pmap_t, vaddr_t, paddr_t *);
#if defined(PMAP_GROWKERNEL)
vaddr_t pmap_growkernel(vaddr_t);
#endif
void pmap_init(void);
void pmap_kenter_pa(vaddr_t, paddr_t, vm_prot_t, u_int);
void pmap_kremove(vaddr_t, vsize_t);
#if !defined(pmap_is_modified)
bool pmap_is_modified(struct vm_page *);
#endif
#if !defined(pmap_is_referenced)
bool pmap_is_referenced(struct vm_page *);
#endif
void pmap_page_protect(struct vm_page *, vm_prot_t);
#if !defined(pmap_phys_address)
paddr_t pmap_phys_address(paddr_t);
#endif
#if !defined(pmap_mmap_flags)
#define pmap_mmap_flags(x) 0
#endif
void pmap_protect(pmap_t, vaddr_t, vaddr_t, vm_prot_t);
#if !defined(pmap_reference)
void pmap_reference(pmap_t);
#endif
#if !defined(pmap_remove)
void pmap_remove(pmap_t, vaddr_t, vaddr_t);
#endif
void pmap_remove_all(struct pmap *);
#if !defined(pmap_update)
void pmap_update(pmap_t);
#endif
#if !defined(pmap_resident_count)
long pmap_resident_count(pmap_t);
#endif
#if !defined(pmap_wired_count)
long pmap_wired_count(pmap_t);
#endif
#if !defined(pmap_zero_page)
void pmap_zero_page(paddr_t);
#endif
void pmap_virtual_space(vaddr_t *, vaddr_t *);
#if defined(PMAP_STEAL_MEMORY)
vaddr_t pmap_steal_memory(vsize_t, vaddr_t *, vaddr_t *);
#endif
#if defined(PMAP_FORK)
void pmap_fork(pmap_t, pmap_t);
#endif
__END_DECLS
#endif /* kernel*/
#endif /* PMAP_EXCLUDE_DECLS */
#endif /* _PMAP_VM_ */

100
sys/uvm/uvm_prot.h Normal file
View File

@@ -0,0 +1,100 @@
/* $NetBSD: uvm_prot.h,v 1.4 2005/12/11 12:25:29 christos Exp $ */
/*
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* The Mach Operating System project at Carnegie-Mellon University.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. 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_prot.h 8.1 (Berkeley) 6/11/93
*
*
* Copyright (c) 1987, 1990 Carnegie-Mellon University.
* All rights reserved.
*
* Authors: Avadis Tevanian, Jr., Michael Wayne Young
*
* 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.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* 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.
*/
/*
* Virtual memory protection definitions.
*/
#ifndef _UVM_PROT_
#define _UVM_PROT_
/*
* Types defined:
*
* vm_prot_t VM protection values.
*/
typedef int vm_prot_t;
/*
* Protection values, defined as bits within the vm_prot_t type
*/
#define VM_PROT_NONE ((vm_prot_t) 0x00)
#define VM_PROT_READ ((vm_prot_t) 0x01) /* read permission */
#define VM_PROT_WRITE ((vm_prot_t) 0x02) /* write permission */
#define VM_PROT_EXECUTE ((vm_prot_t) 0x04) /* execute permission */
/*
* The default protection for newly-created virtual memory
*/
#define VM_PROT_DEFAULT (VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE)
/*
* The maximum privileges possible, for parameter checking.
*/
#define VM_PROT_ALL (VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE)
#endif /* _UVM_PROT_ */

42
sys/uvm/uvm_readahead.h Normal file
View File

@@ -0,0 +1,42 @@
/* $NetBSD: uvm_readahead.h,v 1.4 2009/06/10 01:54:08 yamt Exp $ */
/*-
* Copyright (c)2003, 2005, 2009 YAMAMOTO Takashi,
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
*/
#if !defined(_UVM_UVM_READAHEAD_H_)
#define _UVM_UVM_READAHEAD_H_
struct uvm_object;
struct uvm_ractx;
void uvm_ra_init(void);
struct uvm_ractx *uvm_ra_allocctx(void);
void uvm_ra_freectx(struct uvm_ractx *);
void uvm_ra_request(struct uvm_ractx *, int, struct uvm_object *, off_t,
size_t);
int uvm_readahead(struct uvm_object *, off_t, off_t);
#endif /* defined(_UVM_UVM_READAHEAD_H_) */

74
sys/uvm/uvm_stat.h Normal file
View File

@@ -0,0 +1,74 @@
/* $NetBSD: uvm_stat.h,v 1.51 2012/07/30 23:56:48 matt Exp $ */
/*
* Copyright (c) 2011 Matthew R. Green
* All rights reserved.
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
/*
* Backwards compat for UVMHIST, in the new KERNHIST form.
*/
#ifndef _UVM_UVM_STAT_H_
#define _UVM_UVM_STAT_H_
#if defined(_KERNEL_OPT)
#include "opt_uvmhist.h"
#include "opt_kernhist.h"
#endif
/*
* Make UVMHIST_PRINT force on KERNHIST_PRINT for at least UVMHIST_* usage.
*/
#if defined(UVMHIST_PRINT) && !defined(KERNHIST_PRINT)
#define KERNHIST_PRINT 1
#endif
#include <sys/kernhist.h>
#ifdef UVMHIST
#define UVMHIST_DECL(NAME) KERNHIST_DECL(NAME)
#define UVMHIST_DEFINE(NAME) KERNHIST_DEFINE(NAME)
#define UVMHIST_INIT(NAME,N) KERNHIST_INIT(NAME,N)
#define UVMHIST_INIT_STATIC(NAME,BUF) KERNHIST_INIT_STATIC(NAME,BUF)
#define UVMHIST_LOG(NAME,FMT,A,B,C,D) KERNHIST_LOG(NAME,FMT,A,B,C,D)
#define UVMHIST_CALLED(NAME) KERNHIST_CALLED(NAME)
#define UVMHIST_FUNC(FNAME) KERNHIST_FUNC(FNAME)
#else
#define UVMHIST_DECL(NAME)
#define UVMHIST_DEFINE(NAME)
#define UVMHIST_INIT(NAME,N)
#define UVMHIST_INIT_STATIC(NAME,BUF)
#define UVMHIST_LOG(NAME,FMT,A,B,C,D)
#define UVMHIST_CALLED(NAME)
#define UVMHIST_FUNC(FNAME)
#endif
#endif /* _UVM_UVM_STAT_H_ */

56
sys/uvm/uvm_swap.h Normal file
View File

@@ -0,0 +1,56 @@
/* $NetBSD: uvm_swap.h,v 1.18 2011/04/27 00:35:52 rmind Exp $ */
/*
* Copyright (c) 1997 Matthew R. Green
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
* from: Id: uvm_swap.h,v 1.1.2.6 1997/12/15 05:39:31 mrg Exp
*/
#ifndef _UVM_UVM_SWAP_H_
#define _UVM_UVM_SWAP_H_
#define SWSLOT_BAD (-1)
#ifdef _KERNEL
#if defined(_KERNEL_OPT)
#include "opt_vmswap.h"
#endif
struct swapent;
#if defined(VMSWAP)
int uvm_swap_get(struct vm_page *, int, int);
int uvm_swap_put(int, struct vm_page **, int, int);
int uvm_swap_alloc(int *, bool);
void uvm_swap_free(int, int);
void uvm_swap_markbad(int, int);
bool uvm_swapisfull(void);
#else /* defined(VMSWAP) */
#define uvm_swapisfull() true
#endif /* defined(VMSWAP) */
#endif /* _KERNEL */
#endif /* _UVM_UVM_SWAP_H_ */