MentOS
0.8.0
The Mentoring Operating System
|
Implementation of the Zone Allocator. More...
Macros | |
#define | __DEBUG_HEADER__ "[PMM ]" |
Change header. | |
#define | __DEBUG_LEVEL__ LOGLEVEL_NOTICE |
Set log level. | |
#define | MIN_PAGE_ALIGN(addr) ((addr) & (~(PAGE_SIZE - 1))) |
Aligns the given address down to the nearest page boundary. More... | |
#define | MAX_PAGE_ALIGN(addr) (((addr) & (~(PAGE_SIZE - 1))) + PAGE_SIZE) |
Aligns the given address up to the nearest page boundary. More... | |
#define | MIN_ORDER_ALIGN(addr) ((addr) & (~((PAGE_SIZE << (MAX_BUDDYSYSTEM_GFP_ORDER - 1)) - 1))) |
Aligns the given address down to the nearest order boundary. More... | |
#define | MAX_ORDER_ALIGN(addr) |
Aligns the given address up to the nearest order boundary. More... | |
Functions | |
uint32_t | get_virtual_address_from_page (page_t *page) |
Converts a page structure to its corresponding low memory virtual address. More... | |
uint32_t | get_physical_address_from_page (page_t *page) |
Converts a page structure to its corresponding physical address. More... | |
page_t * | get_page_from_virtual_address (uint32_t vaddr) |
Retrieves the low memory page corresponding to the given virtual address. More... | |
page_t * | get_page_from_physical_address (uint32_t phy_addr) |
Retrieves the page structure corresponding to a given physical address. More... | |
static zone_t * | get_zone_from_page (page_t *page) |
Get the zone that contains a page frame. More... | |
static zone_t * | get_zone_from_flags (gfp_t gfp_mask) |
Get a zone from the specified GFP mask. More... | |
static int | is_memory_clean (gfp_t gfp_mask) |
Checks if the specified memory zone is clean (i.e., all pages are free). More... | |
static int | pmm_check (void) |
Checks if the physical memory manager is working properly. More... | |
static int | zone_init (char *name, int zone_index, uint32_t adr_from, uint32_t adr_to) |
Initializes the memory attributes for a specified zone. More... | |
unsigned int | find_nearest_order_greater (uint32_t base_addr, uint32_t amount) |
Finds the nearest order of memory allocation that can accommodate a given amount of memory. More... | |
int | pmmngr_init (boot_info_t *boot_info) |
Physical memory manager initialization. More... | |
page_t * | alloc_page_cached (gfp_t gfp_mask) |
Allocates a cached page based on the given GFP mask. More... | |
int | free_page_cached (page_t *page) |
Free a page allocated with alloc_page_cached. More... | |
uint32_t | __alloc_page_lowmem (gfp_t gfp_mask) |
Find the first free page frame, set it allocated and return the memory address of the page frame. More... | |
int | free_page_lowmem (uint32_t addr) |
Frees the given page frame address. More... | |
uint32_t | __alloc_pages_lowmem (gfp_t gfp_mask, uint32_t order) |
Find the first free 2^order amount of page frames, set it allocated and return the memory address of the first page frame allocated. More... | |
page_t * | _alloc_pages (gfp_t gfp_mask, uint32_t order) |
Find the first free 2^order amount of page frames, set it allocated and return the memory address of the first page frame allocated. More... | |
int | free_pages_lowmem (uint32_t addr) |
Frees from the given page frame address up to 2^order amount of page frames. More... | |
int | __free_pages (page_t *page) |
Frees from the given page frame address up to 2^order amount of page frames. More... | |
unsigned long | get_zone_total_space (gfp_t gfp_mask) |
Retrieves the total space of the zone corresponding to the given GFP mask. More... | |
unsigned long | get_zone_free_space (gfp_t gfp_mask) |
Retrieves the free space of the zone corresponding to the given GFP mask. More... | |
unsigned long | get_zone_cached_space (gfp_t gfp_mask) |
Retrieves the cached space of the zone corresponding to the given GFP mask. More... | |
Variables | |
page_t * | mem_map = NULL |
Array of all physical memory blocks (pages). More... | |
pg_data_t * | contig_page_data = NULL |
Memory node descriptor for contiguous memory. More... | |
uint32_t | lowmem_virt_base = 0 |
Virtual base address of the low memory (lowmem) zone. More... | |
uint32_t | lowmem_page_base = 0 |
Physical base address of the low memory (lowmem) zone. More... | |
uint32_t | lowmem_phy_start |
Physical start address of low memory (lowmem) zone. More... | |
uint32_t | lowmem_virt_start |
Virtual start address of low memory (lowmem) zone. More... | |
uint32_t | mem_size |
Total size of available physical memory in bytes. More... | |
uint32_t | mem_map_num |
Total number of memory frames (pages) available. More... | |
uint32_t | normal_start_addr |
Start address of the normal (lowmem) zone. More... | |
uint32_t | normal_end_addr |
End address of the normal (lowmem) zone. More... | |
uint32_t | normal_size |
Total size of the normal (lowmem) zone. More... | |
uint32_t | high_start_addr |
Start address of the high memory (highmem) zone. More... | |
uint32_t | high_end_addr |
End address of the high memory (highmem) zone. More... | |
uint32_t | high_size |
Total size of the high memory (highmem) zone. More... | |
Implementation of the Zone Allocator.
#define MAX_ORDER_ALIGN | ( | addr | ) |
Aligns the given address up to the nearest order boundary.
addr | The address to align. |
Aligns the given address up to the nearest page boundary.
addr | The address to align. |
#define MIN_ORDER_ALIGN | ( | addr | ) | ((addr) & (~((PAGE_SIZE << (MAX_BUDDYSYSTEM_GFP_ORDER - 1)) - 1))) |
Aligns the given address down to the nearest order boundary.
addr | The address to align. |
#define MIN_PAGE_ALIGN | ( | addr | ) | ((addr) & (~(PAGE_SIZE - 1))) |
Aligns the given address down to the nearest page boundary.
addr | The address to align. |
Find the first free page frame, set it allocated and return the memory address of the page frame.
gfp_mask | GFP_FLAGS to decide the zone allocation. |
Find the first free 2^order amount of page frames, set it allocated and return the memory address of the first page frame allocated.
gfp_mask | GFP_FLAGS to decide the zone allocation. |
order | The logarithm of the size of the page frame. |
int __free_pages | ( | page_t * | page | ) |
Frees from the given page frame address up to 2^order amount of page frames.
page | The page. |
Find the first free 2^order amount of page frames, set it allocated and return the memory address of the first page frame allocated.
gfp_mask | GFP_FLAGS to decide the zone allocation. |
order | The logarithm of the size of the page frame. |
Allocates a cached page based on the given GFP mask.
gfp_mask | The GFP mask specifying the allocation constraints. |
Finds the nearest order of memory allocation that can accommodate a given amount of memory.
base_addr | the base address from which to calculate the number of pages. |
amount | the amount of memory (in bytes) to allocate. |
int free_page_cached | ( | page_t * | page | ) |
Free a page allocated with alloc_page_cached.
page | Pointer to the page to free. |
int free_page_lowmem | ( | uint32_t | addr | ) |
Frees the given page frame address.
addr | The block address. |
int free_pages_lowmem | ( | uint32_t | addr | ) |
Frees from the given page frame address up to 2^order amount of page frames.
addr | The page frame address. |
Retrieves the page structure corresponding to a given physical address.
paddr | The physical address for which the page structure is requested. |
Retrieves the low memory page corresponding to the given virtual address.
vaddr | the virtual address to convert. |
Converts a page structure to its corresponding physical address.
page | Pointer to the page structure. |
Converts a page structure to its corresponding low memory virtual address.
page | Pointer to the page structure. |
unsigned long get_zone_cached_space | ( | gfp_t | gfp_mask | ) |
Retrieves the cached space of the zone corresponding to the given GFP mask.
gfp_mask | The GFP mask specifying the allocation constraints. |
unsigned long get_zone_free_space | ( | gfp_t | gfp_mask | ) |
Retrieves the free space of the zone corresponding to the given GFP mask.
gfp_mask | The GFP mask specifying the allocation constraints. |
Get a zone from the specified GFP mask.
gfp_mask | GFP flags indicating the type of memory allocation request. |
Get the zone that contains a page frame.
page | A pointer to the page descriptor. |
unsigned long get_zone_total_space | ( | gfp_t | gfp_mask | ) |
Retrieves the total space of the zone corresponding to the given GFP mask.
gfp_mask | The GFP mask specifying the allocation constraints. |
|
static |
Checks if the specified memory zone is clean (i.e., all pages are free).
gfp_mask | The mask that specifies the zone of interest for memory allocation. |
|
static |
Checks if the physical memory manager is working properly.
int pmmngr_init | ( | boot_info_t * | boot_info | ) |
Physical memory manager initialization.
boot_info | Information coming from the booloader. |
Initializes the memory attributes for a specified zone.
name | The zone's name. |
zone_index | The zone's index, which must be valid within the number of zones. |
adr_from | The lowest address of the zone (inclusive). |
adr_to | The highest address of the zone (exclusive). |
Memory node descriptor for contiguous memory.
This variable points to the pg_data_t
structure, which represents a memory node (usually for NUMA systems). It typically describes the memory properties and zones for a contiguous block of physical memory.
uint32_t high_end_addr |
End address of the high memory (highmem) zone.
This variable holds the ending physical address of the high memory zone, which marks the limit of available physical memory.
uint32_t high_size |
Total size of the high memory (highmem) zone.
The size of the high memory zone in bytes. High memory requires special handling as it is not directly accessible by the kernel's virtual address space.
uint32_t high_start_addr |
Start address of the high memory (highmem) zone.
This variable stores the starting physical address of the high memory zone, which is memory not directly addressable by the kernel and requires special handling.
uint32_t lowmem_page_base = 0 |
Physical base address of the low memory (lowmem) zone.
This variable stores the base physical address of the low memory region. It represents the starting point of the lowmem pages in physical memory.
uint32_t lowmem_phy_start |
Physical start address of low memory (lowmem) zone.
This variable stores the physical address where the low memory (which is directly addressable by the kernel) begins.
uint32_t lowmem_virt_base = 0 |
Virtual base address of the low memory (lowmem) zone.
This variable stores the base virtual address of the low memory region. The kernel uses this address to access low memory (directly addressable memory).
uint32_t lowmem_virt_start |
Virtual start address of low memory (lowmem) zone.
This variable stores the virtual address corresponding to the start of the low memory region in the kernel's virtual address space.
Array of all physical memory blocks (pages).
This variable points to an array of page_t
structures representing all physical memory blocks (pages) in the system. It is used to track the state of each page in memory.
uint32_t mem_map_num |
Total number of memory frames (pages) available.
The number of physical memory frames available in the system, calculated as the total memory divided by the size of a memory page.
uint32_t mem_size |
Total size of available physical memory in bytes.
This variable holds the total amount of memory available on the system (both low and high memory).
uint32_t normal_end_addr |
End address of the normal (lowmem) zone.
This variable holds the ending physical address of the normal memory zone (low memory), marking the boundary between lowmem and highmem.
uint32_t normal_size |
Total size of the normal (lowmem) zone.
The size of the normal memory zone in bytes, which is the portion of memory directly addressable by the kernel.
uint32_t normal_start_addr |
Start address of the normal (lowmem) zone.
This variable holds the starting physical address of the normal memory zone, also known as low memory, which is directly addressable by the kernel.