|
PatchworkOS
|
Physical Memory Manager (PMM). More...
Functions | |
| void | pmm_init (const boot_memory_map_t *map) |
| 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_reserved_amount (void) |
| Retrieves the amount of reserved physical memory. | |
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.
| void * pmm_alloc | ( | void | ) |
Allocates a single physical page.
The returned page will not be zeroed.
NULL. Definition at line 162 of file pmm.c.
References address, ENOMEM, errno, pmm_stack_t::free, lock, LOCK_SCOPE, LOG_WARN, NULL, pmm_stack_alloc(), and stack.
Referenced by pipe_open(), pipe_open2(), shmem_object_allocate_pages(), simd_ctx_init(), space_populate_user_region(), and trampoline_init().
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 198 of file pmm.c.
References address, bitmap, count, ENOMEM, errno, pmm_bitmap_t::free, lock, LOCK_SCOPE, LOG_WARN, NULL, and pmm_bitmap_alloc().
Referenced by space_pmm_bitmap_alloc_pages().
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 175 of file pmm.c.
References address, count, ENOMEM, ERR, errno, pmm_stack_t::free, lock, LOCK_SCOPE, LOG_WARN, NULL, pmm_stack_alloc(), pmm_stack_free(), and stack.
Referenced by space_init(), and vmm_alloc().
| 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 211 of file pmm.c.
References address, lock, LOCK_SCOPE, and pmm_free_unlocked().
Referenced by pipe_close(), shmem_object_allocate_pages(), shmem_object_free(), simd_ctx_deinit(), space_pmm_bitmap_alloc_pages(), space_populate_user_region(), and trampoline_deinit().
| uint64_t pmm_free_amount | ( | void | ) |
Retrieves the amount of free physical memory.
Definition at line 238 of file pmm.c.
References bitmap, pmm_bitmap_t::free, pmm_stack_t::free, lock, LOCK_SCOPE, and stack.
Referenced by panic(), pmm_load_memory(), and statistics_mem_read().
| 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 217 of file pmm.c.
References count, lock, LOCK_SCOPE, and pmm_free_unlocked().
Referenced by space_init().
| 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 226 of file pmm.c.
References address, count, lock, LOCK_SCOPE, and pmm_free_pages_unlocked().
Referenced by acpi_reclaim_memory(), and init_free_loader_data().
| void pmm_init | ( | const boot_memory_map_t * | map | ) |
Initializes the Physical Memory Manager.
| map | The EFI memory map provided by the bootloader. |
Definition at line 152 of file pmm.c.
References bitmap, CONFIG_PMM_BITMAP_MAX_ADDR, map, mapBuffer, pmm_bitmap_init(), PMM_BITMAP_SIZE, pmm_detect_memory(), pmm_load_memory(), pmm_stack_init(), and stack.
Referenced by init_early().
| uint64_t pmm_reserved_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).
Definition at line 244 of file pmm.c.
References bitmap, pmm_bitmap_t::free, pmm_stack_t::free, lock, LOCK_SCOPE, pageAmount, and stack.
Referenced by init_finalize(), panic(), and statistics_mem_read().
| uint64_t pmm_total_amount | ( | void | ) |
Retrieves the total amount of physical memory managed by the PMM.
Definition at line 232 of file pmm.c.
References lock, LOCK_SCOPE, and pageAmount.
Referenced by statistics_mem_read().