1.\" $NetBSD: uvm.9,v 1.19 2001/04/21 08:34:11 jdolecek Exp $ 2.\" 3.\" Copyright (c) 1998 Matthew R. Green 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. The name of the author may not be used to endorse or promote products 15.\" derived from this software without specific prior written permission. 16.\" 17.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 22.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 24.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27.\" SUCH DAMAGE. 28.\" 29.\" XXX this manual sets nS to 1 or 0 in the description, to obtain 30.\" synopsis-like function prototypes. any better way? 31.\" 32.Dd March 26, 2000 33.Dt UVM 9 34.Os 35.Sh NAME 36.Nm uvm 37.Nd virtual memory system external interface 38.Sh SYNOPSIS 39.Fd #include <sys/param.h> 40.Fd #include <uvm/uvm.h> 41.Sh DESCRIPTION 42The UVM virtual memory system manages access to the computer's memory 43resources. User processes and the kernel access these resources through 44UVM's external interface. UVM's external interface includes functions that: 45.Pp 46.Bl -hyphen -compact 47.It 48initialise UVM sub-systems 49.It 50manage virtual address spaces 51.It 52resolve page faults 53.It 54memory map files and devices 55.It 56perform uio-based I/O to virtual memory 57.It 58allocate and free kernel virtual memory 59.It 60allocate and free physical memory 61.El 62.Pp 63In addition to exporting these services, UVM has two kernel-level processes: 64pagedaemon and swapper. The pagedaemon process sleeps until physical memory 65becomes scarce. When that happens, pagedaemon is awoken. It scans physical 66memory, paging out and freeing memory that has not been recently used. The 67swapper process swaps in runnable processes that are currently swapped out, 68if there is room. 69.Pp 70There are also several miscellaneous functions. 71.Sh INITIALISATION 72.nr nS 1 73.Pp 74.Ft void 75.Fn uvm_init 76.Ft void 77.Fn uvm_init_limits "struct proc *p" 78.Ft void 79.Fn uvm_setpagesize 80.Ft void 81.Fn uvm_swap_init 82.nr nS 0 83.Pp 84.Fn uvm_init 85sets up the UVM system at system boot time, after the 86copyright has been printed. It initialises 87global state, the page, map, kernel virtual memory state, 88machine-dependent physical map, kernel memory allocator, 89pager and anonymous memory sub-systems, and then enables 90paging of kernel objects. 91.Pp 92.Fn uvm_init_limits 93initialises process limits for the named process. This is for use by 94the system startup for process zero, before any other processes are 95created. 96.Pp 97.Fn uvm_setpagesize 98initialises the uvmexp members pagesize (if not already done by 99machine-dependent code), pageshift and pagemask. It should be called by 100machine-dependent code early in the 101.Xr pmap_init 9 102call. 103.Pp 104.Fn uvm_swap_init 105initialises the swap sub-system. 106.Sh VIRTUAL ADDRESS SPACE MANAGEMENT 107.Pp 108.nr nS 1 109.Ft int 110.Fn uvm_map "vm_map_t map" "vaddr_t *startp" "vsize_t size" "struct uvm_object *uobj" "voff_t uoffset" "uvm_flag_t flags" 111.Ft int 112.Fn uvm_map_pageable "vm_map_t map" "vaddr_t start" "vaddr_t end" "boolean_t new_pageable" "int lockflags" 113.Ft boolean_t 114.Fn uvm_map_checkprot "vm_map_t map" "vaddr_t start" "vaddr_t end" "vm_prot_t protection" 115.Ft int 116.Fn uvm_map_protect "vm_map_t map" "vaddr_t start" "vaddr_t end" "vm_prot_t new_prot" "boolean_t set_max" 117.Ft int 118.Fn uvm_deallocate "vm_map_t map" "vaddr_t start" "vsize_t size" 119 120.Ft struct vmspace * 121.Fn uvmspace_alloc "vaddr_t min" "vaddr_t max" "int pageable" 122.Ft void 123.Fn uvmspace_exec "struct proc *p" 124.Ft struct vmspace * 125.Fn uvmspace_fork "struct vmspace *vm" 126.Ft void 127.Fn uvmspace_free "struct vmspace *vm1" 128.Ft void 129.Fn uvmspace_share "struct proc *p1" "struct proc *p2" 130.Ft void 131.Fn uvmspace_unshare "struct proc *p" 132.nr nS 0 133.Pp 134.Fn uvm_map 135establishes a valid mapping in map 136.Fa map , 137which must be unlocked. The new mapping has size 138.Fa size , 139which must be in 140.Dv PAGE_SIZE 141units. The 142.Fa uobj 143and 144.Fa uoffset 145arguments can have four meanings. When 146.Fa uobj 147is 148.Dv NULL 149and 150.Fa uoffset 151is 152.Dv UVM_UNKNOWN_OFFSET , 153.Fn uvm_map 154does not use the machine-dependant 155.Dv PMAP_PREFER 156function. If 157.Fa uoffset 158is any other value, it is used as the hint to 159.Dv PMAP_PREFER . 160When 161.Fa uobj 162is not 163.Dv NULL 164and 165.Fa uoffset 166is 167.Dv UVM_UNKNOWN_OFFSET , 168.Fn uvm_map 169finds the offset based upon the virtual address, passed as 170.Fa startp . 171If 172.Fa uoffset 173is any other value, we are doing a normal mapping at this offset. The 174start address of the map will be returned in 175.Fa startp . 176.Pp 177.Fa flags 178passed to 179.Fn uvm_map 180are typically created using the 181.Fn UVM_MAPFLAG "vm_prot_t prot" "vm_prot_t maxprot" "vm_inherit_t inh" "int advice" "int flags" 182macro, which uses the following values. 183The 184.Fa prot 185and 186.Fa maxprot 187can take are: 188.Bd -literal 189#define UVM_PROT_MASK 0x07 /* protection mask */ 190#define UVM_PROT_NONE 0x00 /* protection none */ 191#define UVM_PROT_ALL 0x07 /* everything */ 192#define UVM_PROT_READ 0x01 /* read */ 193#define UVM_PROT_WRITE 0x02 /* write */ 194#define UVM_PROT_EXEC 0x04 /* exec */ 195#define UVM_PROT_R 0x01 /* read */ 196#define UVM_PROT_W 0x02 /* write */ 197#define UVM_PROT_RW 0x03 /* read-write */ 198#define UVM_PROT_X 0x04 /* exec */ 199#define UVM_PROT_RX 0x05 /* read-exec */ 200#define UVM_PROT_WX 0x06 /* write-exec */ 201#define UVM_PROT_RWX 0x07 /* read-write-exec */ 202.Ed 203.Pp 204The values that 205.Fa inh 206can take are: 207.Bd -literal 208#define UVM_INH_MASK 0x30 /* inherit mask */ 209#define UVM_INH_SHARE 0x00 /* "share" */ 210#define UVM_INH_COPY 0x10 /* "copy" */ 211#define UVM_INH_NONE 0x20 /* "none" */ 212#define UVM_INH_DONATE 0x30 /* "donate" << not used */ 213.Ed 214.Pp 215The values that 216.Fa advice 217can take are: 218.Bd -literal 219#define UVM_ADV_NORMAL 0x0 /* 'normal' */ 220#define UVM_ADV_RANDOM 0x1 /* 'random' */ 221#define UVM_ADV_SEQUENTIAL 0x2 /* 'sequential' */ 222#define UVM_ADV_MASK 0x7 /* mask */ 223.Ed 224.Pp 225The values that 226.Fa flags 227can take are: 228.Bd -literal 229#define UVM_FLAG_FIXED 0x010000 /* find space */ 230#define UVM_FLAG_OVERLAY 0x020000 /* establish overlay */ 231#define UVM_FLAG_NOMERGE 0x040000 /* don't merge map entries */ 232#define UVM_FLAG_COPYONW 0x080000 /* set copy_on_write flag */ 233#define UVM_FLAG_AMAPPAD 0x100000 /* for bss: pad amap to reduce malloc() */ 234#define UVM_FLAG_TRYLOCK 0x200000 /* fail if we can not lock map */ 235.Ed 236.Pp 237The 238.Dv UVM_MAPFLAG 239macro arguments can be combined with an or operator. There are 240several special purpose macros for checking protection combinations, e.g. the 241.Dv UVM_PROT_WX 242macro. There are also some additional macros to extract bits from 243the flags. The 244.Dv UVM_PROTECTION , 245.Dv UVM_INHERIT , 246.Dv UVM_MAXPROTECTION 247and 248.Dv UVM_ADVICE 249macros return the protection, inheritance, maximum protection and advice, 250respectively. 251.Fn uvm_map 252returns a standard UVM return value. 253.Pp 254.Fn uvm_map_pageable 255changes the pageability of the pages in the range from 256.Fa start 257to 258.Fa end 259in map 260.Fa map 261to 262.Fa new_pageable . 263.Fn uvm_map_pageable 264returns a standard UVM return value. 265.Pp 266.Fn uvm_map_checkprot 267checks the protection of the range from 268.Fa start 269to 270.Fa end 271in map 272.Fa map 273against 274.Fa protection . 275This returns either 276.Dv TRUE 277or 278.Dv FALSE . 279.Pp 280.Fn uvm_map_protect 281changes the protection 282.Fa start 283to 284.Fa end 285in map 286.Fa map 287to 288.Fa new_prot , 289also setting the maximum protection to the region to 290.Fa new_prot 291if 292.Fa set_max 293is non-zero. This function returns a standard UVM return value. 294.Pp 295.Fn uvm_deallocate 296deallocates kernel memory in map 297.Fa map 298from address 299.Fa start 300to 301.Fa start + size . 302.Pp 303.Fn uvmspace_alloc 304allocates and returns a new address space, with ranges from 305.Fa min 306to 307.Fa max , 308setting the pageability of the address space to 309.Fa pageable. 310.Pp 311.Fn uvmspace_exec 312either reuses the address space of process 313.Fa p 314if there are no other references to it, or creates 315a new one with 316.Fn uvmspace_alloc . 317.Pp 318.Fn uvmspace_fork 319creates and returns a new address space based upon the 320.Fa vm1 321address space, typically used when allocating an address space for a 322child process. 323.Pp 324.Fn uvmspace_free 325lowers the reference count on the address space 326.Fa vm , 327freeing the data structures if there are no other references. 328.Pp 329.Fn uvmspace_share 330causes process 331.Pa p2 332to share the address space of 333.Fa p1 . 334.Pp 335.Fn uvmspace_unshare 336ensures that process 337.Fa p 338has its own, unshared address space, by creating a new one if 339necessary by calling 340.Fn uvmspace_fork . 341.Sh PAGE FAULT HANDLING 342.Pp 343.nr nS 1 344.Ft int 345.Fn uvm_fault "vm_map_t orig_map" "vaddr_t vaddr" "vm_fault_t fault_type" "vm_prot_t access_type" 346.nr nS 0 347.Pp 348.Fn uvm_fault 349is the main entry point for faults. It takes 350.Fa orig_map 351as the map the fault originated in, a 352.Fa vaddr 353offset into the map the fault occured, 354.Fa fault_type 355describing the type of fault, and 356.Fa access_type 357describing the type of access requested. 358.Fn uvm_fault 359returns a standard UVM return value. 360.Sh MEMORY MAPPING FILES AND DEVICES 361.Pp 362.nr nS 1 363.Ft struct uvm_object * 364.Fn uvn_attach "void *arg" "vm_prot_t accessprot" 365.Ft void 366.Fn uvm_vnp_setsize "struct vnode *vp" "u_quad_t newsize" 367.Ft void 368.Fn uvm_vnp_sync "struct mount *mp" 369.Ft void 370.Fn uvm_vnp_terminate "struct vnode *vp" 371.Ft boolean_t 372.Fn uvm_vnp_uncache "struct vnode *vp" 373.nr nS 0 374.Pp 375.Fn uvn_attach 376attaches a UVM object to vnode 377.Fa arg , 378creating the object if necessary. The object is returned. 379.Pp 380.Fn uvm_vnp_setsize 381sets the size of vnode 382.Fa vp 383to 384.Fa newsize . 385Caller must hold a reference to the vnode. If the vnode shrinks, pages 386no longer used are discarded. This function will be removed when the 387filesystem and VM buffer caches are merged. 388.Pp 389.Fn uvm_vnp_sync 390flushes dirty vnodes from either the mount point passed in 391.Fa mp , 392or all dirty vnodes if 393.Fa mp 394is 395.Dv NULL . 396This function will be removed when the filesystem and VM buffer caches 397are merged. 398.Pp 399.Fn uvm_vnp_terminate 400frees all VM resources allocated to vnode 401.Fa vp . 402If the vnode still has references, it will not be destroyed; however 403all future operations using this vnode will fail. This function will be 404removed when the filesystem and VM buffer caches are merged. 405.Pp 406.Fn uvm_vnp_uncache 407disables vnode 408.Fa vp 409from persisting when all references are freed. This function will be 410removed when the file-system and UVM caches are unified. Returns 411true if there is no active vnode. 412.Sh VIRTUAL MEMORY I/O 413.Pp 414.nr nS 1 415.Ft int 416.Fn uvm_io "vm_map_t map" "struct uio *uio" 417.nr nS 0 418.Pp 419.Fn uvm_io 420performs the I/O described in 421.Fa uio 422on the memory described in 423.Fa map . 424.Sh ALLOCATION OF KERNEL MEMORY 425.Pp 426.nr nS 1 427.Ft vaddr_t 428.Fn uvm_km_alloc "vm_map_t map" "vsize_t size" 429.Ft vaddr_t 430.Fn uvm_km_zalloc "vm_map_t map" "vsize_t size" 431.Ft vaddr_t 432.Fn uvm_km_alloc1 "vm_map_t map" "vsize_t size" "boolean_t zeroit" 433.Ft vaddr_t 434.Fn uvm_km_kmemalloc "vm_map_t map" "struct uvm_object *obj" "vsize_t size" "int flags" 435.Ft vaddr_t 436.Fn uvm_km_valloc "vm_map_t map" "vsize_t size" 437.Ft vaddr_t 438.Fn uvm_km_valloc_wait "vm_map_t map" "vsize_t size" 439.Ft struct vm_map * 440.Fn uvm_km_suballoc "vm_map_t map" "vaddr_t *min" "vaddr_t *max " "vsize_t size" "boolean_t pageable" "boolean_t fixed" "vm_map_t submap" 441.Ft void 442.Fn uvm_km_free "vm_map_t map" "vaddr_t addr" "vsize_t size" 443.Ft void 444.Fn uvm_km_free_wakeup "vm_map_t map" "vaddr_t addr" "vsize_t size" 445.nr nS 0 446.Pp 447.Fn uvm_km_alloc 448and 449.Fn uvm_km_zalloc 450allocate 451.Fa size 452bytes of wired kernel memory in map 453.Fa map . 454In addition to allocation, 455.Fn uvm_km_zalloc 456zeros the memory. Both of these functions are defined as macros in 457terms of 458.Fn uvm_km_alloc1 , 459and should almost always be used in preference to 460.Fn uvm_km_alloc1 . 461.Pp 462.Fn uvm_km_alloc1 463allocates and returns 464.Fa size 465bytes of wired memory in the kernel map, zeroing the memory if the 466.Fa zeroit 467argument is non-zero. 468.Pp 469.Fn uvm_km_kmemalloc 470allocates and returns 471.Fa size 472bytes of wired kernel memory into 473.Fa obj . 474The flags can be any of: 475.Bd -literal 476#define UVM_KMF_NOWAIT 0x1 /* matches M_NOWAIT */ 477#define UVM_KMF_VALLOC 0x2 /* allocate VA only */ 478#define UVM_KMF_TRYLOCK UVM_FLAG_TRYLOCK /* try locking only */ 479.Ed 480.Pp 481.Dv UVM_KMF_NOWAIT 482causes 483.Fn uvm_km_kmemalloc 484to return immediately if no memory is available. 485.Dv UVM_KMF_VALLOC 486causes no pages to be allocated, only a virtual address. 487.Dv UVM_KMF_TRYLOCK 488causes 489.Fn uvm_km_kmemalloc 490to use 491.Fn simple_lock_try 492when locking maps. 493.Pp 494.Fn uvm_km_valloc 495and 496.Fn uvm_km_valloc_wait 497return a newly allocated zero-filled address in the kernel map of size 498.Fa size . 499.Fn uvm_km_valloc_wait 500will also wait for kernel memory to become available, if there is a 501memory shortage. 502.Sh ALLOCATION OF PHYSICAL MEMORY 503.Pp 504.nr nS 1 505.Ft struct vm_page * 506.Fn uvm_pagealloc "struct uvm_object *uobj" "voff_t off" "struct vm_anon *anon" 507.Ft void 508.Fn uvm_pagerealloc "struct vm_page *pg" "struct uvm_object *newobj" "voff_t newoff" 509.Ft void 510.Fn uvm_pagefree "struct vm_page *pg" 511.Ft int 512.Fn uvm_pglistalloc "psize_t size" "paddr_t low" "paddr_t high" "paddr_t alignment" "paddr_t boundary" "struct pglist *rlist" "int nsegs" "int waitok" 513.Ft void 514.Fn uvm_pglistfree "struct pglist *list" 515.Ft void 516.Fn uvm_page_physload "vaddr_t start" "vaddr_t end" "vaddr_t avail_start" "vaddr_t avail_end" 517.nr nS 0 518.Pp 519.Fn uvm_pagealloc 520allocates a page of memory at virtual address 521.Fa off 522in either the object 523.Fa uobj 524or the anonymous memory 525.Fa anon , 526which must be locked by the caller. Only one of 527.Fa off 528and 529.Fa uobj 530can be non 531.Dv NULL . 532Returns 533.Dv NULL 534when no page can be found. 535.Pp 536.Fn uvm_pagerealloc 537reallocates page 538.Fa pg 539to a new object 540.Fa newobj , 541at a new offset 542.Fa newoff . 543.Pp 544.Fn uvm_pagefree 545free's the physical page 546.Fa pg . 547.Pp 548.Fn uvm_pglistalloc 549allocates a list of pages for size 550.Fa size 551byte under various constraints. 552.Fa low 553and 554.Fa high 555describe the lowest and highest addresses acceptable for the list. If 556.Fa alignment 557is non-zero, it describes the required alignment of the list, in 558power-of-two notation. If 559.Fa boundary 560is non-zero, no segment of the list may cross this power-of-two 561boundary, relative to zero. 562The 563.Fa nsegs 564and 565.Fa waitok 566arguments are currently ignored. 567.Pp 568.Fn uvm_pglistfree 569frees the list of pages pointed to by 570.Fa list . 571.Pp 572.Fn uvm_page_physload 573loads physical memory segments into VM space. It must be called at system 574boot time to setup physical memory management pages. The arguments describe 575the 576.Fa start 577and 578.Fa end 579of the physical addresses of the segment, and the available start and end 580addresses of pages not already in use. 581.\" XXX expand on "system boot time"! 582.Pp 583.Fn uvm_km_suballoc 584allocates submap from 585.Fa map , 586creating a new map if 587.Fa submap 588is 589.Dv NULL . 590The addresses of the submap can be specified exactly by setting the 591.Fa fixed 592argument to non-zero, which causes the 593.Fa min 594argument specify the beginning of the address in thes submap. If 595.Fa fixed 596is zero, any address of size 597.Fa size 598will be allocated from 599.Fa map 600and the start and end addresses returned in 601.Fa min 602and 603.Fa max . 604If 605.Fa pageable 606is non-zero, entries in the map may be paged out. 607.Pp 608.Fn uvm_km_free 609and 610.Fn uvm_km_free_wakeup 611free 612.Fa size 613bytes of memory in the kernal map, starting at address 614.Fa addr . 615.Fn uvm_km_free_wakeup 616calls 617.Fn thread_wakeup 618on the map before unlocking the map. 619.Sh PROCESSES 620.Pp 621.nr nS 1 622.Ft void 623.Fn uvm_pageout 624.Ft void 625.Fn uvm_scheduler 626.Ft void 627.Fn uvm_swapin "struct proc *p" 628.nr nS 0 629.Pp 630.Fn uvm_pageout 631is the main loop for the page daemon. 632.Pp 633.Fn uvm_scheduler 634is the process zero main loop, which is to be called after the 635system has finished starting other processes. It handles the 636swapping in of runnable, swapped out processes in priority 637order. 638.Pp 639.Fn uvm_swapin 640swaps in the named process. 641.Sh MISCELLANEOUS FUNCTIONS 642.nr nS 1 643.Pp 644.Ft struct uvm_object * 645.Fn uao_create "vsize_t size" "int flags" 646.Ft void 647.Fn uao_detach "struct uvm_object *uobj" 648.Ft void 649.Fn uao_reference "struct uvm_object *uobj" 650 651.Ft boolean_t 652.Fn uvm_chgkprot "caddr_t addr" "size_t len" "int rw" 653.Ft void 654.Fn uvm_kernacc "caddr_t addr" "size_t len" "int rw" 655.Ft boolean_t 656.Fn uvm_useracc "caddr_t addr" "size_t len" "int rw" 657 658.Ft int 659.Fn uvm_vslock "struct proc *p" "caddr_t addr" "size_t len" "vm_prot_t prot" 660.Ft void 661.Fn uvm_vsunlock "struct proc *p" "caddr_t addr" "size_t len" 662 663.Ft void 664.Fn uvm_meter 665.Ft int 666.Fn uvm_sysctl "int *name" "u_int namelen" "void *oldp" "size_t *oldlenp" "void *newp " "size_t newlen" "struct proc *p" 667 668.Ft void 669.Fn uvm_fork "struct proc *p1" "struct proc *p2" "boolean_t shared" 670.Ft int 671.Fn uvm_grow "struct proc *p" "vaddr_t sp" 672.Ft int 673.Fn uvm_coredump "struct proc *p" "struct vnode *vp" "struct ucred *cred" "struct core *chdr" 674.nr nS 0 675.Pp 676The 677.Fn uao_create , 678.Fn uao_detach 679and 680.Fn uao_reference 681functions operate on anonymous memory objects, such as those used to support 682System V shared memory. 683.Fn uao_create 684returns an object of size 685.Fa size 686with flags: 687.Bd -literal 688#define UAO_FLAG_KERNOBJ 0x1 /* create kernel object */ 689#define UAO_FLAG_KERNSWAP 0x2 /* enable kernel swap */ 690.Pp 691.Ed 692which can only be used once each at system boot time. 693.Fn uao_reference 694creates an additional reference to the named anonymous memory object. 695.Fn uao_detach 696removes a reference from the named anonymous memory object, destroying 697it if removing the last reference. 698.Pp 699.Fn uvm_chgkprot 700changes the protection of kernel memory from 701.Fa addr 702to 703.Fa addr + len 704to the value of 705.Fa rw . 706This is primarily useful for debuggers, for setting breakpoints. 707This function is only available with options 708.Dv KGDB . 709.Pp 710.Fn uvm_kernacc 711and 712.Fn uvm_useracc 713check the access at address 714.Fa addr 715to 716.Fa addr + len 717for 718.Fa rw 719access, in the kernel address space, and the current process' 720address space respectively. 721.Pp 722.Fn uvm_vslock 723and 724.Fn uvm_vsunlock 725control the wiring and unwiring of pages for process 726.Fa p 727from 728.Fa addr 729to 730.Fa addr + len . 731These functions are normally used to wire memory for I/O. 732.Pp 733.Fn uvm_meter 734calculates the load average and wakes up the swapper if necessary. 735.Pp 736.Fn uvm_sysctl 737provides support for the 738.Dv CTL_VM 739domain of the 740.Xr sysctl 3 741hierarchy. 742.Fn uvm_sysctl 743handles the 744.Dv VM_LOADAVG , 745.Dv VM_METER 746and 747.Dv VM_UVMEXP 748calls, which return the current load averages, calculates current VM 749totals, and returns the uvmexp structure respectively. The load averages 750are access from userland using the 751.Xr getloadavg 3 752function. The uvmexp structure has all global state of the UVM system, 753and has the following members: 754.Bd -literal 755/* vm_page constants */ 756int pagesize; /* size of a page (PAGE_SIZE): must be power of 2 */ 757int pagemask; /* page mask */ 758int pageshift; /* page shift */ 759 760/* vm_page counters */ 761int npages; /* number of pages we manage */ 762int free; /* number of free pages */ 763int active; /* number of active pages */ 764int inactive; /* number of pages that we free'd but may want back */ 765int paging; /* number of pages in the process of being paged out */ 766int wired; /* number of wired pages */ 767int reserve_pagedaemon; /* number of pages reserved for pagedaemon */ 768int reserve_kernel; /* number of pages reserved for kernel */ 769 770/* pageout params */ 771int freemin; /* min number of free pages */ 772int freetarg; /* target number of free pages */ 773int inactarg; /* target number of inactive pages */ 774int wiredmax; /* max number of wired pages */ 775 776/* swap */ 777int nswapdev; /* number of configured swap devices in system */ 778int swpages; /* number of PAGE_SIZE'ed swap pages */ 779int swpginuse; /* number of swap pages in use */ 780int nswget; /* number of times fault calls uvm_swap_get() */ 781int nanon; /* number total of anon's in system */ 782int nfreeanon; /* number of free anon's */ 783 784/* stat counters */ 785int faults; /* page fault count */ 786int traps; /* trap count */ 787int intrs; /* interrupt count */ 788int swtch; /* context switch count */ 789int softs; /* software interrupt count */ 790int syscalls; /* system calls */ 791int pageins; /* pagein operation count */ 792 /* pageouts are in pdpageouts below */ 793int swapins; /* swapins */ 794int swapouts; /* swapouts */ 795int pgswapin; /* pages swapped in */ 796int pgswapout; /* pages swapped out */ 797int forks; /* forks */ 798int forks_ppwait; /* forks where parent waits */ 799int forks_sharevm; /* forks where vmspace is shared */ 800 801/* fault subcounters */ 802int fltnoram; /* number of times fault was out of ram */ 803int fltnoanon; /* number of times fault was out of anons */ 804int fltpgwait; /* number of times fault had to wait on a page */ 805int fltpgrele; /* number of times fault found a released page */ 806int fltrelck; /* number of times fault relock called */ 807int fltrelckok; /* number of times fault relock is a success */ 808int fltanget; /* number of times fault gets anon page */ 809int fltanretry; /* number of times fault retrys an anon get */ 810int fltamcopy; /* number of times fault clears "needs copy" */ 811int fltnamap; /* number of times fault maps a neighbor anon page */ 812int fltnomap; /* number of times fault maps a neighbor obj page */ 813int fltlget; /* number of times fault does a locked pgo_get */ 814int fltget; /* number of times fault does an unlocked get */ 815int flt_anon; /* number of times fault anon (case 1a) */ 816int flt_acow; /* number of times fault anon cow (case 1b) */ 817int flt_obj; /* number of times fault is on object page (2a) */ 818int flt_prcopy; /* number of times fault promotes with copy (2b) */ 819int flt_przero; /* number of times fault promotes with zerofill (2b) */ 820 821/* daemon counters */ 822int pdwoke; /* number of times daemon woke up */ 823int pdrevs; /* number of times daemon rev'd clock hand */ 824int pdswout; /* number of times daemon called for swapout */ 825int pdfreed; /* number of pages daemon freed since boot */ 826int pdscans; /* number of pages daemon scaned since boot */ 827int pdanscan; /* number of anonymous pages scanned by daemon */ 828int pdobscan; /* number of object pages scanned by daemon */ 829int pdreact; /* number of pages daemon reactivated since boot */ 830int pdbusy; /* number of times daemon found a busy page */ 831int pdpageouts; /* number of times daemon started a pageout */ 832int pdpending; /* number of times daemon got a pending pagout */ 833int pddeact; /* number of pages daemon deactivates */ 834.Ed 835.Pp 836.Fn uvm_fork 837forks a virtual address space for process' (old) 838.Fa p1 839and (new) 840.Fa p2 . 841If the 842.Fa shared 843argument is non zero, p1 shares its address space with p2, 844otherwise a new address space is created. This function 845currently has no return value, and thus cannot fail. In 846the future, this function will changed to allowed it to 847fail in low memory conditions. 848.Pp 849.Fn uvm_grow 850increases the stack segment of process 851.Fa p 852to include 853.Fa sp . 854.Pp 855.Fn uvm_coredump 856generates a coredump on vnode 857.Fa vp 858for process 859.Fa p 860with credentials 861.Fa cred 862and core header description in 863.Fa chdr . 864.Sh NOTES 865.Fn uvm_chgkprot 866is only available if the kernel has been compiled with options 867.Dv KGDB . 868.Pp 869All structure and types whose names begin with 870.Dq vm_ 871will be renamed to 872.Dq uvm_ . 873.Pp 874The 875.Xr pmap 9 876manual page is not yet written. 877.Sh HISTORY 878UVM is a new VM system developed at Washington University in St. Louis 879(Missouri). UVM's roots lie partly in the Mach-based 880.Bx 4.4 881VM system, the 882.Fx 883VM system, and the SunOS4 VM system. UVM's basic structure is based on the 884.Bx 4.4 885VM system. UVM's new anonymous memory system is based on the 886anonymous memory system found in the SunOS4 VM (as described in papers by 887published Sun Microsystems, Inc.). UVM also includes a number of feature 888new to 889.Bx 890including page loanout, map entry passing, simplified 891copy-on-write, and clustered anonymous memory pageout. UVM is also 892further documented in a August 1998 dissertation by Charles D. Cranor. 893.Pp 894UVM appeared in 895.Nx 1.4 . 896.Sh AUTHORS 897Charles D. Cranor <chuck@ccrc.wustl.edu> designed and implemented UVM. 898.Pp 899Matthew Green <mrg@eterna.com.au> wrote the swap-space management code 900and handled the logistical issues involved with merging UVM into the 901.Nx 902source tree. 903.Pp 904Chuck Silvers <chuq@chuq.com> implemented the aobj pager, thus allowing 905UVM to support System V shared memory and process swapping. 906.Sh SEE ALSO 907.Xr getloadavg 3 , 908.Xr kvm 3 , 909.Xr sysctl 3 , 910.Xr ddb 4 , 911.Xr options 4 912