rcore-os / buddy_system_allocator Goto Github PK
View Code? Open in Web Editor NEWA buddy system allocator in pure Rust.
License: MIT License
A buddy system allocator in pure Rust.
License: MIT License
Hello! I'm playing around with buddy_system_allocator and have a minimal hello-world program, which I thought should work:
use buddy_system_allocator::LockedHeap;
use libc;
use core::ptr;
fn main() {
#[global_allocator]
static GLOBAL: LockedHeap::<32> = LockedHeap::<32>::empty();
let address: *mut libc::c_void;
unsafe {
address = libc::mmap(ptr::null_mut(), 1<<29 as usize, libc::PROT_READ | libc::PROT_WRITE,
libc::MAP_PRIVATE | libc::MAP_ANON, -1, 0);
}
if address == libc::MAP_FAILED {
panic!("mmap: failed to get mapped memory area for heap");
}
unsafe {
GLOBAL.lock().init(address as usize, 1<<29 as usize);
}
println!("Hello, world!");
}
This fails with message
memory allocation of 4 bytes failed
Aborted (core dumped)
Can you kindly point out what's the issue with my code?
Thanks very much
We need some statistical information to profile our system.
For example: used memory, available memory, and other internal parameters...
When i learning the rcore
in windows platform, i use this crate with version 0.9
, instead of the version in tutorial is 0.6
. I meet the error
and here is the code lab in this commit:
https://github.com/kyrosle/OS/tree/ccb88e0819c230fa53df1cc2993f05c5eab9fcd3
Only using 0.9
will cause this error, but 0.8
seem all right.
Some times we need to allocate space at fixed address. I hope we can support for that
rust-lang/rust@d8e3557#diff-1b08d266cc36e37196b43a2251a5392b
3 月 3 日的一次 commit 中将 alloc
realloc
和 alloc_zeroed
的返回类型从 Result<NonNull<u8>, AllocErr>
变为 Result<(NonNull<u8>, usize), AllocErr>
,额外返回了 layout.size()
There is a bug in lib.rs between L158 to L 178.
Provide the ORDER is 30. If the current_class is 29, i.e. the last index, the L174 will get error "Index out of bounds".
while current_class < self.free_list.len() {
let buddy = current_ptr ^ (1 << current_class);
let mut flag = false;
for block in self.free_list[current_class].iter_mut() {
if block.value() as usize == buddy {
block.pop();
flag = true;
break;
}
}
// Free buddy found
if flag {
self.free_list[current_class].pop();
current_ptr = min(current_ptr, buddy);
current_class += 1;
self.free_list[current_class].push(current_ptr as *mut usize);
} else {
break;
}
}
pub struct FrameAllocator {
// buddy system with max order of 32
free_list: [BTreeSet; 32],
// statistics
allocated: usize,
total: usize,
}
为什么free_list要选择BTreeSet?谢谢
Order 32 of the linked list allows about a 4GB of heap for any process. This can easily be crossed when the crate is used under a 64 bit Virtual Space which can address upto 48 bits of information.
Please provide a larger order or an option to increase the order
For some usecases, e.g. allocating MMIO space for PCI BARs, it is necessary to allocate address space with both a particular size and a particular alignment. It would be useful if FrameAllocator::alloc
took an alignment parameter to specify what alignment is required.
I got a spurious allocation failure even when there is enough space.
The flow is:
init_heap
, I try to allocate X bytes withlet g = alloc::boxed::Box::new([0u8; KERNEL_HEAP_SIZE]);
The problem disappears if I switch to linked_list_allocator
.
Is there any caveat for using this allocator?
spin
is 0.7.0 now.
#[global_allocator]
static HEAP_ALLOCATOR: LockedHeap = LockedHeap::empty();
I use 0.8.0 version. And it reports that "missing generics for struct LockedHeap
expected 1 const argumen"
lib.rs::Heap::dealloc is not O(logN)
You may use something like a bitmap to check if the buddy page is free or not.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.