class PmmNode

Defined at line 56 of file ../../zircon/kernel/vm/include/vm/pmm_node.h

per numa node collection of pmm arenas and worker threads

Public Members

static const int kIndexZeroBits

Public Methods

zx_status_t Init (ktl::span<const memalloc::Range> ranges)

We disable thread safety analysis here, since this function is only called

during early boot before threading exists.

Defined at line 26 of file ../../zircon/kernel/vm/pmm_node.cc

void PmmNode ()

This constructor may be called early in the boot sequence so make sure it does not do any "real

work" or depend on any globals.

Defined at line 60 of file ../../zircon/kernel/vm/include/vm/pmm_node.h

void ~PmmNode ()

Defined at line 61 of file ../../zircon/kernel/vm/include/vm/pmm_node.h

void PmmNode (const PmmNode & )

Defined at line 63 of file ../../zircon/kernel/vm/include/vm/pmm_node.h

void PmmNode (PmmNode && )

Defined at line 63 of file ../../zircon/kernel/vm/include/vm/pmm_node.h

PmmNode & operator= (const PmmNode & )

Defined at line 63 of file ../../zircon/kernel/vm/include/vm/pmm_node.h

PmmNode & operator= (PmmNode && )

Defined at line 63 of file ../../zircon/kernel/vm/include/vm/pmm_node.h

void EndHandoff ()

See pmm_end_handoff().

Defined at line 99 of file ../../zircon/kernel/vm/pmm_node.cc

vm_page_t * PaddrToPage (paddr_t addr)

We don't need to hold the arena lock while executing this, since it is

only accesses values that are set once during system initialization.

Defined at line 395 of file ../../zircon/kernel/vm/include/vm/pmm_node.h

uint32_t PageToIndex (const vm_page_t * page)

Returns compressed representation a page_t*, with the following characteristics:

- zeros in the last kIndexZeroBits bits, used by clients to store metadata.

- The value 0 is never returned, it can be used as "no page" marker.

Note: This method needs to traverse (up to) all the memory pools so it's cost is

low but not trivial.

Defined at line 422 of file ../../zircon/kernel/vm/include/vm/pmm_node.h

vm_page_t * IndexToPage (uint32_t index)

Converts the number returned by PageToIndex() back to a page_t* pointer.

It does not check for invalid indexes such as 0.

Note: This method is faster than PageToIndex(), about the cost of some basic math

and bit manipulation.

Defined at line 406 of file ../../zircon/kernel/vm/include/vm/pmm_node.h

paddr_t IndexToPaddr (uint32_t index)

Converts the number returned by PageToIndex() back to a paddr_t.

It does not check for invalid indexes such as 0 or kIndexReserved0.

Note: This method is faster than IndexToPage()->paddr() as the vm_page_t itself does not have

to be de-referenced, saving a memory load.

Defined at line 414 of file ../../zircon/kernel/vm/include/vm/pmm_node.h

zx::result<vm_page_t *> AllocPage (uint alloc_flags)

main allocator routines

Defined at line 132 of file ../../zircon/kernel/vm/pmm_node.cc

zx_status_t AllocPages (size_t count, uint alloc_flags, VmPageDoublyLinkedList * list)

Defined at line 141 of file ../../zircon/kernel/vm/pmm_node.cc

zx_status_t AllocRange (paddr_t address, size_t count, VmPageDoublyLinkedList * list)

Defined at line 145 of file ../../zircon/kernel/vm/pmm_node.cc

zx_status_t AllocContiguous (size_t count, uint alloc_flags, uint8_t alignment_log2, paddr_t * pa, VmPageDoublyLinkedList * list)

Defined at line 149 of file ../../zircon/kernel/vm/pmm_node.cc

void FreePage (vm_page * page, PmmOptDelayReuse delay_reuse)

Defined at line 226 of file ../../zircon/kernel/vm/pmm_node.cc

void FreeList (VmPageDoublyLinkedList * list, PmmOptDelayReuse delay_reuse)

