1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-29 22:40:34 +02:00
guile/src/freelist.h
Andy Wingo d2e745ac23 Rework large object space
Store allocations in a splay tree so that we can efficiently map from an
edge originating in the lospace to its object.  Defer returning memory
to the OS to a periodic background thread, using a similar strategy as
for nofl and copy-space pages.  Use a size-segregated freelist instead
of requiring a full best-fit search for those pages that haven't yet
been returned to the OS.
2025-01-06 16:59:54 +01:00

31 lines
1.5 KiB
C

#ifndef FREELIST_H
#define FREELIST_H
// A size-segregated freelist with linear-log buckets à la
// https://pvk.ca/Blog/2015/06/27/linear-log-bucketing-fast-versatile-simple/.
#include "gc-assert.h"
#include "gc-histogram.h"
#include <string.h>
#define DEFINE_FREELIST(name, max_value_bits, precision, node) \
struct name { node buckets[((max_value_bits) << (precision)) + 1]; }; \
static inline size_t name##_num_size_classes(void) { \
return ((max_value_bits) << (precision)) + 1; \
} \
static inline uint64_t name##_bucket_min_val(size_t idx) { \
GC_ASSERT(idx < name##_num_size_classes()); \
return gc_histogram_bucket_min_val((precision), idx); \
} \
static inline void name##_init(struct name *f) { \
memset(f, 0, sizeof(*f)); \
} \
static inline size_t name##_size_class(uint64_t val) { \
return gc_histogram_bucket((max_value_bits), (precision), val); \
} \
static inline node* name##_bucket(struct name *f, uint64_t val) { \
return &f->buckets[name##_size_class(val)]; \
}
#endif // FREELIST_H