Lab 3 Buddy Allocator
Understand and improve physical memory allocator
The Problem
Your Task
Task 1:
Task 2:
Solution
Allocate file use buddy allocator
struct file*
filealloc(void)
{
struct file *f;
acquire(&ftable.lock);
char *p = bd_malloc(sizeof(ftable.file));
f = (struct file*) p;
f->ref = 1;
release(&ftable.lock);
return f;
}Close file should release memory
Only one bit for each pair of blocks
Add flip bit helpers
Replace bit_set usage with flip_bit
bit_set usage with flip_bitReplace bit_clear usage with flip_bit
bit_clear usage with flip_bitReplace bit_isset usage with bit_alloc_get
bit_isset usage with bit_alloc_getAdd in range check
Change how buddy allocation initialize
Reduce the bit size
Next Step?
心得
xv6 buddy allocatorLast updated