Defined at line 243 of file ../../zircon/kernel/vm/pmm_node.cc

zx::result<vm_page_t *> AllocLoanedPage (fit::inline_function<void (vm_page_t *), 32> allocated)

Allocates a single page from the loaned pages list. The allocated page will always have

is_loaned() being true, and must be returned by either FreeLoanedPage or FreeLoanedList. If

there are not loaned pages available ZX_ERR_UNAVAILABLE is returned, as an absence of loaned

pages does not constitute an out of memory scenario.

The provided callback must transition the page into a state such that it has a valid backlink,

i.e. it is in the OBJECT state with an owner set, prior to returning.

During the execution of the callback the page contents must *not* be modified.

Defined at line 118 of file ../../zircon/kernel/vm/pmm_node.cc

void BeginFreeLoanedPage (vm_page_t * page, fit::inline_function<void (vm_page_t *)> release_page, FreeLoanedPagesHolder & flph)

Begins freeing a loaned page that was previously allocated by AllocLoanPage by moving into a

holding object. It is an error to attempt to free a non loaned page. When this method is called

the |page| must have a valid backlink (i.e. be in the OBJECT state with an owner set). This

backlink should be removed by the |release_page| callback, which is invoked under the loaned

pages lock, prior to transition the page into the holding state. The caller *must*, at some

point in the future, complete the page freeing process by passing the provided |flph| into a

|FinishFreeLoanedPages| call.

Defined at line 212 of file ../../zircon/kernel/vm/pmm_node.cc

void FinishFreeLoanedPages (FreeLoanedPagesHolder & flph)

Completes the freeing of any loaned pages in |flph|, after which |flph| is allowed to be

destructed. Once this method is called on a given |flph| that object is effectively 'dead' and

is not allowed to be passed to any PmmNode methods.

Defined at line 222 of file ../../zircon/kernel/vm/pmm_node.cc

void BeginFreeLoanedArray (vm_page_t ** pages, size_t count, fit::inline_function<void (vm_page_t **, size_t, VmPageDoublyLinkedList *)> release_list, FreeLoanedPagesHolder & flph)

Begins freeing multiple pages that were allocated by AllocLoanedPage by moving into a holding

object. It is an error to attempt to free any non loaned pages. When this method is called all

pages in the array must have a valid backlink (i.e. be in the OBJECT state with an owner set),

and the |release_list| method must remove the backlink from all pages, and place them in the

provided list in the same order.

The caller *must*, at some point in the future, complete the page freeing process by passing

the provided |flph| into a |FinishFreeLoanedPages| call.

Defined at line 230 of file ../../zircon/kernel/vm/pmm_node.cc

void UnwirePage (vm_page * page)

Defined at line 247 of file ../../zircon/kernel/vm/pmm_node.cc

zx::result<vm_page_t *> WaitForSinglePageAllocation (Deadline deadline, bool suspendable)

Waits the system to exit low memory state and then attempts to allocate.

To prevent herding problem, and because allocation compete for the `PmmNode::lock_` anyway,

only one thread is woken up a time, only if the previous thread successfully allocated.

In normal conditions, when the system is in low memory state, this method will return

`ZX_ERR_TIMED_OUT` if the system didn't transition fast enough. If we run into a TOC to TOU,

for the system race `ZX_ERR_SHOULD_WAIT` will be returned, that is the system transitioned

out and back into low memory state before we managed to perform the allocation.

If `BootOptions::Get()->pmm_alloc_random_wait` is true, then the system

may return spurious `ZX_ERR_SHOULD_WAIT`, in such cases, if the system is

not in a low memory state, a thread is woken up anyway, so forward

progress can be made.

If |suspendable| is true, the wait will terminate early with

`ZX_ERR_INTERNAL_INTR_RETRY` if the thread is suspended. If false, suspension is ignored and

the wait continues.

Defined at line 283 of file ../../zircon/kernel/vm/pmm_node.cc

uint64_t CountFreePages ()

