diff --git a/debian/control b/debian/control index b250e40d1..f37294bee 100644 --- a/debian/control +++ b/debian/control @@ -21,6 +21,7 @@ Build-Depends: libgsf-1-dev, libgtk-3-dev (>= 3.10), libgtk-3-doc, + libjemalloc2-dev, libjson-glib-dev (>= 1.6), libpango1.0-dev, libx11-dev, @@ -88,6 +89,7 @@ Depends: gsettings-desktop-schemas, gvfs (>= 1.3.2), libglib2.0-data, + libjemalloc2, libnemo-extension1 (= ${binary:Version}), nemo-data (= ${source:Version}), shared-mime-info (>= 0.50), diff --git a/meson.build b/meson.build index 5eee1ed34..4c4d042e8 100644 --- a/meson.build +++ b/meson.build @@ -83,6 +83,18 @@ gail = dependency('gail-3.0') x11 = dependency('x11') xapp = dependency('xapp', version: '>=2.0.0') +jemalloc_opt = get_option('jemalloc') +if jemalloc_opt == 'true' + jemalloc = dependency('jemalloc', required: true) + use_jemalloc = true +elif jemalloc_opt == 'auto' + jemalloc = dependency('jemalloc', required: false) + use_jemalloc = jemalloc.found() +else + jemalloc = dependency('', required: false) + use_jemalloc = false +endif + # Facultative dependencies trackerChoice = get_option('tracker') @@ -171,8 +183,11 @@ nemo_definitions = [ '-DNEMO_DATADIR="@0@"'.format(nemoDataPath), '-DNEMO_EXTENSIONDIR="@0@"'.format(nemoExtensionPath), '-DLIBEXECDIR="@0@"'.format(libExecPath), - '-DG_LOG_DOMAIN="Nemo"' + '-DG_LOG_DOMAIN="Nemo"', ] +if use_jemalloc + nemo_definitions += '-DUSE_JEMALLOC' +endif po_subdir = join_paths(meson.project_source_root(), 'po') @@ -201,6 +216,7 @@ message('\n'.join(['', ' exempi support: @0@'.format(exempi_enabled), ' Tracker support: @0@'.format(tracker_enabled), ' Wayland support: @0@'.format(cc.has_header('gdk/gdkwayland.h', dependencies: gtk)), +' Jemalloc support: @0@'.format(use_jemalloc), '', ' nemo-extension documentation: @0@'.format(gtkdoc_enabled), ' nemo-extension introspection: @0@'.format(true), diff --git a/meson_options.txt b/meson_options.txt index 68814d64d..84fd7e41f 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -12,3 +12,5 @@ option('empty_view', type : 'boolean', value : false, description: 'Enable empty view') option('tracker',type : 'combo', choices : ['true', 'false', 'auto'], value : 'false', description: 'Tracker support') +option('jemalloc', type : 'combo', choices : ['true', 'false', 'auto'], value : 'auto', + description: 'Use jemalloc memory allocator if available (auto = enable if found)') diff --git a/src/meson.build b/src/meson.build index 6f6cd55d6..253ce615e 100644 --- a/src/meson.build +++ b/src/meson.build @@ -104,6 +104,9 @@ endif nemo_deps = [ cinnamon, gail, glib, gtk, math, egg, nemo_extension, nemo_private, xapp ] +if use_jemalloc + nemo_deps += jemalloc +endif if exempi_enabled nemo_deps += exempi @@ -113,27 +116,45 @@ if libexif_enabled nemo_deps += libexif endif + +nemo_link_args = [] +if use_jemalloc + nemo_link_args += ['-Wl,--no-as-needed', '-ljemalloc', '-Wl,--as-needed'] +endif nemo = executable('nemo', nemoCommon_sources + nemoWindow_sources, include_directories: [ rootInclude ], c_args: nemo_definitions, dependencies: nemo_deps, + link_args: nemo_link_args, install: true ) + +nemoDesktop_link_args = [] +if use_jemalloc + nemoDesktop_link_args += ['-Wl,--no-as-needed', '-ljemalloc', '-Wl,--as-needed'] +endif nemoDesktop = executable('nemo-desktop', nemoCommon_sources + nemoDesktop_sources, include_directories: [ rootInclude], c_args: nemo_definitions, dependencies: nemo_deps, + link_args: nemoDesktop_link_args, install: true ) + +nemo_autorun_software_link_args = [] +if use_jemalloc + nemo_autorun_software_link_args += ['-Wl,--no-as-needed', '-ljemalloc', '-Wl,--as-needed'] +endif nemo_autorun_software = executable('nemo-autorun-software', [ 'nemo-autorun-software.c' ], include_directories: [ rootInclude, ], c_args: nemo_definitions, dependencies: nemo_deps, + link_args: nemo_autorun_software_link_args, install: true ) diff --git a/src/nemo-main.c b/src/nemo-main.c index 39291eab9..9129ec089 100644 --- a/src/nemo-main.c +++ b/src/nemo-main.c @@ -53,6 +53,20 @@ #include #endif +#ifdef USE_JEMALLOC + static void + nemo_jemalloc_configure(void) __attribute__((constructor)); + + static void + nemo_jemalloc_configure(void) + { + if (getenv("MALLOC_CONF") != NULL) + return; + const char *conf = "narenas:1,metadata_thp:auto,percpu_arena:phycpu"; + setenv("MALLOC_CONF", conf, 0); + } +#endif + int main (int argc, char *argv[]) {