mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-22 23:12:24 +00:00
5ed5fddb7c
This commit removes APIs that were previously marked as deprecated. This change has the following implications: - The use of the global 'env()' accessor is not possible anymore. - Boolean accessor methods are no longer prefixed with 'is_'. E.g., instead of 'is_valid()', use 'valid()'. - The last traces of 'Ram_session' are gone now. The 'Env::ram()' accessor returns the 'Ram_allocator' interface, which is a subset of the 'Pd_session' interface. - All connection constructors need the 'Env' as argument. - The 'Reporter' constructor needs an 'Env' argument now because the reporter creates a report connection. - The old overload 'Child_policy::resolve_session_request' that returned a 'Service' does not exist anymore. - The base/printf.h header has been removed, use base/log.h instead. - The old notion of 'Signal_dispatcher' is gone. Use 'Signal_handler'. - Transitional headers like os/server.h, cap_session/, volatile_object.h, os/attached*_dataspace.h, signal_rpc_dispatcher.h have been removed. - The distinction between 'Thread_state' and 'Thread_state_base' does not exist anymore. - The header cpu_thread/capability.h along with the type definition of 'Cpu_thread_capability' has been removed. Use the type 'Thread_capability' define in cpu_session/cpu_session.h instead. - Several XML utilities (i.e., at os/include/decorator) could be removed because their functionality is nowadays covered by util/xml_node.h. - The 'os/ram_session_guard.h' has been removed. Use 'Constrained_ram_allocator' provided by base/ram_allocator.h instead. Issue #1987
159 lines
3.3 KiB
C++
159 lines
3.3 KiB
C++
/*
|
|
* \brief Slab allocator
|
|
* \author Norman Feske
|
|
* \date 2006-04-18
|
|
*/
|
|
|
|
/*
|
|
* Copyright (C) 2006-2017 Genode Labs GmbH
|
|
*
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
* under the terms of the GNU Affero General Public License version 3.
|
|
*/
|
|
|
|
#ifndef _INCLUDE__BASE__SLAB_H_
|
|
#define _INCLUDE__BASE__SLAB_H_
|
|
|
|
#include <base/allocator.h>
|
|
#include <base/stdint.h>
|
|
|
|
namespace Genode { class Slab; }
|
|
|
|
|
|
class Genode::Slab : public Allocator
|
|
{
|
|
private:
|
|
|
|
struct Block;
|
|
struct Entry;
|
|
|
|
size_t const _slab_size; /* size of one slab entry */
|
|
size_t const _block_size; /* size of slab block */
|
|
size_t const _entries_per_block; /* number of slab entries per block */
|
|
|
|
Block *_initial_sb; /* initial (static) slab block */
|
|
bool _nested; /* indicator for nested call of alloc */
|
|
|
|
size_t _num_blocks = 0;
|
|
size_t _total_avail = 0;
|
|
|
|
/**
|
|
* Block used for attempting the next allocation
|
|
*/
|
|
Block *_curr_sb = nullptr;
|
|
|
|
Allocator *_backing_store;
|
|
|
|
/**
|
|
* Allocate and initialize new slab block
|
|
*/
|
|
Block *_new_slab_block();
|
|
|
|
|
|
/*****************************
|
|
** Methods used by 'Block' **
|
|
*****************************/
|
|
|
|
void _release_backing_store(Block *);
|
|
|
|
/**
|
|
* Insert block into slab block ring
|
|
*
|
|
* \noapi
|
|
*/
|
|
void _insert_sb(Block *);
|
|
|
|
/**
|
|
* Release slab block
|
|
*/
|
|
void _free_curr_sb();
|
|
|
|
/**
|
|
* Free slab entry
|
|
*/
|
|
void _free(void *addr);
|
|
|
|
/*
|
|
* Noncopyable
|
|
*/
|
|
Slab(Slab const &);
|
|
Slab &operator = (Slab const &);
|
|
|
|
public:
|
|
|
|
/**
|
|
* Constructor
|
|
*
|
|
* At construction time, there exists one initial slab
|
|
* block that is used for the first couple of allocations,
|
|
* especially for the allocation of the second slab
|
|
* block.
|
|
*/
|
|
Slab(size_t slab_size, size_t block_size, void *initial_sb,
|
|
Allocator *backing_store = 0);
|
|
|
|
/**
|
|
* Destructor
|
|
*/
|
|
~Slab();
|
|
|
|
/**
|
|
* Return number of bytes consumed per slab entry
|
|
*
|
|
* The function takes the slab-internal meta-data needs and the actual
|
|
* slab entry into account.
|
|
*/
|
|
static size_t entry_costs(size_t slab_size, size_t block_size);
|
|
|
|
/**
|
|
* Return number of unused slab entries
|
|
*/
|
|
size_t avail_entries() const { return _total_avail; }
|
|
|
|
/**
|
|
* Add new slab block as backing store
|
|
*
|
|
* The specified 'ptr' has to point to a buffer with the size of one
|
|
* slab block.
|
|
*/
|
|
void insert_sb(void *ptr);
|
|
|
|
/**
|
|
* Return a used slab element, or nullptr if empty
|
|
*/
|
|
void *any_used_elem();
|
|
|
|
/**
|
|
* Define/request backing-store allocator
|
|
*
|
|
* \noapi
|
|
*/
|
|
void backing_store(Allocator *bs) { _backing_store = bs; }
|
|
|
|
/**
|
|
* Request backing-store allocator
|
|
*
|
|
* \noapi
|
|
*/
|
|
Allocator *backing_store() { return _backing_store; }
|
|
|
|
|
|
/*************************
|
|
** Allocator interface **
|
|
*************************/
|
|
|
|
/**
|
|
* Allocate slab entry
|
|
*
|
|
* The 'size' parameter is ignored as only slab entries with
|
|
* preconfigured slab-entry size are allocated.
|
|
*/
|
|
bool alloc(size_t size, void **addr) override;
|
|
void free(void *addr, size_t) override { _free(addr); }
|
|
size_t consumed() const override;
|
|
size_t overhead(size_t) const override { return _block_size/_entries_per_block; }
|
|
bool need_size_for_free() const override { return false; }
|
|
};
|
|
|
|
#endif /* _INCLUDE__BASE__SLAB_H_ */
|