0

I do not think that this is Linux's disk cache. In htop, the memory bar is green (not orange for cache) and I removed the files stored in Zram. No processes seem to be using a lot of memory.

The load was compiling software with its build files stored in Zram (PORTAGE_TMPDIR(/var/tmp/portage)), with swapfile on Zram too. It had Zram writeback configured so that it would write to disk if there is not much RAM left. I compiled 2 softwares, after 1 software, there seemed to be still about 1/2 the memory used, zramctl said that total data used was near 0G, and no proccess is using much memory, and Linux disk cache wasn't the issue. With kswapd continuously at 100% CPU utilization the kernel OOM killed the process consuming too much RAM. After this there was still RAM being used but nothing I could find was using it. If it was disk cache, the kernel would have handed over the space to the memory consuming process. But it didn't, so this is most likely NOT a disk cache issue, I rebooted the computer and the 2nd software compiled quickly without an issue!

Does anyone know what could be the case, is there any way I could further identify what is using the memory?

  • Are you trying to say "close to full"? Close to available in English means, not available but close to. – ctrl-alt-delor Oct 4 at 19:10
  • I meant as in the command free, but I made a typo and used the word available instead of total. The used value in free is close to the total value, which is a problem because I can't find anything that could possibly use all that space in memory. I've fixed it, thanks – System Oct 4 at 23:18
  • I can't see in the question. Is the zram filesystem now empty (But you are still using lots of ram somewhere)? – ctrl-alt-delor Oct 5 at 9:52
  • A side question: Have you tested? Is using zram any faster than using a file-system on hard disk, or a ziped file-system on hard disk (The kernel may be better at choosing what to cache than you are. It is not always, but usually is ). – ctrl-alt-delor Oct 5 at 9:54
1

Short answer: Use discard mount options when mounting file systems or turning on swap created on the Zram devices.

Extended: When mounting a file system use discard as a mount option, you can set mount options with -o and options separated with a ,, no space between. It should be supported on most Linux file systems, I use it on Btrfs. On swap, use -d when using swapon. You could also in addition to this, periodically run fstrim on the directory that the file system is mounted at, but from what I've seen in the output of zramctl this isn't necessary and the discard mount option is good enough.

Edit: Actually, after some further testing I think it's a good idea to periodically run fstrim on the Zram mount. After compiling Firefox with it's build directory in Zram, there was about 1.1GB of RAM usage. Not nearly as bad as without the discard mount option, but there is room for improvement. Running fstrim on the Zram mount (which only took a couple of seconds to run) caused the RAM usage to go to 400MB, which is normal. I'd probably put it in a cron job or after a portage compile.

Explanation: When files are removed, Zram doesn't remove the compressed pages on memory because it's not notified that the space is not used for data anymore. The discard option performs discard when a file is removed. If you use the discard mount option Zram will be notified about the unused pages and will resize accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.