n67
Posts: 938
Joined: Mon Oct 30, 2017 4:55 pm

Is /tmp ramdisk in Raspbian?

Wed Nov 07, 2018 3:39 pm

In some distros/setups, /tmp is actually RAM - i.e., when you write to it, no actual disk write occurs.

Does Raspbian work that way, or does writing to it actually write to the SD card?

(The underlying point here, of course, is that I'd like to not be writing to the SD card if I can avoid it, for temporary files. Note that I can also setup a regular ramdisk (using /dev/ram0) - and that works - but I'm curious if /tmp would accomplish the same thing.)

P.S. Note that one side effect is that if /tmp is actually RAM, then there is no need to cleanup /tmp as part of the bootup sequence.
"L'enfer, c'est les autres"

G fytc hsqr rum umpbq rm qyw rm rfc kmbq md rfgq dmpsk:

Epmu Sn!

J lnacjrw njbruh-carppnanm vxm rb mnuncrwp vh yxbcb!

gordon77
Posts: 4160
Joined: Sun Aug 05, 2012 3:12 pm

Re: Is /tmp ramdisk in Raspbian?

Wed Nov 07, 2018 3:46 pm

Afaik /tmp is using the SD card, /run/shm is in ram.

n67
Posts: 938
Joined: Mon Oct 30, 2017 4:55 pm

Re: Is /tmp ramdisk in Raspbian?

Wed Nov 07, 2018 6:08 pm

gordon77 wrote:
Wed Nov 07, 2018 3:46 pm
Afaik /tmp is using the SD card, /run/shm is in ram.
Yeah, that's probably right.

According to "df", /dev/shm, /run, /run/lock, /run/user/1000, and /sys/fs/cgroup are all "tmpfs", but /tmp is not among those.

I wonder what would happen if I made /tmp be a link to something on /mnt/ramdisk...
"L'enfer, c'est les autres"

G fytc hsqr rum umpbq rm qyw rm rfc kmbq md rfgq dmpsk:

Epmu Sn!

J lnacjrw njbruh-carppnanm vxm rb mnuncrwp vh yxbcb!

jahboater
Posts: 4673
Joined: Wed Feb 04, 2015 6:38 pm

Re: Is /tmp ramdisk in Raspbian?

Wed Nov 07, 2018 6:13 pm

All my Pi's (including Pi Zero's) have these two lines added to /etc/fstab

Code: Select all

tmpfs /tmp tmpfs defaults,noatime,nosuid 0 0
tmpfs /var/log tmpfs defaults,noatime,nosuid,size=16m 0 0
The default maximum size is half the memory, but of course tmpfs only takes as much memory as the files need.

While you are in /etc/fstab, if you want to reduce writes to the SD then the other simple change is the flush rate.
For the ext4 / mount make sure the options include "commit=600"
That is, for example:

Code: Select all

PARTUUID=e96d960e-02 / ext4 defaults,noatime,commit=600,errors=remount-ro 0 1
Obviously do not do this if your site is prone to power cuts or other unexpected outages.
(dirty pages in the disk cache are written out every ten minutes instead of every five seconds which is the default).
This improves performance as well.
Last edited by jahboater on Wed Nov 07, 2018 8:44 pm, edited 2 times in total.

User avatar
thagrol
Posts: 1825
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Is /tmp ramdisk in Raspbian?

Wed Nov 07, 2018 6:20 pm

Dunno about a link but I have several Pi running with /tmp on tmpfs. I just added a suitable entry to /etc/fstab.
This space unintentionally left blank.

Return to “Raspbian”