Rearrange slab data and constants

The constants logically belong in the sc module. The slab data bitmap isn't
really scoped to an arena; move it to its own module.
This commit is contained in:
David T. Goldblatt 2019-09-20 16:36:42 -07:00 committed by David Goldblatt
parent d1be488cd8
commit e7cf84a8dd
9 changed files with 29 additions and 29 deletions

View File

@ -1,11 +0,0 @@
#ifndef JEMALLOC_INTERNAL_ARENA_STRUCTS_A_H
#define JEMALLOC_INTERNAL_ARENA_STRUCTS_A_H
#include "jemalloc/internal/bitmap.h"
struct arena_slab_data_s {
/* Per region allocated/deallocated bitmap. */
bitmap_t bitmap[BITMAP_GROUPS_MAX];
};
#endif /* JEMALLOC_INTERNAL_ARENA_STRUCTS_A_H */

View File

@ -3,17 +3,12 @@
#include "jemalloc/internal/sc.h" #include "jemalloc/internal/sc.h"
/* Maximum number of regions in one slab. */
#define LG_SLAB_MAXREGS (LG_PAGE - SC_LG_TINY_MIN)
#define SLAB_MAXREGS (1U << LG_SLAB_MAXREGS)
/* Default decay times in milliseconds. */ /* Default decay times in milliseconds. */
#define DIRTY_DECAY_MS_DEFAULT ZD(10 * 1000) #define DIRTY_DECAY_MS_DEFAULT ZD(10 * 1000)
#define MUZZY_DECAY_MS_DEFAULT (0) #define MUZZY_DECAY_MS_DEFAULT (0)
/* Number of event ticks between time checks. */ /* Number of event ticks between time checks. */
#define DECAY_NTICKS_PER_UPDATE 1000 #define DECAY_NTICKS_PER_UPDATE 1000
typedef struct arena_slab_data_s arena_slab_data_t;
typedef struct arena_decay_s arena_decay_t; typedef struct arena_decay_s arena_decay_t;
typedef struct arena_s arena_t; typedef struct arena_s arena_t;
typedef struct arena_tdata_s arena_tdata_t; typedef struct arena_tdata_s arena_tdata_t;

View File

@ -1,7 +1,6 @@
#ifndef JEMALLOC_INTERNAL_BITMAP_H #ifndef JEMALLOC_INTERNAL_BITMAP_H
#define JEMALLOC_INTERNAL_BITMAP_H #define JEMALLOC_INTERNAL_BITMAP_H
#include "jemalloc/internal/arena_types.h"
#include "jemalloc/internal/bit_util.h" #include "jemalloc/internal/bit_util.h"
#include "jemalloc/internal/sc.h" #include "jemalloc/internal/sc.h"
@ -9,9 +8,9 @@ typedef unsigned long bitmap_t;
#define LG_SIZEOF_BITMAP LG_SIZEOF_LONG #define LG_SIZEOF_BITMAP LG_SIZEOF_LONG
/* Maximum bitmap bit count is 2^LG_BITMAP_MAXBITS. */ /* Maximum bitmap bit count is 2^LG_BITMAP_MAXBITS. */
#if LG_SLAB_MAXREGS > LG_CEIL(SC_NSIZES) #if SC_LG_SLAB_MAXREGS > LG_CEIL(SC_NSIZES)
/* Maximum bitmap bit count is determined by maximum regions per slab. */ /* Maximum bitmap bit count is determined by maximum regions per slab. */
# define LG_BITMAP_MAXBITS LG_SLAB_MAXREGS # define LG_BITMAP_MAXBITS SC_LG_SLAB_MAXREGS
#else #else
/* Maximum bitmap bit count is determined by number of extent size classes. */ /* Maximum bitmap bit count is determined by number of extent size classes. */
# define LG_BITMAP_MAXBITS LG_CEIL(SC_NSIZES) # define LG_BITMAP_MAXBITS LG_CEIL(SC_NSIZES)

View File

