четвъртък, 30 юли 2015 г.

How to clean up tmpfs without rebooting

The problem: my /tmp is always full.
I manually deleted stuff from it (it's generally safe) and also from /var/tmp (which might not be that safe) but this didn't help. It turned out the problem is that systemd mounts /tmp into the RAM trough tmpfs (or at least I understand it so, I might be wrong). So even though /tmp as a directory is empty, it's still full somewhere on the RAM. Which creates problems, because even though I have plenty of RAM, the system thinks your tmpfs is full, because its size is the one written in /etc/fstab
One thing to do is to change the memory limit to a higher number, but this makes sense only if you know how to reset the tmpfs. Well, it turned out there is a way.
Zero step: check with:
that the problem is indeed in /tmp and not that your disk is simply full. 

Then, first before deleting anything, check that there's nothing important in your running apps that needs it. You can do:
$lsof /tmp
$fuser -m /tmp
To see what is currently using the /tmp directory. I guess it's a good idea to stop those processes before proceeding.
In mode details:
jane@linux $ fuser -m /tmp 
/tmp:                 2229  2258  3869c  6464 13163m 21380
jane@linux $ ps auxw|grep 21380
jane  7241  0.0  0.0  92088  2448 pts/1    S+   16:31   0:00 grep --colour=auto 21380
jane  8456  1.5  2.0 1856540 341412 ?      Sl  Jul28  46:02 /usr/lib64/firefox/plugin-container /usr/lib64/nsbrowser/plugins/libflashplayer.so -greomni /usr/lib64/firefox/omni.ja -appomni /usr/lib64/firefox/browser/omni.ja -appdir /usr/lib64/firefox/browser 21380 plugin
jane 21380 12.9 23.8 5670228 3889432 ?     Rl   Jul28 395:20 /usr/bin/firefox
Then you kill whatever is on your way.
Afterwards, you need to become
And then 
$umount -l /tmp/
$mount  /tmp/
And ideally, you're a happy person. This should work safely, but still, it's a good idea to close or save anything important for you before umounting /tmp.
Btw, there is a way to turn off the mounting of the tmpfs to RAM by:
echo 'MINTMPKB=0' > /etc/default/mountoverflowtmp
but people are not recommending that and I didn't do it.

You can also mount /tmp with:
$mount -t tmpfs -o size=1048576,mode=1777 overflow /tmp
where the size should be whatever you like. Which probably is the better way to mount it, because automatically, it mount is with size=8156484, which probably is related to the amount of free RAM, but I'm not sure.
You can check your free RAM with:
$free -m -t