buddy_system_allocator
buddy_system_allocator
๋ ๋ฒ๋ ์์คํ
ํ ๋น์๋ฅผ ๊ตฌํํ๋ ์๋ ํํฐ ํฌ๋ ์ดํธ์
๋๋ค. ์ด ํฌ๋ ์ดํธ์ LockedHeap
์ GlobalAlloc
๋ฅผ ๊ตฌํํฉ๋๋ค. ๋ฐ๋ผ์ ์ฌ๋ฌ๋ถ์ ๋ฒ๋ ์์คํ
ํ ๋น์๋ฅผ โallocโ ํฌ๋ ์ดํธ๋ฅผ ํตํด์ ์ฌ์ฉํ ์ ์์ต๋๋ค(์ด์ ์ ํ์ธํจ). ๋๋ ๋ค๋ฅธ ์ฃผ์ ๊ณต๊ฐ์ ํ ๋นํ๋ ๋ฐ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด PCI BAR์ MMIO ๊ณต๊ฐ์ ํ ๋นํ ์ ์์ต๋๋ค.
use buddy_system_allocator::FrameAllocator; use core::alloc::Layout; fn main() { let mut allocator = FrameAllocator::<32>::new(); allocator.add_frame(0x200_0000, 0x400_0000); let layout = Layout::from_size_align(0x100, 0x100).unwrap(); let bar = allocator .alloc_aligned(layout) .expect("Failed to allocate 0x100 byte MMIO region"); println!("Allocated 0x100 byte MMIO region at {:#x}", bar); }
- PCI BAR๋ BAR์์ญ์ ํฌ๊ธฐ์ ๋ง์ถ์ด ์ ๋ ฌ๋ฉ๋๋ค.
src/bare-metal/useful-crates/allocator-example/
์์cargo run
์ ์ฌ์ฉํ์ฌ ์์๋ฅผ ์คํํฉ๋๋ค(์ข ์์ฑ ๋ฌธ์ ๋ก ์ธํด ํ๋ ์ด๊ทธ๋ผ์ด๋์์๋ ์คํ๋์ง ์์ต๋๋ค).