xref: /openbsd-src/share/man/man9/uvm_pagealloc.9 (revision ed8f5e8d82ace15e4cefca2c82941b15cb1a7830)
1*ed8f5e8dSmpi.\"	$OpenBSD: uvm_pagealloc.9,v 1.3 2024/08/24 10:47:59 mpi Exp $
28f128fcdSmpi.\"	$NetBSD: uvm.9,v 1.14 2000/06/29 06:08:44 mrg Exp $
38f128fcdSmpi.\"
48f128fcdSmpi.\" Copyright (c) 1998 Matthew R. Green
58f128fcdSmpi.\" All rights reserved.
68f128fcdSmpi.\"
78f128fcdSmpi.\" Redistribution and use in source and binary forms, with or without
88f128fcdSmpi.\" modification, are permitted provided that the following conditions
98f128fcdSmpi.\" are met:
108f128fcdSmpi.\" 1. Redistributions of source code must retain the above copyright
118f128fcdSmpi.\"    notice, this list of conditions and the following disclaimer.
128f128fcdSmpi.\" 2. Redistributions in binary form must reproduce the above copyright
138f128fcdSmpi.\"    notice, this list of conditions and the following disclaimer in the
148f128fcdSmpi.\"    documentation and/or other materials provided with the distribution.
158f128fcdSmpi.\"
168f128fcdSmpi.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
178f128fcdSmpi.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
188f128fcdSmpi.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
198f128fcdSmpi.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
208f128fcdSmpi.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
218f128fcdSmpi.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
228f128fcdSmpi.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
238f128fcdSmpi.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
248f128fcdSmpi.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
258f128fcdSmpi.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
268f128fcdSmpi.\" SUCH DAMAGE.
278f128fcdSmpi.\"
28*ed8f5e8dSmpi.Dd $Mdocdate: August 24 2024 $
298f128fcdSmpi.Dt UVM_PAGEALLOC 9
308f128fcdSmpi.Os
318f128fcdSmpi.Sh NAME
328f128fcdSmpi.Nm uvm_pagealloc ,
338f128fcdSmpi.Nm uvm_pagerealloc ,
348f128fcdSmpi.Nm uvm_pagefree ,
358f128fcdSmpi.Nm uvm_pglistalloc ,
368f128fcdSmpi.Nm uvm_pglistfree ,
378f128fcdSmpi.Nm uvm_page_physload
388f128fcdSmpi.Nd physical memory allocator
398f128fcdSmpi.Sh SYNOPSIS
408f128fcdSmpi.In sys/param.h
418f128fcdSmpi.In uvm/uvm.h
428f128fcdSmpi.Ft struct vm_page *
438f128fcdSmpi.Fn uvm_pagealloc "struct uvm_object *uobj" "voff_t off" "struct vm_anon *anon" "int flags"
448f128fcdSmpi.Ft void
458f128fcdSmpi.Fn uvm_pagerealloc "struct vm_page *pg" "struct uvm_object *newobj" "voff_t newoff"
468f128fcdSmpi.Ft void
478f128fcdSmpi.Fn uvm_pagefree "struct vm_page *pg"
488f128fcdSmpi.Ft int
498f128fcdSmpi.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"
508f128fcdSmpi.Ft void
518f128fcdSmpi.Fn uvm_pglistfree "struct pglist *list"
528f128fcdSmpi.Ft void
538f128fcdSmpi.Fn uvm_page_physload "paddr_t start" "paddr_t end" "paddr_t avail_start" "paddr_t avail_end" "int free_list"
548f128fcdSmpi.Sh DESCRIPTION
558f128fcdSmpiThe
568f128fcdSmpi.Fn uvm_pagealloc
578f128fcdSmpifunction allocates a page of memory at virtual address
588f128fcdSmpi.Fa off
598f128fcdSmpiin either the object
608f128fcdSmpi.Fa uobj
618f128fcdSmpior the anonymous memory
628f128fcdSmpi.Fa anon ,
638f128fcdSmpior returns
648f128fcdSmpi.Dv NULL
658f128fcdSmpiif no pages are free.
668f128fcdSmpiOnly one of
678f128fcdSmpi.Fa anon
688f128fcdSmpiand
698f128fcdSmpi.Fa uobj
708f128fcdSmpican be non
718f128fcdSmpi.Dv NULL .
728f128fcdSmpiThe
738f128fcdSmpi.Fa flags
748f128fcdSmpican be any of:
758f128fcdSmpi.Bd -literal
768f128fcdSmpi#define UVM_PGA_USERESERVE      0x0001  /* ok to use reserve pages */
778f128fcdSmpi#define UVM_PGA_ZERO            0x0002  /* returned page must be zeroed */
788f128fcdSmpi.Ed
798f128fcdSmpi.Pp
808f128fcdSmpiThe
818f128fcdSmpi.Dv UVM_PGA_USERESERVE
828f128fcdSmpiflag means to allocate a page even if that will result in the number of
838f128fcdSmpifree pages being lower than
848f128fcdSmpi.Dv uvmexp.reserve_pagedaemon
858f128fcdSmpi(if the current thread is the pagedaemon) or
868f128fcdSmpi.Dv uvmexp.reserve_kernel
878f128fcdSmpi(if the current thread is not the pagedaemon).
888f128fcdSmpiThe
898f128fcdSmpi.Dv UVM_PGA_ZERO
908f128fcdSmpiflag causes the returned page to be filled with zeroes, either by allocating it
918f128fcdSmpifrom a pool of pre-zeroed pages or by zeroing it in-line as necessary.
928f128fcdSmpi.Pp
938f128fcdSmpiThe
948f128fcdSmpi.Fn uvm_pagerealloc
958f128fcdSmpifunction reallocates page
968f128fcdSmpi.Fa pg
978f128fcdSmpito a new object
988f128fcdSmpi.Fa newobj ,
998f128fcdSmpiat a new offset
1008f128fcdSmpi.Fa newoff .
1018f128fcdSmpi.Pp
1028f128fcdSmpiThe
1038f128fcdSmpi.Fn uvm_pagefree
1048f128fcdSmpifunction frees the physical page
1058f128fcdSmpi.Fa pg .
1068f128fcdSmpi.Pp
1078f128fcdSmpiThe
1088f128fcdSmpi.Fn uvm_pglistalloc
1098f128fcdSmpifunction allocates a list of pages for size
1108f128fcdSmpi.Fa size
1118f128fcdSmpibyte under various constraints.
1128f128fcdSmpi.Fa low
1138f128fcdSmpiand
1148f128fcdSmpi.Fa high
1158f128fcdSmpidescribe the lowest and highest addresses acceptable for the list.
1168f128fcdSmpiIf
1178f128fcdSmpi.Fa alignment
1188f128fcdSmpiis non-zero, it describes the required alignment of the list, in
1198f128fcdSmpipower-of-two notation.
1208f128fcdSmpiIf
1218f128fcdSmpi.Fa boundary
1228f128fcdSmpiis non-zero, no segment of the list may cross this power-of-two
1238f128fcdSmpiboundary, relative to zero.
1248f128fcdSmpi.Fa nsegs
1258f128fcdSmpiis the maximum number of physically contiguous segments.
1268f128fcdSmpiThe allocated memory is returned in the
1278f128fcdSmpi.Fa rlist
1288f128fcdSmpilist.
1298f128fcdSmpiThe
1308f128fcdSmpi.Fa flags
1318f128fcdSmpican be any of:
1328f128fcdSmpi.Bd -literal
1338f128fcdSmpi#define UVM_PLA_WAITOK	0x0001	/* may sleep */
1348f128fcdSmpi#define UVM_PLA_NOWAIT	0x0002	/* can't sleep */
1358f128fcdSmpi#define UVM_PLA_ZERO	0x0004	/* zero all pages before returning */
1368f128fcdSmpi.Ed
1378f128fcdSmpi.Pp
1388f128fcdSmpiThe
1398f128fcdSmpi.Dv UVM_PLA_WAITOK
1408f128fcdSmpiflag means that the function may sleep while trying to allocate the list of
1418f128fcdSmpipages (this is currently ignored).
1428f128fcdSmpiConversely, the
1438f128fcdSmpi.Dv UVM_PLA_NOWAIT
1448f128fcdSmpiflag signifies that the function may not sleep while allocating.
1458f128fcdSmpiIt is an error not to provide one of the above flags.
1468f128fcdSmpiOptionally, one may also specify the
1478f128fcdSmpi.Dv UVM_PLA_ZERO
1488f128fcdSmpiflag to receive zeroed memory in the page list.
1498f128fcdSmpi.Pp
1508f128fcdSmpiThe
1518f128fcdSmpi.Fn uvm_pglistfree
1528f128fcdSmpifunction frees the list of pages pointed to by
1538f128fcdSmpi.Fa list .
1548f128fcdSmpi.Pp
1558f128fcdSmpiThe
1568f128fcdSmpi.Fn uvm_page_physload
1578f128fcdSmpifunction loads physical memory segments into VM space on the specified
1588f128fcdSmpi.Fa free_list .
1598f128fcdSmpi.Fn uvm_page_physload
1608f128fcdSmpimust be called at system boot time to set up physical memory management pages.
1618f128fcdSmpiThe arguments describe the
1628f128fcdSmpi.Fa start
1638f128fcdSmpiand
1648f128fcdSmpi.Fa end
1658f128fcdSmpiof the physical addresses of the segment, and the available start and end
1668f128fcdSmpiaddresses of pages not already in use.
167