circuitpython/py
Scott Shawcroft 416abe33ed Introduce a long lived section of the heap.
This adapts the allocation process to start from either end of the heap
when searching for free space. The default behavior is identical to the
existing behavior where it starts with the lowest block and looks higher.
Now it can also look from the highest block and lower depending on the
long_lived parameter to gc_alloc. As the heap fills, the two sections may
overlap. When they overlap, a collect may be triggered in order to keep
the long lived section compact. However, free space is always eligable
for each type of allocation.

By starting from either of the end of the heap we have ability to separate
short lived objects from long lived ones. This separation reduces heap
fragmentation because long lived objects are easy to densely pack.

Most objects are short lived initially but may be made long lived when
they are referenced by a type or module. This involves copying the
memory and then letting the collect phase free the old portion.

QSTR pools and chunks are always long lived because they are never freed.

The reallocation, collection and free processes are largely unchanged. They
simply also maintain an index to the highest free block as well as the lowest.
These indices are used to speed up the allocation search until the next collect.

In practice, this change may slightly slow down import statements with the
benefit that memory is much less fragmented afterwards. For example, a test
import into a 20k heap that leaves ~6k free previously had the largest
continuous free space of ~400 bytes. After this change, the largest continuous
free space is over 3400 bytes.
2018-01-24 10:33:46 -08:00
..
argcheck.c Merge tag 'v1.9.3' 2017-11-02 12:41:50 -07:00
asmarm.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
asmarm.h Initial merge of micropython v1.9.2 into circuitpython 2.0.0 (in development) master. 2017-08-25 22:17:07 -04:00
asmbase.c py/asm: Remove need for dummy_data when doing initial assembler passes. 2016-12-09 22:50:58 +11:00
asmbase.h py/asm: Remove need for dummy_data when doing initial assembler passes. 2016-12-09 22:50:58 +11:00
asmthumb.c py/asmthumb: Use existing macro to properly clear the D-cache. 2017-08-23 11:32:27 +10:00
asmthumb.h Initial merge of micropython v1.9.2 into circuitpython 2.0.0 (in development) master. 2017-08-25 22:17:07 -04:00
asmx64.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
asmx64.h Initial merge of micropython v1.9.2 into circuitpython 2.0.0 (in development) master. 2017-08-25 22:17:07 -04:00
asmx86.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
asmx86.h Initial merge of micropython v1.9.2 into circuitpython 2.0.0 (in development) master. 2017-08-25 22:17:07 -04:00
asmxtensa.c py/asm: Remove need for dummy_data when doing initial assembler passes. 2016-12-09 22:50:58 +11:00
asmxtensa.h Merge tag 'v1.9.1' 2017-06-20 10:56:05 -07:00
bc0.h py: Clean up unary and binary enum list to keep groups together. 2017-10-05 10:49:44 +11:00
bc.c Merge tag 'v1.9.3' 2017-11-02 12:41:50 -07:00
bc.h all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
binary.c Initial merge of micropython v1.9.2 into circuitpython 2.0.0 (in development) master. 2017-08-25 22:17:07 -04:00
binary.h py/binary: Change internal bytearray typecode from 0 to 1. 2017-08-17 16:19:35 +10:00
builtin.h py/builtinhelp: Change signature of help text var from pointer to array. 2017-09-12 16:03:52 +10:00
builtinevex.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
builtinhelp.c Merge commit 'f869d6b2e339c04469c6c9ea3fb2fabd7bbb2d8c' into nrf2_merge 2017-10-24 22:31:16 -07:00
builtinimport.c Introduce a long lived section of the heap. 2018-01-24 10:33:46 -08:00
compile.c py/compile: Remove unused pn_colon code when compiling func params. 2017-08-21 22:00:34 +10:00
compile.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
emit.h all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
emitbc.c py/emitbc: Remove stray semicolon in outer scope. 2017-09-13 20:36:06 +10:00
emitcommon.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
emitglue.c py: Add verbose debug compile-time flag MICROPY_DEBUG_VERBOSE. 2017-08-15 11:53:36 +10:00
emitglue.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
emitinlinethumb.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
emitinlinextensa.c py/emitinline: Move common code for end of final pass to compiler. 2016-12-09 21:23:17 +11:00
emitnative.c py/emitnative: Simplify binary op emitter, no need to check inplace ops. 2017-10-12 12:26:49 +11:00
formatfloat.c py/formatfloat: Use standard isinf, isnan funcs instead of custom ones. 2017-10-10 16:27:54 +11:00
formatfloat.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
frozenmod.c Fix issue #207, esp8266 file operations problems (#222) 2017-09-01 16:12:26 -04:00
frozenmod.h Fix issue #207, esp8266 file operations problems (#222) 2017-09-01 16:12:26 -04:00
gc_long_lived.c Introduce a long lived section of the heap. 2018-01-24 10:33:46 -08:00
gc_long_lived.h Introduce a long lived section of the heap. 2018-01-24 10:33:46 -08:00
gc.c Introduce a long lived section of the heap. 2018-01-24 10:33:46 -08:00
gc.h Introduce a long lived section of the heap. 2018-01-24 10:33:46 -08:00
grammar.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
ioctl.h Initial merge of micropython v1.9.2 into circuitpython 2.0.0 (in development) master. 2017-08-25 22:17:07 -04:00
lexer.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
lexer.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
makeqstrdata.py py/objtype: Fit qstrs for special methods in byte type. 2017-10-21 11:06:32 +03:00
makeqstrdefs.py Merge tag 'v1.9.1' 2017-06-20 10:56:05 -07:00
makeversionhdr.py merge from 2.2.0 + fix up board defs 2018-01-02 21:25:41 -05:00
malloc.c Introduce a long lived section of the heap. 2018-01-24 10:33:46 -08:00
map.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
misc.h Introduce a long lived section of the heap. 2018-01-24 10:33:46 -08:00
mkenv.mk merge from 2.2.0 + fix up board defs 2018-01-02 21:25:41 -05:00
mkrules.mk merge from 2.2.0 + fix up board defs 2018-01-02 21:25:41 -05:00
modarray.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
modbuiltins.c Introduce a long lived section of the heap. 2018-01-24 10:33:46 -08:00
modcmath.c py: Change obsolete "///" comment formatting to normal comments. 2017-08-30 21:02:00 +10:00
modcollections.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
modgc.c py: Change obsolete "///" comment formatting to normal comments. 2017-08-30 21:02:00 +10:00
modio.c Initial merge of micropython v1.9.2 into circuitpython 2.0.0 (in development) master. 2017-08-25 22:17:07 -04:00
modmath.c Merge tag 'v1.9.3' 2017-11-02 12:41:50 -07:00
modmicropython.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
modstruct.c py/modstruct: Check and prevent buffer-write overflow in struct packing. 2017-09-01 11:11:09 +10:00
modsys.c Merge commit 'f869d6b2e339c04469c6c9ea3fb2fabd7bbb2d8c' into nrf2_merge 2017-10-24 22:31:16 -07:00
modthread.c py: Add config option to print warnings/errors to stderr. 2017-09-26 11:59:11 +10:00
moduerrno.c py/moduerrno: Make list of errno codes configurable. 2017-02-22 12:58:11 +11:00
mpconfig.h Merge tag 'v1.9.3' 2017-11-02 12:41:50 -07:00
mperrno.h Initial merge of micropython v1.9.2 into circuitpython 2.0.0 (in development) master. 2017-08-25 22:17:07 -04:00
mphal.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
mpprint.c py/mpprint: Only check for null string printing when NDEBUG not defined. 2017-10-04 18:07:32 +11:00
mpprint.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
mpstate.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
mpstate.h Introduce a long lived section of the heap. 2018-01-24 10:33:46 -08:00
mpthread.h all: Unify header guard usage. 2017-07-18 11:57:39 +10:00
mpz.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
mpz.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
nativeglue.c py/emitnative: Implement floor-division and modulo for viper emitter. 2017-10-11 18:54:34 +11:00
nlr.h Initial merge of micropython v1.9.2 into circuitpython 2.0.0 (in development) master. 2017-08-25 22:17:07 -04:00
nlrsetjmp.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
nlrthumb.c Avoid gcc 7.2.1 compiler issues in nlr_push() (#506) 2018-01-02 13:41:34 -08:00
nlrx64.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
nlrx86.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
nlrxtensa.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
obj.c Merge commit 'f869d6b2e339c04469c6c9ea3fb2fabd7bbb2d8c' into nrf2_merge 2017-10-24 22:31:16 -07:00
obj.h Introduce a long lived section of the heap. 2018-01-24 10:33:46 -08:00
objarray.c Merge tag 'v1.9.3' 2017-11-02 12:41:50 -07:00
objarray.h all: Unify header guard usage. 2017-07-18 11:57:39 +10:00
objattrtuple.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
objbool.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
objboundmeth.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
objcell.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
objclosure.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
objcomplex.c Merge commit 'f869d6b2e339c04469c6c9ea3fb2fabd7bbb2d8c' into nrf2_merge 2017-10-24 22:31:16 -07:00
objdict.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
objenumerate.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
objexcept.c Merge commit 'f869d6b2e339c04469c6c9ea3fb2fabd7bbb2d8c' into nrf2_merge 2017-10-24 22:31:16 -07:00
objexcept.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
objfilter.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
objfloat.c Merge commit 'f869d6b2e339c04469c6c9ea3fb2fabd7bbb2d8c' into nrf2_merge 2017-10-24 22:31:16 -07:00
objfun.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
objfun.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
objgenerator.c Merge commit 'f869d6b2e339c04469c6c9ea3fb2fabd7bbb2d8c' into nrf2_merge 2017-10-24 22:31:16 -07:00
objgenerator.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
objgetitemiter.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
objint_longlong.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
objint_mpz.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
objint.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
objint.h py/modbuiltins: Implement abs() by dispatching to MP_UNARY_OP_ABS. 2017-09-18 00:06:43 +03:00
objlist.c Merge tag 'v1.9.3' 2017-11-02 12:41:50 -07:00
objlist.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
objmap.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
objmodule.c Introduce a long lived section of the heap. 2018-01-24 10:33:46 -08:00
objmodule.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
objnamedtuple.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
objnamedtuple.h Initial merge of micropython v1.9.2 into circuitpython 2.0.0 (in development) master. 2017-08-25 22:17:07 -04:00
objnone.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
objobject.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
objpolyiter.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
objproperty.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
objproperty.h Initial merge of micropython v1.9.2 into circuitpython 2.0.0 (in development) master. 2017-08-25 22:17:07 -04:00
objrange.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
objreversed.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
objset.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
objsingleton.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
objslice.c Merge commit 'f869d6b2e339c04469c6c9ea3fb2fabd7bbb2d8c' into nrf2_merge 2017-10-24 22:31:16 -07:00
objstr.c Merge commit 'f869d6b2e339c04469c6c9ea3fb2fabd7bbb2d8c' into nrf2_merge 2017-10-24 22:31:16 -07:00
objstr.h all: Convert mp_uint_t to mp_unary_op_t/mp_binary_op_t where appropriate 2017-08-29 13:16:30 +10:00
objstringio.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
objstringio.h py/objstringio: If created from immutable object, follow copy on write policy. 2017-06-09 17:33:01 +03:00
objstrunicode.c Merge commit 'f869d6b2e339c04469c6c9ea3fb2fabd7bbb2d8c' into nrf2_merge 2017-10-24 22:31:16 -07:00
objtuple.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
objtuple.h Merge commit 'f869d6b2e339c04469c6c9ea3fb2fabd7bbb2d8c' into nrf2_merge 2017-10-24 22:31:16 -07:00
objtype.c Introduce a long lived section of the heap. 2018-01-24 10:33:46 -08:00
objtype.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
objzip.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
opmethods.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
parse.c Merge commit 'f869d6b2e339c04469c6c9ea3fb2fabd7bbb2d8c' into nrf2_merge 2017-10-24 22:31:16 -07:00
parse.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
parsenum.c Initial merge of micropython v1.9.2 into circuitpython 2.0.0 (in development) master. 2017-08-25 22:17:07 -04:00
parsenum.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
parsenumbase.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
parsenumbase.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
persistentcode.c Speed up qstr loading by using the stack to store a temporary 2018-01-23 16:45:22 -08:00
persistentcode.h py: Factor out persistent-code reader into separate files. 2016-11-16 18:13:50 +11:00
py.mk Introduce a long lived section of the heap. 2018-01-24 10:33:46 -08:00
qstr.c Introduce a long lived section of the heap. 2018-01-24 10:33:46 -08:00
qstr.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
qstrdefs.h py/qstrdefs: Remove unused qstrs. 2017-09-01 15:22:25 +10:00
reader.c all: Don't include system errno.h when it's not needed. 2017-07-24 18:43:14 +10:00
reader.h py: Allow lexer to raise exceptions during construction. 2017-03-14 11:52:05 +11:00
repl.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
repl.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
ringbuf.h Initial merge of micropython v1.9.2 into circuitpython 2.0.0 (in development) master. 2017-08-25 22:17:07 -04:00
runtime0.h Merge tag 'v1.9.3' 2017-11-02 12:41:50 -07:00
runtime_utils.c py: Prevent crash with LTO. 2017-11-01 14:32:06 -07:00
runtime.c Merge tag 'v1.9.3' 2017-11-02 12:41:50 -07:00
runtime.h Merge tag 'v1.9.3' 2017-11-02 12:41:50 -07:00
scheduler.c py: Add micropython.schedule() function and associated runtime code. 2017-03-20 15:20:26 +11:00
scope.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
scope.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
sequence.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
showbc.c py: Clean up unary and binary enum list to keep groups together. 2017-10-05 10:49:44 +11:00
smallint.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
smallint.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
stackctrl.c Merge commit 'f869d6b2e339c04469c6c9ea3fb2fabd7bbb2d8c' into nrf2_merge 2017-10-24 22:31:16 -07:00
stackctrl.h Initial merge of micropython v1.9.2 into circuitpython 2.0.0 (in development) master. 2017-08-25 22:17:07 -04:00
stream.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
stream.h py/objstringio: Fix regression with handling SEEK_SET. 2017-08-20 22:02:41 +03:00
unicode.c py/objstr: Add check for valid UTF-8 when making a str from bytes. 2017-09-06 16:43:09 +10:00
unicode.h py/objstr: Add check for valid UTF-8 when making a str from bytes. 2017-09-06 16:43:09 +10:00
vm.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
vmentrytable.h py: Clean up unary and binary enum list to keep groups together. 2017-10-05 10:49:44 +11:00
vstr.c py/vstr: Raise a RuntimeError if fixed vstr buffer overflows. 2017-09-21 20:29:41 +10:00
warning.c py: Add config option to print warnings/errors to stderr. 2017-09-26 11:59:11 +10:00