add configuration for frequency of guard slabs

This commit is contained in:
Daniel Micay 2018-10-06 15:36:03 -04:00
parent 4ee12e64e0
commit 348f9fa557
2 changed files with 5 additions and 2 deletions

View File

@ -3,11 +3,11 @@
#include <stdbool.h> #include <stdbool.h>
#define GUARD_SLABS true
#define WRITE_AFTER_FREE_CHECK true #define WRITE_AFTER_FREE_CHECK true
#define SLOT_RANDOMIZE true #define SLOT_RANDOMIZE true
#define ZERO_ON_FREE true #define ZERO_ON_FREE true
#define SLAB_CANARY true #define SLAB_CANARY true
#define GUARD_SLABS_INTERVAL 1
#define GUARD_SIZE_DIVISOR 2 #define GUARD_SIZE_DIVISOR 2
#endif #endif

View File

@ -141,6 +141,7 @@ static struct size_class {
struct random_state rng; struct random_state rng;
size_t metadata_allocated; size_t metadata_allocated;
size_t metadata_count; size_t metadata_count;
size_t metadata_count_unguarded;
} __attribute__((aligned(CACHELINE_SIZE))) size_class_metadata[N_SIZE_CLASSES]; } __attribute__((aligned(CACHELINE_SIZE))) size_class_metadata[N_SIZE_CLASSES];
static const size_t class_region_size = 128ULL * 1024 * 1024 * 1024; static const size_t class_region_size = 128ULL * 1024 * 1024 * 1024;
@ -180,8 +181,10 @@ static struct slab_metadata *alloc_metadata(struct size_class *c, size_t slab_si
return NULL; return NULL;
} }
c->metadata_count++; c->metadata_count++;
if (GUARD_SLABS) { c->metadata_count_unguarded++;
if (c->metadata_count_unguarded >= GUARD_SLABS_INTERVAL) {
c->metadata_count++; c->metadata_count++;
c->metadata_count_unguarded = 0;
} }
return metadata; return metadata;
} }