8000 add support to split heap in multiple ranges · Issue #3758 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

add support to split heap in multiple ranges #3758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
adritium opened this issue May 3, 2018 · 1 comment
Closed

add support to split heap in multiple ranges #3758

adritium opened this issue May 3, 2018 · 1 comment

Comments

@adritium
Copy link
adritium commented May 3, 2018

In current gc initialization, it is only possible to provide one range for the heap.

micropython/py/gc.c

Lines 108 to 120 in 12a3fcc

void gc_init(void *start, void *end) {
// align end pointer on block boundary
end = (void*)((uintptr_t)end & (~(BYTES_PER_BLOCK - 1)));
DEBUG_printf("Initializing GC heap: %p..%p = " UINT_FMT " bytes\n", start, end, (byte*)end - (byte*)start);
// calculate parameters for GC (T=total, A=alloc table, F=finaliser table, P=pool; all in bytes):
// T = A + F + P
// F = A * BLOCKS_PER_ATB / BLOCKS_PER_FTB
// P = A * BLOCKS_PER_ATB * BYTES_PER_BLOCK
// => T = A * (1 + BLOCKS_PER_ATB / BLOCKS_PER_FTB + BLOCKS_PER_ATB * BYTES_PER_BLOCK)
size_t total_byte_len = (byte*)end - (byte*)start;
#if MICROPY_ENABLE_FINALISER
MP_STATE_MEM(gc_alloc_table_byte_len) = total_byte_len * BITS_PER_BYTE / (BITS_PER_BYTE + BITS_PER_BYTE * BLOCKS_PER_ATB / BLOCKS_PER_FTB + BITS_PER_BYTE * BLOCKS_PER_ATB * BYTES_PER_BLOCK);

However, all the RAM available on a micro-controller might not be in a contiguous range because there might be different types of RAM: SRAM, SDRAM, SPI-RAM, peripheral-dedicated RAM etc.

In my particular case, there is 4K of RAM that is used by a certain peripheral but only if it's enabled but otherwise, it's free for general-purpose use.
Unfortunately, 4K is too small for (most of) my uses as a heap by itself but if I could append it to my main heap, I wouldn't be letting 4K of RAM go to waste.

What do you think?

@dpgeorge
Copy link
Member
dpgeorge commented May 4, 2018

Please see PR #3580 which proposes exactly this.

@dpgeorge dpgeorge closed this as completed May 4, 2018
tannewt pushed a commit to tannewt/circuitpython that referenced this issue Dec 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0