From 152397e641e9d1e6a11f80e24f562c4cf2472a2f Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Wed, 8 Mar 2017 12:00:42 +0100 Subject: yet another revision of memory limiting: the glibc mallinfo() approach has been shown to be unacceptably broken, so the fallback implementation has been improved * mallinfo() is not only broken on 64-bit systems but slows things down linearilly to the memory size of the process. E.g. after 500000<%A>, SciTECO will act sluggish! Shutting down afterwards can take minutes... mallinfo() was thus finally discarded as a memory measurement technique. * Evaluating /proc/self/statm? has also been evaluated and discarded because doing this frequently is even slower. * Instead, the fallback implementation has been drastically improved: * If possible use C++14 global sized deallocators, allowing memory measurements across the entire C++ code base with minimal runtime overhead. Since we only depend on C++11, a lengthy Autoconf check had to be introduced. * Use malloc_usable_size() with global non-sized deallocators to measure the approx. memory usage of the entire process (at least the ones done via C++). The cheaper C++11 sized deallocators implemented via SciTECO::Object still have precedence, so this affects Scintilla code only. * With both improvements the test case sciteco -e '<@EU[X^E\a]"^E\a"%a>' is handled sufficiently well now on glibc and performance is much better now. * The jemalloc-specific technique has been removed since it no longer brings any benefits compared to the improved fallback technique. Even the case of using malloc_usable_size() in strict C++ mode is up to 3 times faster. * The new fallback implementation might actually be good enough for Windows as well if some MSVCRT-specific support is added, like using _msize() instead of malloc_usable_size(). This must be tested and benchmarked, so we keep the Windows-specific implementation for the time being. --- configure.ac | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index e3fd728..1bd446d 100644 --- a/configure.ac +++ b/configure.ac @@ -172,15 +172,35 @@ case $host in ;; esac -# Check for optional glibc features. -# Will probably only be found on Linux/glibc. -AC_CHECK_HEADERS([malloc.h]) -AC_CHECK_FUNCS([malloc_trim mallinfo]) - -# jemalloc-specific functions. -# Will probably only be foudn on FreeBSD. -AC_CHECK_HEADERS([malloc_np.h]) -AC_CHECK_FUNCS([mallctlnametomib mallctlbymib]) +# Check for optional libc features. +# Some of this will only be found on glibc, +# others on FreeBSD/jemalloc. +AC_CHECK_HEADERS([malloc.h malloc_np.h]) +AC_CHECK_FUNCS([malloc_trim malloc_usable_size]) + +# Check whether compiler supports global sized deallocations. +# If yes, this will improve the memory limiting fallback +# implementation. +# Once we can depend on C++14, this check is no longer necessary. +AC_CACHE_CHECK([if C++ compiler supports -fsized-deallocation], + [sciteco_cv_sized_deallocation_result], [ + AC_LANG_PUSH(C++) + OLD_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -fsized-deallocation" + AC_COMPILE_IFELSE([AC_LANG_PROGRAM( + [[#include ]], + [[(::operator delete)(0, 256)]] + )], sciteco_cv_sized_deallocation_result=yes, + sciteco_cv_sized_deallocation_result=no) + CXXFLAGS="$OLD_CXXFLAGS" + AC_LANG_POP(C++) +]) +if [[ x$sciteco_cv_sized_deallocation_result = xyes ]]; then + AC_DEFINE(HAVE_SIZED_DEALLOCATION, 1, + [C++ compiler supports -fsized-deallocation]) +fi +AM_CONDITIONAL(HAVE_SIZED_DEALLOCATION, + test "$sciteco_cv_sized_deallocation_result" = yes) # # Config options -- cgit v1.2.3