One thought at a time, all the time

High RAM usage and no process to blame? Check your tmpfs mounts

Romain Gehrig

TL;DR: See how much memory is used by tmpfs with the following command: df -h | grep -E "Filesystem|tmpfs". The shared memory in htop or free is also a good estimation.

My computer usually has a couple weeks of runtime between reboots. Being on Linux and using hibernation means I only reboot to update graphical drivers. The routine is as simple as it gets: close all programs one by one so I don’t miss unsaved files. However after shutting down the happy memory hogs – the browser with a hundred tabs and the glutton chat app, I noticed my status bar still showed a memory usage of 10GiB, way above the 2GiB or so I expected1. I couldn’t find any obvious culprit with htop and, after the reboot, memory usage was back to normal. No more problem, so back to work.

Fast forward a few days, I think again about the problem and want to scratch the itch. I dig a bit and find the answer on the Unix StackExchange: check the space used by tmpfs. I nearly facepalmed: obviously tmpfs – which stores its files in RAM – will use some and not appear in the process list.

So here’s the command to find how much space tmpfs uses:

$ df -h | grep -E "Filesystem|tmpfs"
Filesystem      Size  Used Avail Use% Mounted on
tmpfs            32G  369M   31G   2% /dev/shm
tmpfs            32G  6.7G   25G  22% /tmp
tmpfs           6.3G   92K  6.3G   1% /run/user/1000

which sums up to about 7.1G.

In free and htop, this amount is accounted under the shared memory.

$ free -h
               total        used        free      shared  buff/cache   available
Mem:            62Gi        17Gi        16Gi       7.5Gi        36Gi        45Gi
Swap:             0B          0B          0B
Figure 1: htop represents the shared memory with red bars.

Figure 1: htop represents the shared memory with red bars.

Notice how free reports 17Gi used, while htop reports 9.39G? They both have access to the same info2 but they differ in how they interpret it. free’s used is equal to MemTotal - MemAvailable3 while htop sums up the memory used by processes. My status bar – the excellent bumblebee-status – shares the same definition as free.

So… which number is correct? It depends on your use. In my case, I wanted to find a process leaking memory and htop’s “memory used by processes” would have tipped me off. However, if my question was “I want to start a 30GB job, do I have enough headroom?” then free’s available memory gives me what I’m looking for4. At least, now I know where to look!


  1. Did I say I use Arch btw? ↩︎

  2. cat /proc/meminfo for all the data. ↩︎

  3. The MemAvailable number is an estimation from the Kernel that takes into account freeable memory pages: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773↩︎

  4. htop also offers the available memory, but only with the memory widget in text mode. ↩︎