AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
buddy.h File Reference
#include <mm/mm.h>

Go to the source code of this file.

Macros

#define BUDDY_MAX_ORDER   (10)
#define BUDDY_MIN_BS   (4096)
#define BUDDY_MAX_BS   (BUDDY_MIN_BS << BUDDY_MAX_ORDER)
#define BUDDY_ZONE_NR   2
#define BUDDY_ZONE_DMA   0
#define BUDDY_ZONE_NORMAL   1

Functions

int buddy_setup (size_t total_mem)
 Sets up the allocator at boot: a bitmap for each zone and order, every top-order block of RAM free, then the kernel and its symbol tables set unusable.
paddr_t buddy_alloc (int zone, size_t size)
 Allocates a block of physical memory from a zone, rounded up to a power of two pages.
void buddy_free (int zone, paddr_t paddr, size_t size)
 Frees a block that buddy_alloc() gave.
void buddy_set_unusable (paddr_t paddr, size_t size)
 Marks a range of physical memory as not free, at boot, before the first allocation: the kernel, the modules, the firmware's ranges.

Variables

uintptr_t buddy_zone_offset []

Macro Definition Documentation

◆ BUDDY_MAX_BS

#define BUDDY_MAX_BS   (BUDDY_MIN_BS << BUDDY_MAX_ORDER)

Definition at line 12 of file buddy.h.

Referenced by buddy_alloc(), buddy_reserved_done(), buddy_set_unusable(), buddy_setup(), and mm_setup().

◆ BUDDY_MAX_ORDER

◆ BUDDY_MIN_BS

#define BUDDY_MIN_BS   (4096)

Definition at line 11 of file buddy.h.

Referenced by buddy_alloc(), buddy_free(), buddy_reserved_done(), and buddy_set_unusable().

◆ BUDDY_ZONE_DMA

#define BUDDY_ZONE_DMA   0

Definition at line 16 of file buddy.h.

Referenced by mm_page_alloc(), and mm_page_dealloc().

◆ BUDDY_ZONE_NORMAL

#define BUDDY_ZONE_NORMAL   1

Definition at line 17 of file buddy.h.

Referenced by mm_page_alloc(), and mm_page_dealloc().

◆ BUDDY_ZONE_NR

#define BUDDY_ZONE_NR   2

Definition at line 15 of file buddy.h.

Referenced by buddy_reserved_done(), buddy_set_unusable(), buddy_setup(), and procfs_buddyinfo().

Function Documentation

◆ buddy_alloc()

paddr_t buddy_alloc ( int zone,
size_t _sz )

Allocates a block of physical memory from a zone, rounded up to a power of two pages.

Parameters
zonethe zone to take it from (BUDDY_ZONE_DMA or BUDDY_ZONE_NORMAL)
_szthe size wanted, in bytes, at most BUDDY_MAX_BS
Returns
the block's physical address, or (paddr_t) -1 if the zone has no free block that large

Definition at line 149 of file buddy.c.

References buddy_alloc(), BUDDY_MAX_BS, BUDDY_MAX_ORDER, BUDDY_MIN_BS, buddy_recursive_alloc(), buddy_reserved_done(), buddy_zone_offset, k_used_mem, panic, and reserved_done.

Referenced by buddy_alloc(), and mm_page_alloc().

◆ buddy_free()

void buddy_free ( int zone,
paddr_t addr,
size_t size )

Frees a block that buddy_alloc() gave.

Parameters
zonethe zone it came from
addrits physical address
sizethe size that was asked for, in bytes

Definition at line 183 of file buddy.c.

References buddy_free(), BUDDY_MAX_ORDER, BUDDY_MIN_BS, buddy_recursive_free(), buddy_zone_offset, k_used_mem, kend, kstart, and panic.

Referenced by buddy_free(), and mm_page_dealloc().

◆ buddy_set_unusable()

void buddy_set_unusable ( paddr_t addr,
size_t size )

Marks a range of physical memory as not free, at boot, before the first allocation: the kernel, the modules, the firmware's ranges.

Parameters
addrthe range's start
sizeits size, in bytes (0 does nothing)

Definition at line 212 of file buddy.c.

References buddy::bitmap, buddies, BUDDY_MAX_BS, BUDDY_MAX_ORDER, BUDDY_MIN_BS, buddy_set_unusable(), BUDDY_ZONE_NR, buddy_zone_offset, buddy::first_free_idx, MAX, bitmap::max_idx, MIN, panic, printk(), reserved, reserved_done, RESERVED_MAX, reserved_nr, and buddy::usable.

Referenced by arch_mm_setup(), buddy_set_unusable(), buddy_setup(), mm_mark_unusable(), and mm_setup().

◆ buddy_setup()

int buddy_setup ( size_t total_mem)

Sets up the allocator at boot: a bitmap for each zone and order, every top-order block of RAM free, then the kernel and its symbol tables set unusable.

Parameters
total_memthe end of RAM, in bytes
Returns
0

Definition at line 328 of file buddy.c.

References __kboot, alloc(), buddy::bitmap, bitmap_clear_range(), bitmap_set_range(), bitmap_size(), buddies, BUDDY_MAX_BS, BUDDY_MAX_ORDER, buddy_set_unusable(), buddy_setup(), BUDDY_ZONE_NR, buddy_zone_offset, buddy::first_free_idx, k_total_mem, k_used_mem, kend, kernel_end, kstart, LMA, bitmap::map, bitmap::max_idx, MIN, printk(), elf32_shdr::sh_addr, elf32_shdr::sh_size, boot::shdr, boot::strtab, boot::symtab, buddy::usable, and zone_blocks.

Referenced by buddy_setup(), and mm_setup().

Variable Documentation

◆ buddy_zone_offset

uintptr_t buddy_zone_offset[]
extern