PatchworkOS
Loading...
Searching...
No Matches
PMM Stack

A generic free stack page allocator. More...

Data Structures

struct  page_buffer_t
 Structure for a page buffer in the PMM stack. More...
 
struct  pmm_stack_t
 PMM stack structure for managing higher physical memory. More...
 

Macros

#define PMM_BUFFER_MAX   ((PAGE_SIZE - sizeof(page_buffer_t)) / sizeof(void*))
 The maximum number of pages that can be stored in a page_buffer_t.
 

Functions

void pmm_stack_init (pmm_stack_t *stack)
 Initializes a PMM stack.
 
void * pmm_stack_alloc (pmm_stack_t *stack)
 Allocates a single page from the stack.
 
void pmm_stack_free (pmm_stack_t *stack, void *address)
 Frees a single page, returning it to the stack.
 

Detailed Description

A generic free stack page allocator.

The PMM stack provides a fast, O(1) allocator for single pages. It uses freed pages to store metadata about other free pages, forming a stack of page buffers.

Macro Definition Documentation

◆ PMM_BUFFER_MAX

#define PMM_BUFFER_MAX   ((PAGE_SIZE - sizeof(page_buffer_t)) / sizeof(void*))

The maximum number of pages that can be stored in a page_buffer_t.

Definition at line 36 of file pmm_stack.h.

Function Documentation

◆ pmm_stack_alloc()

void * pmm_stack_alloc ( pmm_stack_t stack)

Allocates a single page from the stack.

Parameters
stackThe stack to allocate from.
Returns
On success, a pointer to the allocated page. On failure NULL and errno is set.

Definition at line 12 of file pmm_stack.c.

References address, pmm_stack_t::free, pmm_stack_t::index, pmm_stack_t::last, NULL, page_buffer_t::pages, PMM_BUFFER_MAX, page_buffer_t::prev, and stack.

Referenced by pmm_alloc(), and pmm_alloc_pages().

◆ pmm_stack_free()

void pmm_stack_free ( pmm_stack_t stack,
void *  address 
)

Frees a single page, returning it to the stack.

Parameters
stackThe stack to free to.
addressThe address of the page to free.

Definition at line 36 of file pmm_stack.c.

References address, pmm_stack_t::free, pmm_stack_t::index, pmm_stack_t::last, next, NULL, PAGE_SIZE, page_buffer_t::pages, PMM_BUFFER_MAX, page_buffer_t::prev, ROUND_DOWN, and stack.

Referenced by pmm_alloc_pages(), pmm_free_pages_unlocked(), and pmm_free_unlocked().

◆ pmm_stack_init()

void pmm_stack_init ( pmm_stack_t stack)

Initializes a PMM stack.

Parameters
stackThe stack to initialize.

Definition at line 5 of file pmm_stack.c.

References pmm_stack_t::free, pmm_stack_t::index, pmm_stack_t::last, NULL, and stack.

Referenced by pmm_init().