Skip to content
Snippets Groups Projects
Commit 2cb718af authored by Konstantin Osipov's avatar Konstantin Osipov
Browse files

[small] Make a few members uint32_t rather than size_t.

parent 3241663b
No related branches found
No related tags found
No related merge requests found
......@@ -157,7 +157,7 @@ mempool_create_with_order(struct mempool *pool, struct slab_cache *cache,
pool->objsize = objsize;
pool->slab_order = order;
/* Account for slab meta. */
size_t slab_size = slab_order_size(pool->cache, pool->slab_order) -
uint32_t slab_size = slab_order_size(pool->cache, pool->slab_order) -
mslab_sizeof();
/* Calculate how many objects will actually fit in a slab. */
/*
......@@ -169,10 +169,10 @@ mempool_create_with_order(struct mempool *pool, struct slab_cache *cache,
* X * objsize + X/8 = slab_size
* X = (8 * slab_size)/(8 * objsize + 1)
*/
size_t objcount = (CHAR_BIT * slab_size)/(CHAR_BIT * objsize + 1);
uint32_t objcount = (CHAR_BIT * slab_size)/(CHAR_BIT * objsize + 1);
/* How many elements of slab->map can map objcount. */
assert(objcount);
size_t mapsize = (objcount + MEMPOOL_MAP_BIT - 1)/MEMPOOL_MAP_BIT;
uint32_t mapsize = (objcount + MEMPOOL_MAP_BIT - 1)/MEMPOOL_MAP_BIT;
/* Adjust the result of integer division, which may be too large. */
while (objcount * objsize + mapsize * MEMPOOL_MAP_SIZEOF > slab_size) {
objcount--;
......
......@@ -112,7 +112,7 @@ struct mslab {
mbitmap_t map[0];
};
static inline size_t
static inline uint32_t
mslab_sizeof()
{
return small_align(sizeof(struct mslab), sizeof(intptr_t));
......
......@@ -120,7 +120,7 @@ struct rslab
uint32_t used;
};
static inline size_t
static inline uint32_t
rslab_sizeof()
{
return small_align(sizeof(struct rslab), sizeof(intptr_t));
......@@ -133,7 +133,7 @@ rslab_data(struct rslab *slab)
}
/** How much memory is available in a given block? */
static inline size_t
static inline uint32_t
rslab_unused(struct rslab *slab)
{
return slab->slab.size - rslab_sizeof() - slab->used;
......
......@@ -105,7 +105,7 @@ pow2round(size_t size)
void
slab_arena_create(struct slab_arena *arena,
size_t prealloc, size_t maxalloc,
size_t slab_size, int flags)
uint32_t slab_size, int flags)
{
assert(flags & (MAP_PRIVATE | MAP_SHARED));
lf_lifo_init(&arena->cache);
......
......@@ -70,7 +70,7 @@ struct slab_arena {
* Typical value is 4Mb, which makes it possible to
* allocate objects of size up to ~1MB.
*/
size_t slab_size;
uint32_t slab_size;
/**
* How much memory is preallocated during initialization
* of slab_arena.
......@@ -98,8 +98,8 @@ struct slab_arena {
/** Initialize an arena. */
void
slab_arena_create(struct slab_arena *arena, size_t slab_size,
size_t prealloc, size_t maxalloc, int flags);
slab_arena_create(struct slab_arena *arena, size_t prealloc,
size_t maxalloc, uint32_t slab_size, int flags);
/** Destroy an arena. */
void
......
......@@ -160,7 +160,7 @@ slab_merge(struct slab_cache *cache, struct slab *slab, struct slab *buddy)
void
slab_cache_create(struct slab_cache *cache, struct slab_arena *arena,
size_t order0_size)
uint32_t order0_size)
{
cache->arena = arena;
......
......@@ -130,7 +130,7 @@ struct slab_cache {
* defines the number of "orders" of slab cache.
* This distance can't be more than ORDER_MAX.
*/
size_t order0_size;
uint32_t order0_size;
/*
* Binary logarithm of order0_size, useful in pointer
* arithmetics.
......@@ -163,7 +163,7 @@ struct slab_cache {
void
slab_cache_create(struct slab_cache *cache, struct slab_arena *arena,
size_t order0_size);
uint32_t order0_size);
void
slab_cache_destroy(struct slab_cache *cache);
......@@ -181,14 +181,14 @@ struct slab *
slab_from_ptr(struct slab_cache *cache, void *ptr, uint8_t order);
/* Aligned size of slab meta. */
static inline size_t
static inline uint32_t
slab_sizeof()
{
return small_align(sizeof(struct slab), sizeof(intptr_t));
}
/** Useful size of a slab. */
static inline size_t
static inline uint32_t
slab_size(struct slab *slab)
{
return slab->size - slab_sizeof();
......
......@@ -9,7 +9,7 @@ void
slab_arena_print(struct slab_arena *arena)
{
printf("arena->prealloc = %zu\narena->maxalloc = %zu\n"
"arena->used = %zu\narena->slab_size = %zu\n",
"arena->used = %zu\narena->slab_size = %u\n",
arena->prealloc, arena->maxalloc,
arena->used, arena->slab_size);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment