slab: add option to free empty blocks

explictly by a method

Issue #4014
This commit is contained in:
Alexander Boettcher 2021-02-09 23:06:16 +01:00 committed by Norman Feske
parent 19d0142e10
commit 1e84b46c3f
4 changed files with 23 additions and 1 deletions

View File

@ -340,7 +340,11 @@ class Genode::Allocator_avl_tpl : public Allocator_avl_base
_metadata((metadata_chunk_alloc) ? metadata_chunk_alloc : this,
(Block *)&_initial_md_block) { }
~Allocator_avl_tpl() { _revert_allocations_and_ranges(); }
~Allocator_avl_tpl()
{
_metadata.free_empty_blocks();
_revert_allocations_and_ranges();
}
/**
* Return size of slab blocks used for meta data

View File

@ -138,6 +138,12 @@ class Genode::Slab : public Allocator
Allocator *backing_store() { return _backing_store; }
/**
* Free memory of empty slab blocks
*/
void free_empty_blocks();
/*************************
** Allocator interface **
*************************/

View File

@ -208,6 +208,7 @@ _ZN6Genode4Lock4lockEv T
_ZN6Genode4Lock6unlockEv T
_ZN6Genode4LockC1ENS0_5StateE T
_ZN6Genode4Slab13any_used_elemEv T
_ZN6Genode4Slab17free_empty_blocksEv T
_ZN6Genode4Slab5Block11_slab_entryEi T
_ZN6Genode4Slab5Block14any_used_entryEv T
_ZN6Genode4Slab5Block5allocEv T

View File

@ -416,6 +416,17 @@ void Slab::_free(void *addr)
}
void Slab::free_empty_blocks()
{
for (size_t blocks = _num_blocks; blocks > 0; blocks--) {
if (_curr_sb != _initial_sb && _curr_sb->avail() == _entries_per_block)
_free_curr_sb();
else
_curr_sb = _curr_sb->next;
}
}
void *Slab::any_used_elem()
{
if (_total_avail == _num_blocks*_entries_per_block)