@ -168,13 +168,13 @@ extent_past_get(const extent_t *extent) {
extent_size_get(extent)); extent_size_get(extent));
} }
static inline arena_slab_data_t * static inline slab_data_t *
extent_slab_data_get(extent_t *extent) { extent_slab_data_get(extent_t *extent) {
assert(extent_slab_get(extent)); assert(extent_slab_get(extent));
return &extent->e_slab_data; return &extent->e_slab_data;
} }
static inline const arena_slab_data_t * static inline const slab_data_t *
extent_slab_data_get_const(const extent_t *extent) { extent_slab_data_get_const(const extent_t *extent) {
assert(extent_slab_get(extent)); assert(extent_slab_get(extent));
return &extent->e_slab_data; return &extent->e_slab_data;

View File

@ -8,6 +8,7 @@
#include "jemalloc/internal/ql.h" #include "jemalloc/internal/ql.h"
#include "jemalloc/internal/ph.h" #include "jemalloc/internal/ph.h"
#include "jemalloc/internal/sc.h" #include "jemalloc/internal/sc.h"
#include "jemalloc/internal/slab_data.h"
typedef enum { typedef enum {
extent_state_active = 0, extent_state_active = 0,
@ -120,7 +121,7 @@ struct extent_s {
#define EXTENT_BITS_SZIND_SHIFT (EXTENT_BITS_STATE_WIDTH + EXTENT_BITS_STATE_SHIFT) #define EXTENT_BITS_SZIND_SHIFT (EXTENT_BITS_STATE_WIDTH + EXTENT_BITS_STATE_SHIFT)
#define EXTENT_BITS_SZIND_MASK MASK(EXTENT_BITS_SZIND_WIDTH, EXTENT_BITS_SZIND_SHIFT) #define EXTENT_BITS_SZIND_MASK MASK(EXTENT_BITS_SZIND_WIDTH, EXTENT_BITS_SZIND_SHIFT)
#define EXTENT_BITS_NFREE_WIDTH (LG_SLAB_MAXREGS + 1) #define EXTENT_BITS_NFREE_WIDTH (SC_LG_SLAB_MAXREGS + 1)
#define EXTENT_BITS_NFREE_SHIFT (EXTENT_BITS_SZIND_WIDTH + EXTENT_BITS_SZIND_SHIFT) #define EXTENT_BITS_NFREE_SHIFT (EXTENT_BITS_SZIND_WIDTH + EXTENT_BITS_SZIND_SHIFT)
#define EXTENT_BITS_NFREE_MASK MASK(EXTENT_BITS_NFREE_WIDTH, EXTENT_BITS_NFREE_SHIFT) #define EXTENT_BITS_NFREE_MASK MASK(EXTENT_BITS_NFREE_WIDTH, EXTENT_BITS_NFREE_SHIFT)
@ -170,7 +171,7 @@ struct extent_s {
union { union {
/* Small region slab metadata. */ /* Small region slab metadata. */
arena_slab_data_t e_slab_data; slab_data_t e_slab_data;
/* Profiling data, used for large objects. */ /* Profiling data, used for large objects. */
struct { struct {

View File

@ -50,7 +50,6 @@
/* STRUCTS */ /* STRUCTS */
/******************************************************************************/ /******************************************************************************/
#include "jemalloc/internal/arena_structs_a.h"
#include "jemalloc/internal/extent_structs.h" #include "jemalloc/internal/extent_structs.h"
#include "jemalloc/internal/base_structs.h" #include "jemalloc/internal/base_structs.h"
#include "jemalloc/internal/prof_structs.h" #include "jemalloc/internal/prof_structs.h"

View File

@ -264,6 +264,11 @@
/* The largest size class supported. */ /* The largest size class supported. */
#define SC_LARGE_MAXCLASS (SC_MAX_BASE + (SC_NGROUP - 1) * SC_MAX_DELTA) #define SC_LARGE_MAXCLASS (SC_MAX_BASE + (SC_NGROUP - 1) * SC_MAX_DELTA)
/* Maximum number of regions in one slab. */
#define SC_LG_SLAB_MAXREGS (LG_PAGE - SC_LG_TINY_MIN)
#define SC_SLAB_MAXREGS (1U << LG_SLAB_MAXREGS)
typedef struct sc_s sc_t; typedef struct sc_s sc_t;
struct sc_s { struct sc_s {
/* Size class index, or -1 if not a valid size class. */ /* Size class index, or -1 if not a valid size class. */

View File

@ -0,0 +1,12 @@
#ifndef JEMALLOC_INTERNAL_SLAB_DATA_H
#define JEMALLOC_INTERNAL_SLAB_DATA_H
#include "jemalloc/internal/bitmap.h"
typedef struct slab_data_s slab_data_t;
struct slab_data_s {
/* Per region allocated/deallocated bitmap. */
bitmap_t bitmap[BITMAP_GROUPS_MAX];
};
#endif /* JEMALLOC_INTERNAL_SLAB_DATA_H */

View File

@ -270,7 +270,7 @@ arena_extents_dirty_dalloc(tsdn_t *tsdn, arena_t *arena,
static void * static void *
arena_slab_reg_alloc(extent_t *slab, const bin_info_t *bin_info) { arena_slab_reg_alloc(extent_t *slab, const bin_info_t *bin_info) {
void *ret; void *ret;
arena_slab_data_t *slab_data = extent_slab_data_get(slab); slab_data_t *slab_data = extent_slab_data_get(slab);
size_t regind; size_t regind;
assert(extent_nfree_get(slab) > 0); assert(extent_nfree_get(slab) > 0);
@ -286,7 +286,7 @@ arena_slab_reg_alloc(extent_t *slab, const bin_info_t *bin_info) {
static void static void
arena_slab_reg_alloc_batch(extent_t *slab, const bin_info_t *bin_info, arena_slab_reg_alloc_batch(extent_t *slab, const bin_info_t *bin_info,
unsigned cnt, void** ptrs) { unsigned cnt, void** ptrs) {
arena_slab_data_t *slab_data = extent_slab_data_get(slab); slab_data_t *slab_data = extent_slab_data_get(slab);
assert(extent_nfree_get(slab) >= cnt); assert(extent_nfree_get(slab) >= cnt);
assert(!bitmap_full(slab_data->bitmap, &bin_info->bitmap_info)); assert(!bitmap_full(slab_data->bitmap, &bin_info->bitmap_info));
@ -356,7 +356,7 @@ arena_slab_regind(extent_t *slab, szind_t binind, const void *ptr) {
} }
static void static void
arena_slab_reg_dalloc(extent_t *slab, arena_slab_data_t *slab_data, void *ptr) { arena_slab_reg_dalloc(extent_t *slab, slab_data_t *slab_data, void *ptr) {
szind_t binind = extent_szind_get(slab); szind_t binind = extent_szind_get(slab);
const bin_info_t *bin_info = &bin_infos[binind]; const bin_info_t *bin_info = &bin_infos[binind];
size_t regind = arena_slab_regind(slab, binind, ptr); size_t regind = arena_slab_regind(slab, binind, ptr);
@ -1253,7 +1253,7 @@ arena_slab_alloc(tsdn_t *tsdn, arena_t *arena, szind_t binind, unsigned binshard
assert(extent_slab_get(slab)); assert(extent_slab_get(slab));
/* Initialize slab internals. */ /* Initialize slab internals. */
arena_slab_data_t *slab_data = extent_slab_data_get(slab); slab_data_t *slab_data = extent_slab_data_get(slab);
extent_nfree_binshard_set(slab, bin_info->nregs, binshard); extent_nfree_binshard_set(slab, bin_info->nregs, binshard);
bitmap_init(slab_data->bitmap, &bin_info->bitmap_info, false); bitmap_init(slab_data->bitmap, &bin_info->bitmap_info, false);
@ -1686,7 +1686,7 @@ arena_bin_lower_slab(tsdn_t *tsdn, arena_t *arena, extent_t *slab,
static void static void
arena_dalloc_bin_locked_impl(tsdn_t *tsdn, arena_t *arena, bin_t *bin, arena_dalloc_bin_locked_impl(tsdn_t *tsdn, arena_t *arena, bin_t *bin,
szind_t binind, extent_t *slab, void *ptr, bool junked) { szind_t binind, extent_t *slab, void *ptr, bool junked) {
arena_slab_data_t *slab_data = extent_slab_data_get(slab); slab_data_t *slab_data = extent_slab_data_get(slab);
const bin_info_t *bin_info = &bin_infos[binind]; const bin_info_t *bin_info = &bin_infos[binind];
if (!junked && config_fill && unlikely(opt_junk_free)) { if (!junked && config_fill && unlikely(opt_junk_free)) {