-
Notifications
You must be signed in to change notification settings - Fork 328
[WIP] 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
base: master
Are you sure you want to change the base?
Conversation
|
Hi, this is very interesting, but I get the impression jemalloc is no longer actively maintained, perhaps there are other alternatives that would bring a similar benefit? Also, does this have any performance cost? For a quick check you can do: I usually also clear the disk cache first before I run this: Thanks! |
Maybe mimalloc, jemalloc is archived. |
I don't know why they keep the repository as archived, but it is constantly receiving updates, with the last updates made 4 days ago and in the Issues there is information that a new stable release should be released this semester. |
Performance Benchmark ResultsTest 1: Without changes or clean cache
Test 2: With JEMALLOC without clean cache
Test 3: Without changes and CLEAN cache
Test 4: With JEMALLOC and CLEAN cache
It seems to me that there is no significant difference in performance, but the small difference seems positive for Jemalloc. |
109476c to
7eaf1a8
Compare
…stem and at compilation time you can force it to be activated or not.
|
Includes some changes to avoid compatibility issues. When compiling nemo, if meson detects that jemalloc is installed, it will automatically use it in nemo, in addition to having the option to enable or disable it. |
| } | ||
| #endif | ||
|
|
||
| int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block probably needs to be in nemo-desktop-main.c also?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly, I'm not sure, I ran the tests with the file manager, but I didn't test the desktop part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably wouldn't need to worry about it there, it's used strictly for the desktop view, any folders opened from there launch the nemo-main process. I imagine the memory stays fairly static.
| dependencies: nemo_deps, | ||
| link_args: nemo_autorun_software_link_args, | ||
| install: true | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this needs to use jemalloc, it's just a Gtk dialog for when media gets inserted.
|
The performance gain isn't significant to justify the added complexity. Can we measure a gain in memory usage? If there are actual memory leaks, surely they'll remain no matter what allocator we're using. Note: The github repo has seen no commits since June and it's still archived. |
|
I think nemo can use so much memory so quickly with large folders that allocator has trouble with freeing it later - I think it's being conservative, expecting you to need it again later, so it hangs onto it. I've used valgrind on nemo for years - there's really just one major area - icon cache - that has a very tricky lifespan issue, but I don't think it's a large factor in its memory footprint. This new allocator made a huge impact when leaving a large folder that temporarily required a lot of extra memory to be used. I did a bit of research and looked at discussions on jemalloc's 'future'... it's still heavily used - Meta/Facebook, Firefox, supported in chromium, etc... and it exists in all unreleased Ubuntu and Debian repositories, so I'm less concerned about using it than I was initially. |
|
After making that pull request, I continued testing memory allocators and programs that improve when the allocator is changed. It seems that practically all GTK3 or GTK4 programs that display many items don't deallocate the memory used by the GCC allocator, but using some other allocators with specific configurations solves or reduces this problem. In the case of Nemo, it seems that mimalloc is even better than jemalloc. I created a library to help with testing, because using LD_PRELOAD causes subprocesses to also use a different allocator, which generates problems in some programs. With libchildenv, we can use LD_PRELOAD to change a program's library without affecting child processes: https://github.com/biglinux/libchildenv I haven't tested it yet, but a friend was testing the Cinnamon process with jemalloc and told me that memory management also improved significantly. |
In the past few days, I tried several approaches to resolve memory leak issues in Nemo. I have a folder with 29,000 subfolders that I was using for testing. Scrolling quickly through this folder causes memory usage to exceed 1 GB.
Even after leaving the folder, the memory consumption remains high. However, when using jemalloc, switching to another folder brings memory usage back to normal, around 50 MB.
I used this folder with a huge number of subfolders to make testing easier, but folders with a thousand files are already sufficient to identify the issue.