10

My current laptop hard drive (Seagate ST940818SM) is slow (max 42MB/s R/W speed) and out of space. Mounting /tmp and /var/tmp as tmpfs does a lot of performance improvement. So is it safe to mount /var/log as tmpfs?

I don't care about logs on my laptop. Will it improve battery backup time somewhat? As log files are on RAM, this allows complete hard drive spin down during no activity period.

2
  • Do you write much to /var/log anyway? Also, some programs write to subdirectories under /var/log and may be upset when these suddenly disappear after a reboot. Commented Jun 20, 2015 at 18:09
  • It might not be a good idea to mount /var/tmp as tmps: reference
    – jarno
    Commented Feb 4, 2016 at 9:46

2 Answers 2

8

Technically, you can mount /var/log as tmpfs. You'd need to be sure that /var/log is mounted before syslogd starts, but that's the case by default on most distributions since they support /var on a separate partition.

You'll obviously lose all logs, which I guarantee will be a problem one day. Logs are there for a purpose — there're rarely needed, but they're there when they're needed. For example, if your system crashes, what was it doing before the crash? Since when has this package been incstalled? When did I print this document? etc.

You won't gain much disk space: logs don't take much space relative to a hard disk. Check how much space they use on your system; I'd expect something like 0.1% of the disk size.

You won't gain any performance. Logs amount to a negligible part of disk bandwidth on a normal desktop-type configuration.

The only gain would be to allow the disk to stay down, rather than spin up all the time to write new log entries. Spinning the disk down doesn't save much electricity if any: the hard disk is only a small part of a laptop power consumption, and spinning up requires a power surge. Furthermore spin cycles wear down the disk, so don't spin down too often. The main reason to spin down is the noise.

Rather than putting logs on tmpfs, arrange for your disk not to spin up when a file is written. Install Laptop Mode, which causes writes to disk to be suspended while the disk is spun down — only a full write buffer, an explicit sync or a disk read will spin the disk back up.

Depending on your configuration, you may need to instruct the syslog daemon not to call sync after each write. With the traditional syslog daemon, make sure that all file names in /etc/syslog.conf have - before them, e.g.

auth,authpriv.*         -/var/log/auth.log

With rsyslog, also make sure that log file names have - before them; the log files are configured in /etc/rsyslog.conf and /etc/rsyslog.d/*.

5
  • Probably, if something go wrong, it is easy to just comment out the line with tmpfs in /etc/fstab. In fact, I can think of the case when one needs to move logs to tmpfs — I just have one ☺ It is when the system is installed to a cheap usb stick, they tends to have very slow IO.
    – Hi-Angel
    Commented Jan 31, 2016 at 14:23
  • @Hi-Angel Logs can be useful when investigating past events. Commenting out the fstab entry will only allow to investigate future events. That might make a big difference.
    – jlliagre
    Commented Sep 9, 2016 at 11:40
  • 8
    This can be useful when reducing the number of writes on a drive to increase the lifespan (especially for embedded systems with SD-cards).
    – Yeti
    Commented Jan 30, 2017 at 13:23
  • 2
    "You won't gain much disk space: logs don't take much space relative to a hard disk." My logs grow at a rate of a few GB per hour. Commented Jun 11, 2019 at 4:26
  • But in this case ram disk wont save you !
    – basos
    Commented Nov 3, 2022 at 16:02
1

The other answer here is correct: You don't need to / want to do this for any sane circumstances. Doing so has various drawbacks and usually zero benefits. If your Linux system is on a hard drive (whether SSD or spinning), the simple answer is: You don't need this. If your system is spamming errors, this is still not a solution; it means you have a serious problem that needs investigation ASAP.

My own circumstances aren't sane. I'm running a toy project where I've installed a Linux OS on an ancient 8GB USB with far less than 1MB/s write speed, but on a computer with a good amount of RAM. It's not a production system. My system keeps hard-freezing for seconds at a time because of too many concurrent processes trying to write to my very slow drive. By sending all my cache and tmp dirs to RAM, I get a responsive system.

Here's the answer to your question:

  • Edit /etc/fstab as root.
  • Add something like this:
tmpfs /var/tmp tmpfs defaults,mode=1777,size=256M 0 0
tmpfs /var/log tmpfs defaults,mode=1775,size=512M 0 0

I've added ,size=256M and ,size=512M to limit their respective sizes, you may remove these if you want to them to consume up to 50% of your RAM.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .