San: Implement bump alloc
The new allocator will be used to allocate guarded extents used as slabs for guarded small allocations.
This commit is contained in:
committed by
Alexander Lapenkov
parent
34b00f8969
commit
0f6da1257d
@@ -30,14 +30,20 @@ void ecache_dalloc(tsdn_t *tsdn, pac_t *pac, ehooks_t *ehooks,
|
||||
edata_t *ecache_evict(tsdn_t *tsdn, pac_t *pac, ehooks_t *ehooks,
|
||||
ecache_t *ecache, size_t npages_min);
|
||||
|
||||
void extent_gdump_add(tsdn_t *tsdn, const edata_t *edata);
|
||||
void extent_record(tsdn_t *tsdn, pac_t *pac, ehooks_t *ehooks, ecache_t *ecache,
|
||||
edata_t *edata);
|
||||
void extent_dalloc_gap(tsdn_t *tsdn, pac_t *pac, ehooks_t *ehooks,
|
||||
edata_t *edata);
|
||||
edata_t *extent_alloc_wrapper(tsdn_t *tsdn, pac_t *pac, ehooks_t *ehooks,
|
||||
void *new_addr, size_t size, size_t alignment, bool zero, bool *commit,
|
||||
bool growing_retained);
|
||||
void extent_dalloc_wrapper(tsdn_t *tsdn, pac_t *pac, ehooks_t *ehooks,
|
||||
edata_t *edata);
|
||||
void extent_destroy_wrapper(tsdn_t *tsdn, pac_t *pac, ehooks_t *ehooks,
|
||||
edata_t *edata);
|
||||
bool extent_commit_wrapper(tsdn_t *tsdn, ehooks_t *ehooks, edata_t *edata,
|
||||
size_t offset, size_t length);
|
||||
size_t offset, size_t length, bool growing_retained);
|
||||
bool extent_decommit_wrapper(tsdn_t *tsdn, ehooks_t *ehooks, edata_t *edata,
|
||||
size_t offset, size_t length);
|
||||
bool extent_purge_lazy_wrapper(tsdn_t *tsdn, ehooks_t *ehooks, edata_t *edata,
|
||||
@@ -45,7 +51,8 @@ bool extent_purge_lazy_wrapper(tsdn_t *tsdn, ehooks_t *ehooks, edata_t *edata,
|
||||
bool extent_purge_forced_wrapper(tsdn_t *tsdn, ehooks_t *ehooks, edata_t *edata,
|
||||
size_t offset, size_t length);
|
||||
edata_t *extent_split_wrapper(tsdn_t *tsdn, pac_t *pac,
|
||||
ehooks_t *ehooks, edata_t *edata, size_t size_a, size_t size_b);
|
||||
ehooks_t *ehooks, edata_t *edata, size_t size_a, size_t size_b,
|
||||
bool holding_core_locks);
|
||||
bool extent_merge_wrapper(tsdn_t *tsdn, pac_t *pac, ehooks_t *ehooks,
|
||||
edata_t *a, edata_t *b);
|
||||
size_t extent_sn_next(pac_t *pac);
|
||||
|
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "jemalloc/internal/exp_grow.h"
|
||||
#include "jemalloc/internal/pai.h"
|
||||
#include "san_bump.h"
|
||||
|
||||
|
||||
/*
|
||||
@@ -127,6 +128,11 @@ pac_mapped(pac_t *pac) {
|
||||
return atomic_load_zu(&pac->stats->pac_mapped, ATOMIC_RELAXED);
|
||||
}
|
||||
|
||||
static inline ehooks_t *
|
||||
pac_ehooks_get(pac_t *pac) {
|
||||
return base_ehooks_get(pac->base);
|
||||
}
|
||||
|
||||
/*
|
||||
* All purging functions require holding decay->mtx. This is one of the few
|
||||
* places external modules are allowed to peek inside pa_shard_t internals.
|
||||
|
@@ -4,7 +4,8 @@
|
||||
#include "jemalloc/internal/ehooks.h"
|
||||
#include "jemalloc/internal/emap.h"
|
||||
|
||||
#define PAGE_GUARDS_SIZE (2 * PAGE)
|
||||
#define SAN_PAGE_GUARD PAGE
|
||||
#define SAN_PAGE_GUARDS_SIZE (SAN_PAGE_GUARD * 2)
|
||||
|
||||
#define SAN_GUARD_LARGE_EVERY_N_EXTENTS_DEFAULT 0
|
||||
#define SAN_GUARD_SMALL_EVERY_N_EXTENTS_DEFAULT 0
|
||||
@@ -14,9 +15,9 @@ extern size_t opt_san_guard_large;
|
||||
extern size_t opt_san_guard_small;
|
||||
|
||||
void san_guard_pages(tsdn_t *tsdn, ehooks_t *ehooks, edata_t *edata,
|
||||
emap_t *emap);
|
||||
emap_t *emap, bool left, bool right, bool remap);
|
||||
void san_unguard_pages(tsdn_t *tsdn, ehooks_t *ehooks, edata_t *edata,
|
||||
emap_t *emap);
|
||||
emap_t *emap, bool left, bool right);
|
||||
/*
|
||||
* Unguard the extent, but don't modify emap boundaries. Must be called on an
|
||||
* extent that has been erased from emap and shouldn't be placed back.
|
||||
@@ -25,6 +26,45 @@ void san_unguard_pages_pre_destroy(tsdn_t *tsdn, ehooks_t *ehooks,
|
||||
edata_t *edata, emap_t *emap);
|
||||
void tsd_san_init(tsd_t *tsd);
|
||||
|
||||
static inline void
|
||||
san_guard_pages_two_sided(tsdn_t *tsdn, ehooks_t *ehooks, edata_t *edata,
|
||||
emap_t *emap, bool remap) {
|
||||
return san_guard_pages(tsdn, ehooks, edata, emap, true, true,
|
||||
remap);
|
||||
}
|
||||
|
||||
static inline void
|
||||
san_unguard_pages_two_sided(tsdn_t *tsdn, ehooks_t *ehooks, edata_t *edata,
|
||||
emap_t *emap) {
|
||||
return san_unguard_pages(tsdn, ehooks, edata, emap, true, true);
|
||||
}
|
||||
|
||||
static inline size_t
|
||||
san_two_side_unguarded_sz(size_t size) {
|
||||
assert(size % PAGE == 0);
|
||||
assert(size >= SAN_PAGE_GUARDS_SIZE);
|
||||
return size - SAN_PAGE_GUARDS_SIZE;
|
||||
}
|
||||
|
||||
static inline size_t
|
||||
san_two_side_guarded_sz(size_t size) {
|
||||
assert(size % PAGE == 0);
|
||||
return size + SAN_PAGE_GUARDS_SIZE;
|
||||
}
|
||||
|
||||
static inline size_t
|
||||
san_one_side_unguarded_sz(size_t size) {
|
||||
assert(size % PAGE == 0);
|
||||
assert(size >= SAN_PAGE_GUARD);
|
||||
return size - SAN_PAGE_GUARD;
|
||||
}
|
||||
|
||||
static inline size_t
|
||||
san_one_side_guarded_sz(size_t size) {
|
||||
assert(size % PAGE == 0);
|
||||
return size + SAN_PAGE_GUARD;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
san_enabled(void) {
|
||||
return (opt_san_guard_large != 0 || opt_san_guard_small != 0);
|
||||
@@ -50,7 +90,7 @@ san_large_extent_decide_guard(tsdn_t *tsdn, ehooks_t *ehooks, size_t size,
|
||||
}
|
||||
|
||||
if (n == 1 && (alignment <= PAGE) &&
|
||||
(size + PAGE_GUARDS_SIZE <= SC_LARGE_MAXCLASS)) {
|
||||
(san_two_side_guarded_sz(size) <= SC_LARGE_MAXCLASS)) {
|
||||
*tsd_san_extents_until_guard_largep_get(tsd) =
|
||||
opt_san_guard_large;
|
||||
return true;
|
||||
|
27
include/jemalloc/internal/san_bump.h
Normal file
27
include/jemalloc/internal/san_bump.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef JEMALLOC_INTERNAL_SAN_BUMP_H
|
||||
#define JEMALLOC_INTERNAL_SAN_BUMP_H
|
||||
|
||||
#include "jemalloc/internal/edata.h"
|
||||
#include "jemalloc/internal/exp_grow.h"
|
||||
#include "jemalloc/internal/mutex.h"
|
||||
|
||||
extern const size_t SBA_RETAINED_ALLOC_SIZE;
|
||||
|
||||
typedef struct ehooks_s ehooks_t;
|
||||
typedef struct pac_s pac_t;
|
||||
|
||||
typedef struct san_bump_alloc_s san_bump_alloc_t;
|
||||
struct san_bump_alloc_s {
|
||||
malloc_mutex_t mtx;
|
||||
|
||||
edata_t *curr_reg;
|
||||
};
|
||||
|
||||
bool
|
||||
san_bump_alloc_init(san_bump_alloc_t* sba);
|
||||
|
||||
edata_t *
|
||||
san_bump_alloc(tsdn_t *tsdn, san_bump_alloc_t* sba, pac_t *pac, ehooks_t *ehooks,
|
||||
size_t size, bool zero);
|
||||
|
||||
#endif /* JEMALLOC_INTERNAL_SAN_BUMP_H */
|
@@ -48,6 +48,7 @@ enum witness_rank_e {
|
||||
|
||||
WITNESS_RANK_EXTENT_GROW,
|
||||
WITNESS_RANK_HPA_SHARD_GROW = WITNESS_RANK_EXTENT_GROW,
|
||||
WITNESS_RANK_SAN_BUMP_ALLOC = WITNESS_RANK_EXTENT_GROW,
|
||||
|
||||
WITNESS_RANK_EXTENTS,
|
||||
WITNESS_RANK_HPA_SHARD = WITNESS_RANK_EXTENTS,
|
||||
|
Reference in New Issue
Block a user