Skip to content

Commit 3fcc4d7

Browse files
authored
Disable emmalloc_trim (#23344)
I believe this function has not been working correctly since #13442 when sbrk stopped accepting negative values. Maybe we can find a way to bring this functionality back but disabling it for now seems safest. See: #23343
1 parent 138126e commit 3fcc4d7

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

system/lib/emmalloc.c

+8
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,7 @@ struct mallinfo emmalloc_mallinfo() {
12271227
}
12281228
EMMALLOC_ALIAS(mallinfo, emmalloc_mallinfo);
12291229

1230+
#if 0
12301231
// Note! This function is not fully multithreading safe: while this function is running, other threads should not be
12311232
// allowed to call sbrk()!
12321233
static int trim_dynamic_heap_reservation(size_t pad) {
@@ -1280,12 +1281,19 @@ static int trim_dynamic_heap_reservation(size_t pad) {
12801281
// All successful, and we actually trimmed memory!
12811282
return 1;
12821283
}
1284+
#endif
12831285

12841286
int emmalloc_trim(size_t pad) {
1287+
// Reducing the size of the sbrk region is currently broken.
1288+
// See https://github.com/emscripten-core/emscripten/issues/23343
1289+
// And https://github.com/emscripten-core/emscripten/pull/13442
1290+
return 0;
1291+
/*
12851292
MALLOC_ACQUIRE();
12861293
int success = trim_dynamic_heap_reservation(pad);
12871294
MALLOC_RELEASE();
12881295
return success;
1296+
*/
12891297
}
12901298
EMMALLOC_ALIAS(malloc_trim, emmalloc_trim)
12911299

test/test_core.py

+1
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,7 @@ def test_emmalloc_memory_statistics(self):
821821
@no_4gb('output is sensitive to absolute data layout')
822822
@no_asan('ASan does not support custom memory allocators')
823823
@no_lsan('LSan does not support custom memory allocators')
824+
@disabled('https://github.com/emscripten-core/emscripten/issues/23343')
824825
def test_emmalloc_trim(self):
825826
self.set_setting('MALLOC', 'emmalloc')
826827
self.emcc_args += ['-sINITIAL_MEMORY=128MB', '-sALLOW_MEMORY_GROWTH', '-sMAXIMUM_MEMORY=2147418112']

0 commit comments

Comments
 (0)