From 561199762f2440a2e00d7aec0aecf64dce5e729a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 30 Mar 2012 09:54:18 +0200 Subject: [PATCH] Move trim malloc from KWorkspace to KWin It is only used by KWin and KWin does not use anything else from KWorkspace. REVIEW: 104446 --- CMakeLists.txt | 3 +-- main.cpp | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c2b7cb7673..6e29be2145 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,7 +54,6 @@ include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/libkdecorations ${CMAKE_CURRENT_SOURCE_DIR}/effects ${CMAKE_CURRENT_SOURCE_DIR}/tabbox - ${KDEBASE_WORKSPACE_SOURCE_DIR}/libs/kworkspace ) add_subdirectory( libkdecorations ) @@ -173,7 +172,7 @@ qt4_add_dbus_interface( kwin_KDEINIT_SRCS qt4_add_resources( kwin_KDEINIT_SRCS resources.qrc ) -set(kwinLibs ${KDE4_KDEUI_LIBS} ${KDE4_PLASMA_LIBS} ${QT_QTDECLARATIVE_LIBRARY} kdeclarative kworkspace kdecorations kwineffects ${X11_LIBRARIES} ${X11_Xrandr_LIB} ${X11_Xcomposite_LIB} ${X11_Xdamage_LIB} ${X11_Xrender_LIB} ${X11_Xfixes_LIB}) +set(kwinLibs ${KDE4_KDEUI_LIBS} ${KDE4_PLASMA_LIBS} ${QT_QTDECLARATIVE_LIBRARY} kdeclarative kdecorations kwineffects ${X11_LIBRARIES} ${X11_Xrandr_LIB} ${X11_Xcomposite_LIB} ${X11_Xdamage_LIB} ${X11_Xrender_LIB} ${X11_Xfixes_LIB}) find_library(XF86VM_LIBRARY Xxf86vm) if (XF86VM_LIBRARY) diff --git a/main.cpp b/main.cpp index 06738a8504..7ad973208a 100644 --- a/main.cpp +++ b/main.cpp @@ -53,7 +53,16 @@ along with this program. If not, see . #include #include #include -#include + +#include "config-workspace.h" + +#ifdef HAVE_UNISTD_H +#include +#endif // HAVE_UNISTD_H + +#ifdef HAVE_MALLOC_H +#include +#endif // HAVE_MALLOC_H #include @@ -407,7 +416,20 @@ KDE_EXPORT int kdemain(int argc, char * argv[]) } } - KWorkSpace::trimMalloc(); +#ifdef M_TRIM_THRESHOLD + // Prevent fragmentation of the heap by malloc (glibc). + // + // The default threshold is 128*1024, which can result in a large memory usage + // due to fragmentation especially if we use the raster graphicssystem. On the + // otherside if the threshold is too low, free() starts to permanently ask the kernel + // about shrinking the heap. +#ifdef HAVE_UNISTD_H + const int pagesize = sysconf(_SC_PAGESIZE); +#else + const int pagesize = 4*1024; +#endif // HAVE_UNISTD_H + mallopt(M_TRIM_THRESHOLD, 5*pagesize); +#endif // M_TRIM_THRESHOLD // the raster graphicssystem has a quite terrible performance on the XRender backend or when not // compositing at all while some to many decorations suffer from bad performance of the native