Improve system performance by moving your log files to RAM

The Ramlog project lets you keep your system logs in RAM while your machine is running and copies them to disk when you shut down. If you are running a laptop or mobile device with syslog enabled, Ramlog might help you increase your battery life or the life of the flash drive on your mobile device. As a side effect of using Ramlog, you will be less likely to be caught out by a daemon that suddenly starts sending a message to syslog every 30 seconds and saps your battery keeping the hard disk spinning.

The life of the flash drive is an important consideration if you are using a solid state drive. It is likely that the /usr partition does not get written to very much, with /var and /tmp taking the lion's share of disk writes compared to the handful of times you might save source code in your home directory per day. Moving your system logs to RAM means that the solid state drive will see a lot less write activity. That means it should take longer to start producing unwritable sectors. The tradeoff is that if the laptop crashes instead of shutting down gracefully, you will lose the logs that were in RAM, but most of the time on a laptop the logs are not mission-critical.

The repositories for openSUSE, Ubuntu, and Fedora do not contain packages for Ramlog. The project's home page includes .rpm files for Fedora, .deb files for Ubuntu, and a source tarball. I'll build from source on a 64-bit Fedora 8 machine using Ramlog version 1.1.0.

The first steps of installation are shown below. Note that the 1.1.0 tarball of Ramlog expands directly into the current directory instead of creating a new subdirectory. These steps put the files in place ready for the final stage of installation. If you are running Ubuntu, see the Ramlog INSTALL file for the commands that you should execute instead of the chkconfig ones shown here for Fedora.

The getlogsize option to the ramlog command causes it to print how large your current /var/log directory is. You then select how large you want your RAM disk to be so that your log files will fit onto it. If you are using logrotate to keep your log files from growing infinitely, adding 30-50% to the current size of your log files should provide sufficient space in the RAM disk for your logging. If you do not set the size of your RAM disk explicitly then you are relying on the value that your distribution has selected for you. To explicitly set the value, edit your grub.conf file and append ramdisk_size=n, where n selects how many kilobytes to make the RAM disk. Because my existing /var/log was a little over 50MB, I selected a RAM disk size of 80MB.

To start using Ramlog you can either reboot, or stop every program that is using /var/log, start ramlog, and then restart the programs you stopped. One upshot of rebooting is that your RAM disk size parameter will be in effect; if you try to force ramlog to start on a running system, you are at the mercy of whatever RAM disk size is currently available (64MB according to the Ramlog documentation). The below command shows you what is currently using /var/log; in my case, quite a few daemons and the X Window System are active, making a reboot the more attractive option for starting to use Ramlog. If you accidentally boot a kernel that uses a RAM disk that is too small, then Ramlog will fail to start during boot, your /var/log will remain on hard disk, and things will function as they did before you installed Ramlog.

# service ramlog teststartstop
The list of open files: (You need to close below daemons if you want to start/stop ramlog manually)

When you boot from a kernel that has a sufficient RAM disk size and the ramlog service is enabled, during system boot your /var/log directory is copied to a RAM disk and the RAM disk is mounted at /var/log. The contents of the log directory on hard disk are still available through the /var/log.hdd path. This allows you to see both filesystems if you want to perform any manual operations. For example, if you want to delete a file, you should delete it from /var/log.hdd to avoid it being copied back to the RAM disk the next time you reboot. As shown below, the log.hdd directory is located on the LogVol LVM, and /var/log itself is on the ram9 disk.

If you want to save the log files from your RAM disk to your hard disk, execute service ramlog restart as root.

It would be nice if ramlog were aware of logrotate and kept the logrotate files themselves on your hard disk, storing only softlinks in the RAM disk. This would allow a smaller RAM disk to be used for storing only the log files that are still active. Perhaps the developers will consider this enhancement for future versions.

Wrap up

Knowing that you have a fixed chunk of RAM that contains your log files means that your laptop's hard disk doesn't have to spin up regularly if something needs to be logged by an overly verbose daemon. The fixed-size RAM disk Ramlog uses will keep an overly verbose daemon from exhausting all your system RAM. If you are using a solid state disk on a laptop with a few gigabytes of RAM, Ramlog can save you many write cycles on your solid state disk by sacrificing 50-80MB of RAM.