1 1.1 christos #ifndef JEMALLOC_INTERNAL_ESET_H 2 1.1 christos #define JEMALLOC_INTERNAL_ESET_H 3 1.1 christos 4 1.1 christos #include "jemalloc/internal/atomic.h" 5 1.1 christos #include "jemalloc/internal/fb.h" 6 1.1 christos #include "jemalloc/internal/edata.h" 7 1.1 christos #include "jemalloc/internal/mutex.h" 8 1.1 christos 9 1.1 christos /* 10 1.1 christos * An eset ("extent set") is a quantized collection of extents, with built-in 11 1.1 christos * LRU queue. 12 1.1 christos * 13 1.1 christos * This class is not thread-safe; synchronization must be done externally if 14 1.1 christos * there are mutating operations. One exception is the stats counters, which 15 1.1 christos * may be read without any locking. 16 1.1 christos */ 17 1.1 christos 18 1.1 christos typedef struct eset_bin_s eset_bin_t; 19 1.1 christos struct eset_bin_s { 20 1.1 christos edata_heap_t heap; 21 1.1 christos /* 22 1.1 christos * We do first-fit across multiple size classes. If we compared against 23 1.1 christos * the min element in each heap directly, we'd take a cache miss per 24 1.1 christos * extent we looked at. If we co-locate the edata summaries, we only 25 1.1 christos * take a miss on the edata we're actually going to return (which is 26 1.1 christos * inevitable anyways). 27 1.1 christos */ 28 1.1 christos edata_cmp_summary_t heap_min; 29 1.1 christos }; 30 1.1 christos 31 1.1 christos typedef struct eset_bin_stats_s eset_bin_stats_t; 32 1.1 christos struct eset_bin_stats_s { 33 1.1 christos atomic_zu_t nextents; 34 1.1 christos atomic_zu_t nbytes; 35 1.1 christos }; 36 1.1 christos 37 1.1 christos typedef struct eset_s eset_t; 38 1.1 christos struct eset_s { 39 1.1 christos /* Bitmap for which set bits correspond to non-empty heaps. */ 40 1.1 christos fb_group_t bitmap[FB_NGROUPS(SC_NPSIZES + 1)]; 41 1.1 christos 42 1.1 christos /* Quantized per size class heaps of extents. */ 43 1.1 christos eset_bin_t bins[SC_NPSIZES + 1]; 44 1.1 christos 45 1.1 christos eset_bin_stats_t bin_stats[SC_NPSIZES + 1]; 46 1.1 christos 47 1.1 christos /* LRU of all extents in heaps. */ 48 1.1 christos edata_list_inactive_t lru; 49 1.1 christos 50 1.1 christos /* Page sum for all extents in heaps. */ 51 1.1 christos atomic_zu_t npages; 52 1.1 christos 53 1.1 christos /* 54 1.1 christos * A duplication of the data in the containing ecache. We use this only 55 1.1 christos * for assertions on the states of the passed-in extents. 56 1.1 christos */ 57 1.1 christos extent_state_t state; 58 1.1 christos }; 59 1.1 christos 60 1.1 christos void eset_init(eset_t *eset, extent_state_t state); 61 1.1 christos 62 1.1 christos size_t eset_npages_get(eset_t *eset); 63 1.1 christos /* Get the number of extents in the given page size index. */ 64 1.1 christos size_t eset_nextents_get(eset_t *eset, pszind_t ind); 65 1.1 christos /* Get the sum total bytes of the extents in the given page size index. */ 66 1.1 christos size_t eset_nbytes_get(eset_t *eset, pszind_t ind); 67 1.1 christos 68 1.1 christos void eset_insert(eset_t *eset, edata_t *edata); 69 1.1 christos void eset_remove(eset_t *eset, edata_t *edata); 70 1.1 christos /* 71 1.1 christos * Select an extent from this eset of the given size and alignment. Returns 72 1.1 christos * null if no such item could be found. 73 1.1 christos */ 74 1.1 christos edata_t *eset_fit(eset_t *eset, size_t esize, size_t alignment, bool exact_only, 75 1.1 christos unsigned lg_max_fit); 76 1.1 christos 77 1.1 christos #endif /* JEMALLOC_INTERNAL_ESET_H */ 78