Defined at line 249 of file ../../zircon/kernel/vm/pmm_node.cc

uint64_t CountLoanedFreePages ()

Defined at line 253 of file ../../zircon/kernel/vm/pmm_node.cc

uint64_t CountLoanCancelledPages ()

Defined at line 265 of file ../../zircon/kernel/vm/pmm_node.cc

uint64_t CountLoanedNotFreePages ()

Not actually used and cancelled is still not free, since the page can't be allocated in that

state.

Defined at line 257 of file ../../zircon/kernel/vm/pmm_node.cc

uint64_t CountLoanedPages ()

Defined at line 261 of file ../../zircon/kernel/vm/pmm_node.cc

uint64_t CountTotalBytes ()

Defined at line 269 of file ../../zircon/kernel/vm/pmm_node.cc

void DumpFree ()

printf free and overall state of the internal arenas

NOTE: both functions skip mutexes and can be called inside timer or crash context

though the data they return may be questionable

Defined at line 273 of file ../../zircon/kernel/vm/pmm_node.cc

zx_status_t GetArenaInfo (size_t count, uint64_t i, pmm_arena_info_t * buffer, size_t buffer_size)

Copies |count| pmm_arena_info_t objects into |buffer| starting with the |i|-th arena ordered by

base address. For example, passing an |i| of 1 would skip the 1st arena.

The objects will be sorted in ascending order by arena base address.

Returns ZX_ERR_OUT_OF_RANGE if |count| is 0 or |i| and |count| specificy an invalid range.

Returns ZX_ERR_BUFFER_TOO_SMALL if the buffer is too small.

Defined at line 101 of file ../../zircon/kernel/vm/pmm_node.cc

void FillFreePagesAndArm ()

Fill all free pages (both non-loaned and loaned) with a pattern and arm the checker. See

|PmmChecker|.

This is a no-op if the checker is not enabled. See |EnableFreePageFilling|

Defined at line 106 of file ../../zircon/kernel/vm/pmm_node.cc

void CheckAllFreePages ()

Synchronously walk the PMM's free list (and free loaned list) and validate each page. This is

an incredibly expensive operation and should only be used for debugging purposes.

Defined at line 108 of file ../../zircon/kernel/vm/pmm_node.cc

bool EnableFreePageFilling (size_t fill_size, CheckFailAction action)

Enable the free fill checker with the specified fill size and action, and begin filling freed

pages (including freed loaned pages) going forward. See |PmmChecker| for definition of fill

size.

Note, pages freed piror to calling this method will remain unfilled. To fill them, call

|FillFreePagesAndArm|.

Returns true if the checker was enabled with the requested fill_size, or |false| otherwise.

Defined at line 114 of file ../../zircon/kernel/vm/pmm_node.cc

size_t NumArenas ()

Returns the number of active arenas.

Defined at line 178 of file ../../zircon/kernel/vm/include/vm/pmm_node.h

PageQueues * GetPageQueues ()

Defined at line 193 of file ../../zircon/kernel/vm/include/vm/pmm_node.h

VmCompression * GetPageCompression ()

Retrieve any page compression instance. If this returns non-null then it's return value will

not change and the result can be cached.

Defined at line 197 of file ../../zircon/kernel/vm/include/vm/pmm_node.h

PmmChecker * Checker ()

Return a pointer to this object's free fill checker.

For test and diagnostic purposes.

Defined at line 230 of file ../../zircon/kernel/vm/include/vm/pmm_node.h

void Dump (bool is_panic)

Defined at line 275 of file ../../zircon/kernel/vm/pmm_node.cc

void SeedRandomShouldWait ()

If randomly waiting on allocations is enabled, this re-seeds from the global prng, otherwise it

does nothing.

Defined at line 281 of file ../../zircon/kernel/vm/pmm_node.cc

void ReportAllocFailure (AllocFailure failure)

Defined at line 277 of file ../../zircon/kernel/vm/pmm_node.cc

Records