From 078a3433ebe4c211cd93c84cd9c2148c3aa23238 Mon Sep 17 00:00:00 2001 From: Tim Peters Date: Wed, 31 Mar 2021 22:46:31 -0500 Subject: When printing stats, move radix tree info to its own section. (GH-25125) When printing stats, move radix tree info to its own section. Restore that the breakdown of bytes in arenas exactly accounts for the total of arena bytes allocated. Add an assert so that invariant doesn't break again. --- Objects/obmalloc.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index 76ff6f9..c1c1279 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -3027,12 +3027,6 @@ _PyObject_DebugMallocStats(FILE *out) (void)printone(out, "# arenas reclaimed", ntimes_arena_allocated - narenas); (void)printone(out, "# arenas highwater mark", narenas_highwater); (void)printone(out, "# arenas allocated current", narenas); -#ifdef USE_INTERIOR_NODES - (void)printone(out, "# arena map mid nodes", arena_map_mid_count); - (void)printone(out, "# arena map bot nodes", arena_map_bot_count); - fputc('\n', out); -#endif - PyOS_snprintf(buf, sizeof(buf), "%zu arenas * %d bytes/arena", @@ -3041,6 +3035,7 @@ _PyObject_DebugMallocStats(FILE *out) fputc('\n', out); + /* Account for what all of those arena bytes are being used for. */ total = printone(out, "# bytes in allocated blocks", allocated_bytes); total += printone(out, "# bytes in available blocks", available_bytes); @@ -3051,16 +3046,26 @@ _PyObject_DebugMallocStats(FILE *out) total += printone(out, "# bytes lost to pool headers", pool_header_bytes); total += printone(out, "# bytes lost to quantization", quantization); total += printone(out, "# bytes lost to arena alignment", arena_alignment); -#ifdef WITH_PYMALLOC_RADIX_TREE - total += printone(out, "# bytes lost to arena map root", sizeof(arena_map_root)); + (void)printone(out, "Total", total); + assert(narenas * ARENA_SIZE == total); + +#if WITH_PYMALLOC_RADIX_TREE + fputs("\narena map counts\n", out); +#ifdef USE_INTERIOR_NODES + (void)printone(out, "# arena map mid nodes", arena_map_mid_count); + (void)printone(out, "# arena map bot nodes", arena_map_bot_count); + fputc('\n', out); #endif + total = printone(out, "# bytes lost to arena map root", sizeof(arena_map_root)); #ifdef USE_INTERIOR_NODES total += printone(out, "# bytes lost to arena map mid", sizeof(arena_map_mid_t) * arena_map_mid_count); total += printone(out, "# bytes lost to arena map bot", sizeof(arena_map_bot_t) * arena_map_bot_count); -#endif (void)printone(out, "Total", total); +#endif +#endif + return 1; } -- cgit v0.12