delay allocating slab metadata from reservation

pull/65/head
Daniel Micay 2018-10-18 15:19:54 -04:00
parent 74139112d0
commit fe30f6c2ea
2 changed files with 13 additions and 5 deletions

View File

@ -176,7 +176,7 @@ static struct slab_metadata *alloc_metadata(struct size_class *c, size_t slab_si
errno = ENOMEM;
return NULL;
}
size_t allocate = c->metadata_allocated * 2;
size_t allocate = max(c->metadata_allocated * 2, PAGE_SIZE / sizeof(struct slab_metadata));
if (allocate > metadata_max) {
allocate = metadata_max;
}
@ -825,10 +825,6 @@ COLD static void init_slow_path(void) {
if (c->slab_info == NULL) {
fatal_error("failed to allocate slab metadata");
}
c->metadata_allocated = PAGE_SIZE / sizeof(struct slab_metadata);
if (memory_protect_rw(c->slab_info, c->metadata_allocated * sizeof(struct slab_metadata))) {
fatal_error("failed to allocate initial slab info");
}
}
deallocate_pages(rng, sizeof(struct random_state), PAGE_SIZE);

12
util.h
View File

@ -7,6 +7,18 @@
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#define min(x, y) ({ \
__typeof__(x) _x = (x); \
__typeof__(y) _y = (y); \
(void) (&_x == &_y); \
_x < _y ? _x : _y; })
#define max(x, y) ({ \
__typeof__(x) _x = (x); \
__typeof__(y) _y = (y); \
(void) (&_x == &_y); \
_x > _y ? _x : _y; })
#define COLD __attribute__((cold))
#define UNUSED __attribute__((unused))
#define EXPORT __attribute__((visibility("default")))