mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-31 00:24:51 +00:00
core: implement core allocator's free (ref #1573)
This commit is contained in:
parent
6f167b449c
commit
409ac1468e
@ -188,13 +188,14 @@ class Genode::Page_slab : public Genode::Allocator
|
|||||||
*/
|
*/
|
||||||
void free(void *addr)
|
void free(void *addr)
|
||||||
{
|
{
|
||||||
for (List_element<Slab_block> *le = _b_list.first();
|
for (List_element<Slab_block> *le = _b_list.first(); le;) {
|
||||||
le; le = le->next()) {
|
List_element<Slab_block> *cur = le;
|
||||||
if (!le->object()->free(addr)) continue;
|
le = le->next();
|
||||||
|
if (!cur->object()->free(addr)) continue;
|
||||||
|
|
||||||
if (_free_slab_entries++ > (MIN_SLABS+SLABS_PER_BLOCK)
|
if (_free_slab_entries++ > (MIN_SLABS+SLABS_PER_BLOCK)
|
||||||
&& !le->object()->ref_counter)
|
&& !cur->object()->ref_counter)
|
||||||
_free_slab_block(le->object());
|
_free_slab_block(cur->object());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,3 +75,21 @@ Core_mem_allocator::Mapped_mem_allocator::alloc_aligned(size_t size, void **out_
|
|||||||
|
|
||||||
return Alloc_return::OK;
|
return Alloc_return::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Core_mem_allocator::Mapped_mem_allocator::free(void *addr, size_t size)
|
||||||
|
{
|
||||||
|
using Block = Mapped_avl_allocator::Block;
|
||||||
|
Block *b = static_cast<Block *>(_virt_alloc->_find_by_address((addr_t)addr));
|
||||||
|
if (!b) return;
|
||||||
|
|
||||||
|
_unmap_local((addr_t)addr, b->size());
|
||||||
|
_phys_alloc->free(b->map_addr, b->size());
|
||||||
|
_virt_alloc->free(addr, b->size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Core_mem_allocator::Mapped_mem_allocator::free(void *addr)
|
||||||
|
{
|
||||||
|
PWRN("Not implemented!");
|
||||||
|
}
|
||||||
|
@ -68,12 +68,16 @@ class Genode::Core_mem_allocator : public Genode::Core_mem_translator
|
|||||||
*/
|
*/
|
||||||
struct Metadata { void * map_addr; };
|
struct Metadata { void * map_addr; };
|
||||||
|
|
||||||
|
class Mapped_mem_allocator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Page-size granular allocator that links ranges to related ones.
|
* Page-size granular allocator that links ranges to related ones.
|
||||||
*/
|
*/
|
||||||
class Mapped_avl_allocator
|
class Mapped_avl_allocator
|
||||||
: public Allocator_avl_tpl<Metadata, get_page_size()>
|
: public Allocator_avl_tpl<Metadata, get_page_size()>
|
||||||
{
|
{
|
||||||
|
friend class Mapped_mem_allocator;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -166,7 +170,7 @@ class Genode::Core_mem_allocator : public Genode::Core_mem_translator
|
|||||||
addr_t to = ~0UL) override;
|
addr_t to = ~0UL) override;
|
||||||
Alloc_return alloc_addr(size_t size, addr_t addr) override {
|
Alloc_return alloc_addr(size_t size, addr_t addr) override {
|
||||||
return Alloc_return::RANGE_CONFLICT; }
|
return Alloc_return::RANGE_CONFLICT; }
|
||||||
void free(void *addr) override { }
|
void free(void *addr) override;
|
||||||
size_t avail() const override { return _phys_alloc->avail(); }
|
size_t avail() const override { return _phys_alloc->avail(); }
|
||||||
bool valid_addr(addr_t addr) const override {
|
bool valid_addr(addr_t addr) const override {
|
||||||
return _virt_alloc->valid_addr(addr); }
|
return _virt_alloc->valid_addr(addr); }
|
||||||
@ -178,7 +182,7 @@ class Genode::Core_mem_allocator : public Genode::Core_mem_translator
|
|||||||
|
|
||||||
bool alloc(size_t size, void **out_addr) override {
|
bool alloc(size_t size, void **out_addr) override {
|
||||||
return alloc_aligned(size, out_addr).is_ok(); }
|
return alloc_aligned(size, out_addr).is_ok(); }
|
||||||
void free(void *addr, size_t) override { free(addr); }
|
void free(void *addr, size_t) override;
|
||||||
size_t consumed() const override { return _phys_alloc->consumed(); }
|
size_t consumed() const override { return _phys_alloc->consumed(); }
|
||||||
size_t overhead(size_t size) const override {
|
size_t overhead(size_t size) const override {
|
||||||
return _phys_alloc->overhead(size); }
|
return _phys_alloc->overhead(size); }
|
||||||
@ -300,7 +304,11 @@ class Genode::Core_mem_allocator : public Genode::Core_mem_translator
|
|||||||
bool alloc(size_t size, void **out_addr) override {
|
bool alloc(size_t size, void **out_addr) override {
|
||||||
return alloc_aligned(size, out_addr).is_ok(); }
|
return alloc_aligned(size, out_addr).is_ok(); }
|
||||||
|
|
||||||
void free(void *addr, size_t) override { free(addr); }
|
void free(void *addr, size_t size) override
|
||||||
|
{
|
||||||
|
Lock::Guard lock_guard(_lock);
|
||||||
|
return _mem_alloc.free(addr, size);
|
||||||
|
}
|
||||||
|
|
||||||
size_t consumed() const override { return _phys_alloc.consumed(); }
|
size_t consumed() const override { return _phys_alloc.consumed(); }
|
||||||
size_t overhead(size_t size) const override { return _phys_alloc.overhead(size); }
|
size_t overhead(size_t size) const override { return _phys_alloc.overhead(size); }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user