format buddy.c
This commit is contained in:
parent
fd018168a9
commit
a3e56b886e
@ -11,8 +11,7 @@
|
|||||||
* The usable memory: [pool_start_addr, pool_start_addr + pool_mem_size).
|
* The usable memory: [pool_start_addr, pool_start_addr + pool_mem_size).
|
||||||
*/
|
*/
|
||||||
void init_buddy(struct phys_mem_pool *pool, struct page *start_page,
|
void init_buddy(struct phys_mem_pool *pool, struct page *start_page,
|
||||||
vaddr_t start_addr, u64 page_num)
|
vaddr_t start_addr, u64 page_num) {
|
||||||
{
|
|
||||||
int order;
|
int order;
|
||||||
int page_idx;
|
int page_idx;
|
||||||
struct page *page;
|
struct page *page;
|
||||||
@ -31,7 +30,7 @@ void init_buddy(struct phys_mem_pool *pool, struct page *start_page,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Clear the page_metadata area. */
|
/* Clear the page_metadata area. */
|
||||||
memset((char *)start_page, 0, page_num * sizeof(struct page));
|
memset((char *) start_page, 0, page_num * sizeof(struct page));
|
||||||
|
|
||||||
/* Init the page_metadata area. */
|
/* Init the page_metadata area. */
|
||||||
for (page_idx = 0; page_idx < page_num; ++page_idx) {
|
for (page_idx = 0; page_idx < page_num; ++page_idx) {
|
||||||
@ -48,8 +47,7 @@ void init_buddy(struct phys_mem_pool *pool, struct page *start_page,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct page *get_buddy_chunk(struct phys_mem_pool *pool,
|
static struct page *get_buddy_chunk(struct phys_mem_pool *pool,
|
||||||
struct page *chunk)
|
struct page *chunk) {
|
||||||
{
|
|
||||||
u64 chunk_addr;
|
u64 chunk_addr;
|
||||||
u64 buddy_chunk_addr;
|
u64 buddy_chunk_addr;
|
||||||
int order;
|
int order;
|
||||||
@ -72,7 +70,7 @@ static struct page *get_buddy_chunk(struct phys_mem_pool *pool,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return virt_to_page(pool, (void *)buddy_chunk_addr);
|
return virt_to_page(pool, (void *) buddy_chunk_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -87,8 +85,7 @@ static struct page *get_buddy_chunk(struct phys_mem_pool *pool,
|
|||||||
* smaller sub-pages.
|
* smaller sub-pages.
|
||||||
*/
|
*/
|
||||||
static struct page *split_page(struct phys_mem_pool *pool, u64 order,
|
static struct page *split_page(struct phys_mem_pool *pool, u64 order,
|
||||||
struct page *page)
|
struct page *page) {
|
||||||
{
|
|
||||||
// <lab2>
|
// <lab2>
|
||||||
struct page *split_page = NULL;
|
struct page *split_page = NULL;
|
||||||
return split_page;
|
return split_page;
|
||||||
@ -103,8 +100,7 @@ static struct page *split_page(struct phys_mem_pool *pool, u64 order,
|
|||||||
* Hints: Find the corresonding free_list which can allocate 1<<order
|
* Hints: Find the corresonding free_list which can allocate 1<<order
|
||||||
* continuous pages and don't forget to split the list node after allocation
|
* continuous pages and don't forget to split the list node after allocation
|
||||||
*/
|
*/
|
||||||
struct page *buddy_get_pages(struct phys_mem_pool *pool, u64 order)
|
struct page *buddy_get_pages(struct phys_mem_pool *pool, u64 order) {
|
||||||
{
|
|
||||||
// <lab2>
|
// <lab2>
|
||||||
struct page *page = NULL;
|
struct page *page = NULL;
|
||||||
|
|
||||||
@ -121,8 +117,7 @@ struct page *buddy_get_pages(struct phys_mem_pool *pool, u64 order)
|
|||||||
* there is not corresponding buddy page. get_buddy_chunk
|
* there is not corresponding buddy page. get_buddy_chunk
|
||||||
* is helpful in this function.
|
* is helpful in this function.
|
||||||
*/
|
*/
|
||||||
static struct page *merge_page(struct phys_mem_pool *pool, struct page *page)
|
static struct page *merge_page(struct phys_mem_pool *pool, struct page *page) {
|
||||||
{
|
|
||||||
// <lab2>
|
// <lab2>
|
||||||
|
|
||||||
struct page *merge_page = NULL;
|
struct page *merge_page = NULL;
|
||||||
@ -137,25 +132,22 @@ static struct page *merge_page(struct phys_mem_pool *pool, struct page *page)
|
|||||||
*
|
*
|
||||||
* Hints: you can invoke merge_page.
|
* Hints: you can invoke merge_page.
|
||||||
*/
|
*/
|
||||||
void buddy_free_pages(struct phys_mem_pool *pool, struct page *page)
|
void buddy_free_pages(struct phys_mem_pool *pool, struct page *page) {
|
||||||
{
|
|
||||||
// <lab2>
|
// <lab2>
|
||||||
|
|
||||||
// </lab2>
|
// </lab2>
|
||||||
}
|
}
|
||||||
|
|
||||||
void *page_to_virt(struct phys_mem_pool *pool, struct page *page)
|
void *page_to_virt(struct phys_mem_pool *pool, struct page *page) {
|
||||||
{
|
|
||||||
u64 addr;
|
u64 addr;
|
||||||
|
|
||||||
/* page_idx * BUDDY_PAGE_SIZE + start_addr */
|
/* page_idx * BUDDY_PAGE_SIZE + start_addr */
|
||||||
addr = (page - pool->page_metadata) * BUDDY_PAGE_SIZE +
|
addr = (page - pool->page_metadata) * BUDDY_PAGE_SIZE +
|
||||||
pool->pool_start_addr;
|
pool->pool_start_addr;
|
||||||
return (void *)addr;
|
return (void *) addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct page *virt_to_page(struct phys_mem_pool *pool, void *addr)
|
struct page *virt_to_page(struct phys_mem_pool *pool, void *addr) {
|
||||||
{
|
|
||||||
struct page *page;
|
struct page *page;
|
||||||
|
|
||||||
page = pool->page_metadata +
|
page = pool->page_metadata +
|
||||||
@ -163,8 +155,7 @@ struct page *virt_to_page(struct phys_mem_pool *pool, void *addr)
|
|||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 get_free_mem_size_from_buddy(struct phys_mem_pool * pool)
|
u64 get_free_mem_size_from_buddy(struct phys_mem_pool *pool) {
|
||||||
{
|
|
||||||
int order;
|
int order;
|
||||||
struct free_list *list;
|
struct free_list *list;
|
||||||
u64 current_order_size;
|
u64 current_order_size;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user