|
PatchworkOS
c9fea19
A non-POSIX operating system.
|
Physical Memory Manager (PMM). More...
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. | |
| void pmm_init | ( | void | ) |
| void * pmm_alloc | ( | void | ) |
Allocates a single physical page.
The returned page will not be zeroed.
NULL. Definition at line 171 of file pmm.c.
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.
| addresses | An array where the higher half physical addresses of the allocated pages will be stored. |
| count | The number of pages to allocate. |
0. On failure, ERR and errno is set. Definition at line 184 of file pmm.c.
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.
| count | The number of contiguous pages to allocate. |
| maxAddr | The maximum physical address (exclusive) for the allocation. |
| alignment | The required alignment for the allocated region, in bytes. |
NULL. Definition at line 207 of file pmm.c.
| 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.
| address | The higher half physical address of the page to free. |
Definition at line 220 of file pmm.c.
| 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.
| addresses | An array containing the higher half physical addresses of the pages to free. |
| count | The number of pages to free. |
Definition at line 226 of file pmm.c.
| 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.
| address | The higher half physical address of the first page in the region to free. |
| count | The number of pages to free. |
Definition at line 235 of file pmm.c.
| uint64_t pmm_total_amount | ( | void | ) |
| uint64_t pmm_free_amount | ( | void | ) |
| uint64_t pmm_used_amount | ( | void | ) |