-
Notifications
You must be signed in to change notification settings - Fork 259
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
Far too high RSS memory consumption (memory leak?) with gocryptfs #569
Comments
@rfjakob Please let me know if you need assistance via my access to Debian's |
@rfjakob : Please also let me know if there is anything I can do to assist you fixing this, e.g. running a profiled or new version on my system... |
Thanks for the excellent report! Also thanks for the offers @lechner and @Slartibartfast27 . I will see if I can repro on amd64 first. @Slartibartfast27 could you check what
says? The "sleep 5 minutes" is to allow for the Go scavenger to run. PS: Note to self for testing: How to create 500000 empty files quickly (500 directories with 1000 files each):
|
Hello @rfjakob, thanks for the extremely quick response. Here are the requested results for the "small" Initial state after remount:
Final state after
Just a remark in case it eventually matters: My architecture is 32bit, not 64bit: |
Thanks! Some background: Go versions 1.12 to 1.15 use From your data I see: Initial state:
The After drop_caches you have:
|
Would it make sense if I compile 1.8 and try again? |
1.8 should be the same, but could you check how the memory usage of v2.0-beta4-21 (attached) looks like? This is compiled with Go 1.16, so no more LazyFree. gocryptfs.v2.0-beta4-21-g242cdf9.armv7.gz On amd64 (=64 bit Intel) I get this:
|
RSS values were collected using
Also I figured out why RSS does not go back down to "fresh mount" level: The hash tables tracking the inodes cannot shrink back to empty completely ( golang/go#20135 ). There are no tracked inodes after drop_caches, but the memory will be resused on the next "ls -R". |
Wow!
Teaser: I'm going to iterate over all 12,000,000 files over night, but don't expect any changes of the overall result. Steps performed:
Detailed logs attached VmRSS-gocryptfs.v2.0-beta4-21-g242cdf9.log
Just for technical curiosity, although definitely not needed: Which option would you recommend me now? |
This... looks too good to be true. Did you have little free memory on the system? I recommend waiting for 2.0 final as I'm still working on some minor issues discovered by xfstests testing. |
I just tried running the gocryptfs.v2.0-beta4-21-g242cdf9.armv7 binary on a Raspberry Pi 4 (armv8 64 bit) that I have. Seems to work fine! But I see
after "ls -R". I guess it should be a little lower because 32 bit pointers take half as much space as 64 bit pointers, but still, it's in the same range as amd64 |
Maybe the difference is that your system has swap space? That may also explain the fact that you saw EncFS at RSS zero? |
Maps do not free all memory when elements get deleted ( golang/go#20135 ). As a workaround, we recreate our two big maps (kernelNodeIds & stableAttrs) when they have shrunk dramatically (100 x smaller). Benchmarkung with loopback (go version go1.16.2 linux/amd64) shows: Before this change: State VmRSS (kiB) ----- ----------- Fresh mount 4000 ls -R 500k files 271100 after drop_cache 336448 wait ~ 3 minutes 101588 After: State VmRSS (kiB) ----- ----------- Fresh mount 4012 ls -R 500k files 271100 after drop_cache 31528 Results for gocryptfs are similar. Fixes: rfjakob/gocryptfs#569 Change-Id: Idcae1ab953270516735839a034d586717647b8db
Sure: Otherwise EncFS could not exist with 0 memory. I defined 16 GB of SWAP but basically never need to use it. |
There could be two reasons:
B) If you run the default Raspberry Pi 4 image, you'll have an 32 bit OS. The 64 bit RP4-OS is only beta. |
A) Yes I guess the other chown is preventing too much caching in gocryptfs B) It's been a while since I installed this, I guess it's the beta
|
PS @ A): I don't think it matters if it on a different disk, what matters is that there is another process touching a lot of files. This will push files out of the gocryptfs cache. |
Even after iteration over 12,000,000 files over night, there were absolutely no RSS-problems:
Logs: VmRSS-gocryptfs.v2.0-beta4-21-g242cdf9.log So I'll be happily and patiently waiting for the 2.0 release before I do the switch from EncFS --> gocrpytfs ;-) |
I'll do some more tests when my system is idle again, likely in approx 1 week... |
Maps do not free all memory when elements get deleted ( golang/go#20135 ). As a workaround, we recreate our two big maps (kernelNodeIds & stableAttrs) when they have shrunk dramatically (100 x smaller). Benchmarkung with loopback (go version go1.16.2 linux/amd64) shows: Before this change: State VmRSS (kiB) ----- ----------- Fresh mount 4000 ls -R 500k files 271100 after drop_cache 336448 wait ~ 3 minutes 101588 After: State VmRSS (kiB) ----- ----------- Fresh mount 4012 ls -R 500k files 271100 after drop_cache 31528 Results for gocryptfs are similar. Fixes: rfjakob/gocryptfs#569 Change-Id: Idcae1ab953270516735839a034d586717647b8db
Hello @rfjakob, here are the promised results of my tests on an idle system (Odroid XU4Q with Armbian) :
I tested everything with the attached script in 2 ways:
Wanted to do the test also against an
So I executed the tests with these commands:
Here are the results as charts: During the tests, I always had plenty of RAM available (less than 1 GB RSS-Sum of total 2 GB): Overall for me the results of For me there is no need to optimize anything anymore in terms of RAM usage. But if you like and give me a compiled exe, I'll be happy to repeat the test on my system with merged rfjakob/go-fuse@aa124b1 ... Here are the scripts I used for testing: |
Maps do not free all memory when elements get deleted ( golang/go#20135 ). As a workaround, we recreate our two big maps (kernelNodeIds & stableAttrs) when they have shrunk dramatically (100 x smaller). Benchmarkung with loopback (go version go1.16.2 linux/amd64) shows: Before this change: Step VmRSS (kiB) ----- ----------- Fresh mount 4000 ls -R 500k files 271100 after drop_cache 336448 wait ~ 3 minutes 101588 After: Step VmRSS (kiB) ----- ----------- Fresh mount 4012 ls -R 500k files 271100 after drop_cache 31528 Results for gocryptfs are similar. Fixes: rfjakob/gocryptfs#569 Change-Id: Idcae1ab953270516735839a034d586717647b8db
Maps do not free all memory when elements get deleted ( golang/go#20135 ). As a workaround, we recreate our two big maps (kernelNodeIds & stableAttrs) when they have shrunk dramatically (100 x smaller). Benchmarkung with loopback (go version go1.16.2 linux/amd64) shows: Before this change: Step VmRSS (kiB) ----- ----------- Fresh mount 4000 ls -R 500k files 271100 after drop_cache 336448 wait ~ 3 minutes 101588 After: Step VmRSS (kiB) ----- ----------- Fresh mount 4012 ls -R 500k files 271100 after drop_cache 31528 Results for gocryptfs are similar. Has survived xfstests via gocryptfs. Fixes: rfjakob/gocryptfs#569 Change-Id: Idcae1ab953270516735839a034d586717647b8db
Maps do not free all memory when elements get deleted ( golang/go#20135 ). As a workaround, we recreate our two big maps (kernelNodeIds & stableAttrs) when they have shrunk dramatically (100 x smaller). Benchmarkung with loopback (go version go1.16.2 linux/amd64) shows: Before this change: Step VmRSS (kiB) ----- ----------- Fresh mount 4000 ls -R 500k files 271100 after drop_cache 336448 wait ~ 3 minutes 101588 After: Step VmRSS (kiB) ----- ----------- Fresh mount 4012 ls -R 500k files 271100 after drop_cache 31528 Results for gocryptfs are similar. Has survived xfstests via gocryptfs. Fixes: rfjakob/gocryptfs#569 Change-Id: Idcae1ab953270516735839a034d586717647b8db
Memory usage after drop_caches should be much better now. Some numbers are here: Again thanks for the excellent report & testing! |
Far too high RSS memory consumption (memory leak?) with gocryptfs
I'm about to migrate my backup from EncFS to gocryptfs as gocryptfs IMHO is the best choice you can currently make for encrypted filesystems on Unix.
My version of gocryptfs is the one installed with
apt install gocryptfs
from my linux distribution Armbian (basically an Ubuntu 20.04 LTS Focal)My setup uses https://dirvish.org/ to create frequent rotating hard-link-snapshots, which results in approximately these numbers:
Before migrating from EncFS to gocryptfs there were absolutely no problems with the EncFS RAM (RSS) usage, typically approx 100 kB or even zero (!).
The RSS memory consumption with EncFS was perfectly low, especially with respect to the fact, that approx. 20 docker containers are running on the system.
After switching to gocryptfs, the RAM usage exploded. gocryptfs consumes 32.5% of the total available RSS RAM (645 MB of 2 GB):
Even after waiting approx 7 days (without any activity in gocryptfs!), gocryptfs still holds the same amount of RAM.
Here is a historical comparison with encfs:
How to read it (see also https://github.com/prometheus/node_exporter ):
I found #132 and tried to force the kernel to drop all caches (taken from https://askubuntu.com/questions/609226/freeing-page-cache-using-echo-3-proc-sys-vm-drop-caches-doesnt-work ):
Unfortunately this had no effect in the RAM usage of gocryptfs.
I also tried to allocate 2 GB of RAM with a shell script for 10 Minutes (taken from https://stackoverflow.com/questions/4964799/write-a-bash-shell-script-that-consumes-a-constant-amount-of-ram-for-a-user-defi ):
This also had no effect on the RAM usage of gocryptfs.
Only remounting of the gocrypt filesystem could reduce the RAM usage:
Very nice RAM usage after remount:
When doing a
ls -R
only over the approx. 500,000 "real" files, not over the hardlink snapshots (which basically matches the behaviour of the dailyrsync
job), the gocryptfs RAM usage again goes up.Doing the same thing a couple of consecutive times, basically all memory usages constantly increase, which could be an indicator for a memory leak (detailed log see attached file rss-mem-log-1.txt ):
Doing the same thing a couple of consecutive times over all files including the hardlink snapshots (approx 12,000,000), basically all memory usages constantly increase, which could be an indicator for a memory leak (detailed log see attached file rss-mem-log-2.txt ):
In case of interest: Here are some details of the gocryptfs process with an RSS of 918 MB:
pmap.txt
With these numbers it's a really hard decision, whether to to do the final switch from EncFS to gocryptfs.
Does anybody know, whether there have been improvements in this area from the current version distributed by apt (gocryptfs 1.7.1) to the current stable version (gocryptfs 1.8.0) or the current beta version (v2.0-beta4)?
Any other hints what to use gocryptfs without wasting so much RSS RAM?
The text was updated successfully, but these errors were encountered: