File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -311,8 +311,9 @@ void gc_add(void *start, void *end) {
311
311
#if MICROPY_GC_SPLIT_HEAP_AUTO
312
312
// CIRCUITPY-CHANGE: Added function to compute heap size with selective collect table
313
313
static size_t compute_heap_size (size_t total_blocks ) {
314
- // Add two blocks to account for allocation alignment.
315
- total_blocks += 2 ;
314
+ // Round up to the nearest multiple of BLOCKS_PER_ATB. Partial ATB blocks aren't supported and
315
+ // will result in a heap that is too small.
316
+ total_blocks = ((total_blocks + BLOCKS_PER_ATB - 1 ) / BLOCKS_PER_ATB ) * BLOCKS_PER_ATB ;
316
317
size_t atb_bytes = (total_blocks + BLOCKS_PER_ATB - 1 ) / BLOCKS_PER_ATB ;
317
318
size_t ftb_bytes = 0 ;
318
319
size_t ctb_bytes = 0 ;
@@ -326,12 +327,13 @@ static size_t compute_heap_size(size_t total_blocks) {
326
327
327
328
// Compute bytes needed to build a heap with total_blocks blocks.
328
329
size_t total_heap =
329
- atb_bytes
330
+ sizeof (mp_state_mem_area_t )
331
+ + atb_bytes
332
+ + ALLOC_TABLE_GAP_BYTE
330
333
+ ftb_bytes
331
334
+ ctb_bytes
332
335
+ pool_bytes
333
- + ALLOC_TABLE_GAP_BYTE
334
- + sizeof (mp_state_mem_area_t );
336
+ + BYTES_PER_BLOCK ; // Extra block of bytes to account for end pointer alignment
335
337
336
338
// Round up size to the nearest multiple of BYTES_PER_BLOCK.
337
339
total_heap = (total_heap + BYTES_PER_BLOCK - 1 ) / BYTES_PER_BLOCK ;
You can’t perform that action at this time.
0 commit comments