Skip to content
Snippets Groups Projects
Commit 5570784c authored by Alexandr Lyapunov's avatar Alexandr Lyapunov Committed by Konstantin Osipov
Browse files

minor fixes of arena and its comments

parent 17f2bdce
No related branches found
No related tags found
No related merge requests found
......@@ -42,12 +42,13 @@
#define MAP_ANONYMOUS MAP_ANON
#endif
void
static void
munmap_checked(void *addr, size_t size)
{
if (munmap(addr, size)) {
char buf[64];
intptr_t ignore_it = (intptr_t)strerror_r(errno, buf, sizeof(buf));
intptr_t ignore_it = (intptr_t)strerror_r(errno, buf,
sizeof(buf));
(void)ignore_it;
fprintf(stderr, "Error in munmap(%p, %zu): %s\n",
addr, size, buf);
......@@ -76,7 +77,7 @@ mmap_checked(size_t size, size_t align, int flags)
munmap_checked(map, size);
/*
* mmap twice the requested amount to be able to align
* mmap enough amount to be able to align
* the mapped address. This can lead to virtual memory
* fragmentation depending on the kernels allocation
* strategy.
......@@ -187,8 +188,13 @@ slab_map(struct slab_arena *arena)
if (used <= arena->prealloc)
return arena->arena + used - arena->slab_size;
return mmap_checked(arena->slab_size, arena->slab_size,
arena->flags);
ptr = mmap_checked(arena->slab_size, arena->slab_size,
arena->flags);
if (!ptr) {
__sync_sub_and_fetch(&arena->used, arena->slab_size);
quota_release(arena->quota, arena->slab_size);
}
return ptr;
}
void
......
......@@ -68,9 +68,8 @@ struct slab_arena {
*/
size_t prealloc;
/**
* How much memory in the preallocated arena has
* How much memory in the arena has
* already been initialized for slabs.
* @invariant used <= prealloc.
*/
size_t used;
/**
......
......@@ -109,9 +109,12 @@ slab_is_free(struct slab *slab)
static inline void
slab_poison(struct slab *slab)
{
static const char poison_char = 'P';
(void)slab;
#ifndef NDEBUG
const char poison_char = 'P';
memset((char *) slab + slab_sizeof(), poison_char,
slab->size - slab_sizeof());
#endif
}
static inline void
......
......@@ -37,7 +37,7 @@ void
memory_init()
{
static struct quota runtime_quota;
static const size_t SLAB_SIZE = 4 * 1024 * 1024;
const size_t SLAB_SIZE = 4 * 1024 * 1024;
/* default quota initialization */
quota_init(&runtime_quota, QUOTA_MAX);
......
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