mirror of
https://github.com/genodelabs/genode.git
synced 2025-04-21 17:42:40 +00:00
parent
73d6171850
commit
e69e0e3f1c
@ -95,10 +95,6 @@ class Genode::Slab : public Allocator
|
||||
* block that is used for the first couple of allocations,
|
||||
* especially for the allocation of the second slab
|
||||
* block.
|
||||
*
|
||||
* \throw Out_of_ram
|
||||
* \throw Out_of_caps
|
||||
* \throw Allocator::Denied failed to obtain initial slab block
|
||||
*/
|
||||
Slab(size_t slab_size, size_t block_size, void *initial_sb,
|
||||
Allocator *backing_store = 0);
|
||||
@ -143,7 +139,6 @@ class Genode::Slab : public Allocator
|
||||
*/
|
||||
Allocator *backing_store() { return _backing_store; }
|
||||
|
||||
|
||||
/**
|
||||
* Free memory of empty slab blocks
|
||||
*/
|
||||
|
@ -221,26 +221,10 @@ Slab::Slab(size_t slab_size, size_t block_size, void *initial_sb,
|
||||
/ (_slab_size + sizeof(Entry) + 1)),
|
||||
_initial_sb((Block *)initial_sb),
|
||||
_nested(false),
|
||||
_curr_sb((Block *)initial_sb),
|
||||
_backing_store(backing_store)
|
||||
{
|
||||
static_assert(sizeof(Slab::Block) <= overhead_per_block());
|
||||
static_assert(sizeof(Slab::Entry) <= overhead_per_entry());
|
||||
|
||||
/* if no initial slab block was specified, try to get one */
|
||||
if (!_curr_sb && _backing_store)
|
||||
_new_slab_block().with_result(
|
||||
[&] (Block *sb) { _curr_sb = sb; },
|
||||
[&] (Alloc_error error) {
|
||||
Allocator::throw_alloc_error(error); });
|
||||
|
||||
if (!_curr_sb)
|
||||
throw Allocator::Denied();
|
||||
|
||||
/* init first slab block */
|
||||
construct_at<Block>(_curr_sb, *this);
|
||||
_total_avail = _entries_per_block;
|
||||
_num_blocks = 1;
|
||||
}
|
||||
|
||||
|
||||
@ -280,6 +264,9 @@ Slab::New_slab_block_result Slab::_new_slab_block()
|
||||
|
||||
void Slab::_release_backing_store(Block *block)
|
||||
{
|
||||
if (!block)
|
||||
return;
|
||||
|
||||
if (block->avail() != _entries_per_block)
|
||||
error("freeing non-empty slab block");
|
||||
|
||||
@ -375,6 +362,24 @@ Allocator::Alloc_result Slab::try_alloc(size_t size)
|
||||
return Alloc_error::DENIED;
|
||||
}
|
||||
|
||||
/* init very first block */
|
||||
if (!_curr_sb) {
|
||||
Alloc_error error = Alloc_error::DENIED;
|
||||
if (_initial_sb)
|
||||
_curr_sb = _initial_sb;
|
||||
else
|
||||
_new_slab_block().with_result(
|
||||
[&] (Block *sb) { _curr_sb = sb; },
|
||||
[&] (Alloc_error e) { error = e; });
|
||||
|
||||
if (!_curr_sb)
|
||||
return error;
|
||||
|
||||
construct_at<Block>(_curr_sb, *this);
|
||||
_total_avail = _entries_per_block;
|
||||
_num_blocks = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we run out of slab, we need to allocate a new slab block. For the
|
||||
* special case that this block is allocated using the allocator that by
|
||||
|
Loading…
x
Reference in New Issue
Block a user