You are not logged in.

#1 2008-02-08 06:25:05

thetrivialstuff
Member
Registered: 2006-05-10
Posts: 191

tmpfs free space versus the "free" command

I've always thought this possible, so today I tried it:

I have 2 gigs of physical RAM, and no swap partitions, so my memory limit is a hard 2 gigs.

I made 2 1-gig tmpfs mounts; nothing complained.

I filled them up one at a time, and kept checking both free memory (with free) and free space on the tmpfs mounts -- as I started to get near the limit of my system's RAM, free still showed plenty of RAM free in the +/- row.

Neither free nor df gave me any indication that the system was dangerously low on memory. (I assume from a bit of Googling  that "free" considers the size of tmpfs's to be part of the "cached" column, as nothing else was big enough to contain them.)

Anyhow, I added a few more files to the tmpfs and the system locked up for a while... After about 3 minutes of hard drive thrashing (which was a bit distressing, but since my files look OK I guess it was desperately running sync again and again to try to free RAM for the tmpfs), a couple programs died and everything went back to normal.

So, in an effort to have that not happen again (since I use tmpfs heavily; it's a nice way to screw around with big files without waiting on hard drives), I wrote this little shell script:

#!/bin/bash

#prints worst-case free memory, from /proc/meminfo

total=`grep MemTotal /proc/meminfo | gawk '{print $2}'`
used=`grep Committed_AS /proc/meminfo | gawk '{print $2}'`

echo "Free RAM in the worst case: " $(($total - $used)) "kB"

and put this in my .bashrc:

alias free='free; wcfree'
alias df='df; wcfree'

~Felix.

PS: If it's not possible to make stuff crash with only a single tmpfs, please let me know -- that would be good knowledge, and make me feel silly for writing this :P

Offline

Board footer

Powered by FluxBB