Skip to content

Changes the memory allocator to use jemalloc to address memory leak issues #3566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down
18 changes: 17 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)')
21 changes: 21 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)

Expand Down
14 changes: 14 additions & 0 deletions src/nemo-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@
#include <exempi/xmp.h>
#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[])
{
Expand Down