On Thu, Dec 05, 2019 at 01:55:00PM +0100, Martin Pieuchot wrote: > Diff below split uvm(9) into the following: > > - uvm_init(9) > - uvm_fault(9) > - uvm_km_alloc(9) > - uvm_map(9) > - uvm_pagealloc(9) > - uvn_attach(9) > > That will allow us to work on smaller pages and improve the overall > documentation of UVM. > > This split doesn't include changes. > > Ok? >
makes sense to me. one comment though: > Index: Makefile > =================================================================== > RCS file: /cvs/src/share/man/man9/Makefile,v > retrieving revision 1.297 > diff -u -p -r1.297 Makefile > --- Makefile 8 Nov 2019 07:36:52 -0000 1.297 > +++ Makefile 5 Dec 2019 12:48:33 -0000 > @@ -39,7 +39,10 @@ MAN= aml_evalnode.9 atomic_add_int.9 ato > socreate.9 sosplice.9 strcmp.9 style.9 syscall.9 sysctl_int.9 \ > task_add.9 tc_init.9 tfind.9 thread_fork.9 \ > time_second.9 timeout.9 tsleep.9 tvtohz.9 \ > - uiomove.9 uvm.9 usb_add_task.9 usbd_close_pipe.9 usbd_open_pipe.9 \ > + uiomove.9 \ > + uvm_fault.9 uvm_init.9 uvm_km_alloc.9 uvm_map.9 uvm_pagealloc.9 \ > + uvn_attach.9 \ uv*m*_attach jmc > + usb_add_task.9 usbd_close_pipe.9 usbd_open_pipe.9 \ > usbd_ref_wait.9 usbd_transfer.9 vfs.9 vfs_busy.9 \ > vfs_cache.9 vaccess.9 vclean.9 vcount.9 vdevgone.9 vfinddev.9 vflush.9 \ > vflushbuf.9 vget.9 vgone.9 vhold.9 vinvalbuf.9 vnode.9 vnsubr.9 \ > Index: uvm.9 > =================================================================== > RCS file: uvm.9 > diff -N uvm.9 > --- uvm.9 5 Nov 2019 08:18:47 -0000 1.71 > +++ /dev/null 1 Jan 1970 00:00:00 -0000 > @@ -1,1085 +0,0 @@ > -.\" $OpenBSD: uvm.9,v 1.71 2019/11/05 08:18:47 mpi Exp $ > -.\" $NetBSD: uvm.9,v 1.14 2000/06/29 06:08:44 mrg Exp $ > -.\" > -.\" Copyright (c) 1998 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. > -.\" > -.\" XXX this manual sets nS to 1 or 0 in the description, to obtain > -.\" synopsis-like function prototypes. any better way? > -.\" > -.Dd $Mdocdate: November 5 2019 $ > -.Dt UVM_INIT 9 > -.Os > -.Sh NAME > -.Nm uvm_init , > -.Nm uvm_init_limits , > -.Nm uvm_setpagesize , > -.Nm uvm_swap_init , > -.Nm uvm_map , > -.Nm uvm_map_pageable , > -.Nm uvm_map_pageable_all , > -.Nm uvm_map_checkprot , > -.Nm uvm_map_protect , > -.Nm uvmspace_alloc , > -.Nm uvmspace_exec , > -.Nm uvmspace_fork , > -.Nm uvmspace_free , > -.Nm uvmspace_share , > -.Nm uvm_uarea_alloc , > -.Nm uvm_uarea_free , > -.Nm UVM_MAPFLAG , > -.Nm uvm_fault , > -.Nm uvn_attach , > -.Nm uvm_vnp_setsize , > -.Nm uvm_vnp_sync , > -.Nm uvm_vnp_terminate , > -.Nm uvm_vnp_uncache , > -.Nm uvm_io , > -.Nm uvm_km_alloc , > -.Nm uvm_km_zalloc , > -.Nm uvm_km_alloc1 , > -.Nm uvm_km_kmemalloc , > -.Nm uvm_km_valloc , > -.Nm uvm_km_valloc_wait , > -.Nm uvm_km_suballoc , > -.Nm uvm_km_free , > -.Nm uvm_km_free_wakeup , > -.Nm uvm_pagealloc , > -.Nm uvm_pagerealloc , > -.Nm uvm_pagefree , > -.Nm uvm_pglistalloc , > -.Nm uvm_pglistfree , > -.Nm uvm_page_physload , > -.Nm uvm_pageout , > -.Nm uao_create , > -.Nm uao_detach , > -.Nm uao_reference , > -.Nm uvm_chgkprot , > -.Nm uvm_kernacc , > -.Nm uvm_vslock , > -.Nm uvm_vsunlock , > -.Nm uvm_meter , > -.Nm uvm_sysctl , > -.Nm uvm_grow , > -.Nm uvm_coredump > -.Nd virtual memory system external interface > -.Sh SYNOPSIS > -.In sys/param.h > -.In uvm/uvm.h > -.Sh DESCRIPTION > -The UVM virtual memory system manages access to the computer's memory > -resources. > -User processes and the kernel access these resources through > -UVM's external interface. > -UVM's external interface includes functions that: > -.Pp > -.Bl -hyphen -compact > -.It > -initialise UVM subsystems > -.It > -manage virtual address spaces > -.It > -resolve page faults > -.It > -memory map files and devices > -.It > -perform uio-based I/O to virtual memory > -.It > -allocate and free kernel virtual memory > -.It > -allocate and free physical memory > -.El > -.Pp > -In addition to exporting these services, UVM has two kernel-level processes: > -pagedaemon and swapper. > -The pagedaemon process sleeps until physical memory becomes scarce. > -When that happens, pagedaemon is awoken. > -It scans physical memory, paging out and freeing memory that has not been > -recently used. > -The swapper process swaps in runnable processes that are currently swapped > out, > -if there is room. > -.Pp > -UVM has a machine independent and a machine dependent layer. > -See > -.Xr pmap 9 > -for the machine dependent layer. > -.Sh INITIALISATION > -.nr nS 1 > -.Ft void > -.Fn uvm_init "void" > -.Ft void > -.Fn uvm_init_limits "struct plimit *limit0" > -.Ft void > -.Fn uvm_setpagesize "void" > -.Ft void > -.Fn uvm_swap_init "void" > -.nr nS 0 > -.Pp > -The > -.Fn uvm_init > -function sets up the UVM system at system boot time, after the > -copyright has been printed. > -It initialises global state, the page, map, kernel virtual memory state, > -machine-dependent physical map, kernel memory allocator, > -pager and anonymous memory subsystems, and then enables > -paging of kernel objects. > -.Fn uvm_init > -must be called after machine-dependent code has registered some free RAM > -with the > -.Fn uvm_page_physload > -function. > -.Pp > -The > -.Fn uvm_init_limits > -function initialises process limits in the given limit structure. > -This is for use by the system startup for process zero, before any other > -processes are created. > -.Pp > -The > -.Fn uvm_setpagesize > -function initialises the uvmexp members pagesize (if not already done by > -machine-dependent code), pageshift and pagemask. > -It should be called by machine-dependent code early in the > -.Xr pmap_init 9 > -call. > -.Pp > -The > -.Fn uvm_swap_init > -function initialises the swap subsystem. > -.Sh VIRTUAL ADDRESS SPACE MANAGEMENT > -.nr nS 1 > -.Ft int > -.Fn uvm_map "vm_map_t map" "vaddr_t *startp" "vsize_t size" "struct > uvm_object *uobj" "voff_t uoffset" "vsize_t alignment" "unsigned int flags" > -.Ft int > -.Fn uvm_map_pageable "vm_map_t map" "vaddr_t start" "vaddr_t end" "boolean_t > new_pageable" "int lockflags" > -.Ft int > -.Fn uvm_map_pageable_all "vm_map_t map" "int flags" "vsize_t limit" > -.Ft boolean_t > -.Fn uvm_map_checkprot "vm_map_t map" "vaddr_t start" "vaddr_t end" > "vm_prot_t protection" > -.Ft int > -.Fn uvm_map_protect "vm_map_t map" "vaddr_t start" "vaddr_t end" "vm_prot_t > new_prot" "boolean_t set_max" > -.Ft struct vmspace * > -.Fn uvmspace_alloc "vaddr_t min" "vaddr_t max" "boolean_t pageable" > "boolean_t remove_holes" > -.Ft void > -.Fn uvmspace_exec "struct proc *p" "vaddr_t start" "vaddr_t end" > -.Ft struct vmspace * > -.Fn uvmspace_fork "struct process *pr" > -.Ft void > -.Fn uvmspace_free "struct vmspace *vm" > -.Ft struct vmspace * > -.Fn uvmspace_share "struct process *pr" > -.Ft vaddr_t > -.Fn uvm_uarea_alloc "void" > -.Ft void > -.Fn uvm_uarea_free "struct proc *p" > -.Ft unsigned int > -.Fn UVM_MAPFLAG "vm_prot_t prot" "vm_prot_t maxprot" "vm_inherit_t inh" "int > advice" "int flags" > -.nr nS 0 > -.Pp > -The > -.Fn uvm_map > -function establishes a valid mapping in map > -.Fa map , > -which must be unlocked. > -The new mapping has size > -.Fa size , > -which must be in > -.Dv PAGE_SIZE > -units. > -If > -.Fa alignment > -is non-zero, it describes the required alignment of the list, in > -power-of-two notation. > -The > -.Fa uobj > -and > -.Fa uoffset > -arguments can have four meanings. > -When > -.Fa uobj > -is > -.Dv NULL > -and > -.Fa uoffset > -is > -.Dv UVM_UNKNOWN_OFFSET , > -.Fn uvm_map > -does not use the machine-dependent > -.Dv PMAP_PREFER > -function. > -If > -.Fa uoffset > -is any other value, it is used as the hint to > -.Dv PMAP_PREFER . > -When > -.Fa uobj > -is not > -.Dv NULL > -and > -.Fa uoffset > -is > -.Dv UVM_UNKNOWN_OFFSET , > -.Fn uvm_map > -finds the offset based upon the virtual address, passed as > -.Fa startp . > -If > -.Fa uoffset > -is any other value, we are doing a normal mapping at this offset. > -The start address of the map will be returned in > -.Fa startp . > -.Pp > -.Fa flags > -passed to > -.Fn uvm_map > -are typically created using the > -.Fn UVM_MAPFLAG > -macro, which uses the following values. > -The > -.Fa prot > -and > -.Fa maxprot > -can take a mix of the following values: > -.Bd -literal > -#define PROT_MASK 0x07 /* protection mask */ > -#define PROT_NONE 0x00 /* protection none */ > -#define PROT_READ 0x01 /* read */ > -#define PROT_WRITE 0x02 /* write */ > -#define PROT_EXEC 0x04 /* exec */ > -.Ed > -.Pp > -The values that > -.Fa inh > -can take are: > -.Bd -literal > -#define MAP_INHERIT_MASK 0x30 /* inherit mask */ > -#define MAP_INHERIT_SHARE 0x00 /* "share" */ > -#define MAP_INHERIT_COPY 0x10 /* "copy" */ > -#define MAP_INHERIT_NONE 0x20 /* "none" */ > -#define MAP_INHERIT_ZERO 0x30 /* "zero" */ > -.Ed > -.Pp > -The values that > -.Fa advice > -can take are: > -.Bd -literal > -#define MADV_NORMAL 0x0 /* 'normal' */ > -#define MADV_RANDOM 0x1 /* 'random' */ > -#define MADV_SEQUENTIAL 0x2 /* 'sequential' */ > -#define MADV_MASK 0x7 /* mask */ > -.Ed > -.Pp > -The values that > -.Fa flags > -can take are: > -.Bd -literal > -#define UVM_FLAG_FIXED 0x0010000 /* find space */ > -#define UVM_FLAG_OVERLAY 0x0020000 /* establish overlay */ > -#define UVM_FLAG_NOMERGE 0x0040000 /* don't merge map entries */ > -#define UVM_FLAG_COPYONW 0x0080000 /* set copy_on_write flag */ > -#define UVM_FLAG_TRYLOCK 0x0100000 /* fail if we can not lock map */ > -#define UVM_FLAG_HOLE 0x0200000 /* no backend */ > -#define UVM_FLAG_QUERY 0x0400000 /* do everything, > - except actual execution */ > -#define UVM_FLAG_NOFAULT 0x0800000 /* don't fault */ > -#define UVM_FLAG_UNMAP 0x1000000 /* unmap to make space */ > -#define UVM_FLAG_STACK 0x2000000 /* page may contain a stack */ > -.Ed > -.Pp > -The > -.Dv UVM_MAPFLAG > -macro arguments can be combined with an or operator. > -There are also some additional macros to extract bits from the flags. > -The > -.Dv UVM_PROTECTION , > -.Dv UVM_INHERIT , > -.Dv UVM_MAXPROTECTION > -and > -.Dv UVM_ADVICE > -macros return the protection, inheritance, maximum protection and advice, > -respectively. > -.Fn uvm_map > -returns a standard errno. > -.Pp > -The > -.Fn uvm_map_pageable > -function changes the pageability of the pages in the range from > -.Fa start > -to > -.Fa end > -in map > -.Fa map > -to > -.Fa new_pageable . > -The > -.Fn uvm_map_pageable_all > -function changes the pageability of all mapped regions. > -If > -.Fa limit > -is non-zero and > -.Fn pmap_wired_count > -is implemented, > -.Dv ENOMEM > -is returned if the amount of wired pages exceed > -.Fa limit . > -The map is locked on entry if > -.Fa lockflags > -contain > -.Dv UVM_LK_ENTER , > -and locked on exit if > -.Fa lockflags > -contain > -.Dv UVM_LK_EXIT . > -.Fn uvm_map_pageable > -and > -.Fn uvm_map_pageable_all > -return a standard errno. > -.Pp > -The > -.Fn uvm_map_checkprot > -function checks the protection of the range from > -.Fa start > -to > -.Fa end > -in map > -.Fa map > -against > -.Fa protection . > -This returns either > -.Dv TRUE > -or > -.Dv FALSE . > -.Pp > -The > -.Fn uvm_map_protect > -function changes the protection > -.Fa start > -to > -.Fa end > -in map > -.Fa map > -to > -.Fa new_prot , > -also setting the maximum protection to the region to > -.Fa new_prot > -if > -.Fa set_max > -is non-zero. > -This function returns a standard errno. > -.Pp > -The > -.Fn uvmspace_alloc > -function allocates and returns a new address space, with ranges from > -.Fa min > -to > -.Fa max , > -setting the pageability of the address space to > -.Fa pageable . > -If > -.Fa remove_holes > -is non-zero, hardware > -.Sq holes > -in the virtual address space will be removed from the newly allocated > -address space. > -.Pp > -The > -.Fn uvmspace_exec > -function either reuses the address space of process > -.Fa p > -if there are no other references to it, or creates > -a new one with > -.Fn uvmspace_alloc . > -The range of valid addresses in the address space is reset to > -.Fa start > -through > -.Fa end . > -.Pp > -The > -.Fn uvmspace_fork > -function creates and returns a new address space based upon the > -address space of process > -.Fa pr > -and is typically used when allocating an address space for a > -child process. > -.Pp > -The > -.Fn uvmspace_free > -function lowers the reference count on the address space > -.Fa vm , > -freeing the data structures if there are no other references. > -.Pp > -The > -.Fn uvmspace_share > -function returns a reference to the address space of process > -.Fa pr , > -increasing its reference count. > -.Pp > -The > -.Fn uvm_uarea_alloc > -function allocates a thread's > -.Sq uarea , > -the memory where its kernel stack and PCB are stored. > -The > -.Fn uvm_uarea_free > -function frees the uarea for > -thread > -.Fa p , > -which must no longer be running. > -.Sh PAGE FAULT HANDLING > -.nr nS 1 > -.Ft int > -.Fn uvm_fault "vm_map_t orig_map" "vaddr_t vaddr" "vm_fault_t fault_type" > "vm_prot_t access_type" > -.nr nS 0 > -.Pp > -The > -.Fn uvm_fault > -function is the main entry point for faults. > -It takes > -.Fa orig_map > -as the map the fault originated in, a > -.Fa vaddr > -offset into the map the fault occurred, > -.Fa fault_type > -describing the type of fault, and > -.Fa access_type > -describing the type of access requested. > -.Fn uvm_fault > -returns a standard errno. > -.Sh MEMORY MAPPING FILES AND DEVICES > -.nr nS 1 > -.Ft struct uvm_object * > -.Fn uvn_attach "struct vnode *vp" "vm_prot_t accessprot" > -.Ft void > -.Fn uvm_vnp_setsize "struct vnode *vp" "voff_t newsize" > -.Ft void > -.Fn uvm_vnp_sync "struct mount *mp" > -.Ft void > -.Fn uvm_vnp_terminate "struct vnode *vp" > -.Ft boolean_t > -.Fn uvm_vnp_uncache "struct vnode *vp" > -.nr nS 0 > -.Pp > -The > -.Fn uvn_attach > -function attaches a UVM object to vnode > -.Fa vp , > -creating the object if necessary. > -The object is returned. > -.Pp > -The > -.Fn uvm_vnp_setsize > -function sets the size of vnode > -.Fa vp > -to > -.Fa newsize . > -Caller must hold a reference to the vnode. > -If the vnode shrinks, pages no longer used are discarded. > -This function will be removed when the file system and VM buffer caches > -are merged. > -.Pp > -The > -.Fn uvm_vnp_sync > -function flushes dirty vnodes from either the mount point passed in > -.Fa mp , > -or all dirty vnodes if > -.Fa mp > -is > -.Dv NULL . > -This function will be removed when the file system and VM buffer caches > -are merged. > -.Pp > -The > -.Fn uvm_vnp_terminate > -function frees all VM resources allocated to vnode > -.Fa vp . > -If the vnode still has references, it will not be destroyed; however > -all future operations using this vnode will fail. > -This function will be removed when the file system and VM buffer caches > -are merged. > -.Pp > -The > -.Fn uvm_vnp_uncache > -function disables vnode > -.Fa vp > -from persisting when all references are freed. > -This function will be removed when the file system and UVM caches > -are unified. > -Returns true if there is no active vnode. > -.Sh VIRTUAL MEMORY I/O > -.nr nS 1 > -.Ft int > -.Fn uvm_io "vm_map_t map" "struct uio *uio" > -.nr nS 0 > -.Pp > -The > -.Fn uvm_io > -function performs the I/O described in > -.Fa uio > -on the memory described in > -.Fa map . > -.Sh ALLOCATION OF KERNEL MEMORY > -.nr nS 1 > -.Ft vaddr_t > -.Fn uvm_km_alloc "vm_map_t map" "vsize_t size" > -.Ft vaddr_t > -.Fn uvm_km_zalloc "vm_map_t map" "vsize_t size" > -.Ft vaddr_t > -.Fn uvm_km_alloc1 "vm_map_t map" "vsize_t size" "vsize_t align" "boolean_t > zeroit" > -.Ft vaddr_t > -.Fn uvm_km_kmemalloc "vm_map_t map" "struct uvm_object *obj" "vsize_t size" > "int flags" > -.Ft vaddr_t > -.Fn uvm_km_valloc "vm_map_t map" "vsize_t size" > -.Ft vaddr_t > -.Fn uvm_km_valloc_wait "vm_map_t map" "vsize_t size" > -.Ft struct vm_map * > -.Fn uvm_km_suballoc "vm_map_t map" "vaddr_t *min" "vaddr_t *max " "vsize_t > size" "int flags" "boolean_t fixed" "vm_map_t submap" > -.Ft void > -.Fn uvm_km_free "vm_map_t map" "vaddr_t addr" "vsize_t size" > -.Ft void > -.Fn uvm_km_free_wakeup "vm_map_t map" "vaddr_t addr" "vsize_t size" > -.nr nS 0 > -.Pp > -The > -.Fn uvm_km_alloc > -and > -.Fn uvm_km_zalloc > -functions allocate > -.Fa size > -bytes of wired kernel memory in map > -.Fa map . > -In addition to allocation, > -.Fn uvm_km_zalloc > -zeros the memory. > -Both of these functions are defined as macros in terms of > -.Fn uvm_km_alloc1 , > -and should almost always be used in preference to > -.Fn uvm_km_alloc1 . > -.Pp > -The > -.Fn uvm_km_alloc1 > -function allocates and returns > -.Fa size > -bytes of wired memory in the kernel map aligned to the > -.Fa align > -boundary, zeroing the memory if the > -.Fa zeroit > -argument is non-zero. > -.Pp > -The > -.Fn uvm_km_kmemalloc > -function allocates and returns > -.Fa size > -bytes of wired kernel memory into > -.Fa obj . > -The flags can be any of: > -.Bd -literal > -#define UVM_KMF_NOWAIT 0x1 /* matches M_NOWAIT */ > -#define UVM_KMF_VALLOC 0x2 /* allocate VA only */ > -#define UVM_KMF_TRYLOCK UVM_FLAG_TRYLOCK /* try locking only */ > -.Ed > -.Pp > -The > -.Dv UVM_KMF_NOWAIT > -flag causes > -.Fn uvm_km_kmemalloc > -to return immediately if no memory is available. > -.Dv UVM_KMF_VALLOC > -causes no pages to be allocated, only a virtual address. > -.Dv UVM_KMF_TRYLOCK > -causes > -.Fn uvm_km_kmemalloc > -to only try and not sleep when locking maps. > -.Pp > -The > -.Fn uvm_km_valloc > -and > -.Fn uvm_km_valloc_wait > -functions return a newly allocated zero-filled address in the kernel map of > size > -.Fa size . > -.Fn uvm_km_valloc_wait > -will also wait for kernel memory to become available, if there is a > -memory shortage. > -.Pp > -The > -.Fn uvm_km_suballoc > -function allocates submap (with the specified > -.Fa flags , > -as described above) from > -.Fa map , > -creating a new map if > -.Fa submap > -is > -.Dv NULL . > -The addresses of the submap can be specified exactly by setting the > -.Fa fixed > -argument to non-zero, which causes the > -.Fa min > -argument to specify the beginning of the address in the submap. > -If > -.Fa fixed > -is zero, any address of size > -.Fa size > -will be allocated from > -.Fa map > -and the start and end addresses returned in > -.Fa min > -and > -.Fa max . > -.Pp > -The > -.Fn uvm_km_free > -and > -.Fn uvm_km_free_wakeup > -functions free > -.Fa size > -bytes of memory in the kernel map, starting at address > -.Fa addr . > -.Fn uvm_km_free_wakeup > -calls > -.Fn wakeup > -on the map before unlocking the map. > -.Sh ALLOCATION OF PHYSICAL MEMORY > -.nr nS 1 > -.Ft struct vm_page * > -.Fn uvm_pagealloc "struct uvm_object *uobj" "voff_t off" "struct vm_anon > *anon" "int flags" > -.Ft void > -.Fn uvm_pagerealloc "struct vm_page *pg" "struct uvm_object *newobj" "voff_t > newoff" > -.Ft void > -.Fn uvm_pagefree "struct vm_page *pg" > -.Ft int > -.Fn uvm_pglistalloc "psize_t size" "paddr_t low" "paddr_t high" "paddr_t > alignment" "paddr_t boundary" "struct pglist *rlist" "int nsegs" "int flags" > -.Ft void > -.Fn uvm_pglistfree "struct pglist *list" > -.Ft void > -.Fn uvm_page_physload "paddr_t start" "paddr_t end" "paddr_t avail_start" > "paddr_t avail_end" "int free_list" > -.nr nS 0 > -.Pp > -The > -.Fn uvm_pagealloc > -function allocates a page of memory at virtual address > -.Fa off > -in either the object > -.Fa uobj > -or the anonymous memory > -.Fa anon , > -or returns > -.Dv NULL > -if no pages are free. > -Only one of > -.Fa anon > -and > -.Fa uobj > -can be non > -.Dv NULL . > -The > -.Fa flags > -can be any of: > -.Bd -literal > -#define UVM_PGA_USERESERVE 0x0001 /* ok to use reserve pages */ > -#define UVM_PGA_ZERO 0x0002 /* returned page must be zeroed */ > -.Ed > -.Pp > -The > -.Dv UVM_PGA_USERESERVE > -flag means to allocate a page even if that will result in the number of > -free pages being lower than > -.Dv uvmexp.reserve_pagedaemon > -(if the current thread is the pagedaemon) or > -.Dv uvmexp.reserve_kernel > -(if the current thread is not the pagedaemon). > -The > -.Dv UVM_PGA_ZERO > -flag causes the returned page to be filled with zeroes, either by allocating > it > -from a pool of pre-zeroed pages or by zeroing it in-line as necessary. > -.Pp > -The > -.Fn uvm_pagerealloc > -function reallocates page > -.Fa pg > -to a new object > -.Fa newobj , > -at a new offset > -.Fa newoff . > -.Pp > -The > -.Fn uvm_pagefree > -function frees the physical page > -.Fa pg . > -.Pp > -The > -.Fn uvm_pglistalloc > -function allocates a list of pages for size > -.Fa size > -byte under various constraints. > -.Fa low > -and > -.Fa high > -describe the lowest and highest addresses acceptable for the list. > -If > -.Fa alignment > -is non-zero, it describes the required alignment of the list, in > -power-of-two notation. > -If > -.Fa boundary > -is non-zero, no segment of the list may cross this power-of-two > -boundary, relative to zero. > -.Fa nsegs > -is the maximum number of physically contiguous segments. > -The allocated memory is returned in the > -.Fa rlist > -list. > -The > -.Fa flags > -can be any of: > -.Bd -literal > -#define UVM_PLA_WAITOK 0x0001 /* may sleep */ > -#define UVM_PLA_NOWAIT 0x0002 /* can't sleep */ > -#define UVM_PLA_ZERO 0x0004 /* zero all pages before returning */ > -.Ed > -.Pp > -The > -.Dv UVM_PLA_WAITOK > -flag means that the function may sleep while trying to allocate the list of > -pages (this is currently ignored). > -Conversely, the > -.Dv UVM_PLA_NOWAIT > -flag signifies that the function may not sleep while allocating. > -It is an error not to provide one of the above flags. > -Optionally, one may also specify the > -.Dv UVM_PLA_ZERO > -flag to receive zeroed memory in the page list. > -.Pp > -The > -.Fn uvm_pglistfree > -function frees the list of pages pointed to by > -.Fa list . > -.Pp > -The > -.Fn uvm_page_physload > -function loads physical memory segments into VM space on the specified > -.Fa free_list . > -.Fn uvm_page_physload > -must be called at system boot time to set up physical memory management > pages. > -The arguments describe the > -.Fa start > -and > -.Fa end > -of the physical addresses of the segment, and the available start and end > -addresses of pages not already in use. > -.\" XXX expand on "system boot time"! > -.Sh PROCESSES > -.nr nS 1 > -.Ft void > -.Fn uvm_pageout "void *arg" > -.nr nS 0 > -.Pp > -The > -.Fn uvm_pageout > -function is the main loop for the page daemon. > -The > -.Fa arg > -argument is ignored. > -.Sh MISCELLANEOUS FUNCTIONS > -.nr nS 1 > -.Ft struct uvm_object * > -.Fn uao_create "vsize_t size" "int flags" > -.Ft void > -.Fn uao_detach "struct uvm_object *uobj" > -.Ft void > -.Fn uao_reference "struct uvm_object *uobj" > -.Ft boolean_t > -.Fn uvm_chgkprot "caddr_t addr" "size_t len" "int rw" > -.Ft void > -.Fn uvm_kernacc "caddr_t addr" "size_t len" "int rw" > -.Ft void > -.Fn uvm_vslock "struct proc *p" "caddr_t addr" "size_t len" \ > - "vm_prot_t access_type" > -.Ft void > -.Fn uvm_vsunlock "struct proc *p" "caddr_t addr" "size_t len" > -.Ft void > -.Fn uvm_meter > -.Ft int > -.Fn uvm_sysctl "int *name" "u_int namelen" "void *oldp" "size_t *oldlenp" > "void *newp " "size_t newlen" "struct proc *p" > -.Ft int > -.Fn uvm_grow "struct proc *p" "vaddr_t sp" > -.Ft int > -.Fn uvm_coredump "struct proc *p" "struct vnode *vp" "struct ucred *cred" > "struct core *chdr" > -.nr nS 0 > -.Pp > -The > -.Fn uao_create , > -.Fn uao_detach > -and > -.Fn uao_reference > -functions operate on anonymous memory objects, such as those used to support > -System V shared memory. > -.Fn uao_create > -returns an object of size > -.Fa size > -with flags: > -.Bd -literal > -#define UAO_FLAG_KERNOBJ 0x1 /* create kernel object */ > -#define UAO_FLAG_KERNSWAP 0x2 /* enable kernel swap */ > -.Pp > -.Ed > -which can only be used once each at system boot time. > -.Fn uao_reference > -creates an additional reference to the named anonymous memory object. > -.Fn uao_detach > -removes a reference from the named anonymous memory object, destroying > -it if removing the last reference. > -.Pp > -The > -.Fn uvm_kernacc > -function checks the access at address > -.Fa addr > -to > -.Fa addr + len > -for > -.Fa rw > -access, in the kernel address space. > -.Pp > -The > -.Fn uvm_vslock > -and > -.Fn uvm_vsunlock > -functions control the wiring and unwiring of pages for process > -.Fa p > -from > -.Fa addr > -to > -.Fa addr + len . > -The > -.Fa access_type > -argument of > -.Fn uvm_vslock > -is passed to > -.Fn uvm_fault . > -These functions are normally used to wire memory for I/O. > -.Pp > -The > -.Fn uvm_meter > -function calculates the load average and wakes up the swapper if necessary. > -.Pp > -The > -.Fn uvm_sysctl > -function provides support for the > -.Dv CTL_VM > -domain of the > -.Xr sysctl 2 > -hierarchy. > -.Fn uvm_sysctl > -handles the > -.Dv VM_LOADAVG , > -.Dv VM_METER > -and > -.Dv VM_UVMEXP > -calls, which return the current load averages, calculates current VM > -totals, and returns the uvmexp structure respectively. > -The load averages are accessed from userland using the > -.Xr getloadavg 3 > -function. > -The uvmexp structure has all global state of the UVM system, and has > -the following members: > -.Bd -literal > -/* 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 active; /* number of active pages */ > -int inactive; /* number of pages that we free'd but may want back */ > -int paging; /* number of pages in the process of being paged out */ > -int wired; /* number of wired pages */ > - > -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 */ > -int unused01; /* formerly anonpages */ > -int vnodepages; /* XXX # of pages used by vnode page cache */ > -int vtextpages; /* XXX # of pages used by vtext vnodes */ > - > -/* pageout params */ > -int freemin; /* min number of free pages */ > -int freetarg; /* target number of free pages */ > -int inactarg; /* target number of inactive pages */ > -int wiredmax; /* max number of wired pages */ > -int anonmin; /* min threshold for anon pages */ > -int vtextmin; /* min threshold for vtext pages */ > -int vnodemin; /* min threshold for vnode pages */ > -int anonminpct; /* min percent anon pages */ > -int vtextminpct;/* min percent vtext pages */ > -int vnodeminpct;/* min percent vnode pages */ > - > -/* swap */ > -int nswapdev; /* number of configured swap devices in system */ > -int swpages; /* number of PAGE_SIZE'ed swap pages */ > -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() */ > -int nanon; /* XXX number total of anon's in system */ > -int unused05; /* formerly nanonneeded */ > -int unused06; /* formerly nfreeanon */ > - > -/* stat counters */ > -int faults; /* page fault count */ > -int traps; /* trap count */ > -int intrs; /* interrupt count */ > -int swtch; /* context switch count */ > -int softs; /* software interrupt count */ > -int syscalls; /* system calls */ > -int pageins; /* pagein operation count */ > - /* pageouts are in pdpageouts below */ > -int unused07; /* formerly obsolete_swapins */ > -int unused08; /* formerly obsolete_swapouts */ > -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 unused09; /* formerly zeroaborts */ > - > -/* fault subcounters */ > -int fltnoram; /* number of times fault was out of ram */ > -int fltnoanon; /* number of times fault was out of anons */ > -int fltnoamap; /* number of times fault was out of amap chunks */ > -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 */ > -int pdwoke; /* number of times daemon woke up */ > -int pdrevs; /* number of times daemon rev'd clock hand */ > -int pdswout; /* number of times daemon called for swapout */ > -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 unused11; /* formerly pdreanon */ > -int unused12; /* formerly pdrevnode */ > -int unused13; /* formerly pdrevtext */ > - > -int fpswtch; /* FPU context switches */ > -int kmapent; /* number of kernel map entries */ > -.Ed > -.Pp > -The > -.Fn uvm_grow > -function increases the stack segment of process > -.Fa p > -to include > -.Fa sp . > -.Pp > -The > -.Fn uvm_coredump > -function generates a coredump on vnode > -.Fa vp > -for process > -.Fa p > -with credentials > -.Fa cred > -and core header description in > -.Fa chdr . > -.Sh NOTES > -The structure and types whose names begin with > -.Dq vm_ > -were named so UVM could coexist with BSD VM during the early > -development stages. > -.Sh SEE ALSO > -.Xr sysctl 2 , > -.Xr getloadavg 3 , > -.Xr kvm 3 , > -.Xr ddb 4 , > -.Xr options 4 , > -.Xr pmap 9 > -.Rs > -.%A Charles D. Cranor > -.%D August 1998 > -.%C St. Louis, Missouri > -.%Q Department of Computer Science, Sever Institute of Technology, > Washington University > -.%T Design and Implementation of the UVM Virtual Memory System, D.Sc. > dissertation > -.Re > -.Sh HISTORY > -The UVM virtual memory system was developed at Washington University in St. > Louis. > -UVM's roots lie partly in the Mach-based > -.Bx 4.4 > -VM system, the > -.Fx > -VM system, and the SunOS4 VM system. > -UVM's basic structure is based on the > -.Bx 4.4 > -VM system. > -UVM's new anonymous memory system is based on the > -anonymous memory system found in the SunOS4 VM (as described in papers > -published by Sun Microsystems, Inc.). > -UVM also includes a number of features > -new to > -.Bx > -including page loanout, map entry passing, simplified > -copy-on-write, and clustered anonymous memory pageout. > -.Pp > -UVM appeared in > -.Ox 2.9 . > -.Sh AUTHORS > -.An -nosplit > -.An Charles D. Cranor Aq Mt [email protected] > -designed and implemented UVM. > -.Pp > -.An Matthew Green Aq Mt [email protected] > -wrote the swap-space management code. > -.Pp > -.An Chuck Silvers Aq Mt [email protected] > -implemented the aobj pager, thus allowing > -UVM to support System V shared memory and process swapping. > -.Pp > -.An Artur Grabowski Aq Mt [email protected] > -handled the logistical issues involved with merging UVM into the > -.Ox > -source tree. > Index: uvm_fault.9 > =================================================================== > RCS file: uvm_fault.9 > diff -N uvm_fault.9 > --- /dev/null 1 Jan 1970 00:00:00 -0000 > +++ uvm_fault.9 5 Dec 2019 12:34:11 -0000 > @@ -0,0 +1,55 @@ > +.\" $OpenBSD: uvm.9,v 1.71 2019/11/05 08:18:47 mpi Exp $ > +.\" $NetBSD: uvm.9,v 1.14 2000/06/29 06:08:44 mrg Exp $ > +.\" > +.\" Copyright (c) 1998 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. > +.\" > +.Dd $Mdocdate: November 5 2019 $ > +.Dt UVM_FAULT 9 > +.Os > +.Sh NAME > +.Nm uvm_fault > +.Nd page fault handling > +.Sh SYNOPSIS > +.In sys/param.h > +.In uvm/uvm.h > +.Ft int > +.Fn uvm_fault "vm_map_t orig_map" "vaddr_t vaddr" "vm_fault_t fault_type" > "vm_prot_t access_type" > +.Sh DESCRIPTION > +The > +.Fn uvm_fault > +function is the main entry point for faults. > +It takes > +.Fa orig_map > +as the map the fault originated in, a > +.Fa vaddr > +offset into the map the fault occurred, > +.Fa fault_type > +describing the type of fault, and > +.Fa access_type > +describing the type of access requested. > +.Fn uvm_fault > +returns a standard errno. > +.Sh SEE ALSO > +.Xr pmap 9 > Index: uvm_init.9 > =================================================================== > RCS file: uvm_init.9 > diff -N uvm_init.9 > --- /dev/null 1 Jan 1970 00:00:00 -0000 > +++ uvm_init.9 5 Dec 2019 12:42:08 -0000 > @@ -0,0 +1,441 @@ > +.\" $OpenBSD: uvm.9,v 1.71 2019/11/05 08:18:47 mpi Exp $ > +.\" $NetBSD: uvm.9,v 1.14 2000/06/29 06:08:44 mrg Exp $ > +.\" > +.\" Copyright (c) 1998 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. > +.\" > +.\" XXX this manual sets nS to 1 or 0 in the description, to obtain > +.\" synopsis-like function prototypes. any better way? > +.\" > +.Dd $Mdocdate: November 5 2019 $ > +.Dt UVM_INIT 9 > +.Os > +.Sh NAME > +.Nm uvm_init , > +.Nm uvm_init_limits , > +.Nm uvm_setpagesize , > +.Nm uvm_swap_init , > +.Nm uvm_io , > +.Nm uvm_pageout , > +.Nm uao_create , > +.Nm uao_detach , > +.Nm uao_reference , > +.Nm uvm_chgkprot , > +.Nm uvm_kernacc , > +.Nm uvm_vslock , > +.Nm uvm_vsunlock , > +.Nm uvm_meter , > +.Nm uvm_sysctl , > +.Nm uvm_grow , > +.Nm uvm_coredump > +.Nd virtual memory system external interface > +.Sh SYNOPSIS > +.In sys/param.h > +.In uvm/uvm.h > +.Sh DESCRIPTION > +The UVM virtual memory system manages access to the computer's memory > +resources. > +User processes and the kernel access these resources through > +UVM's external interface. > +UVM's external interface includes functions that: > +.Pp > +.Bl -hyphen -compact > +.It > +initialise UVM subsystems > +.It > +manage virtual address spaces > +.It > +resolve page faults > +.It > +memory map files and devices > +.It > +perform uio-based I/O to virtual memory > +.It > +allocate and free kernel virtual memory > +.It > +allocate and free physical memory > +.El > +.Pp > +In addition to exporting these services, UVM has two kernel-level processes: > +pagedaemon and swapper. > +The pagedaemon process sleeps until physical memory becomes scarce. > +When that happens, pagedaemon is awoken. > +It scans physical memory, paging out and freeing memory that has not been > +recently used. > +The swapper process swaps in runnable processes that are currently swapped > out, > +if there is room. > +.Pp > +UVM has a machine independent and a machine dependent layer. > +See > +.Xr pmap 9 > +for the machine dependent layer. > +.Sh INITIALISATION > +.nr nS 1 > +.Ft void > +.Fn uvm_init "void" > +.Ft void > +.Fn uvm_init_limits "struct plimit *limit0" > +.Ft void > +.Fn uvm_setpagesize "void" > +.Ft void > +.Fn uvm_swap_init "void" > +.nr nS 0 > +.Pp > +The > +.Fn uvm_init > +function sets up the UVM system at system boot time, after the > +copyright has been printed. > +It initialises global state, the page, map, kernel virtual memory state, > +machine-dependent physical map, kernel memory allocator, > +pager and anonymous memory subsystems, and then enables > +paging of kernel objects. > +.Fn uvm_init > +must be called after machine-dependent code has registered some free RAM > +with the > +.Fn uvm_page_physload > +function. > +.Pp > +The > +.Fn uvm_init_limits > +function initialises process limits in the given limit structure. > +This is for use by the system startup for process zero, before any other > +processes are created. > +.Pp > +The > +.Fn uvm_setpagesize > +function initialises the uvmexp members pagesize (if not already done by > +machine-dependent code), pageshift and pagemask. > +It should be called by machine-dependent code early in the > +.Xr pmap_init 9 > +call. > +.Pp > +The > +.Fn uvm_swap_init > +function initialises the swap subsystem. > +.Sh VIRTUAL MEMORY I/O > +.nr nS 1 > +.Ft int > +.Fn uvm_io "vm_map_t map" "struct uio *uio" > +.nr nS 0 > +.Pp > +The > +.Fn uvm_io > +function performs the I/O described in > +.Fa uio > +on the memory described in > +.Fa map . > +.Sh PROCESSES > +.nr nS 1 > +.Ft void > +.Fn uvm_pageout "void *arg" > +.nr nS 0 > +.Pp > +The > +.Fn uvm_pageout > +function is the main loop for the page daemon. > +The > +.Fa arg > +argument is ignored. > +.Sh MISCELLANEOUS FUNCTIONS > +.nr nS 1 > +.Ft struct uvm_object * > +.Fn uao_create "vsize_t size" "int flags" > +.Ft void > +.Fn uao_detach "struct uvm_object *uobj" > +.Ft void > +.Fn uao_reference "struct uvm_object *uobj" > +.Ft boolean_t > +.Fn uvm_chgkprot "caddr_t addr" "size_t len" "int rw" > +.Ft void > +.Fn uvm_kernacc "caddr_t addr" "size_t len" "int rw" > +.Ft void > +.Fn uvm_vslock "struct proc *p" "caddr_t addr" "size_t len" \ > + "vm_prot_t access_type" > +.Ft void > +.Fn uvm_vsunlock "struct proc *p" "caddr_t addr" "size_t len" > +.Ft void > +.Fn uvm_meter > +.Ft int > +.Fn uvm_sysctl "int *name" "u_int namelen" "void *oldp" "size_t *oldlenp" > "void *newp " "size_t newlen" "struct proc *p" > +.Ft int > +.Fn uvm_grow "struct proc *p" "vaddr_t sp" > +.Ft int > +.Fn uvm_coredump "struct proc *p" "struct vnode *vp" "struct ucred *cred" > "struct core *chdr" > +.nr nS 0 > +.Pp > +The > +.Fn uao_create , > +.Fn uao_detach > +and > +.Fn uao_reference > +functions operate on anonymous memory objects, such as those used to support > +System V shared memory. > +.Fn uao_create > +returns an object of size > +.Fa size > +with flags: > +.Bd -literal > +#define UAO_FLAG_KERNOBJ 0x1 /* create kernel object */ > +#define UAO_FLAG_KERNSWAP 0x2 /* enable kernel swap */ > +.Pp > +.Ed > +which can only be used once each at system boot time. > +.Fn uao_reference > +creates an additional reference to the named anonymous memory object. > +.Fn uao_detach > +removes a reference from the named anonymous memory object, destroying > +it if removing the last reference. > +.Pp > +The > +.Fn uvm_kernacc > +function checks the access at address > +.Fa addr > +to > +.Fa addr + len > +for > +.Fa rw > +access, in the kernel address space. > +.Pp > +The > +.Fn uvm_vslock > +and > +.Fn uvm_vsunlock > +functions control the wiring and unwiring of pages for process > +.Fa p > +from > +.Fa addr > +to > +.Fa addr + len . > +The > +.Fa access_type > +argument of > +.Fn uvm_vslock > +is passed to > +.Fn uvm_fault . > +These functions are normally used to wire memory for I/O. > +.Pp > +The > +.Fn uvm_meter > +function calculates the load average and wakes up the swapper if necessary. > +.Pp > +The > +.Fn uvm_sysctl > +function provides support for the > +.Dv CTL_VM > +domain of the > +.Xr sysctl 2 > +hierarchy. > +.Fn uvm_sysctl > +handles the > +.Dv VM_LOADAVG , > +.Dv VM_METER > +and > +.Dv VM_UVMEXP > +calls, which return the current load averages, calculates current VM > +totals, and returns the uvmexp structure respectively. > +The load averages are accessed from userland using the > +.Xr getloadavg 3 > +function. > +The uvmexp structure has all global state of the UVM system, and has > +the following members: > +.Bd -literal > +/* 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 active; /* number of active pages */ > +int inactive; /* number of pages that we free'd but may want back */ > +int paging; /* number of pages in the process of being paged out */ > +int wired; /* number of wired pages */ > + > +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 */ > +int unused01; /* formerly anonpages */ > +int vnodepages; /* XXX # of pages used by vnode page cache */ > +int vtextpages; /* XXX # of pages used by vtext vnodes */ > + > +/* pageout params */ > +int freemin; /* min number of free pages */ > +int freetarg; /* target number of free pages */ > +int inactarg; /* target number of inactive pages */ > +int wiredmax; /* max number of wired pages */ > +int anonmin; /* min threshold for anon pages */ > +int vtextmin; /* min threshold for vtext pages */ > +int vnodemin; /* min threshold for vnode pages */ > +int anonminpct; /* min percent anon pages */ > +int vtextminpct;/* min percent vtext pages */ > +int vnodeminpct;/* min percent vnode pages */ > + > +/* swap */ > +int nswapdev; /* number of configured swap devices in system */ > +int swpages; /* number of PAGE_SIZE'ed swap pages */ > +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() */ > +int nanon; /* XXX number total of anon's in system */ > +int unused05; /* formerly nanonneeded */ > +int unused06; /* formerly nfreeanon */ > + > +/* stat counters */ > +int faults; /* page fault count */ > +int traps; /* trap count */ > +int intrs; /* interrupt count */ > +int swtch; /* context switch count */ > +int softs; /* software interrupt count */ > +int syscalls; /* system calls */ > +int pageins; /* pagein operation count */ > + /* pageouts are in pdpageouts below */ > +int unused07; /* formerly obsolete_swapins */ > +int unused08; /* formerly obsolete_swapouts */ > +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 unused09; /* formerly zeroaborts */ > + > +/* fault subcounters */ > +int fltnoram; /* number of times fault was out of ram */ > +int fltnoanon; /* number of times fault was out of anons */ > +int fltnoamap; /* number of times fault was out of amap chunks */ > +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 */ > +int pdwoke; /* number of times daemon woke up */ > +int pdrevs; /* number of times daemon rev'd clock hand */ > +int pdswout; /* number of times daemon called for swapout */ > +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 unused11; /* formerly pdreanon */ > +int unused12; /* formerly pdrevnode */ > +int unused13; /* formerly pdrevtext */ > + > +int fpswtch; /* FPU context switches */ > +int kmapent; /* number of kernel map entries */ > +.Ed > +.Pp > +The > +.Fn uvm_grow > +function increases the stack segment of process > +.Fa p > +to include > +.Fa sp . > +.Pp > +The > +.Fn uvm_coredump > +function generates a coredump on vnode > +.Fa vp > +for process > +.Fa p > +with credentials > +.Fa cred > +and core header description in > +.Fa chdr . > +.Sh NOTES > +The structure and types whose names begin with > +.Dq vm_ > +were named so UVM could coexist with BSD VM during the early > +development stages. > +.Sh SEE ALSO > +.Xr sysctl 2 , > +.Xr getloadavg 3 , > +.Xr kvm 3 , > +.Xr ddb 4 , > +.Xr options 4 , > +.Xr pmap 9 > +.Rs > +.%A Charles D. Cranor > +.%D August 1998 > +.%C St. Louis, Missouri > +.%Q Department of Computer Science, Sever Institute of Technology, > Washington University > +.%T Design and Implementation of the UVM Virtual Memory System, D.Sc. > dissertation > +.Re > +.Sh HISTORY > +The UVM virtual memory system was developed at Washington University in St. > Louis. > +UVM's roots lie partly in the Mach-based > +.Bx 4.4 > +VM system, the > +.Fx > +VM system, and the SunOS4 VM system. > +UVM's basic structure is based on the > +.Bx 4.4 > +VM system. > +UVM's new anonymous memory system is based on the > +anonymous memory system found in the SunOS4 VM (as described in papers > +published by Sun Microsystems, Inc.). > +UVM also includes a number of features > +new to > +.Bx > +including page loanout, map entry passing, simplified > +copy-on-write, and clustered anonymous memory pageout. > +.Pp > +UVM appeared in > +.Ox 2.9 . > +.Sh AUTHORS > +.An -nosplit > +.An Charles D. Cranor Aq Mt [email protected] > +designed and implemented UVM. > +.Pp > +.An Matthew Green Aq Mt [email protected] > +wrote the swap-space management code. > +.Pp > +.An Chuck Silvers Aq Mt [email protected] > +implemented the aobj pager, thus allowing > +UVM to support System V shared memory and process swapping. > +.Pp > +.An Artur Grabowski Aq Mt [email protected] > +handled the logistical issues involved with merging UVM into the > +.Ox > +source tree. > Index: uvm_km_alloc.9 > =================================================================== > RCS file: uvm_km_alloc.9 > diff -N uvm_km_alloc.9 > --- /dev/null 1 Jan 1970 00:00:00 -0000 > +++ uvm_km_alloc.9 5 Dec 2019 12:37:18 -0000 > @@ -0,0 +1,165 @@ > +.\" $OpenBSD: uvm.9,v 1.71 2019/11/05 08:18:47 mpi Exp $ > +.\" $NetBSD: uvm.9,v 1.14 2000/06/29 06:08:44 mrg Exp $ > +.\" > +.\" Copyright (c) 1998 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. > +.\" > +.Dd $Mdocdate: November 5 2019 $ > +.Dt UVM_KM_ALLOC 9 > +.Os > +.Sh NAME > +.Nm uvm_km_alloc , > +.Nm uvm_km_zalloc , > +.Nm uvm_km_alloc1 , > +.Nm uvm_km_kmemalloc , > +.Nm uvm_km_valloc , > +.Nm uvm_km_valloc_wait , > +.Nm uvm_km_suballoc , > +.Nm uvm_km_free , > +.Nm uvm_km_free_wakeup > +.Nd raw kernel memory or address space allocator > +.Sh SYNOPSIS > +.In sys/param.h > +.In uvm/uvm.h > +.Ft vaddr_t > +.Fn uvm_km_alloc "vm_map_t map" "vsize_t size" > +.Ft vaddr_t > +.Fn uvm_km_zalloc "vm_map_t map" "vsize_t size" > +.Ft vaddr_t > +.Fn uvm_km_alloc1 "vm_map_t map" "vsize_t size" "vsize_t align" "boolean_t > zeroit" > +.Ft vaddr_t > +.Fn uvm_km_kmemalloc "vm_map_t map" "struct uvm_object *obj" "vsize_t size" > "int flags" > +.Ft vaddr_t > +.Fn uvm_km_valloc "vm_map_t map" "vsize_t size" > +.Ft vaddr_t > +.Fn uvm_km_valloc_wait "vm_map_t map" "vsize_t size" > +.Ft struct vm_map * > +.Fn uvm_km_suballoc "vm_map_t map" "vaddr_t *min" "vaddr_t *max " "vsize_t > size" "int flags" "boolean_t fixed" "vm_map_t submap" > +.Ft void > +.Fn uvm_km_free "vm_map_t map" "vaddr_t addr" "vsize_t size" > +.Ft void > +.Fn uvm_km_free_wakeup "vm_map_t map" "vaddr_t addr" "vsize_t size" > +.Sh DESCRIPTION > +.Pp > +The > +.Fn uvm_km_alloc > +and > +.Fn uvm_km_zalloc > +functions allocate > +.Fa size > +bytes of wired kernel memory in map > +.Fa map . > +In addition to allocation, > +.Fn uvm_km_zalloc > +zeros the memory. > +Both of these functions are defined as macros in terms of > +.Fn uvm_km_alloc1 , > +and should almost always be used in preference to > +.Fn uvm_km_alloc1 . > +.Pp > +The > +.Fn uvm_km_alloc1 > +function allocates and returns > +.Fa size > +bytes of wired memory in the kernel map aligned to the > +.Fa align > +boundary, zeroing the memory if the > +.Fa zeroit > +argument is non-zero. > +.Pp > +The > +.Fn uvm_km_kmemalloc > +function allocates and returns > +.Fa size > +bytes of wired kernel memory into > +.Fa obj . > +The flags can be any of: > +.Bd -literal > +#define UVM_KMF_NOWAIT 0x1 /* matches M_NOWAIT */ > +#define UVM_KMF_VALLOC 0x2 /* allocate VA only */ > +#define UVM_KMF_TRYLOCK UVM_FLAG_TRYLOCK /* try locking only */ > +.Ed > +.Pp > +The > +.Dv UVM_KMF_NOWAIT > +flag causes > +.Fn uvm_km_kmemalloc > +to return immediately if no memory is available. > +.Dv UVM_KMF_VALLOC > +causes no pages to be allocated, only a virtual address. > +.Dv UVM_KMF_TRYLOCK > +causes > +.Fn uvm_km_kmemalloc > +to only try and not sleep when locking maps. > +.Pp > +The > +.Fn uvm_km_valloc > +and > +.Fn uvm_km_valloc_wait > +functions return a newly allocated zero-filled address in the kernel map of > size > +.Fa size . > +.Fn uvm_km_valloc_wait > +will also wait for kernel memory to become available, if there is a > +memory shortage. > +.Pp > +The > +.Fn uvm_km_suballoc > +function allocates submap (with the specified > +.Fa flags , > +as described above) from > +.Fa map , > +creating a new map if > +.Fa submap > +is > +.Dv NULL . > +The addresses of the submap can be specified exactly by setting the > +.Fa fixed > +argument to non-zero, which causes the > +.Fa min > +argument to specify the beginning of the address in the submap. > +If > +.Fa fixed > +is zero, any address of size > +.Fa size > +will be allocated from > +.Fa map > +and the start and end addresses returned in > +.Fa min > +and > +.Fa max . > +.Pp > +The > +.Fn uvm_km_free > +and > +.Fn uvm_km_free_wakeup > +functions free > +.Fa size > +bytes of memory in the kernel map, starting at address > +.Fa addr . > +.Fn uvm_km_free_wakeup > +calls > +.Fn wakeup > +on the map before unlocking the map. > +.Sh SEE ALSO > +.Xr km_alloc 9 > Index: uvm_map.9 > =================================================================== > RCS file: uvm_map.9 > diff -N uvm_map.9 > --- /dev/null 1 Jan 1970 00:00:00 -0000 > +++ uvm_map.9 5 Dec 2019 12:25:19 -0000 > @@ -0,0 +1,325 @@ > +.\" $OpenBSD: uvm.9,v 1.71 2019/11/05 08:18:47 mpi Exp $ > +.\" $NetBSD: uvm.9,v 1.14 2000/06/29 06:08:44 mrg Exp $ > +.\" > +.\" Copyright (c) 1998 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. > +.\" > +.Dd $Mdocdate: November 5 2019 $ > +.Dt UVM_MAP 9 > +.Os > +.Sh NAME > +.Nm uvm_map , > +.Nm uvm_map_pageable , > +.Nm uvm_map_pageable_all , > +.Nm uvm_map_checkprot , > +.Nm uvm_map_protect , > +.Nm uvmspace_alloc , > +.Nm uvmspace_exec , > +.Nm uvmspace_fork , > +.Nm uvmspace_free , > +.Nm uvmspace_share , > +.Nm uvm_uarea_alloc , > +.Nm uvm_uarea_free , > +.Nm UVM_MAPFLAG > +.Nd virtual address space management interface > +.Sh SYNOPSIS > +.In sys/param.h > +.In uvm/uvm.h > +.Ft int > +.Fn uvm_map "vm_map_t map" "vaddr_t *startp" "vsize_t size" "struct > uvm_object *uobj" "voff_t uoffset" "vsize_t alignment" "unsigned int flags" > +.Ft int > +.Fn uvm_map_pageable "vm_map_t map" "vaddr_t start" "vaddr_t end" "boolean_t > new_pageable" "int lockflags" > +.Ft int > +.Fn uvm_map_pageable_all "vm_map_t map" "int flags" "vsize_t limit" > +.Ft boolean_t > +.Fn uvm_map_checkprot "vm_map_t map" "vaddr_t start" "vaddr_t end" > "vm_prot_t protection" > +.Ft int > +.Fn uvm_map_protect "vm_map_t map" "vaddr_t start" "vaddr_t end" "vm_prot_t > new_prot" "boolean_t set_max" > +.Ft struct vmspace * > +.Fn uvmspace_alloc "vaddr_t min" "vaddr_t max" "boolean_t pageable" > "boolean_t remove_holes" > +.Ft void > +.Fn uvmspace_exec "struct proc *p" "vaddr_t start" "vaddr_t end" > +.Ft struct vmspace * > +.Fn uvmspace_fork "struct process *pr" > +.Ft void > +.Fn uvmspace_free "struct vmspace *vm" > +.Ft struct vmspace * > +.Fn uvmspace_share "struct process *pr" > +.Ft vaddr_t > +.Fn uvm_uarea_alloc "void" > +.Ft void > +.Fn uvm_uarea_free "struct proc *p" > +.Ft unsigned int > +.Fn UVM_MAPFLAG "vm_prot_t prot" "vm_prot_t maxprot" "vm_inherit_t inh" "int > advice" "int flags" > +.Sh DESCRIPTION > +The > +.Fn uvm_map > +function establishes a valid mapping in map > +.Fa map , > +which must be unlocked. > +The new mapping has size > +.Fa size , > +which must be in > +.Dv PAGE_SIZE > +units. > +If > +.Fa alignment > +is non-zero, it describes the required alignment of the list, in > +power-of-two notation. > +The > +.Fa uobj > +and > +.Fa uoffset > +arguments can have four meanings. > +When > +.Fa uobj > +is > +.Dv NULL > +and > +.Fa uoffset > +is > +.Dv UVM_UNKNOWN_OFFSET , > +.Fn uvm_map > +does not use the machine-dependent > +.Dv PMAP_PREFER > +function. > +If > +.Fa uoffset > +is any other value, it is used as the hint to > +.Dv PMAP_PREFER . > +When > +.Fa uobj > +is not > +.Dv NULL > +and > +.Fa uoffset > +is > +.Dv UVM_UNKNOWN_OFFSET , > +.Fn uvm_map > +finds the offset based upon the virtual address, passed as > +.Fa startp . > +If > +.Fa uoffset > +is any other value, we are doing a normal mapping at this offset. > +The start address of the map will be returned in > +.Fa startp . > +.Pp > +.Fa flags > +passed to > +.Fn uvm_map > +are typically created using the > +.Fn UVM_MAPFLAG > +macro, which uses the following values. > +The > +.Fa prot > +and > +.Fa maxprot > +can take a mix of the following values: > +.Bd -literal > +#define PROT_MASK 0x07 /* protection mask */ > +#define PROT_NONE 0x00 /* protection none */ > +#define PROT_READ 0x01 /* read */ > +#define PROT_WRITE 0x02 /* write */ > +#define PROT_EXEC 0x04 /* exec */ > +.Ed > +.Pp > +The values that > +.Fa inh > +can take are: > +.Bd -literal > +#define MAP_INHERIT_MASK 0x30 /* inherit mask */ > +#define MAP_INHERIT_SHARE 0x00 /* "share" */ > +#define MAP_INHERIT_COPY 0x10 /* "copy" */ > +#define MAP_INHERIT_NONE 0x20 /* "none" */ > +#define MAP_INHERIT_ZERO 0x30 /* "zero" */ > +.Ed > +.Pp > +The values that > +.Fa advice > +can take are: > +.Bd -literal > +#define MADV_NORMAL 0x0 /* 'normal' */ > +#define MADV_RANDOM 0x1 /* 'random' */ > +#define MADV_SEQUENTIAL 0x2 /* 'sequential' */ > +#define MADV_MASK 0x7 /* mask */ > +.Ed > +.Pp > +The values that > +.Fa flags > +can take are: > +.Bd -literal > +#define UVM_FLAG_FIXED 0x0010000 /* find space */ > +#define UVM_FLAG_OVERLAY 0x0020000 /* establish overlay */ > +#define UVM_FLAG_NOMERGE 0x0040000 /* don't merge map entries */ > +#define UVM_FLAG_COPYONW 0x0080000 /* set copy_on_write flag */ > +#define UVM_FLAG_TRYLOCK 0x0100000 /* fail if we can not lock map */ > +#define UVM_FLAG_HOLE 0x0200000 /* no backend */ > +#define UVM_FLAG_QUERY 0x0400000 /* do everything, > + except actual execution */ > +#define UVM_FLAG_NOFAULT 0x0800000 /* don't fault */ > +#define UVM_FLAG_UNMAP 0x1000000 /* unmap to make space */ > +#define UVM_FLAG_STACK 0x2000000 /* page may contain a stack */ > +.Ed > +.Pp > +The > +.Dv UVM_MAPFLAG > +macro arguments can be combined with an or operator. > +There are also some additional macros to extract bits from the flags. > +The > +.Dv UVM_PROTECTION , > +.Dv UVM_INHERIT , > +.Dv UVM_MAXPROTECTION > +and > +.Dv UVM_ADVICE > +macros return the protection, inheritance, maximum protection and advice, > +respectively. > +.Fn uvm_map > +returns a standard errno. > +.Pp > +The > +.Fn uvm_map_pageable > +function changes the pageability of the pages in the range from > +.Fa start > +to > +.Fa end > +in map > +.Fa map > +to > +.Fa new_pageable . > +The > +.Fn uvm_map_pageable_all > +function changes the pageability of all mapped regions. > +If > +.Fa limit > +is non-zero and > +.Fn pmap_wired_count > +is implemented, > +.Dv ENOMEM > +is returned if the amount of wired pages exceed > +.Fa limit . > +The map is locked on entry if > +.Fa lockflags > +contain > +.Dv UVM_LK_ENTER , > +and locked on exit if > +.Fa lockflags > +contain > +.Dv UVM_LK_EXIT . > +.Fn uvm_map_pageable > +and > +.Fn uvm_map_pageable_all > +return a standard errno. > +.Pp > +The > +.Fn uvm_map_checkprot > +function checks the protection of the range from > +.Fa start > +to > +.Fa end > +in map > +.Fa map > +against > +.Fa protection . > +This returns either > +.Dv TRUE > +or > +.Dv FALSE . > +.Pp > +The > +.Fn uvm_map_protect > +function changes the protection > +.Fa start > +to > +.Fa end > +in map > +.Fa map > +to > +.Fa new_prot , > +also setting the maximum protection to the region to > +.Fa new_prot > +if > +.Fa set_max > +is non-zero. > +This function returns a standard errno. > +.Pp > +The > +.Fn uvmspace_alloc > +function allocates and returns a new address space, with ranges from > +.Fa min > +to > +.Fa max , > +setting the pageability of the address space to > +.Fa pageable . > +If > +.Fa remove_holes > +is non-zero, hardware > +.Sq holes > +in the virtual address space will be removed from the newly allocated > +address space. > +.Pp > +The > +.Fn uvmspace_exec > +function either reuses the address space of process > +.Fa p > +if there are no other references to it, or creates > +a new one with > +.Fn uvmspace_alloc . > +The range of valid addresses in the address space is reset to > +.Fa start > +through > +.Fa end . > +.Pp > +The > +.Fn uvmspace_fork > +function creates and returns a new address space based upon the > +address space of process > +.Fa pr > +and is typically used when allocating an address space for a > +child process. > +.Pp > +The > +.Fn uvmspace_free > +function lowers the reference count on the address space > +.Fa vm , > +freeing the data structures if there are no other references. > +.Pp > +The > +.Fn uvmspace_share > +function returns a reference to the address space of process > +.Fa pr , > +increasing its reference count. > +.Pp > +The > +.Fn uvm_uarea_alloc > +function allocates a thread's > +.Sq uarea , > +the memory where its kernel stack and PCB are stored. > +The > +.Fn uvm_uarea_free > +function frees the uarea for > +thread > +.Fa p , > +which must no longer be running. > +.Sh SEE ALSO > +.Xr pmap 9 > Index: uvm_pagealloc.9 > =================================================================== > RCS file: uvm_pagealloc.9 > diff -N uvm_pagealloc.9 > --- /dev/null 1 Jan 1970 00:00:00 -0000 > +++ uvm_pagealloc.9 5 Dec 2019 12:38:34 -0000 > @@ -0,0 +1,169 @@ > +.\" $OpenBSD: uvm.9,v 1.71 2019/11/05 08:18:47 mpi Exp $ > +.\" $NetBSD: uvm.9,v 1.14 2000/06/29 06:08:44 mrg Exp $ > +.\" > +.\" Copyright (c) 1998 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. > +.\" > +.Dd $Mdocdate: November 5 2019 $ > +.Dt UVM_PAGEALLOC 9 > +.Os > +.Sh NAME > +.Nm uvm_pagealloc , > +.Nm uvm_pagerealloc , > +.Nm uvm_pagefree , > +.Nm uvm_pglistalloc , > +.Nm uvm_pglistfree , > +.Nm uvm_page_physload > +.Nd physical memory allocator > +.Sh SYNOPSIS > +.In sys/param.h > +.In uvm/uvm.h > +.Ft struct vm_page * > +.Fn uvm_pagealloc "struct uvm_object *uobj" "voff_t off" "struct vm_anon > *anon" "int flags" > +.Ft void > +.Fn uvm_pagerealloc "struct vm_page *pg" "struct uvm_object *newobj" "voff_t > newoff" > +.Ft void > +.Fn uvm_pagefree "struct vm_page *pg" > +.Ft int > +.Fn uvm_pglistalloc "psize_t size" "paddr_t low" "paddr_t high" "paddr_t > alignment" "paddr_t boundary" "struct pglist *rlist" "int nsegs" "int flags" > +.Ft void > +.Fn uvm_pglistfree "struct pglist *list" > +.Ft void > +.Fn uvm_page_physload "paddr_t start" "paddr_t end" "paddr_t avail_start" > "paddr_t avail_end" "int free_list" > +.Sh DESCRIPTION > +The > +.Fn uvm_pagealloc > +function allocates a page of memory at virtual address > +.Fa off > +in either the object > +.Fa uobj > +or the anonymous memory > +.Fa anon , > +or returns > +.Dv NULL > +if no pages are free. > +Only one of > +.Fa anon > +and > +.Fa uobj > +can be non > +.Dv NULL . > +The > +.Fa flags > +can be any of: > +.Bd -literal > +#define UVM_PGA_USERESERVE 0x0001 /* ok to use reserve pages */ > +#define UVM_PGA_ZERO 0x0002 /* returned page must be zeroed */ > +.Ed > +.Pp > +The > +.Dv UVM_PGA_USERESERVE > +flag means to allocate a page even if that will result in the number of > +free pages being lower than > +.Dv uvmexp.reserve_pagedaemon > +(if the current thread is the pagedaemon) or > +.Dv uvmexp.reserve_kernel > +(if the current thread is not the pagedaemon). > +The > +.Dv UVM_PGA_ZERO > +flag causes the returned page to be filled with zeroes, either by allocating > it > +from a pool of pre-zeroed pages or by zeroing it in-line as necessary. > +.Pp > +The > +.Fn uvm_pagerealloc > +function reallocates page > +.Fa pg > +to a new object > +.Fa newobj , > +at a new offset > +.Fa newoff . > +.Pp > +The > +.Fn uvm_pagefree > +function frees the physical page > +.Fa pg . > +.Pp > +The > +.Fn uvm_pglistalloc > +function allocates a list of pages for size > +.Fa size > +byte under various constraints. > +.Fa low > +and > +.Fa high > +describe the lowest and highest addresses acceptable for the list. > +If > +.Fa alignment > +is non-zero, it describes the required alignment of the list, in > +power-of-two notation. > +If > +.Fa boundary > +is non-zero, no segment of the list may cross this power-of-two > +boundary, relative to zero. > +.Fa nsegs > +is the maximum number of physically contiguous segments. > +The allocated memory is returned in the > +.Fa rlist > +list. > +The > +.Fa flags > +can be any of: > +.Bd -literal > +#define UVM_PLA_WAITOK 0x0001 /* may sleep */ > +#define UVM_PLA_NOWAIT 0x0002 /* can't sleep */ > +#define UVM_PLA_ZERO 0x0004 /* zero all pages before returning */ > +.Ed > +.Pp > +The > +.Dv UVM_PLA_WAITOK > +flag means that the function may sleep while trying to allocate the list of > +pages (this is currently ignored). > +Conversely, the > +.Dv UVM_PLA_NOWAIT > +flag signifies that the function may not sleep while allocating. > +It is an error not to provide one of the above flags. > +Optionally, one may also specify the > +.Dv UVM_PLA_ZERO > +flag to receive zeroed memory in the page list. > +.Pp > +The > +.Fn uvm_pglistfree > +function frees the list of pages pointed to by > +.Fa list . > +.Pp > +The > +.Fn uvm_page_physload > +function loads physical memory segments into VM space on the specified > +.Fa free_list . > +.Fn uvm_page_physload > +must be called at system boot time to set up physical memory management > pages. > +The arguments describe the > +.Fa start > +and > +.Fa end > +of the physical addresses of the segment, and the available start and end > +addresses of pages not already in use. > +.\" XXX expand on "system boot time"! > +.Sh SEE ALSO > +.Xr uvm_km_alloc 9 > Index: uvn_attach.9 > =================================================================== > RCS file: uvn_attach.9 > diff -N uvn_attach.9 > --- /dev/null 1 Jan 1970 00:00:00 -0000 > +++ uvn_attach.9 5 Dec 2019 12:29:27 -0000 > @@ -0,0 +1,99 @@ > +.\" $OpenBSD: uvm.9,v 1.71 2019/11/05 08:18:47 mpi Exp $ > +.\" $NetBSD: uvm.9,v 1.14 2000/06/29 06:08:44 mrg Exp $ > +.\" > +.\" Copyright (c) 1998 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. > +.\" > +.Dd $Mdocdate: November 5 2019 $ > +.Dt UVN_ATTACH 9 > +.Os > +.Sh NAME > +.Nm uvn_attach , > +.Nm uvm_vnp_setsize , > +.Nm uvm_vnp_sync , > +.Nm uvm_vnp_terminate , > +.Nm uvm_vnp_uncache > +.Nd memory mapping files and devices > +.Sh SYNOPSIS > +.In sys/param.h > +.In uvm/uvm.h > +.Ft struct uvm_object * > +.Fn uvn_attach "struct vnode *vp" "vm_prot_t accessprot" > +.Ft void > +.Fn uvm_vnp_setsize "struct vnode *vp" "voff_t newsize" > +.Ft void > +.Fn uvm_vnp_sync "struct mount *mp" > +.Ft void > +.Fn uvm_vnp_terminate "struct vnode *vp" > +.Ft boolean_t > +.Fn uvm_vnp_uncache "struct vnode *vp" > +.Sh DESCRIPTION > +The > +.Fn uvn_attach > +function attaches a UVM object to vnode > +.Fa vp , > +creating the object if necessary. > +The object is returned. > +.Pp > +The > +.Fn uvm_vnp_setsize > +function sets the size of vnode > +.Fa vp > +to > +.Fa newsize . > +Caller must hold a reference to the vnode. > +If the vnode shrinks, pages no longer used are discarded. > +This function will be removed when the file system and VM buffer caches > +are merged. > +.Pp > +The > +.Fn uvm_vnp_sync > +function flushes dirty vnodes from either the mount point passed in > +.Fa mp , > +or all dirty vnodes if > +.Fa mp > +is > +.Dv NULL . > +This function will be removed when the file system and VM buffer caches > +are merged. > +.Pp > +The > +.Fn uvm_vnp_terminate > +function frees all VM resources allocated to vnode > +.Fa vp . > +If the vnode still has references, it will not be destroyed; however > +all future operations using this vnode will fail. > +This function will be removed when the file system and VM buffer caches > +are merged. > +.Pp > +The > +.Fn uvm_vnp_uncache > +function disables vnode > +.Fa vp > +from persisting when all references are freed. > +This function will be removed when the file system and UVM caches > +are unified. > +Returns true if there is no active vnode. > +.Sh SEE ALSO > +.Xr uvm_init 9 >
