diff --git a/repos/base/include/base/slab.h b/repos/base/include/base/slab.h
index 3e9d9d05aa..d6fe19d9a1 100644
--- a/repos/base/include/base/slab.h
+++ b/repos/base/include/base/slab.h
@@ -109,13 +109,8 @@ class Genode::Slab : public Allocator
*/
~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);
+ static constexpr size_t overhead_per_block() { return 4*sizeof(addr_t); }
+ static constexpr size_t overhead_per_entry() { return sizeof(addr_t) + 1; }
/**
* Return number of unused slab entries
diff --git a/repos/base/include/base/tslab.h b/repos/base/include/base/tslab.h
index b47a207ef0..6e759109d7 100644
--- a/repos/base/include/base/tslab.h
+++ b/repos/base/include/base/tslab.h
@@ -16,12 +16,16 @@
#include
-namespace Genode { template struct Tslab; }
+namespace Genode { template struct Tslab; }
-template
+template
struct Genode::Tslab : Slab
{
+ /* check if reasonable amount of entries + overhead fits one block */
+ static_assert(MIN_SLABS_PER_BLOCK*(sizeof(T)+overhead_per_entry())
+ + overhead_per_block() <= BLOCK_SIZE);
+
Tslab(Allocator *backing_store, void *initial_sb = 0)
: Slab(sizeof(T), BLOCK_SIZE, initial_sb, backing_store)
{ }
diff --git a/repos/base/src/lib/base/slab.cc b/repos/base/src/lib/base/slab.cc
index cf088b7e2d..3d7f26feec 100644
--- a/repos/base/src/lib/base/slab.cc
+++ b/repos/base/src/lib/base/slab.cc
@@ -219,12 +219,14 @@ Slab::Slab(size_t slab_size, size_t block_size, void *initial_sb,
*/
_entries_per_block((_block_size - sizeof(Block) - sizeof(umword_t))
/ (_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(