} Allocator;
/* --- prototypes --- */
-static gpointer slab_allocator_alloc_chunk (guint chunk_size);
-static void slab_allocator_free_chunk (guint chunk_size,
+static gpointer slab_allocator_alloc_chunk (gsize chunk_size);
+static void slab_allocator_free_chunk (gsize chunk_size,
gpointer mem);
static void private_thread_memory_cleanup (gpointer data);
static gpointer allocator_memalign (gsize alignment,
static void allocator_memfree (gsize memsize,
gpointer mem);
static inline void magazine_cache_update_stamp (void);
-static inline guint allocator_get_magazine_threshold (Allocator *allocator,
+static inline gsize allocator_get_magazine_threshold (Allocator *allocator,
guint ix);
/* --- variables --- */
}
static inline guint
-allocator_categorize (guint aligned_chunk_size)
+allocator_categorize (gsize aligned_chunk_size)
{
/* speed up the likely path */
if (G_LIKELY (aligned_chunk_size && aligned_chunk_size <= allocator->max_slab_chunk_size_for_magazine_cache))
static inline void
g_mutex_lock_a (GMutex *mutex,
- guint *threshold)
+ guint *contention_counter)
{
gboolean contention = FALSE;
if (!g_mutex_trylock (mutex))
if (allocator->mutex_counter >= 1) /* quickly adapt to contention */
{
allocator->mutex_counter = 0;
- *threshold = MIN (*threshold + 1, MAX_MAGAZINE_SIZE);
+ *contention_counter = MIN (*contention_counter + 1, MAX_MAGAZINE_SIZE);
}
}
else /* !contention */
if (allocator->mutex_counter < -11) /* moderately recover magazine sizes */
{
allocator->mutex_counter = 0;
- *threshold = MAX (*threshold, 1) - 1;
+ *contention_counter = MAX (*contention_counter, 1) - 1;
}
}
}
return chunk;
}
+#if 0 /* useful for debugging */
static guint
magazine_count (ChunkLink *head)
{
}
return count;
}
+#endif
-static inline guint
+static inline gsize
allocator_get_magazine_threshold (Allocator *allocator,
guint ix)
{
* MAX_MAGAZINE_SIZE. for larger chunks, this number is scaled down so that
* the content of a single magazine doesn't exceed ca. 16KB.
*/
- guint chunk_size = SLAB_CHUNK_SIZE (allocator, ix);
+ gsize chunk_size = SLAB_CHUNK_SIZE (allocator, ix);
guint threshold = MAX (MIN_MAGAZINE_SIZE, allocator->max_page_size / MAX (5 * chunk_size, 5 * 32));
guint contention_counter = allocator->contention_counters[ix];
if (G_UNLIKELY (contention_counter)) /* single CPU bias */
/* free trash */
if (trash)
{
- const guint chunk_size = SLAB_CHUNK_SIZE (allocator, ix);
+ const gsize chunk_size = SLAB_CHUNK_SIZE (allocator, ix);
g_mutex_lock (allocator->slab_mutex);
while (trash)
{
magazine_cache_push_magazine (ix, mag->chunks, mag->count);
else
{
- const guint chunk_size = SLAB_CHUNK_SIZE (allocator, ix);
+ const gsize chunk_size = SLAB_CHUNK_SIZE (allocator, ix);
g_mutex_lock (allocator->slab_mutex);
while (mag->chunks)
{
}
gpointer
-g_slice_alloc0 (guint mem_size)
+g_slice_alloc0 (gsize mem_size)
{
gpointer mem = g_slice_alloc (mem_size);
if (mem)
}
void
-g_slice_free1 (guint mem_size,
+g_slice_free1 (gsize mem_size,
gpointer mem_block)
{
- guint chunk_size = P2ALIGN (mem_size);
+ gsize chunk_size = P2ALIGN (mem_size);
guint acat = allocator_categorize (chunk_size);
if (G_UNLIKELY (!mem_block))
/* pass */;
}
void
-g_slice_free_chain (guint mem_size,
+g_slice_free_chain (gsize mem_size,
gpointer mem_chain,
- guint next_offset)
+ gsize next_offset)
{
GSList *slice = mem_chain;
g_return_if_fail (next_offset == G_STRUCT_OFFSET (GSList, next));
static void
allocator_add_slab (Allocator *allocator,
guint ix,
- guint chunk_size)
+ gsize chunk_size)
{
SlabInfo *sinfo;
gsize padding, n_chunks, color = 0;
}
static gpointer
-slab_allocator_alloc_chunk (guint chunk_size)
+slab_allocator_alloc_chunk (gsize chunk_size)
{
guint ix = SLAB_INDEX (allocator, chunk_size);
/* ensure non-empty slab */
}
static void
-slab_allocator_free_chunk (guint chunk_size,
+slab_allocator_free_chunk (gsize chunk_size,
gpointer mem)
{
guint ix = SLAB_INDEX (allocator, chunk_size);