Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb796e3d

Browse files
committed
py: Reduce fragmentation of GC heap.
Recent speed up of GC allocation made the GC have a fragmented heap.This patch restores "original fragmentation behaviour" whilst stillretaining relatively fast allocation. This patch works because there isalways going to be a single block allocated now and then, which advancesthe gc_last_free_atb_index pointer often enough so that the whole heapdoesn't need scanning.Should address issueadafruit#836.
1 parenta97e091 commitb796e3d

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

‎py/gc.c‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -386,13 +386,6 @@ void *gc_alloc(mp_uint_t n_bytes, bool has_finaliser) {
386386
if (ATB_2_IS_FREE(a)) {if (++n_free >=n_blocks) {i=i*BLOCKS_PER_ATB+2; gotofound; } }else {n_free=0; }
387387
if (ATB_3_IS_FREE(a)) {if (++n_free >=n_blocks) {i=i*BLOCKS_PER_ATB+3; gotofound; } }else {n_free=0; }
388388
}
389-
for (i=0;i<gc_last_free_atb_index;i++) {
390-
bytea=gc_alloc_table_start[i];
391-
if (ATB_0_IS_FREE(a)) {if (++n_free >=n_blocks) {i=i*BLOCKS_PER_ATB+0; gotofound; } }else {n_free=0; }
392-
if (ATB_1_IS_FREE(a)) {if (++n_free >=n_blocks) {i=i*BLOCKS_PER_ATB+1; gotofound; } }else {n_free=0; }
393-
if (ATB_2_IS_FREE(a)) {if (++n_free >=n_blocks) {i=i*BLOCKS_PER_ATB+2; gotofound; } }else {n_free=0; }
394-
if (ATB_3_IS_FREE(a)) {if (++n_free >=n_blocks) {i=i*BLOCKS_PER_ATB+3; gotofound; } }else {n_free=0; }
395-
}
396389

397390
// nothing found!
398391
if (collected) {
@@ -409,8 +402,13 @@ void *gc_alloc(mp_uint_t n_bytes, bool has_finaliser) {
409402
end_block=i;
410403
start_block=i-n_free+1;
411404

412-
// set last free ATB index to last block we found, for start of next scan
413-
gc_last_free_atb_index=i /BLOCKS_PER_ATB;
405+
// Set last free ATB index to block after last block we found, for start of
406+
// next scan. To reduce fragmentation, we only do this if we were looking
407+
// for a single free block, which guarantees that there are no free blocks
408+
// before this one.
409+
if (n_free==1) {
410+
gc_last_free_atb_index= (i+1) /BLOCKS_PER_ATB;
411+
}
414412

415413
// mark first block as used head
416414
ATB_FREE_TO_HEAD(start_block);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp