aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2021-06-04 17:16:11 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2021-06-05 02:31:39 +0200
commit9fa78ca99e32c0f27b6071cc2ddffdf43cb9b9d4 (patch)
treed7f1f6aa6f22d61904db5cfef479d299b4f746f0 /src
parent5167dad198508e2dac10bf89c6b2991cfc791ee6 (diff)
downloadsciteco-9fa78ca99e32c0f27b6071cc2ddffdf43cb9b9d4.tar.gz
use memory polling (--disable-malloc-replacement) on Mac OS X
* I could not get malloc replacement via dlmalloc to work. This does not work like on Linux by overwriting weak malloc() functions. It should theoretically be possible to overwrite the default malloc zone but I could not properly debug this since I can only build for Mac OS via CI. * memory polling seems to work though - test suite runs through and it includes memory limiting test cases.
Diffstat (limited to 'src')
-rw-r--r--src/memory.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/memory.c b/src/memory.c
index 302939b..9846753 100644
--- a/src/memory.c
+++ b/src/memory.c
@@ -273,7 +273,7 @@
* malloc_trim().
* Malloc overriding can be disabled at compile time to aid in memory
* debugging.
- * On Windows, we never even try to link in dlmalloc.
+ * On Windows and Mac OS, we never even try to link in dlmalloc.
* If disabled, we try to directly measure memory consumption using
* OS APIs.
* Polling of the RSS takes place in a dedicated thread that is started
@@ -434,7 +434,15 @@ teco_memory_get_usage(void)
*
* FIXME: Benchmark whether polling in a thread really
* improves performances as much as on Linux.
- * Is this even critical or can we link in dlmalloc?
+ * FIXME: There is no malloc_trim() natively on Mac OS - can
+ * we recover from OOMs?
+ * FIXME: We cannot simply overwrite weak malloc() functions
+ * like on Linux since this does not affect shared libraries
+ * unless $DYLD_FORCE_FLAT_NAMESPACE is set.
+ * It should be possible to change the default malloc zone, though.
+ * First experiments have been unsuccessful.
+ * But see https://github.com/gperftools/gperftools/blob/master/src/libc_override_osx.h
+ * https://chromium.googlesource.com/chromium/src/base/+/refs/heads/main/allocator/allocator_interception_mac.mm
*/
static gsize
teco_memory_get_usage(void)
@@ -444,7 +452,7 @@ teco_memory_get_usage(void)
if (G_UNLIKELY(task_info(mach_task_self(), MACH_TASK_BASIC_INFO,
(task_info_t)&info, &info_count) != KERN_SUCCESS))
- return 0; // FIXME
+ return 0;
return info.resident_size;
}