class PmmNode

Defined at line 57 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

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 61 of file ../../zircon/kernel/vm/include/vm/pmm_node.h

void ~PmmNode ()

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

void PmmNode (const PmmNode & )

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

void PmmNode (PmmNode && )

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

PmmNode & operator= (const PmmNode & )

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

PmmNode & operator= (PmmNode && )

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

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 82 of file ../../zircon/kernel/vm/pmm_node.cc

void EndHandoff ()

See pmm_end_handoff().

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

size_t NumArenas ()

Returns the number of active arenas.

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

PageQueues * GetPageQueues ()

Defined at line 228 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 232 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 268 of file ../../zircon/kernel/vm/include/vm/pmm_node.h

Evictor * GetEvictor ()

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

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 534 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 561 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 545 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 553 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 368 of file ../../zircon/kernel/vm/pmm_node.cc

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

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

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

Defined at line 487 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, list_node * list)

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

void FreePage (vm_page * page, PmmOptDelayReuse delay_reuse)

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

void FreeList (list_node * list, PmmOptDelayReuse delay_reuse)

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

void WithLoanedPage (vm_page_t * page, fit::inline_function<void (vm_page_t *)> with_page)

Calls the provided function, passing |page| back into it, serialized with any other calls to

|AllocLoanedPage|, |BeginFreeLoanedPage| and |FinishFreeLoanedPages|. This allows caller to

know that while the |with_page| callback is running there are no in progress calls to these

methods, and that the page is not presently in holding object, i.e. it is either fully owned by

the PmmNode, or fully owned by an object.

Defined at line 798 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 332 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 742 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 762 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, list_node_t *)> 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 901 of file ../../zircon/kernel/vm/pmm_node.cc

void UnwirePage (vm_page * page)

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

void BeginLoan (list_node * page_list, PmmOptDelayReuse delay_reuse)

Frees all pages in the given list and places them in the loaned state available to be returned

from AllocLoanedPage.

|delay_reuse| controls whether the newly loaned pages are eligile for immediate or delayed

reuse.

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

void CancelLoan (vm_page_t * page)

Marks a page that had been previously provided to BeginLoan as cancelled. This page may be in

the FREE_LOANED state, or presently in use.

This call prevents the page from being reused for any new purpose until EndLoan(). For

presently-FREE_LOANED pages, this removes the pages from free_loaned_list_. For presently-used

pages, this specifies that the page will not be added to free_loaned_list_ when later freed.

Once this page is FREE_LOANED (to be ensured by the caller via PhysicalPageProvider reclaim of

the pages), the loan can be ended with EndLoan().

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

void EndLoan (vm_page_t * page)

Allocates the page to the caller as a regular non-loaned page. Must currently be:

* Loaned (via BeginLoan).

* Have had its loan cancelled (via CancelLoan).

* Be in the FREE_LOANED state.

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

bool SetFreeMemorySignal (uint64_t free_lower_bound, uint64_t free_upper_bound, uint64_t delay_allocations_pages, Event * event)

See |pmm_set_free_memory_signal|

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

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

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.

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

void StopReturningShouldWait ()

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

uint64_t CountFreePages ()

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

uint64_t CountLoanedFreePages ()

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

uint64_t CountLoanCancelledPages ()

Defined at line 988 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 975 of file ../../zircon/kernel/vm/pmm_node.cc

uint64_t CountLoanedPages ()

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

uint64_t CountTotalBytes ()

Defined at line 992 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 996 of file ../../zircon/kernel/vm/pmm_node.cc

void Dump (bool is_panic)

Defined at line 1001 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 160 of file ../../zircon/kernel/vm/pmm_node.cc

void AddFreePages (list_node * list)

add new pages to the free queue. used when boostrapping a PmmArena

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

zx_status_t SetPageCompression (fbl::RefPtr<VmCompression> compression)

Set the page compression instance. Returns an error if one has already been set.

Defined at line 1204 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 208 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 232 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 281 of file ../../zircon/kernel/vm/pmm_node.cc

int64_t get_alloc_failed_count ()

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

bool has_alloc_failed_no_mem ()

See |pmm_has_alloc_failed_no_mem|.

Defined at line 1071 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 1196 of file ../../zircon/kernel/vm/pmm_node.cc

void ReportAllocFailure (AllocFailure failure)

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

AllocFailure GetFirstAllocFailure ()

Retrieves information given to |ReportAllocFailure|. Due to book keeping limitations this will

only return information from the first failure.

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

Records