MOS Source Code
|
#include "mos/lib/sync/spinlock.h"
#include "mos/mm/physical/buddy.h"
#include "mos/mm/physical/pmm.h"
#include "mos/syslog/printk.h"
#include <mos/lib/structures/list.h>
#include <mos_stdlib.h>
Go to the source code of this file.
Macros | |
#define | log2(x) |
#define | log2_ceil(x) |
Functions | |
static void | add_to_freelist (size_t order, phyframe_t *frame) |
static pfn_t | get_buddy_pfn (size_t page_pfn, size_t order) |
static void | dump_list (size_t order) |
static void | populate_freelist (const size_t start_pfn, const size_t nframes, const size_t order) |
Add [start_pfn, start_pfn + nframes - 1] to the freelist of order order | |
static void | break_this_pfn (pfn_t this_pfn, size_t this_order) |
static void | extract_exact_range (pfn_t start, size_t nframes, enum phyframe_state state) |
static void | break_the_order (const size_t order) |
static bool | try_merge (const pfn_t pfn, u8 order) |
Try finding a buddy frame and merging it with the given frame. | |
void | buddy_dump_all () |
Dump the state of the buddy allocator. | |
void | buddy_init (size_t max_nframes) |
Initialize the buddy allocator with the given maximum number of frames. | |
void | buddy_reserve_n (pfn_t pfn, size_t nframes) |
Reserve several frames at the given physical frame number. | |
phyframe_t * | buddy_alloc_n_exact (size_t nframes) |
Allocate nframes of contiguous physical memory. | |
void | buddy_free_n (pfn_t pfn, size_t nframes) |
Free nframes of contiguous physical memory. | |
Variables | ||
static const size_t | orders [] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 } | |
static const size_t | max_order = MOS_ARRAY_SIZE(orders) - 1 | |
struct { | ||
list_head freelists [MOS_ARRAY_SIZE(orders)] | ||
} | buddy = { 0 } | |
static spinlock_t | buddy_lock = SPINLOCK_INIT | |
#define log2 | ( | x | ) |
Definition at line 11 of file buddy_core.c.
Referenced by buddy_init().
#define log2_ceil | ( | x | ) |
Definition at line 16 of file buddy_core.c.
Referenced by buddy_alloc_n_exact(), and buddy_free_n().
|
static |
Definition at line 28 of file buddy_core.c.
Referenced by break_the_order(), break_this_pfn(), buddy_free_n(), populate_freelist(), and try_merge().
Definition at line 46 of file buddy_core.c.
Referenced by try_merge().
Definition at line 52 of file buddy_core.c.
Referenced by buddy_dump_all().
|
static |
Add [start_pfn, start_pfn + nframes - 1] to the freelist of order order
start_pfn | physical frame number of the first frame in the block |
nframes | number of frames in the block |
order | order of the block, must be in [0, MAX_ORDER] |
Definition at line 74 of file buddy_core.c.
Referenced by buddy_init(), and populate_freelist().
Definition at line 102 of file buddy_core.c.
Referenced by extract_exact_range().
Definition at line 123 of file buddy_core.c.
Referenced by buddy_alloc_n_exact(), and buddy_reserve_n().
Definition at line 216 of file buddy_core.c.
Referenced by break_the_order(), and buddy_alloc_n_exact().
Try finding a buddy frame and merging it with the given frame.
pfn | physical frame number |
order | order of the frame, given by log2(nframes) |
Definition at line 257 of file buddy_core.c.
Referenced by buddy_free_n(), and try_merge().
void buddy_dump_all | ( | ) |
Dump the state of the buddy allocator.
Definition at line 301 of file buddy_core.c.
Referenced by pmm_dump_lists().
Initialize the buddy allocator with the given maximum number of frames.
max_nframes | The maximum number of frames that are addressable on the system. |
Definition at line 309 of file buddy_core.c.
Referenced by pmm_init().
Reserve several frames at the given physical frame number.
pfn | The physical frame number to reserve. |
nframes | The number of frames to reserve. |
Definition at line 323 of file buddy_core.c.
Referenced by pmm_reserve_frames().
phyframe_t * buddy_alloc_n_exact | ( | size_t | nframes | ) |
Allocate nframes of contiguous physical memory.
nframes | The number of frames to allocate. |
Definition at line 331 of file buddy_core.c.
Referenced by pmm_allocate_frames().
Free nframes of contiguous physical memory.
pfn | The physical frame number of the first frame in the contiguous block. |
nframes | The number of frames to free. |
Definition at line 370 of file buddy_core.c.
Referenced by pmm_free_frames().
|
static |
Definition at line 18 of file buddy_core.c.
Referenced by break_the_order(), buddy_alloc_n_exact(), buddy_init(), and try_merge().
|
static |
Definition at line 19 of file buddy_core.c.
Referenced by extract_exact_range().
list_head freelists[MOS_ARRAY_SIZE(orders)] |
Definition at line 23 of file buddy_core.c.
struct { ... } buddy |
Referenced by add_to_freelist(), break_the_order(), buddy_alloc_n_exact(), buddy_dump_all(), buddy_init(), dump_list(), extract_exact_range(), and try_merge().
|
static |
Definition at line 26 of file buddy_core.c.
Referenced by add_to_freelist(), break_this_pfn(), buddy_alloc_n_exact(), buddy_free_n(), buddy_init(), buddy_reserve_n(), dump_list(), extract_exact_range(), and populate_freelist().