Skip to content

Commit 3e8aed9

Browse files
projectgusdpgeorge
authored andcommitted
py/gc: Add "max new split" value in result of gc.mem_free().
Follow-up to 519c24d when MICROPY_GC_SPLIT_HEAP_AUTO is enabled, based on discussion at https://github.com/orgs/micropython/discussions/12316#discussioncomment-6858007 gc.mem_free() is always a heuristic, but this makes it a more useful heuristic for common use cases. Signed-off-by: Angus Gratton <[email protected]>
1 parent 174bb28 commit 3e8aed9

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

py/gc.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,11 @@ void gc_info(gc_info_t *info) {
701701

702702
info->used *= BYTES_PER_BLOCK;
703703
info->free *= BYTES_PER_BLOCK;
704+
705+
#if MICROPY_GC_SPLIT_HEAP_AUTO
706+
info->max_new_split = gc_get_max_new_split();
707+
#endif
708+
704709
GC_EXIT();
705710
}
706711

@@ -1159,7 +1164,7 @@ void gc_dump_info(const mp_print_t *print) {
11591164
mp_printf(print, "GC: total: %u, used: %u, free: %u",
11601165
(uint)info.total, (uint)info.used, (uint)info.free);
11611166
#if MICROPY_GC_SPLIT_HEAP_AUTO
1162-
mp_printf(print, ", max new split: %u", (uint)gc_get_max_new_split());
1167+
mp_printf(print, ", max new split: %u", (uint)info.max_new_split);
11631168
#endif
11641169
mp_printf(print, "\n No. of 1-blocks: %u, 2-blocks: %u, max blk sz: %u, max free sz: %u\n",
11651170
(uint)info.num_1block, (uint)info.num_2block, (uint)info.max_block, (uint)info.max_free);

py/gc.h

+3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ typedef struct _gc_info_t {
7575
size_t num_1block;
7676
size_t num_2block;
7777
size_t max_block;
78+
#if MICROPY_GC_SPLIT_HEAP_AUTO
79+
size_t max_new_split;
80+
#endif
7881
} gc_info_t;
7982

8083
void gc_info(gc_info_t *info);

py/modgc.c

+5
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ MP_DEFINE_CONST_FUN_OBJ_0(gc_isenabled_obj, gc_isenabled);
6464
STATIC mp_obj_t gc_mem_free(void) {
6565
gc_info_t info;
6666
gc_info(&info);
67+
#if MICROPY_GC_SPLIT_HEAP_AUTO
68+
// Include max_new_split value here as a more useful heuristic
69+
return MP_OBJ_NEW_SMALL_INT(info.free + info.max_new_split);
70+
#else
6771
return MP_OBJ_NEW_SMALL_INT(info.free);
72+
#endif
6873
}
6974
MP_DEFINE_CONST_FUN_OBJ_0(gc_mem_free_obj, gc_mem_free);
7075

0 commit comments

Comments
 (0)