diff --git a/src/gc.h b/src/gc.h index 1328ef88c2d7c..72899b721a102 100644 --- a/src/gc.h +++ b/src/gc.h @@ -33,8 +33,8 @@ extern "C" { #endif -#define GC_PAGE_LG2 14 // log2(size of a page) -#define GC_PAGE_SZ (1 << GC_PAGE_LG2) // 16k +#define GC_PAGE_LG2 16 // log2(size of a page) +#define GC_PAGE_SZ (1 << GC_PAGE_LG2) // 64k #define GC_PAGE_OFFSET (JL_HEAP_ALIGNMENT - (sizeof(jl_taggedvalue_t) % JL_HEAP_ALIGNMENT)) #define jl_malloc_tag ((void*)0xdeadaa01) @@ -230,19 +230,23 @@ STATIC_INLINE jl_gc_pagemeta_t *pop_lf_page_metadata_back(jl_gc_global_page_pool } } +// Region values are +// index shift = ptr_size - shift of the page counts before +// i.e 64 - 18 = 46 ... +// after that AND with the actual page count #ifdef _P64 #define REGION0_PG_COUNT (1 << 16) -#define REGION1_PG_COUNT (1 << 16) +#define REGION1_PG_COUNT (1 << 14) #define REGION2_PG_COUNT (1 << 18) -#define REGION0_INDEX(p) (((uintptr_t)(p) >> 14) & 0xFFFF) // shift by GC_PAGE_LG2 -#define REGION1_INDEX(p) (((uintptr_t)(p) >> 30) & 0xFFFF) +#define REGION0_INDEX(p) (((uintptr_t)(p) >> GC_PAGE_LG2) & 0xFFFF) // shift by GC_PAGE_LG2 +#define REGION1_INDEX(p) (((uintptr_t)(p) >> 32) & 0x3FFF) #define REGION_INDEX(p) (((uintptr_t)(p) >> 46) & 0x3FFFF) #else #define REGION0_PG_COUNT (1 << 8) -#define REGION1_PG_COUNT (1 << 10) +#define REGION1_PG_COUNT (1 << 8) #define REGION2_PG_COUNT (1 << 0) -#define REGION0_INDEX(p) (((uintptr_t)(p) >> 14) & 0xFF) // shift by GC_PAGE_LG2 -#define REGION1_INDEX(p) (((uintptr_t)(p) >> 22) & 0x3FF) +#define REGION0_INDEX(p) (((uintptr_t)(p) >> GC_PAGE_LG2) & 0xFF) // shift by GC_PAGE_LG2 +#define REGION1_INDEX(p) (((uintptr_t)(p) >> 24) & 0xFF) // 32 - pgcount1 shift #define REGION_INDEX(p) (0) #endif diff --git a/src/julia_internal.h b/src/julia_internal.h index cf65521770681..9cba1c8f0e3cf 100644 --- a/src/julia_internal.h +++ b/src/julia_internal.h @@ -345,7 +345,7 @@ void *jl_gc_perm_alloc(size_t sz, int zero, void gc_sweep_sysimg(void); -// pools are 16376 bytes large (GC_POOL_SZ - GC_PAGE_OFFSET) +// pools are 65528 bytes large (GC_POOL_SZ - GC_PAGE_OFFSET) static const int jl_gc_sizeclasses[] = { #ifdef _P64 8, @@ -364,23 +364,22 @@ static const int jl_gc_sizeclasses[] = { 144, 160, 176, 192, 208, 224, 240, 256, // the following tables are computed for maximum packing efficiency via the formula: - // pg = 2^14 + // pg = 2^16 -8 // sz = (div.(pg-8, rng).÷16)*16; hcat(sz, (pg-8).÷sz, pg .- (pg-8).÷sz.*sz)' - // rng = 60:-4:32 (8 pools) + // rng = 240:-16:128 (8 pools) 272, 288, 304, 336, 368, 400, 448, 496, -// 60, 56, 53, 48, 44, 40, 36, 33, /pool -// 64, 256, 272, 256, 192, 384, 256, 16, bytes lost - - // rng = 30:-2:16 (8 pools) + // 240, 227, 215, 195, 178, 163, 146, 132, /pool + // 248, 152, 168, 8, 24, 328, 120, 56, bytes lost + // rng = 120:-8:64 (8 pools) 544, 576, 624, 672, 736, 816, 896, 1008, -// 30, 28, 26, 24, 22, 20, 18, 16, /pool -// 64, 256, 160, 256, 192, 64, 256, 256, bytes lost + // 120, 113, 105, 97, 89, 80, 73, 65, /pool + // 248, 440, 8, 344, 24, 248, 120, 8, bytes lost - // rng = 15:-1:8 (8 pools) + // rng = 60:-4:32 (8 pools) 1088, 1168, 1248, 1360, 1488, 1632, 1808, 2032 -// 15, 14, 13, 12, 11, 10, 9, 8, /pool -// 64, 32, 160, 64, 16, 64, 112, 128, bytes lost + // 60, 56, 52, 48, 44, 40, 36, 32, /pool + // 248, 120, 632, 248, 56, 248, 440, 504, bytes lost }; static_assert(sizeof(jl_gc_sizeclasses) / sizeof(jl_gc_sizeclasses[0]) == JL_GC_N_POOLS, "");