You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a125493
Browse filesBrowse the repository at this point in the historyBrowse files
Give the memory of freed large buffers back to the system with glibc (#434)
glibc keeps a freed buffer's memory in its heap, unless it had mapped
the buffer on its own. It maps buffers of 128 KB or more on their own at
first, but each time one is freed it raises that size to the freed
buffer's, up to 32 MB on 64 bits, so later buffers of those sizes come
from the heap and stay there once freed. After a burst of large
allocations the process stayed as large as the burst, although the
collector had freed the buffers and MEM_INFO_RESERVED no longer counted
them.
In an OpenFL game that reads 17 MB texture files while a level loads,
glibc held 722 MB of free memory once the level was loaded, out of
1740 MB of anonymous memory. With this change the same point is at
1160 MB.
The collector now counts what it frees to the C heap, the large buffers
and the block groups, and calls malloc_trim once that reaches 16 MB.
The trim runs on the thread that frees dropped buffers, after its batch,
so no other thread waits for it: it took up to 26 ms in the game, for
360 MB. A collection that frees its buffers itself, as a compacting one
does, trims before it returns. A collection with no buffers to drop
still wakes the thread when a trim is due, for what the sweep freed.
Tests: test/regression/LargeFreedMemoryReturned drops 384 MB of 4 MB
buffers, after freeing some 8 MB ones so that glibc takes them from its
heap. It stayed at 396 MB resident and now returns to 12 MB. It reads
the resident size from VmRSS in /proc/self/status, and passes without
measuring where that is missing and under ASan, whose allocator keeps
freed memory in its quarantine.
Co-authored-by: Chris Speciale <christopher.gaf@gmail.com>
* Fixed a program on Linux with glibc staying as large as its largest burst of large allocations, such as the files a game reads while it loads: glibc keeps a freed buffer's memory in its heap unless it had mapped the buffer on its own, and once a buffer mapped on its own has been freed it stops mapping those of that size or less, up to 32 MB. The memory of the large buffers a collection freed then stayed the process's. The collector now trims the C heap once 16 MB has been freed to it, on the thread that frees the buffers. A program that dropped 384 MB of 4 MB buffers stayed at 396 MB resident and now returns to 12 MB
5
6
* Fixed a native extension that includes hx/CFFI.h before hx/CFFIPrime.h, as SteamWrap does, failing to compile with hxs_encoding, hxs_utf16 and alloc_hxs_utf8 not declared: CFFI.h included first declares the CFFI API without HXCPP_PRIME, so without the Prime string functions that the ordinary wrapper of a DEFINE_PRIME function now uses. CFFIPrime.h declares them then
6
7
* Made the collector's thread context on Linux a __thread pointer, read with one load from the thread pointer, instead of a call to pthread_getspecific each time an allocation leaves the inline path or a String or number is boxed. It was 3 to 4% of an OpenFL game's main thread. HXCPP_PTHREAD_FAST_TLS keeps pthread_getspecific (libhxcpp #429)
7
8
* Fixed a call on a null Array<Dynamic> in cppia ending the process under HXCPP_CHECK_POINTER: push, contains, remove, indexOf, lastIndexOf, join, toString, sort, insert and unshift used the array without checking it, interpreted and under the JIT. They throw Null Object Reference, as a typed array's calls and the other Array<Dynamic> calls do
0 commit comments