1 /* GLIB sliced memory - fast concurrent memory chunk allocator
2 * Copyright (C) 2005 Tim Janik
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
23 #if defined HAVE_POSIX_MEMALIGN && defined POSIX_MEMALIGN_WITH_COMPLIANT_ALLOCS
24 # define HAVE_COMPLIANT_POSIX_MEMALIGN 1
27 #ifdef HAVE_COMPLIANT_POSIX_MEMALIGN
28 #define _XOPEN_SOURCE 600 /* posix_memalign() */
30 #include <stdlib.h> /* posix_memalign() */
33 #include "gmem.h" /* gslice.h */
34 #include "gthreadprivate.h"
38 #include <unistd.h> /* sysconf() */
45 /* the GSlice allocator is split up into 4 layers, roughly modelled after the slab
46 * allocator and magazine extensions as outlined in:
47 * + [Bonwick94] Jeff Bonwick, The slab allocator: An object-caching kernel
48 * memory allocator. USENIX 1994, http://citeseer.ist.psu.edu/bonwick94slab.html
49 * + [Bonwick01] Bonwick and Jonathan Adams, Magazines and vmem: Extending the
50 * slab allocator to many cpu's and arbitrary resources.
51 * USENIX 2001, http://citeseer.ist.psu.edu/bonwick01magazines.html
53 * - the thread magazines. for each (aligned) chunk size, a magazine (a list)
54 * of recently freed and soon to be allocated chunks is maintained per thread.
55 * this way, most alloc/free requests can be quickly satisfied from per-thread
56 * free lists which only require one g_private_get() call to retrive the
58 * - the magazine cache. allocating and freeing chunks to/from threads only
59 * occours at magazine sizes from a global depot of magazines. the depot
60 * maintaines a 15 second working set of allocated magazines, so full
61 * magazines are not allocated and released too often.
62 * the chunk size dependent magazine sizes automatically adapt (within limits,
63 * see [3]) to lock contention to properly scale performance across a variety
65 * - the slab allocator. this allocator allocates slabs (blocks of memory) close
66 * to the system page size or multiples thereof which have to be page aligned.
67 * the blocks are divided into smaller chunks which are used to satisfy
68 * allocations from the upper layers. the space provided by the reminder of
69 * the chunk size division is used for cache colorization (random distribution
70 * of chunk addresses) to improve processor cache utilization. multiple slabs
71 * with the same chunk size are kept in a partially sorted ring to allow O(1)
72 * freeing and allocation of chunks (as long as the allocation of an entirely
73 * new slab can be avoided).
74 * - the page allocator. on most modern systems, posix_memalign(3) or
75 * memalign(3) should be available, so this is used to allocate blocks with
76 * system page size based alignments and sizes or multiples thereof.
77 * if no memalign variant is provided, valloc() is used instead and
78 * block sizes are limited to the system page size (no multiples thereof).
79 * as a fallback, on system without even valloc(), a malloc(3)-based page
80 * allocator with alloc-only behaviour is used.
83 * [1] some systems memalign(3) implementations may rely on boundary tagging for
84 * the handed out memory chunks. to avoid excessive page-wise fragmentation,
85 * we reserve 2 * sizeof (void*) per block size for the systems memalign(3),
86 * specified in NATIVE_MALLOC_PADDING.
87 * [2] using the slab allocator alone already provides for a fast and efficient
88 * allocator, it doesn't properly scale beyond single-threaded uses though.
89 * also, the slab allocator implements eager free(3)-ing, i.e. does not
90 * provide any form of caching or working set maintenance. so if used alone,
91 * it's vulnerable to trashing for sequences of balanced (alloc, free) pairs
92 * at certain thresholds.
93 * [3] magazine sizes are bound by an implementation specific minimum size and
94 * a chunk size specific maximum to limit magazine storage sizes to roughly
96 * [4] allocating ca. 8 chunks per block/page keeps a good balance between
97 * external and internal fragmentation (<= 12.5%). [Bonwick94]
100 /* --- macros and constants --- */
101 #define LARGEALIGNMENT (256)
102 #define P2ALIGNMENT (2 * sizeof (gsize)) /* fits 2 pointers (assumed to be 2 * GLIB_SIZEOF_SIZE_T below) */
103 #define ALIGN(size, base) ((base) * (gsize) (((size) + (base) - 1) / (base)))
104 #define NATIVE_MALLOC_PADDING P2ALIGNMENT /* per-page padding left for native malloc(3) see [1] */
105 #define SLAB_INFO_SIZE P2ALIGN (sizeof (SlabInfo) + NATIVE_MALLOC_PADDING)
106 #define MAX_MAGAZINE_SIZE (256) /* see [3] and allocator_get_magazine_threshold() for this */
107 #define MIN_MAGAZINE_SIZE (4)
108 #define MAX_STAMP_COUNTER (7) /* distributes the load of gettimeofday() */
109 #define MAX_SLAB_CHUNK_SIZE(al) (((al)->max_page_size - SLAB_INFO_SIZE) / 8) /* we want at last 8 chunks per page, see [4] */
110 #define MAX_SLAB_INDEX(al) (SLAB_INDEX (al, MAX_SLAB_CHUNK_SIZE (al)) + 1)
111 #define SLAB_INDEX(al, asize) ((asize) / P2ALIGNMENT - 1) /* asize must be P2ALIGNMENT aligned */
112 #define SLAB_CHUNK_SIZE(al, ix) (((ix) + 1) * P2ALIGNMENT)
113 #define SLAB_BPAGE_SIZE(al,csz) (8 * (csz) + SLAB_INFO_SIZE)
115 /* optimized version of ALIGN (size, P2ALIGNMENT) */
116 #if GLIB_SIZEOF_SIZE_T * 2 == 8 /* P2ALIGNMENT */
117 #define P2ALIGN(size) (((size) + 0x7) & ~(gsize) 0x7)
118 #elif GLIB_SIZEOF_SIZE_T * 2 == 16 /* P2ALIGNMENT */
119 #define P2ALIGN(size) (((size) + 0xf) & ~(gsize) 0xf)
121 #define P2ALIGN(size) ALIGN (size, P2ALIGNMENT)
124 /* special helpers to avoid gmessage.c dependency */
125 static void mem_error (const char *format, ...) G_GNUC_PRINTF (1,2);
126 #define mem_assert(cond) do { if (G_LIKELY (cond)) ; else mem_error ("assertion failed: %s", #cond); } while (0)
128 /* --- structures --- */
129 typedef struct _ChunkLink ChunkLink;
130 typedef struct _SlabInfo SlabInfo;
131 typedef struct _CachedMagazine CachedMagazine;
139 SlabInfo *next, *prev;
143 gsize count; /* approximative chunks list length */
146 Magazine *magazine1; /* array of MAX_SLAB_INDEX (allocator) */
147 Magazine *magazine2; /* array of MAX_SLAB_INDEX (allocator) */
150 gboolean always_malloc;
151 gboolean bypass_magazines;
152 gboolean debug_blocks;
153 gsize working_set_msecs;
154 guint color_increment;
157 /* const after initialization */
158 gsize min_page_size, max_page_size;
160 gsize max_slab_chunk_size_for_magazine_cache;
162 GMutex *magazine_mutex;
163 ChunkLink **magazines; /* array of MAX_SLAB_INDEX (allocator) */
164 guint *contention_counters; /* array of MAX_SLAB_INDEX (allocator) */
170 SlabInfo **slab_stack; /* array of MAX_SLAB_INDEX (allocator) */
174 /* --- g-slice prototypes --- */
175 static gpointer slab_allocator_alloc_chunk (gsize chunk_size);
176 static void slab_allocator_free_chunk (gsize chunk_size,
178 static void private_thread_memory_cleanup (gpointer data);
179 static gpointer allocator_memalign (gsize alignment,
181 static void allocator_memfree (gsize memsize,
183 static inline void magazine_cache_update_stamp (void);
184 static inline gsize allocator_get_magazine_threshold (Allocator *allocator,
187 /* --- g-slice memory checker --- */
188 static void smc_notify_alloc (void *pointer,
190 static int smc_notify_free (void *pointer,
193 /* --- variables --- */
194 static GPrivate *private_thread_memory = NULL;
195 static gsize sys_page_size = 0;
196 static Allocator allocator[1] = { { 0, }, };
197 static SliceConfig slice_config = {
198 FALSE, /* always_malloc */
199 FALSE, /* bypass_magazines */
200 FALSE, /* debug_blocks */
201 15 * 1000, /* working_set_msecs */
202 1, /* color increment, alt: 0x7fffffff */
204 static GMutex *smc_tree_mutex = NULL; /* mutex for G_SLICE=debug-blocks */
209 static pthread_mutex_t sdt_mutex = PTHREAD_MUTEX_INITIALIZER;
210 #define SDT_LOCK() pthread_mutex_lock (&sdt_mutex)
211 #define SDT_UNLOCK() pthread_mutex_unlock (&sdt_mutex)
215 /* We don't want to depend on pthreads on Win32, at least for now. But
216 * if we change GThread to use pthreads-win32 we could use pthreads
220 static CRITICAL_SECTION sdt_mutex;
221 #define SDT_LOCK() EnterCriticalSection (&sdt_mutex)
222 #define SDT_UNLOCK() LeaveCriticalSection (&sdt_mutex)
226 /* --- auxillary funcitons --- */
228 g_slice_set_config (GSliceConfig ckey,
231 g_return_if_fail (sys_page_size == 0);
234 case G_SLICE_CONFIG_ALWAYS_MALLOC:
235 slice_config.always_malloc = value != 0;
237 case G_SLICE_CONFIG_BYPASS_MAGAZINES:
238 slice_config.bypass_magazines = value != 0;
240 case G_SLICE_CONFIG_WORKING_SET_MSECS:
241 slice_config.working_set_msecs = value;
243 case G_SLICE_CONFIG_COLOR_INCREMENT:
244 slice_config.color_increment = value;
250 g_slice_get_config (GSliceConfig ckey)
254 case G_SLICE_CONFIG_ALWAYS_MALLOC:
255 return slice_config.always_malloc;
256 case G_SLICE_CONFIG_BYPASS_MAGAZINES:
257 return slice_config.bypass_magazines;
258 case G_SLICE_CONFIG_WORKING_SET_MSECS:
259 return slice_config.working_set_msecs;
260 case G_SLICE_CONFIG_CHUNK_SIZES:
261 return MAX_SLAB_INDEX (allocator);
262 case G_SLICE_CONFIG_COLOR_INCREMENT:
263 return slice_config.color_increment;
270 g_slice_get_config_state (GSliceConfig ckey,
275 g_return_val_if_fail (n_values != NULL, NULL);
280 case G_SLICE_CONFIG_CONTENTION_COUNTER:
281 array[i++] = SLAB_CHUNK_SIZE (allocator, address);
282 array[i++] = allocator->contention_counters[address];
283 array[i++] = allocator_get_magazine_threshold (allocator, address);
285 return g_memdup (array, sizeof (array[0]) * *n_values);
292 slice_config_init (SliceConfig *config)
294 /* don't use g_malloc/g_message here */
296 const gchar *val = _g_getenv_nomalloc ("G_SLICE", buffer);
297 static const GDebugKey keys[] = {
298 { "always-malloc", 1 << 0 },
299 { "debug-blocks", 1 << 1 },
301 gint flags = !val ? 0 : g_parse_debug_string (val, keys, G_N_ELEMENTS (keys));
302 *config = slice_config;
303 if (flags & (1 << 0)) /* always-malloc */
304 config->always_malloc = TRUE;
305 if (flags & (1 << 1)) /* debug-blocks */
306 config->debug_blocks = TRUE;
310 g_slice_init_nomessage (void)
312 /* we may not use g_error() or friends here */
313 mem_assert (sys_page_size == 0);
314 mem_assert (MIN_MAGAZINE_SIZE >= 4);
318 SYSTEM_INFO system_info;
319 GetSystemInfo (&system_info);
320 sys_page_size = system_info.dwPageSize;
323 sys_page_size = sysconf (_SC_PAGESIZE); /* = sysconf (_SC_PAGE_SIZE); = getpagesize(); */
325 mem_assert (sys_page_size >= 2 * LARGEALIGNMENT);
326 mem_assert ((sys_page_size & (sys_page_size - 1)) == 0);
327 slice_config_init (&allocator->config);
328 allocator->min_page_size = sys_page_size;
329 #if HAVE_COMPLIANT_POSIX_MEMALIGN || HAVE_MEMALIGN
330 /* allow allocation of pages up to 8KB (with 8KB alignment).
331 * this is useful because many medium to large sized structures
332 * fit less than 8 times (see [4]) into 4KB pages.
333 * we allow very small page sizes here, to reduce wastage in
334 * threads if only small allocations are required (this does
335 * bear the risk of incresing allocation times and fragmentation
338 allocator->min_page_size = MAX (allocator->min_page_size, 4096);
339 allocator->max_page_size = MAX (allocator->min_page_size, 8192);
340 allocator->min_page_size = MIN (allocator->min_page_size, 128);
342 /* we can only align to system page size */
343 allocator->max_page_size = sys_page_size;
345 allocator->magazine_mutex = NULL; /* _g_slice_thread_init_nomessage() */
346 allocator->magazines = g_new0 (ChunkLink*, MAX_SLAB_INDEX (allocator));
347 allocator->contention_counters = g_new0 (guint, MAX_SLAB_INDEX (allocator));
348 allocator->mutex_counter = 0;
349 allocator->stamp_counter = MAX_STAMP_COUNTER; /* force initial update */
350 allocator->last_stamp = 0;
351 allocator->slab_mutex = NULL; /* _g_slice_thread_init_nomessage() */
352 allocator->slab_stack = g_new0 (SlabInfo*, MAX_SLAB_INDEX (allocator));
353 allocator->color_accu = 0;
354 magazine_cache_update_stamp();
355 /* values cached for performance reasons */
356 allocator->max_slab_chunk_size_for_magazine_cache = MAX_SLAB_CHUNK_SIZE (allocator);
357 if (allocator->config.always_malloc || allocator->config.bypass_magazines)
358 allocator->max_slab_chunk_size_for_magazine_cache = 0; /* non-optimized cases */
359 /* at this point, g_mem_gc_friendly() should be initialized, this
360 * should have been accomplished by the above g_malloc/g_new calls
365 allocator_categorize (gsize aligned_chunk_size)
367 /* speed up the likely path */
368 if (G_LIKELY (aligned_chunk_size && aligned_chunk_size <= allocator->max_slab_chunk_size_for_magazine_cache))
369 return 1; /* use magazine cache */
371 /* the above will fail (max_slab_chunk_size_for_magazine_cache == 0) if the
372 * allocator is still uninitialized, or if we are not configured to use the
376 g_slice_init_nomessage ();
377 if (!allocator->config.always_malloc &&
378 aligned_chunk_size &&
379 aligned_chunk_size <= MAX_SLAB_CHUNK_SIZE (allocator))
381 if (allocator->config.bypass_magazines)
382 return 2; /* use slab allocator, see [2] */
383 return 1; /* use magazine cache */
385 return 0; /* use malloc() */
389 _g_slice_thread_init_nomessage (void)
391 /* we may not use g_error() or friends here */
393 mem_error ("g_thread_init() must be called before GSlice is used, memory corrupted...");
394 g_slice_init_nomessage();
395 private_thread_memory = g_private_new (private_thread_memory_cleanup);
396 allocator->magazine_mutex = g_mutex_new();
397 allocator->slab_mutex = g_mutex_new();
398 if (allocator->config.debug_blocks)
400 smc_tree_mutex = g_mutex_new();
402 InitializeCriticalSection (&sdt_mutex);
408 g_mutex_lock_a (GMutex *mutex,
409 guint *contention_counter)
411 gboolean contention = FALSE;
412 if (!g_mutex_trylock (mutex))
414 g_mutex_lock (mutex);
419 allocator->mutex_counter++;
420 if (allocator->mutex_counter >= 1) /* quickly adapt to contention */
422 allocator->mutex_counter = 0;
423 *contention_counter = MIN (*contention_counter + 1, MAX_MAGAZINE_SIZE);
426 else /* !contention */
428 allocator->mutex_counter--;
429 if (allocator->mutex_counter < -11) /* moderately recover magazine sizes */
431 allocator->mutex_counter = 0;
432 *contention_counter = MAX (*contention_counter, 1) - 1;
437 static inline ThreadMemory*
438 thread_memory_from_self (void)
440 ThreadMemory *tmem = g_private_get (private_thread_memory);
441 if (G_UNLIKELY (!tmem))
443 const guint n_magazines = MAX_SLAB_INDEX (allocator);
444 tmem = g_malloc0 (sizeof (ThreadMemory) + sizeof (Magazine) * 2 * n_magazines);
445 tmem->magazine1 = (Magazine*) (tmem + 1);
446 tmem->magazine2 = &tmem->magazine1[n_magazines];
447 g_private_set (private_thread_memory, tmem);
452 static inline ChunkLink*
453 magazine_chain_pop_head (ChunkLink **magazine_chunks)
455 /* magazine chains are linked via ChunkLink->next.
456 * each ChunkLink->data of the toplevel chain may point to a subchain,
457 * linked via ChunkLink->next. ChunkLink->data of the subchains just
458 * contains uninitialized junk.
460 ChunkLink *chunk = (*magazine_chunks)->data;
461 if (G_UNLIKELY (chunk))
463 /* allocating from freed list */
464 (*magazine_chunks)->data = chunk->next;
468 chunk = *magazine_chunks;
469 *magazine_chunks = chunk->next;
474 #if 0 /* useful for debugging */
476 magazine_count (ChunkLink *head)
483 ChunkLink *child = head->data;
485 for (child = head->data; child; child = child->next)
494 allocator_get_magazine_threshold (Allocator *allocator,
497 /* the magazine size calculated here has a lower bound of MIN_MAGAZINE_SIZE,
498 * which is required by the implementation. also, for moderately sized chunks
499 * (say >= 64 bytes), magazine sizes shouldn't be much smaller then the number
500 * of chunks available per page/2 to avoid excessive traffic in the magazine
501 * cache for small to medium sized structures.
502 * the upper bound of the magazine size is effectively provided by
503 * MAX_MAGAZINE_SIZE. for larger chunks, this number is scaled down so that
504 * the content of a single magazine doesn't exceed ca. 16KB.
506 gsize chunk_size = SLAB_CHUNK_SIZE (allocator, ix);
507 guint threshold = MAX (MIN_MAGAZINE_SIZE, allocator->max_page_size / MAX (5 * chunk_size, 5 * 32));
508 guint contention_counter = allocator->contention_counters[ix];
509 if (G_UNLIKELY (contention_counter)) /* single CPU bias */
511 /* adapt contention counter thresholds to chunk sizes */
512 contention_counter = contention_counter * 64 / chunk_size;
513 threshold = MAX (threshold, contention_counter);
518 /* --- magazine cache --- */
520 magazine_cache_update_stamp (void)
522 if (allocator->stamp_counter >= MAX_STAMP_COUNTER)
525 g_get_current_time (&tv);
526 allocator->last_stamp = tv.tv_sec * 1000 + tv.tv_usec / 1000; /* milli seconds */
527 allocator->stamp_counter = 0;
530 allocator->stamp_counter++;
533 static inline ChunkLink*
534 magazine_chain_prepare_fields (ChunkLink *magazine_chunks)
540 /* checked upon initialization: mem_assert (MIN_MAGAZINE_SIZE >= 4); */
541 /* ensure a magazine with at least 4 unused data pointers */
542 chunk1 = magazine_chain_pop_head (&magazine_chunks);
543 chunk2 = magazine_chain_pop_head (&magazine_chunks);
544 chunk3 = magazine_chain_pop_head (&magazine_chunks);
545 chunk4 = magazine_chain_pop_head (&magazine_chunks);
546 chunk4->next = magazine_chunks;
547 chunk3->next = chunk4;
548 chunk2->next = chunk3;
549 chunk1->next = chunk2;
553 /* access the first 3 fields of a specially prepared magazine chain */
554 #define magazine_chain_prev(mc) ((mc)->data)
555 #define magazine_chain_stamp(mc) ((mc)->next->data)
556 #define magazine_chain_uint_stamp(mc) GPOINTER_TO_UINT ((mc)->next->data)
557 #define magazine_chain_next(mc) ((mc)->next->next->data)
558 #define magazine_chain_count(mc) ((mc)->next->next->next->data)
561 magazine_cache_trim (Allocator *allocator,
565 /* g_mutex_lock (allocator->mutex); done by caller */
566 /* trim magazine cache from tail */
567 ChunkLink *current = magazine_chain_prev (allocator->magazines[ix]);
568 ChunkLink *trash = NULL;
569 while (ABS (stamp - magazine_chain_uint_stamp (current)) >= allocator->config.working_set_msecs)
572 ChunkLink *prev = magazine_chain_prev (current);
573 ChunkLink *next = magazine_chain_next (current);
574 magazine_chain_next (prev) = next;
575 magazine_chain_prev (next) = prev;
576 /* clear special fields, put on trash stack */
577 magazine_chain_next (current) = NULL;
578 magazine_chain_count (current) = NULL;
579 magazine_chain_stamp (current) = NULL;
580 magazine_chain_prev (current) = trash;
582 /* fixup list head if required */
583 if (current == allocator->magazines[ix])
585 allocator->magazines[ix] = NULL;
590 g_mutex_unlock (allocator->magazine_mutex);
594 const gsize chunk_size = SLAB_CHUNK_SIZE (allocator, ix);
595 g_mutex_lock (allocator->slab_mutex);
599 trash = magazine_chain_prev (current);
600 magazine_chain_prev (current) = NULL; /* clear special field */
603 ChunkLink *chunk = magazine_chain_pop_head (¤t);
604 slab_allocator_free_chunk (chunk_size, chunk);
607 g_mutex_unlock (allocator->slab_mutex);
612 magazine_cache_push_magazine (guint ix,
613 ChunkLink *magazine_chunks,
614 gsize count) /* must be >= MIN_MAGAZINE_SIZE */
616 ChunkLink *current = magazine_chain_prepare_fields (magazine_chunks);
617 ChunkLink *next, *prev;
618 g_mutex_lock (allocator->magazine_mutex);
619 /* add magazine at head */
620 next = allocator->magazines[ix];
622 prev = magazine_chain_prev (next);
624 next = prev = current;
625 magazine_chain_next (prev) = current;
626 magazine_chain_prev (next) = current;
627 magazine_chain_prev (current) = prev;
628 magazine_chain_next (current) = next;
629 magazine_chain_count (current) = (gpointer) count;
631 magazine_cache_update_stamp();
632 magazine_chain_stamp (current) = GUINT_TO_POINTER (allocator->last_stamp);
633 allocator->magazines[ix] = current;
634 /* free old magazines beyond a certain threshold */
635 magazine_cache_trim (allocator, ix, allocator->last_stamp);
636 /* g_mutex_unlock (allocator->mutex); was done by magazine_cache_trim() */
640 magazine_cache_pop_magazine (guint ix,
643 g_mutex_lock_a (allocator->magazine_mutex, &allocator->contention_counters[ix]);
644 if (!allocator->magazines[ix])
646 guint magazine_threshold = allocator_get_magazine_threshold (allocator, ix);
647 gsize i, chunk_size = SLAB_CHUNK_SIZE (allocator, ix);
648 ChunkLink *chunk, *head;
649 g_mutex_unlock (allocator->magazine_mutex);
650 g_mutex_lock (allocator->slab_mutex);
651 head = slab_allocator_alloc_chunk (chunk_size);
654 for (i = 1; i < magazine_threshold; i++)
656 chunk->next = slab_allocator_alloc_chunk (chunk_size);
661 g_mutex_unlock (allocator->slab_mutex);
667 ChunkLink *current = allocator->magazines[ix];
668 ChunkLink *prev = magazine_chain_prev (current);
669 ChunkLink *next = magazine_chain_next (current);
671 magazine_chain_next (prev) = next;
672 magazine_chain_prev (next) = prev;
673 allocator->magazines[ix] = next == current ? NULL : next;
674 g_mutex_unlock (allocator->magazine_mutex);
675 /* clear special fields and hand out */
676 *countp = (gsize) magazine_chain_count (current);
677 magazine_chain_prev (current) = NULL;
678 magazine_chain_next (current) = NULL;
679 magazine_chain_count (current) = NULL;
680 magazine_chain_stamp (current) = NULL;
685 /* --- thread magazines --- */
687 private_thread_memory_cleanup (gpointer data)
689 ThreadMemory *tmem = data;
690 const guint n_magazines = MAX_SLAB_INDEX (allocator);
692 for (ix = 0; ix < n_magazines; ix++)
696 mags[0] = &tmem->magazine1[ix];
697 mags[1] = &tmem->magazine2[ix];
698 for (j = 0; j < 2; j++)
700 Magazine *mag = mags[j];
701 if (mag->count >= MIN_MAGAZINE_SIZE)
702 magazine_cache_push_magazine (ix, mag->chunks, mag->count);
705 const gsize chunk_size = SLAB_CHUNK_SIZE (allocator, ix);
706 g_mutex_lock (allocator->slab_mutex);
709 ChunkLink *chunk = magazine_chain_pop_head (&mag->chunks);
710 slab_allocator_free_chunk (chunk_size, chunk);
712 g_mutex_unlock (allocator->slab_mutex);
720 thread_memory_magazine1_reload (ThreadMemory *tmem,
723 Magazine *mag = &tmem->magazine1[ix];
724 mem_assert (mag->chunks == NULL); /* ensure that we may reset mag->count */
726 mag->chunks = magazine_cache_pop_magazine (ix, &mag->count);
730 thread_memory_magazine2_unload (ThreadMemory *tmem,
733 Magazine *mag = &tmem->magazine2[ix];
734 magazine_cache_push_magazine (ix, mag->chunks, mag->count);
740 thread_memory_swap_magazines (ThreadMemory *tmem,
743 Magazine xmag = tmem->magazine1[ix];
744 tmem->magazine1[ix] = tmem->magazine2[ix];
745 tmem->magazine2[ix] = xmag;
748 static inline gboolean
749 thread_memory_magazine1_is_empty (ThreadMemory *tmem,
752 return tmem->magazine1[ix].chunks == NULL;
755 static inline gboolean
756 thread_memory_magazine2_is_full (ThreadMemory *tmem,
759 return tmem->magazine2[ix].count >= allocator_get_magazine_threshold (allocator, ix);
762 static inline gpointer
763 thread_memory_magazine1_alloc (ThreadMemory *tmem,
766 Magazine *mag = &tmem->magazine1[ix];
767 ChunkLink *chunk = magazine_chain_pop_head (&mag->chunks);
768 if (G_LIKELY (mag->count > 0))
774 thread_memory_magazine2_free (ThreadMemory *tmem,
778 Magazine *mag = &tmem->magazine2[ix];
779 ChunkLink *chunk = mem;
781 chunk->next = mag->chunks;
786 /* --- API functions --- */
788 g_slice_alloc (gsize mem_size)
793 chunk_size = P2ALIGN (mem_size);
794 acat = allocator_categorize (chunk_size);
795 if (G_LIKELY (acat == 1)) /* allocate through magazine layer */
797 ThreadMemory *tmem = thread_memory_from_self();
798 guint ix = SLAB_INDEX (allocator, chunk_size);
799 if (G_UNLIKELY (thread_memory_magazine1_is_empty (tmem, ix)))
801 thread_memory_swap_magazines (tmem, ix);
802 if (G_UNLIKELY (thread_memory_magazine1_is_empty (tmem, ix)))
803 thread_memory_magazine1_reload (tmem, ix);
805 mem = thread_memory_magazine1_alloc (tmem, ix);
807 else if (acat == 2) /* allocate through slab allocator */
809 g_mutex_lock (allocator->slab_mutex);
810 mem = slab_allocator_alloc_chunk (chunk_size);
811 g_mutex_unlock (allocator->slab_mutex);
813 else /* delegate to system malloc */
814 mem = g_malloc (mem_size);
815 if (G_UNLIKELY (allocator->config.debug_blocks))
816 smc_notify_alloc (mem, mem_size);
821 g_slice_alloc0 (gsize mem_size)
823 gpointer mem = g_slice_alloc (mem_size);
825 memset (mem, 0, mem_size);
830 g_slice_free1 (gsize mem_size,
833 gsize chunk_size = P2ALIGN (mem_size);
834 guint acat = allocator_categorize (chunk_size);
835 if (G_UNLIKELY (!mem_block))
837 if (G_UNLIKELY (allocator->config.debug_blocks) &&
838 !smc_notify_free (mem_block, mem_size))
840 if (G_LIKELY (acat == 1)) /* allocate through magazine layer */
842 ThreadMemory *tmem = thread_memory_from_self();
843 guint ix = SLAB_INDEX (allocator, chunk_size);
844 if (G_UNLIKELY (thread_memory_magazine2_is_full (tmem, ix)))
846 thread_memory_swap_magazines (tmem, ix);
847 if (G_UNLIKELY (thread_memory_magazine2_is_full (tmem, ix)))
848 thread_memory_magazine2_unload (tmem, ix);
850 if (G_UNLIKELY (g_mem_gc_friendly))
851 memset (mem_block, 0, chunk_size);
852 thread_memory_magazine2_free (tmem, ix, mem_block);
854 else if (acat == 2) /* allocate through slab allocator */
856 if (G_UNLIKELY (g_mem_gc_friendly))
857 memset (mem_block, 0, chunk_size);
858 g_mutex_lock (allocator->slab_mutex);
859 slab_allocator_free_chunk (chunk_size, mem_block);
860 g_mutex_unlock (allocator->slab_mutex);
862 else /* delegate to system malloc */
864 if (G_UNLIKELY (g_mem_gc_friendly))
865 memset (mem_block, 0, mem_size);
871 g_slice_free_chain_with_offset (gsize mem_size,
875 gpointer slice = mem_chain;
876 /* while the thread magazines and the magazine cache are implemented so that
877 * they can easily be extended to allow for free lists containing more free
878 * lists for the first level nodes, which would allow O(1) freeing in this
879 * function, the benefit of such an extension is questionable, because:
880 * - the magazine size counts will become mere lower bounds which confuses
881 * the code adapting to lock contention;
882 * - freeing a single node to the thread magazines is very fast, so this
883 * O(list_length) operation is multiplied by a fairly small factor;
884 * - memory usage histograms on larger applications seem to indicate that
885 * the amount of released multi node lists is negligible in comparison
886 * to single node releases.
887 * - the major performance bottle neck, namely g_private_get() or
888 * g_mutex_lock()/g_mutex_unlock() has already been moved out of the
889 * inner loop for freeing chained slices.
891 gsize chunk_size = P2ALIGN (mem_size);
892 guint acat = allocator_categorize (chunk_size);
893 if (G_LIKELY (acat == 1)) /* allocate through magazine layer */
895 ThreadMemory *tmem = thread_memory_from_self();
896 guint ix = SLAB_INDEX (allocator, chunk_size);
899 guint8 *current = slice;
900 slice = *(gpointer*) (current + next_offset);
901 if (G_UNLIKELY (allocator->config.debug_blocks) &&
902 !smc_notify_free (current, mem_size))
904 if (G_UNLIKELY (thread_memory_magazine2_is_full (tmem, ix)))
906 thread_memory_swap_magazines (tmem, ix);
907 if (G_UNLIKELY (thread_memory_magazine2_is_full (tmem, ix)))
908 thread_memory_magazine2_unload (tmem, ix);
910 if (G_UNLIKELY (g_mem_gc_friendly))
911 memset (current, 0, chunk_size);
912 thread_memory_magazine2_free (tmem, ix, current);
915 else if (acat == 2) /* allocate through slab allocator */
917 g_mutex_lock (allocator->slab_mutex);
920 guint8 *current = slice;
921 slice = *(gpointer*) (current + next_offset);
922 if (G_UNLIKELY (allocator->config.debug_blocks) &&
923 !smc_notify_free (current, mem_size))
925 if (G_UNLIKELY (g_mem_gc_friendly))
926 memset (current, 0, chunk_size);
927 slab_allocator_free_chunk (chunk_size, current);
929 g_mutex_unlock (allocator->slab_mutex);
931 else /* delegate to system malloc */
934 guint8 *current = slice;
935 slice = *(gpointer*) (current + next_offset);
936 if (G_UNLIKELY (allocator->config.debug_blocks) &&
937 !smc_notify_free (current, mem_size))
939 if (G_UNLIKELY (g_mem_gc_friendly))
940 memset (current, 0, mem_size);
945 /* --- single page allocator --- */
947 allocator_slab_stack_push (Allocator *allocator,
951 /* insert slab at slab ring head */
952 if (!allocator->slab_stack[ix])
959 SlabInfo *next = allocator->slab_stack[ix], *prev = next->prev;
965 allocator->slab_stack[ix] = sinfo;
969 allocator_aligned_page_size (Allocator *allocator,
972 gsize val = 1 << g_bit_storage (n_bytes - 1);
973 val = MAX (val, allocator->min_page_size);
978 allocator_add_slab (Allocator *allocator,
984 gsize addr, padding, n_chunks, color = 0;
985 gsize page_size = allocator_aligned_page_size (allocator, SLAB_BPAGE_SIZE (allocator, chunk_size));
986 /* allocate 1 page for the chunks and the slab */
987 gpointer aligned_memory = allocator_memalign (page_size, page_size - NATIVE_MALLOC_PADDING);
988 guint8 *mem = aligned_memory;
992 const gchar *syserr = "unknown error";
994 syserr = strerror (errno);
996 mem_error ("failed to allocate %u bytes (alignment: %u): %s\n",
997 (guint) (page_size - NATIVE_MALLOC_PADDING), (guint) page_size, syserr);
999 /* mask page adress */
1000 addr = ((gsize) mem / page_size) * page_size;
1001 /* assert alignment */
1002 mem_assert (aligned_memory == (gpointer) addr);
1003 /* basic slab info setup */
1004 sinfo = (SlabInfo*) (mem + page_size - SLAB_INFO_SIZE);
1005 sinfo->n_allocated = 0;
1006 sinfo->chunks = NULL;
1007 /* figure cache colorization */
1008 n_chunks = ((guint8*) sinfo - mem) / chunk_size;
1009 padding = ((guint8*) sinfo - mem) - n_chunks * chunk_size;
1012 color = (allocator->color_accu * P2ALIGNMENT) % padding;
1013 allocator->color_accu += allocator->config.color_increment;
1015 /* add chunks to free list */
1016 chunk = (ChunkLink*) (mem + color);
1017 sinfo->chunks = chunk;
1018 for (i = 0; i < n_chunks - 1; i++)
1020 chunk->next = (ChunkLink*) ((guint8*) chunk + chunk_size);
1021 chunk = chunk->next;
1023 chunk->next = NULL; /* last chunk */
1024 /* add slab to slab ring */
1025 allocator_slab_stack_push (allocator, ix, sinfo);
1029 slab_allocator_alloc_chunk (gsize chunk_size)
1032 guint ix = SLAB_INDEX (allocator, chunk_size);
1033 /* ensure non-empty slab */
1034 if (!allocator->slab_stack[ix] || !allocator->slab_stack[ix]->chunks)
1035 allocator_add_slab (allocator, ix, chunk_size);
1036 /* allocate chunk */
1037 chunk = allocator->slab_stack[ix]->chunks;
1038 allocator->slab_stack[ix]->chunks = chunk->next;
1039 allocator->slab_stack[ix]->n_allocated++;
1040 /* rotate empty slabs */
1041 if (!allocator->slab_stack[ix]->chunks)
1042 allocator->slab_stack[ix] = allocator->slab_stack[ix]->next;
1047 slab_allocator_free_chunk (gsize chunk_size,
1052 guint ix = SLAB_INDEX (allocator, chunk_size);
1053 gsize page_size = allocator_aligned_page_size (allocator, SLAB_BPAGE_SIZE (allocator, chunk_size));
1054 gsize addr = ((gsize) mem / page_size) * page_size;
1055 /* mask page adress */
1056 guint8 *page = (guint8*) addr;
1057 SlabInfo *sinfo = (SlabInfo*) (page + page_size - SLAB_INFO_SIZE);
1058 /* assert valid chunk count */
1059 mem_assert (sinfo->n_allocated > 0);
1060 /* add chunk to free list */
1061 was_empty = sinfo->chunks == NULL;
1062 chunk = (ChunkLink*) mem;
1063 chunk->next = sinfo->chunks;
1064 sinfo->chunks = chunk;
1065 sinfo->n_allocated--;
1066 /* keep slab ring partially sorted, empty slabs at end */
1070 SlabInfo *next = sinfo->next, *prev = sinfo->prev;
1073 if (allocator->slab_stack[ix] == sinfo)
1074 allocator->slab_stack[ix] = next == sinfo ? NULL : next;
1075 /* insert slab at head */
1076 allocator_slab_stack_push (allocator, ix, sinfo);
1078 /* eagerly free complete unused slabs */
1079 if (!sinfo->n_allocated)
1082 SlabInfo *next = sinfo->next, *prev = sinfo->prev;
1085 if (allocator->slab_stack[ix] == sinfo)
1086 allocator->slab_stack[ix] = next == sinfo ? NULL : next;
1088 allocator_memfree (page_size, page);
1092 /* --- memalign implementation --- */
1093 #ifdef HAVE_MALLOC_H
1094 #include <malloc.h> /* memalign() */
1098 * define HAVE_POSIX_MEMALIGN 1 // if free(posix_memalign(3)) works, <stdlib.h>
1099 * define HAVE_COMPLIANT_POSIX_MEMALIGN 1 // if free(posix_memalign(3)) works for sizes != 2^n, <stdlib.h>
1100 * define HAVE_MEMALIGN 1 // if free(memalign(3)) works, <malloc.h>
1101 * define HAVE_VALLOC 1 // if free(valloc(3)) works, <stdlib.h> or <malloc.h>
1102 * if none is provided, we implement malloc(3)-based alloc-only page alignment
1105 #if !(HAVE_COMPLIANT_POSIX_MEMALIGN || HAVE_MEMALIGN || HAVE_VALLOC)
1106 static GTrashStack *compat_valloc_trash = NULL;
1110 allocator_memalign (gsize alignment,
1113 gpointer aligned_memory = NULL;
1115 #if HAVE_COMPLIANT_POSIX_MEMALIGN
1116 err = posix_memalign (&aligned_memory, alignment, memsize);
1119 aligned_memory = memalign (alignment, memsize);
1123 aligned_memory = valloc (memsize);
1126 /* simplistic non-freeing page allocator */
1127 mem_assert (alignment == sys_page_size);
1128 mem_assert (memsize <= sys_page_size);
1129 if (!compat_valloc_trash)
1131 const guint n_pages = 16;
1132 guint8 *mem = malloc (n_pages * sys_page_size);
1137 guint8 *amem = (guint8*) ALIGN ((gsize) mem, sys_page_size);
1139 i--; /* mem wasn't page aligned */
1141 g_trash_stack_push (&compat_valloc_trash, amem + i * sys_page_size);
1144 aligned_memory = g_trash_stack_pop (&compat_valloc_trash);
1146 if (!aligned_memory)
1148 return aligned_memory;
1152 allocator_memfree (gsize memsize,
1155 #if HAVE_COMPLIANT_POSIX_MEMALIGN || HAVE_MEMALIGN || HAVE_VALLOC
1158 mem_assert (memsize <= sys_page_size);
1159 g_trash_stack_push (&compat_valloc_trash, mem);
1166 mem_error (const char *format,
1171 /* at least, put out "MEMORY-ERROR", in case we segfault during the rest of the function */
1172 fputs ("\n***MEMORY-ERROR***: ", stderr);
1173 pname = g_get_prgname();
1174 fprintf (stderr, "%s[%u]: GSlice: ", pname ? pname : "", getpid());
1175 va_start (args, format);
1176 vfprintf (stderr, format, args);
1178 fputs ("\n", stderr);
1183 /* --- g-slice memory checker tree --- */
1184 typedef size_t SmcKType; /* key type */
1185 typedef size_t SmcVType; /* value type */
1190 static void smc_tree_insert (SmcKType key,
1192 static gboolean smc_tree_lookup (SmcKType key,
1194 static gboolean smc_tree_remove (SmcKType key);
1197 /* --- g-slice memory checker implementation --- */
1199 smc_notify_alloc (void *pointer,
1202 size_t adress = (size_t) pointer;
1204 smc_tree_insert (adress, size);
1209 smc_notify_ignore (void *pointer)
1211 size_t adress = (size_t) pointer;
1213 smc_tree_remove (adress);
1218 smc_notify_free (void *pointer,
1221 size_t adress = (size_t) pointer;
1223 return 1; /* ignore */
1225 gboolean found_one = smc_tree_lookup (adress, &real_size);
1228 fprintf (stderr, "GSlice: MemChecker: attempt to release non-allocated block: %p size=%zu\n", pointer, size);
1231 if (real_size != size && (real_size || size))
1233 fprintf (stderr, "GSlice: MemChecker: attempt to release block with invalid size: %p size=%zu invalid-size=%zu\n", pointer, real_size, size);
1236 if (!smc_tree_remove (adress))
1238 fprintf (stderr, "GSlice: MemChecker: attempt to release non-allocated block: %p size=%zu\n", pointer, size);
1241 return 1; /* all fine */
1244 /* --- g-slice memory checker tree implementation --- */
1245 #define SMC_TRUNK_COUNT (4093 /* 16381 */) /* prime, to distribute trunk collisions (big, allocated just once) */
1246 #define SMC_BRANCH_COUNT (511) /* prime, to distribute branch collisions */
1247 #define SMC_TRUNK_EXTENT (SMC_BRANCH_COUNT * 2039) /* key adress space per trunk, should distribute uniformly across BRANCH_COUNT */
1248 #define SMC_TRUNK_HASH(k) ((k / SMC_TRUNK_EXTENT) % SMC_TRUNK_COUNT) /* generate new trunk hash per megabyte (roughly) */
1249 #define SMC_BRANCH_HASH(k) (k % SMC_BRANCH_COUNT)
1253 unsigned int n_entries;
1256 static SmcBranch **smc_tree_root = NULL;
1259 smc_tree_abort (int errval)
1261 const char *syserr = "unknown error";
1263 syserr = strerror (errval);
1265 mem_error ("MemChecker: failure in debugging tree: %s", syserr);
1268 static inline SmcEntry*
1269 smc_tree_branch_grow_L (SmcBranch *branch,
1272 unsigned int old_size = branch->n_entries * sizeof (branch->entries[0]);
1273 unsigned int new_size = old_size + sizeof (branch->entries[0]);
1275 mem_assert (index <= branch->n_entries);
1276 branch->entries = (SmcEntry*) realloc (branch->entries, new_size);
1277 if (!branch->entries)
1278 smc_tree_abort (errno);
1279 entry = branch->entries + index;
1280 g_memmove (entry + 1, entry, (branch->n_entries - index) * sizeof (entry[0]));
1281 branch->n_entries += 1;
1285 static inline SmcEntry*
1286 smc_tree_branch_lookup_nearest_L (SmcBranch *branch,
1289 unsigned int n_nodes = branch->n_entries, offs = 0;
1290 SmcEntry *check = branch->entries;
1292 while (offs < n_nodes)
1294 unsigned int i = (offs + n_nodes) >> 1;
1295 check = branch->entries + i;
1296 cmp = key < check->key ? -1 : key != check->key;
1298 return check; /* return exact match */
1301 else /* (cmp > 0) */
1304 /* check points at last mismatch, cmp > 0 indicates greater key */
1305 return cmp > 0 ? check + 1 : check; /* return insertion position for inexact match */
1309 smc_tree_insert (SmcKType key,
1313 g_mutex_lock (smc_tree_mutex);
1314 unsigned int ix0 = SMC_TRUNK_HASH (key), ix1 = SMC_BRANCH_HASH (key);
1317 smc_tree_root = calloc (SMC_TRUNK_COUNT, sizeof (smc_tree_root[0]));
1319 smc_tree_abort (errno);
1321 if (!smc_tree_root[ix0])
1323 smc_tree_root[ix0] = calloc (SMC_BRANCH_COUNT, sizeof (smc_tree_root[0][0]));
1324 if (!smc_tree_root[ix0])
1325 smc_tree_abort (errno);
1327 SmcEntry *entry = smc_tree_branch_lookup_nearest_L (&smc_tree_root[ix0][ix1], key);
1328 if (!entry || /* need create */
1329 entry >= smc_tree_root[ix0][ix1].entries + smc_tree_root[ix0][ix1].n_entries || /* need append */
1330 entry->key != key) /* need insert */
1331 entry = smc_tree_branch_grow_L (&smc_tree_root[ix0][ix1], entry - smc_tree_root[ix0][ix1].entries);
1333 entry->value = value;
1334 g_mutex_unlock (smc_tree_mutex);
1339 smc_tree_lookup (SmcKType key,
1342 unsigned int ix0 = SMC_TRUNK_HASH (key), ix1 = SMC_BRANCH_HASH (key);
1343 gboolean found_one = FALSE;
1346 g_mutex_lock (smc_tree_mutex);
1347 SmcEntry *entry = NULL;
1348 if (smc_tree_root && smc_tree_root[ix0])
1350 entry = smc_tree_branch_lookup_nearest_L (&smc_tree_root[ix0][ix1], key);
1352 entry < smc_tree_root[ix0][ix1].entries + smc_tree_root[ix0][ix1].n_entries &&
1356 *value_p = entry->value;
1359 g_mutex_unlock (smc_tree_mutex);
1365 smc_tree_remove (SmcKType key)
1367 unsigned int ix0 = SMC_TRUNK_HASH (key), ix1 = SMC_BRANCH_HASH (key);
1368 gboolean found_one = FALSE;
1370 g_mutex_lock (smc_tree_mutex);
1371 if (smc_tree_root && smc_tree_root[ix0])
1373 SmcEntry *entry = smc_tree_branch_lookup_nearest_L (&smc_tree_root[ix0][ix1], key);
1375 entry < smc_tree_root[ix0][ix1].entries + smc_tree_root[ix0][ix1].n_entries &&
1378 unsigned int i = entry - smc_tree_root[ix0][ix1].entries;
1379 smc_tree_root[ix0][ix1].n_entries -= 1;
1380 g_memmove (entry, entry + 1, (smc_tree_root[ix0][ix1].n_entries - i) * sizeof (entry[0]));
1381 if (!smc_tree_root[ix0][ix1].n_entries)
1383 /* avoid useless pressure on the memory system */
1384 free (smc_tree_root[ix0][ix1].entries);
1385 smc_tree_root[ix0][ix1].entries = NULL;
1390 g_mutex_unlock (smc_tree_mutex);
1395 #ifdef G_ENABLE_DEBUG
1397 g_slice_debug_tree_statistics (void)
1400 g_mutex_lock (smc_tree_mutex);
1403 unsigned int i, j, t = 0, o = 0, b = 0, su = 0, ex = 0, en = 4294967295u;
1405 for (i = 0; i < SMC_TRUNK_COUNT; i++)
1406 if (smc_tree_root[i])
1409 for (j = 0; j < SMC_BRANCH_COUNT; j++)
1410 if (smc_tree_root[i][j].n_entries)
1413 su += smc_tree_root[i][j].n_entries;
1414 en = MIN (en, smc_tree_root[i][j].n_entries);
1415 ex = MAX (ex, smc_tree_root[i][j].n_entries);
1417 else if (smc_tree_root[i][j].entries)
1418 o++; /* formerly used, now empty */
1421 tf = MAX (t, 1.0); // max(1) to be a valid divisor
1422 bf = MAX (b, 1.0); // max(1) to be a valid divisor
1423 fprintf (stderr, "GSlice: MemChecker: %u trunks, %u branches, %u old branches\n", t, b, o);
1424 fprintf (stderr, "GSlice: MemChecker: %f branches per trunk, %.2f%% utilization\n",
1426 100.0 - (SMC_BRANCH_COUNT - b / tf) / (0.01 * SMC_BRANCH_COUNT));
1427 fprintf (stderr, "GSlice: MemChecker: %f entries per branch, %u minimum, %u maximum\n",
1431 fprintf (stderr, "GSlice: MemChecker: root=NULL\n");
1432 g_mutex_unlock (smc_tree_mutex);
1435 /* sample statistics (beast + GSLice + 24h scripted core & GUI activity):
1436 * PID %CPU %MEM VSZ RSS COMMAND
1437 * 8887 30.3 45.8 456068 414856 beast-0.7.1 empty.bse
1438 * $ cat /proc/8887/statm # total-program-size resident-set-size shared-pages text/code data/stack library dirty-pages
1439 * 114017 103714 2354 344 0 108676 0
1440 * $ cat /proc/8887/status
1451 * (gdb) print g_slice_debug_tree_statistics ()
1452 * GSlice: MemChecker: 422 trunks, 213068 branches, 0 old branches
1453 * GSlice: MemChecker: 504.900474 branches per trunk, 98.81% utilization
1454 * GSlice: MemChecker: 4.965039 entries per branch, 1 minimum, 37 maximum
1457 #endif /* G_ENABLE_DEBUG */
1459 #define __G_SLICE_C__
1460 #include "galiasdef.c"