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