|
Packit |
345191 |
#ifndef JEMALLOC_INTERNAL_BIN_H
|
|
Packit |
345191 |
#define JEMALLOC_INTERNAL_BIN_H
|
|
Packit |
345191 |
|
|
Packit |
345191 |
#include "jemalloc/internal/bin_stats.h"
|
|
Packit |
345191 |
#include "jemalloc/internal/bin_types.h"
|
|
Packit |
345191 |
#include "jemalloc/internal/extent_types.h"
|
|
Packit |
345191 |
#include "jemalloc/internal/extent_structs.h"
|
|
Packit |
345191 |
#include "jemalloc/internal/mutex.h"
|
|
Packit |
345191 |
#include "jemalloc/internal/sc.h"
|
|
Packit |
345191 |
|
|
Packit |
345191 |
/*
|
|
Packit |
345191 |
* A bin contains a set of extents that are currently being used for slab
|
|
Packit |
345191 |
* allocations.
|
|
Packit |
345191 |
*/
|
|
Packit |
345191 |
|
|
Packit |
345191 |
/*
|
|
Packit |
345191 |
* Read-only information associated with each element of arena_t's bins array
|
|
Packit |
345191 |
* is stored separately, partly to reduce memory usage (only one copy, rather
|
|
Packit |
345191 |
* than one per arena), but mainly to avoid false cacheline sharing.
|
|
Packit |
345191 |
*
|
|
Packit |
345191 |
* Each slab has the following layout:
|
|
Packit |
345191 |
*
|
|
Packit |
345191 |
* /--------------------\
|
|
Packit |
345191 |
* | region 0 |
|
|
Packit |
345191 |
* |--------------------|
|
|
Packit |
345191 |
* | region 1 |
|
|
Packit |
345191 |
* |--------------------|
|
|
Packit |
345191 |
* | ... |
|
|
Packit |
345191 |
* | ... |
|
|
Packit |
345191 |
* | ... |
|
|
Packit |
345191 |
* |--------------------|
|
|
Packit |
345191 |
* | region nregs-1 |
|
|
Packit |
345191 |
* \--------------------/
|
|
Packit |
345191 |
*/
|
|
Packit |
345191 |
typedef struct bin_info_s bin_info_t;
|
|
Packit |
345191 |
struct bin_info_s {
|
|
Packit |
345191 |
/* Size of regions in a slab for this bin's size class. */
|
|
Packit |
345191 |
size_t reg_size;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
/* Total size of a slab for this bin's size class. */
|
|
Packit |
345191 |
size_t slab_size;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
/* Total number of regions in a slab for this bin's size class. */
|
|
Packit |
345191 |
uint32_t nregs;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
/* Number of sharded bins in each arena for this size class. */
|
|
Packit |
345191 |
uint32_t n_shards;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
/*
|
|
Packit |
345191 |
* Metadata used to manipulate bitmaps for slabs associated with this
|
|
Packit |
345191 |
* bin.
|
|
Packit |
345191 |
*/
|
|
Packit |
345191 |
bitmap_info_t bitmap_info;
|
|
Packit |
345191 |
};
|
|
Packit |
345191 |
|
|
Packit |
345191 |
extern bin_info_t bin_infos[SC_NBINS];
|
|
Packit |
345191 |
|
|
Packit |
345191 |
typedef struct bin_s bin_t;
|
|
Packit |
345191 |
struct bin_s {
|
|
Packit |
345191 |
/* All operations on bin_t fields require lock ownership. */
|
|
Packit |
345191 |
malloc_mutex_t lock;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
/*
|
|
Packit |
345191 |
* Current slab being used to service allocations of this bin's size
|
|
Packit |
345191 |
* class. slabcur is independent of slabs_{nonfull,full}; whenever
|
|
Packit |
345191 |
* slabcur is reassigned, the previous slab must be deallocated or
|
|
Packit |
345191 |
* inserted into slabs_{nonfull,full}.
|
|
Packit |
345191 |
*/
|
|
Packit |
345191 |
extent_t *slabcur;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
/*
|
|
Packit |
345191 |
* Heap of non-full slabs. This heap is used to assure that new
|
|
Packit |
345191 |
* allocations come from the non-full slab that is oldest/lowest in
|
|
Packit |
345191 |
* memory.
|
|
Packit |
345191 |
*/
|
|
Packit |
345191 |
extent_heap_t slabs_nonfull;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
/* List used to track full slabs. */
|
|
Packit |
345191 |
extent_list_t slabs_full;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
/* Bin statistics. */
|
|
Packit |
345191 |
bin_stats_t stats;
|
|
Packit |
345191 |
};
|
|
Packit |
345191 |
|
|
Packit |
345191 |
/* A set of sharded bins of the same size class. */
|
|
Packit |
345191 |
typedef struct bins_s bins_t;
|
|
Packit |
345191 |
struct bins_s {
|
|
Packit |
345191 |
/* Sharded bins. Dynamically sized. */
|
|
Packit |
345191 |
bin_t *bin_shards;
|
|
Packit |
345191 |
};
|
|
Packit |
345191 |
|
|
Packit |
345191 |
void bin_shard_sizes_boot(unsigned bin_shards[SC_NBINS]);
|
|
Packit |
345191 |
bool bin_update_shard_size(unsigned bin_shards[SC_NBINS], size_t start_size,
|
|
Packit |
345191 |
size_t end_size, size_t nshards);
|
|
Packit |
345191 |
void bin_boot(sc_data_t *sc_data, unsigned bin_shard_sizes[SC_NBINS]);
|
|
Packit |
345191 |
|
|
Packit |
345191 |
/* Initializes a bin to empty. Returns true on error. */
|
|
Packit |
345191 |
bool bin_init(bin_t *bin);
|
|
Packit |
345191 |
|
|
Packit |
345191 |
/* Forking. */
|
|
Packit |
345191 |
void bin_prefork(tsdn_t *tsdn, bin_t *bin);
|
|
Packit |
345191 |
void bin_postfork_parent(tsdn_t *tsdn, bin_t *bin);
|
|
Packit |
345191 |
void bin_postfork_child(tsdn_t *tsdn, bin_t *bin);
|
|
Packit |
345191 |
|
|
Packit |
345191 |
/* Stats. */
|
|
Packit |
345191 |
static inline void
|
|
Packit |
345191 |
bin_stats_merge(tsdn_t *tsdn, bin_stats_t *dst_bin_stats, bin_t *bin) {
|
|
Packit |
345191 |
malloc_mutex_lock(tsdn, &bin->lock);
|
|
Packit |
345191 |
malloc_mutex_prof_accum(tsdn, &dst_bin_stats->mutex_data, &bin->lock);
|
|
Packit |
345191 |
dst_bin_stats->nmalloc += bin->stats.nmalloc;
|
|
Packit |
345191 |
dst_bin_stats->ndalloc += bin->stats.ndalloc;
|
|
Packit |
345191 |
dst_bin_stats->nrequests += bin->stats.nrequests;
|
|
Packit |
345191 |
dst_bin_stats->curregs += bin->stats.curregs;
|
|
Packit |
345191 |
dst_bin_stats->nfills += bin->stats.nfills;
|
|
Packit |
345191 |
dst_bin_stats->nflushes += bin->stats.nflushes;
|
|
Packit |
345191 |
dst_bin_stats->nslabs += bin->stats.nslabs;
|
|
Packit |
345191 |
dst_bin_stats->reslabs += bin->stats.reslabs;
|
|
Packit |
345191 |
dst_bin_stats->curslabs += bin->stats.curslabs;
|
|
Packit |
345191 |
dst_bin_stats->nonfull_slabs += bin->stats.nonfull_slabs;
|
|
Packit |
345191 |
malloc_mutex_unlock(tsdn, &bin->lock);
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
#endif /* JEMALLOC_INTERNAL_BIN_H */
|