PatchworkOS  c9fea19
A non-POSIX operating system.
Loading...
Searching...
No Matches

Physical Memory Manager (PMM). More...

Collaboration diagram for PMM:

Detailed Description

Physical Memory Manager (PMM).

The Physical Memory Manager (PMM) is responsible for managing physical memory pages. It uses a free stack for allocating single pages in constant-time, and for more specialized allocations (requiring a specific address range or alignment) a bitmap allocator is used. The bitmap allocator should only be used when no other option is available.

All physical memory is identity mapped to the beginning of the higher half of the address space. This means that for example NULL is always an invalid address and that the PMM returns addresses in the higher half.

The free stack provides some advantages over for instance a free list, mainly due to cache improvements.

Functions

void pmm_init (void)
 Initializes the Physical Memory Manager.
 
void * pmm_alloc (void)
 Allocates a single physical page.
 
uint64_t pmm_alloc_pages (void **addresses, uint64_t count)
 Allocates multiple physical pages.
 
void * pmm_alloc_bitmap (uint64_t count, uintptr_t maxAddr, uint64_t alignment)
 Allocates a contiguous region of physical pages managed by the bitmap.
 
void pmm_free (void *address)
 Frees a single physical page.
 
void pmm_free_pages (void **addresses, uint64_t count)
 Frees multiple physical pages.
 
void pmm_free_region (void *address, uint64_t count)
 Frees a contiguous region of physical pages.
 
uint64_t pmm_total_amount (void)
 Retrieves the total amount of physical memory managed by the PMM.
 
uint64_t pmm_free_amount (void)
 Retrieves the amount of free physical memory.
 
uint64_t pmm_used_amount (void)
 Retrieves the amount of reserved physical memory.
 

Function Documentation

◆ pmm_init()

void pmm_init ( void  )

Initializes the Physical Memory Manager.

Definition at line 158 of file pmm.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pmm_alloc()

void * pmm_alloc ( void  )

Allocates a single physical page.

The returned page will not be zeroed.

Returns
On success, returns the higher half physical address of the allocated page. On failure, returns NULL.

Definition at line 171 of file pmm.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pmm_alloc_pages()

uint64_t pmm_alloc_pages ( void **  addresses,
uint64_t  count 
)

Allocates multiple physical pages.

The pmm_alloc_pages function allocates count non-contiguous physical pages from the free stack, by using this function its possible to avoid holding the lock for each page allocation, improving performance when allocating many pages at once.

The returned pages will not be zeroed.

Parameters
addressesAn array where the higher half physical addresses of the allocated pages will be stored.
countThe number of pages to allocate.
Returns
On success, 0. On failure, ERR and errno is set.

Definition at line 184 of file pmm.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pmm_alloc_bitmap()

void * pmm_alloc_bitmap ( uint64_t  count,
uintptr_t  maxAddr,
uint64_t  alignment 
)

Allocates a contiguous region of physical pages managed by the bitmap.

The pmm_alloc_bitmap function allocates a contiguous block of count physical pages from the memory region managed by the bitmap. It also enforces a maximum address and alignment for the allocation.

The returned pages will not be zeroed.

Parameters
countThe number of contiguous pages to allocate.
maxAddrThe maximum physical address (exclusive) for the allocation.
alignmentThe required alignment for the allocated region, in bytes.
Returns
On success, returns the higher half physical address of the allocated region. On failure, returns NULL.

Definition at line 207 of file pmm.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pmm_free()

void pmm_free ( void *  address)

Frees a single physical page.

The pmm_free function frees a page returning ownership of it to the PMM. The PMM will determine based on the address if it's owned by the bitmap or the free stack.

Parameters
addressThe higher half physical address of the page to free.

Definition at line 220 of file pmm.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pmm_free_pages()

void pmm_free_pages ( void **  addresses,
uint64_t  count 
)

Frees multiple physical pages.

The pmm_free_pages function frees count physical pages returning ownership of them to the PMM. The PMM will determine based on the addresses if they're owned by the bitmap or the free stack.

Parameters
addressesAn array containing the higher half physical addresses of the pages to free.
countThe number of pages to free.

Definition at line 226 of file pmm.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pmm_free_region()

void pmm_free_region ( void *  address,
uint64_t  count 
)

Frees a contiguous region of physical pages.

The pmm_free_region function frees a contiguous block of count physical pages, returning ownership of them to the PMM. The PMM will determine based on the address if it's owned by the bitmap or the free stack.

Parameters
addressThe higher half physical address of the first page in the region to free.
countThe number of pages to free.

Definition at line 235 of file pmm.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pmm_total_amount()

uint64_t pmm_total_amount ( void  )

Retrieves the total amount of physical memory managed by the PMM.

Returns
The total amount of physical memory in pages.

Definition at line 241 of file pmm.c.

Here is the caller graph for this function:

◆ pmm_free_amount()

uint64_t pmm_free_amount ( void  )

Retrieves the amount of free physical memory.

Returns
The amount of currently free physical memory in pages.

Definition at line 247 of file pmm.c.

Here is the caller graph for this function:

◆ pmm_used_amount()

uint64_t pmm_used_amount ( void  )

Retrieves the amount of reserved physical memory.

Reserved memory includes memory that is not available for allocation (e.g., kernel code, hardware regions).

Returns
The amount of reserved physical memory in pages.

Definition at line 253 of file pmm.c.

Here is the caller graph for this function: