jbudd
Posts: 1446
Joined: Mon Dec 16, 2013 10:23 am

No /tmp filesystem

Sat Feb 08, 2020 3:39 pm

I only just noticed this when trying to upgrade one of my Pies (8GB SD, Raspbian Buster Lite, Sept 2019)

/tmp is just a directory not a filesystem and accumulated junk there caused the root filesystem to fill up.

Code: Select all

pi@APi:/ $ df -k
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/root        7312912 7295432         0 100% /
devtmpfs          240340       0    240340   0% /dev
tmpfs             244948       0    244948   0% /dev/shm
tmpfs             244948   24900    220048  11% /run
tmpfs               5120       4      5116   1% /run/lock
tmpfs             244948       0    244948   0% /sys/fs/cgroup
/dev/mmcblk0p1    258095   53443    204653  21% /boot
tmpfs              48988       0     48988   0% /run/user/1000
How come there isn't a /tmp filesystem - which could presumably be type tmpfs rather than stored on the SD card?
I presume there is a good reason, please enlighten me!

jahboater
Posts: 5825
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: No /tmp filesystem

Sat Feb 08, 2020 5:09 pm

You need to add it yourself for Raspbian.
I append this to /etc/fstab

Code: Select all

tmpfs /tmp tmpfs defaults,noatime 0 0
tmpfs /var/log tmpfs defaults,noatime,size=16m 0 0
Pi4 8GB running PIOS64

jbudd
Posts: 1446
Joined: Mon Dec 16, 2013 10:23 am

Re: No /tmp filesystem

Sun Feb 09, 2020 1:43 pm

Thanks jahboater.

A Pi is constrained by a) potentially only 256MB memory and b) limited writes before the SD card dies
I guess a) is why /tmp isn't a tmpfs filesystem?

What happens if a /tmp filesystem uses up the allocated memory - the Pi grinds to a halt, or frantic swapping?

jahboater
Posts: 5825
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: No /tmp filesystem

Sun Feb 09, 2020 1:57 pm

jbudd wrote:
Sun Feb 09, 2020 1:43 pm
What happens if a /tmp filesystem uses up the allocated memory - the Pi grinds to a halt, or frantic swapping?
tmpfs is different from ramfs in that it resides in "virtual" memory. And the virtual memory occupied is that used by the files only.
There is a slight overhead for an empty tmpfs filesystem of around 100KB (I think).
Any "size=" option is a maximum.
Without a size= option, the default maximum size is 1/2 the amount of physical memory. My mount entry for /tmp does not use it, which means the maximum size adjusts itself automatically for a Pi Zero up to a 4GB Pi4, or even a 16GB PC.
I can just paste the two entries in whenever I configure a new Pi.

Modern Pi's have 1GB to 4GB of memory.
The Zero does still have only 512MB but I use the fstab entries above with never a problem.
You wont find many with 256MB!!!

Note that I limit the size of /var/log

Its up to you, how much are you planning to store in /tmp ?

As for limited writes, I also add "commit=600" to the ext4 filesystem which reduces writes, and speeds things up, at the expense of resilience to unplanned power outages.
Pi4 8GB running PIOS64

jbudd
Posts: 1446
Joined: Mon Dec 16, 2013 10:23 am

Re: No /tmp filesystem

Sun Feb 09, 2020 2:08 pm

Well I wasn't "planning" on storing anything there!

The Pi with 100% full root fs has PiVPN installed on it, using wireshark.
Currently wireshark is dumping a 40 - 50 MB file into /tmp every 20 minutes and the VPN isn't even in use. Obviously that's not a problem to discuss here.

Edit - I have had /var/log fill the root filesystem too. I think that was PiHole.

jahboater
Posts: 5825
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: No /tmp filesystem

Sun Feb 09, 2020 2:12 pm

If you limit the maximum size of /tmp or /var/log with the "size=" option, you can ensure the system will still run (reasonably) happily even when they are full.

Sounds like you need a 4GB Pi4!
Pi4 8GB running PIOS64

User avatar
rpdom
Posts: 17275
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: No /tmp filesystem

Sun Feb 09, 2020 7:24 pm

I vaguely remember when I used to follow the Debian mailing list (or Usenet groups or something) that there was a big argument about this. A change was made on one release that had /tmp as a ramfs and a lot of people complained because they were creating DVD images and things in there and they wouldn't fit in the available space in RAM and swap.

The change was reverted to having /tmp as just part of the main file system.
Unreadable squiggle

User avatar
dickon
Posts: 1595
Joined: Sun Dec 09, 2012 3:54 pm
Location: Home, just outside Reading

Re: No /tmp filesystem

Sun Feb 09, 2020 7:49 pm

Back in the day (mid-'90s), /tmp was a tmpfs-equivalent, and /var/tmp was a proper filesystem, which may or may not have been nuked on a reboot, depending on the OS. You were expected to stick big temp files in /var/tmp, and trivial small things (pidfiles, sockets, draft email texts, for example) in /tmp.

It's a model I still stick to, personally.

Return to “General discussion”