MentOS
0.8.0
The Mentoring Operating System
|
Buddy System. More...
Macros | |
#define | __DEBUG_HEADER__ "[BUDDY ]" |
Change header. | |
#define | __DEBUG_LEVEL__ LOGLEVEL_NOTICE |
Set log level. | |
#define | LOW_WATERMARK_LEVEL 10 |
Cache level low limit after which allocation starts. | |
#define | HIGH_WATERMARK_LEVEL 70 |
Cache level high limit, above it deallocation happens. | |
#define | MID_WATERMARK_LEVEL ((LOW_WATERMARK_LEVEL + HIGH_WATERMARK_LEVEL) / 2) |
Cache level midway limit. | |
Enumerations | |
enum | bb_flag { FREE_PAGE = 0 , ROOT_PAGE = 1 } |
Bitwise flags for identifying page types and statuses. More... | |
Functions | |
static void | __bb_set_flag (bb_page_t *page, int flag) |
Sets the given flag in the page. More... | |
static void | __bb_clear_flag (bb_page_t *page, int flag) |
Clears the given flag from the page. More... | |
static int | __bb_test_flag (bb_page_t *page, int flag) |
Gets the given flag from the page. More... | |
static bb_page_t * | __get_page_from_base (bb_instance_t *instance, bb_page_t *base, unsigned int index) |
Returns the page at the given index, starting from the given base. More... | |
static bb_page_t * | __get_page_at_index (bb_instance_t *instance, unsigned int index) |
Returns the page at the given index, starting from the first page of the BB system. More... | |
static unsigned int | __get_page_range (bb_instance_t *instance, bb_page_t *begin, bb_page_t *end) |
Computes the number of pages separating the two pages (begin, end). More... | |
static unsigned long | __get_buddy_at_index (unsigned long page_idx, unsigned int order) |
Get the buddy index of a page. More... | |
static bb_free_area_t * | __get_area_of_order (bb_instance_t *instance, unsigned int order) |
Returns the pointer to the free-area manager for the given order. More... | |
static int | __page_is_buddy (bb_page_t *page, unsigned int order) |
Checks if the page is FREE and has the same order. More... | |
bb_page_t * | bb_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... | |
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... | |
static void | __cache_extend (bb_instance_t *instance, int count) |
Extenmds the cache of the given amount. More... | |
static void | __cache_shrink (bb_instance_t *instance, int count) |
Shrinks the cache. More... | |
static bb_page_t * | __cached_alloc (bb_instance_t *instance) |
Allocate memory using the given cache. More... | |
static void | __cached_free (bb_instance_t *instance, bb_page_t *page) |
Frees the memory of the allocated page. More... | |
bb_page_t * | bb_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... | |
Buddy System.
enum bb_flag |
|
inlinestatic |
Clears the given flag from the page.
page | The page of which we want to modify the flag. |
flag | The flag we want to clear. |
|
inlinestatic |
Sets the given flag in the page.
page | The page of which we want to modify the flag. |
flag | The flag we want to set. |
|
inlinestatic |
Gets the given flag from the page.
page | The page of which we want to modify the flag. |
flag | The flag we want to test. |
|
static |
Extenmds the cache of the given amount.
instance | the cache instance. |
count | the amount to extend to. |
|
static |
Shrinks the cache.
instance | the cache instance. |
count | the amount to shrink. |
|
static |
Allocate memory using the given cache.
instance | the cache instance. |
|
static |
Frees the memory of the allocated page.
instance | the cache instance. |
page | a pointer to the allocated page. |
|
inlinestatic |
Returns the pointer to the free-area manager for the given order.
instance | the buddysystem instance. |
order | the desired order. |
|
inlinestatic |
Get the buddy index of a page.
--------------------— xor --------------------— | page_idx ^ (1UL << order) = buddy_idx | | 1 1 0 |
If the bit of page_idx that corresponds to the block size, is 1, then we have to take the block on the left (0), otherwise we have to take the block on the right (1).
page_idx | the page index. |
order | the logarithm of the size of the block. |
|
inlinestatic |
Returns the page at the given index, starting from the first page of the BB system.
instance | The buddy system instance we are working with. |
index | The number of pages we want to move from the first page. |
|
inlinestatic |
Returns the page at the given index, starting from the given base.
instance | The buddy system instance we are working with. |
base | The base page from which we move at the given index. |
index | The number of pages we want to move from the base. |
|
inlinestatic |
Computes the number of pages separating the two pages (begin, end).
instance | the buddy system instance we are working with. |
begin | the first page. |
end | the second page. |
|
inlinestatic |
Checks if the page is FREE and has the same order.
page | the page to check. |
order | the oder to check. |
bb_page_t* bb_alloc_page_cached | ( | bb_instance_t * | instance | ) |
Alloc a page using bb cache.
instance | Buddy system instance. |
bb_page_t* bb_alloc_pages | ( | bb_instance_t * | instance, |
unsigned int | order | ||
) |
Allocate a block of page frames of size 2^order.
instance | A buddy system instance. |
order | The logarithm of the size of the block. |
void bb_free_page_cached | ( | bb_instance_t * | instance, |
bb_page_t * | page | ||
) |
Free a page allocated with bb_alloc_page_cached.
instance | Buddy system instance. |
page | The address of the first page descriptor of the block. |
void bb_free_pages | ( | bb_instance_t * | instance, |
bb_page_t * | page | ||
) |
Free a block of page frames of size 2^order.
instance | A buddy system instance. |
page | The address of the first page descriptor of the block. |
void buddy_system_dump | ( | bb_instance_t * | instance | ) |
Print the size of free_list of each free_area.
instance | A buddy system instance. |
unsigned long buddy_system_get_cached_space | ( | bb_instance_t * | instance | ) |
Returns the cached space for the given instance.
instance | A buddy system instance. |
unsigned long buddy_system_get_free_space | ( | bb_instance_t * | instance | ) |
Returns the free space for the given instance.
instance | A buddy system instance. |
unsigned long buddy_system_get_total_space | ( | bb_instance_t * | instance | ) |
Returns the total space for the given instance.
instance | A buddy system instance. |
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.
instance | A buddysystem instance. |
name | The name of the current instance (for debug purposes) |
pages_start | The start address of the page structures |
bbpage_offset | The offset from the start of the whole page of the bb_page_t struct. |
pages_stride | The (padded) size of the whole page structure |
pages_count | The number of pages in this region |