While working with netbooks and other portable computers over the years I have always looked for new ways to improve battery life, but I have also been concerned with maximizing performance of these small systems. Today I would like to share with you a simple trick to improve performance and the overall "feel" of your computer.
tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/log tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/tmp tmpfs defaults,noatime,mode=1777 0 0
Next, lets stop the syslog services and clean out your current temp and log directories. We'll also mount the new RAM disks and restart the syslog service. Note: the name of the syslog service will change from distribution to distribution.
sudo /etc/init.d/rsyslog stop
sudo rm -rf /tmp/*
sudo rm -rf /var/log/*
sudo rm -rf /var/tmp/*
sudo mount -a
sudo /etc/init.d/rsyslog start
To improve performance while also improving battery life we will be moving all of your temp files and logs to RAM. This significantly reduces IO from some applications (think Firefox / flash) while eliminating the need to wake your hard drive from a sleep state (think battery life).
First, edit FSTAB and add the following lines:
tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/log tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/tmp tmpfs defaults,noatime,mode=1777 0 0
sudo rm -rf /tmp/*
sudo rm -rf /var/log/*
sudo rm -rf /var/tmp/*
sudo mount -a
sudo /etc/init.d/rsyslog start
Please note that moving these logs and temp directories to memory will cause the contents to be lost when you restart. If there is a need to save these logs to disk before restarting, manually copy them to another directory before you reboot.
rsync -av /var/log/* ~/saved_logfiles
Now that you have moved your temporary directories and logs to RAM, lets tweak Firefox. Open Firefox, and in the address bar type 'about:config'. Click through the warning message. Right click anywhere in the parameter listing and select New -> String. Set the preference name to 'browser.cache.disk.parent_directory' (without the ticks) and set the value to '/tmp' (without the ticks).
Restart Firefox. You should find that Firefox is a little "snappier", and sites that use flash like Hulu may even work a little better. Additionally, if you are on battery and using a utility like Jupiter that manages your laptop modes you should see an increase in battery life.
NOTE: There has been some discussion of the possibility of files that need to be retained across a reboot being stored in /var/tmp. I have not seen this myself in testing, however before moving /var/tmp to tmpfs, evaluate the content of the directory to be safe.
rsync -av /var/log/* ~/saved_logfiles
Now that you have moved your temporary directories and logs to RAM, lets tweak Firefox. Open Firefox, and in the address bar type 'about:config'. Click through the warning message. Right click anywhere in the parameter listing and select New -> String. Set the preference name to 'browser.cache.disk.parent_directory' (without the ticks) and set the value to '/tmp' (without the ticks).
Restart Firefox. You should find that Firefox is a little "snappier", and sites that use flash like Hulu may even work a little better. Additionally, if you are on battery and using a utility like Jupiter that manages your laptop modes you should see an increase in battery life.
NOTE: There has been some discussion of the possibility of files that need to be retained across a reboot being stored in /var/tmp. I have not seen this myself in testing, however before moving /var/tmp to tmpfs, evaluate the content of the directory to be safe.
13 comments:
Thanks for the tip - I had to read the tmpfs wiki article for a bit more on internals, but in the end this is what I did with my eeePc 701.
I faced a little problem after making the changes as suggested. The problem is that I have LAMP installed in my netbook (Ubuntu 10.04 Lucid installed). Since the "error.log" and "access.log" are located in /var/log/apache2/ the files get wiped out I guess every time I shut down the machine. After restart, Apache does not start automatically and I have to manually create the folder "apache2" in /var/log and the create the files "error.log" and access.log after which I can start Apache manually. It apparently runs fine till I restart the computer and then I have to repeat the process.
This was to be expected I suppose.
Thanks though :)
Doesn't Fedora use rsyslog?
Or is this Ubuntu only tutorial?
This is an older out of date article that I need to update.
The procedure for Fedora:
su -
/etc/init.d/rsyslog stop
echo "tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0" >>/etc/fstab
echo "tmpfs /var/log tmpfs defaults,noatime,mode=1777 0 0" >>/etc/fstab
mv /tmp /tmp2
mkdir /tmp
mv /var/log
mkdir /var/log
mount -a
rsync -av /tmp2/ /tmp
rsync -av /var/log2/ /var/log
rm -rf /tmp2
rm -rf /var/log2
/etc/init.d/rsyslog start
I shared your page in my twitter and in my local Linux IRC and got a few comments.
First is something I don't understand and that is that "all of that is already in page cache"
"you can use async write for logs"
and a few "why write logs in ram when you discard then anyway when you reboot. It's better to disable logging and enable it when you need it."
And also got a few responses that maybe it would be better to tune commit and noatime mount parameters.
Hope this helps.
Cheers,
Valent.
Hi Valent.
Page cache is important for reads more so than writes. Writes are committed to page cache as a "dirty" IO and then flushed out to disk, and unless the IO block being written is already resident in memory it won't exist in this cache on the initial write causing a spindle wakeup. A spindle wakeup uses a considerable amount of power, and injects latency into IO. I and others have found that reducing this latency improves desktop response, and also reduces power consumption while on battery.
Using an asynchronous write for logging won't reduce power consumption, or IO latency.
Configuring noatime is important with older kernels that don't default to relatime, Using atime on a filesystem causes three writes for every readm but relatime has been a default for quite some time which reduces these writes to 1 for every read. If you have /var/log and /tmp in memory, you have no latency for this read or write.
In all cases, I and others have seen significant reductions in latency and spindle wakeups using this tweak. In addition, one of the other common complaints is the use of memory for this tweak, running with /tmp and /var/log in RAM uses ~1MB over the period of a week with typical use which with most computers less than 5 years old is less than 1% of physical memory. I no longer recommend putting /var/tmp in memory though, and will update this article when I have some more time to reflect that change.
I would be happy to chat about this further with you and anyone else that cares to discuss this in the Fuduntu forum, just make a thread about it. :D
I'm running Minefield 4.0b9 nightlies & unless its confirmation bias, it really seems to have sped up FF a lot on my ageing laptop - the endless disk thrashing has calmed right down - great tip
hi FEWT, maybe I'm wrong but typing '/tmp' as firefox cache directory creates a folder with name Cache and permissions 755, which are not secure.
Maybe it is better to type '/tmp/ff-cache'. This way, the folder ff-cache will have 700 permissions (and will contain the Cache folder with unsecure permissions).
cheers,
ukayp
Hi,
very interesting performance enhancement. thanks for sharing.
as for retaining tmp files across reboots, how about writing a script that will save tmp files to hard drive before reboot and then restore after/at reboot?
Excuse I'm asking in such an old article, but if we use the memory for temporary files what are we using for our apps? In mi case when working on big images with Gimp I may have several GB in my temp directory; also when compiling Firefox (I'm on Gentoo) it devoures 2'5 GB in /var/tmp. Wouldn't my system run out of memory and begin to use swap, ergo the remedy would be even worse than the illness?
Thanks and regards
@Carlos - It's intended for general computing. If you are doing more advanced things like building software, or working on files that are that large, by all means turn it off.
The neat thing about this is that it can also be easily used to speed up Google Chrome/Chromium -> Just need to create another fstab line for /Home//.cache/chromium and see the speed.
Works so far but still need to test it more, perhaps I'll put a topic about it on the Fuduntu forums when I'm done.
Would be great to know which directories have the largest I/O and a decent size so that they can be moved to ramcache without any risks.
Is there a way to make the ramcache sync it's contents to the disk once in a while (or before a shutdown) to the same directory on the physical disc (same path as the ramcache mount) ?
It would be pretty simple to write an init script that would rsync the data back and forth.
The only issue is that a kernel panic would cause a loss of any data that wasn't synced when the panic occurred.
Post a Comment