MentOS  0.8.0
The Mentoring Operating System
Classes | Macros | Typedefs | Functions
buddysystem.h File Reference

Buddy System. More...

Go to the source code of this file.

Classes

struct  bb_page_t
 The base structure representing a bb page. More...
 
struct  bb_free_area_t
 Buddy system descriptor: collection of free page blocks. Each block represents 2^k free contiguous page. More...
 
struct  bb_instance_t
 Buddy system instance, that represents a memory area managed by the buddy system. More...
 

Macros

#define MAX_BUDDYSYSTEM_GFP_ORDER   14
 Max gfp pages order of buddysystem blocks.
 
#define BBSTRUCT_OFFSET(page, element)    ((uint32_t) & (((page *)NULL)->element))
 Provide the offset of the element inside the given type of page.
 
#define PG_FROM_BBSTRUCT(bbstruct, page, element)    ((page *)(((uint32_t)(bbstruct)) - BBSTRUCT_OFFSET(page, element)))
 Returns the address of the given element of a given type of page, based on the provided bbstruct.
 

Typedefs

typedef struct bb_page_t bb_page_t
 The base structure representing a bb page.
 
typedef struct bb_free_area_t bb_free_area_t
 Buddy system descriptor: collection of free page blocks. Each block represents 2^k free contiguous page.
 
typedef struct bb_instance_t bb_instance_t
 Buddy system instance, that represents a memory area managed by the buddy system.
 

Functions

bb_page_tbb_alloc_pages (bb_instance_t *instance, unsigned int order)
 Allocate a block of page frames of size 2^order. More...
 
void bb_free_pages (bb_instance_t *instance, bb_page_t *page)
 Free a block of page frames of size 2^order. More...
 
bb_page_tbb_alloc_page_cached (bb_instance_t *instance)
 Alloc a page using bb cache. More...
 
void bb_free_page_cached (bb_instance_t *instance, bb_page_t *page)
 Free a page allocated with bb_alloc_page_cached. More...
 
void buddy_system_init (bb_instance_t *instance, const char *name, void *pages_start, uint32_t bbpage_offset, uint32_t pages_stride, uint32_t pages_count)
 Initialize Buddy System. More...
 
void buddy_system_dump (bb_instance_t *instance)
 Print the size of free_list of each free_area. More...
 
unsigned long buddy_system_get_total_space (bb_instance_t *instance)
 Returns the total space for the given instance. More...
 
unsigned long buddy_system_get_free_space (bb_instance_t *instance)
 Returns the free space for the given instance. More...
 
unsigned long buddy_system_get_cached_space (bb_instance_t *instance)
 Returns the cached space for the given instance. More...
 

Detailed Description

Buddy System.

Function Documentation

◆ bb_alloc_page_cached()

bb_page_t* bb_alloc_page_cached ( bb_instance_t instance)

Alloc a page using bb cache.

Parameters
instanceBuddy system instance.
Returns
An allocated page.

◆ bb_alloc_pages()

bb_page_t* bb_alloc_pages ( bb_instance_t instance,
unsigned int  order 
)

Allocate a block of page frames of size 2^order.

Parameters
instanceA buddy system instance.
orderThe logarithm of the size of the block.
Returns
The address of the first page descriptor of the block, or NULL.

◆ bb_free_page_cached()

void bb_free_page_cached ( bb_instance_t instance,
bb_page_t page 
)

Free a page allocated with bb_alloc_page_cached.

Parameters
instanceBuddy system instance.
pageThe address of the first page descriptor of the block.

◆ bb_free_pages()

void bb_free_pages ( bb_instance_t instance,
bb_page_t page 
)

Free a block of page frames of size 2^order.

Parameters
instanceA buddy system instance.
pageThe address of the first page descriptor of the block.

◆ buddy_system_dump()

void buddy_system_dump ( bb_instance_t instance)

Print the size of free_list of each free_area.

Parameters
instanceA buddy system instance.

◆ buddy_system_get_cached_space()

unsigned long buddy_system_get_cached_space ( bb_instance_t instance)

Returns the cached space for the given instance.

Parameters
instanceA buddy system instance.
Returns
The requested total sapce.

◆ buddy_system_get_free_space()

unsigned long buddy_system_get_free_space ( bb_instance_t instance)

Returns the free space for the given instance.

Parameters
instanceA buddy system instance.
Returns
The requested total sapce.

◆ buddy_system_get_total_space()

unsigned long buddy_system_get_total_space ( bb_instance_t instance)

Returns the total space for the given instance.

Parameters
instanceA buddy system instance.
Returns
The requested total sapce.

◆ buddy_system_init()

void buddy_system_init ( bb_instance_t instance,
const char *  name,
void *  pages_start,
uint32_t  bbpage_offset,
uint32_t  pages_stride,
uint32_t  pages_count 
)

Initialize Buddy System.

Parameters
instanceA buddysystem instance.
nameThe name of the current instance (for debug purposes)
pages_startThe start address of the page structures
bbpage_offsetThe offset from the start of the whole page of the bb_page_t struct.
pages_strideThe (padded) size of the whole page structure
pages_countThe number of pages in this region