Reduce hard disk writes in Ubuntu

Frequent hard disk write keeps the drive from going to low power mode (especially with the Green drives). Therefore, we need the drive to be inactive for a while to turn on the low power state. In order to do this in Ubuntu Server, the frequency at which things are written to the drive needs to be changed. In the long run this can save some energy costs as well as increase the drives life. This is what I did to reduce hard disk writes in my Ubuntu server:

Reduce Hard Disk Writes

First, to find out how often something is written to my hard disk, use the following command:

echo 1 > /proc/sys/vm/block_dump while true ; do dmesg -c | grep WRITE | grep sda ; done

Hard Disk | Smarthomebeginner This showed that something was written to the disk by processes 584, 824, and 263 about every 5 seconds. Doing some research and using ps -elf | grep pid (where pid = 584, 824, or 263) I found that these processes were related to the journaling file system (Note: the pid numbers can change).

Although many blogs suggest leaving vm.swappiness on server install to the default level of 60, my server is small one and I have enough RAM (2 GB on a headless install). So i set the swappiness to 30.

sudo echo 30 > /proc/sys/vm/swappiness

Then, I also changed the following,

sysctl -w vm.dirty_writeback_centisecs=60003
sysctl -w vm.dirty_expire_centisecs=30001

I did not however modify my hard disk's sleep settings. I left it to default (and its a GreenDrive anyways).

Finally, my server install is not very important to me and I do not mind loosing data during rare power offs, I set my commit value to 30 min (1800 seconds) in fstab.

/dev/sda5 /home ext4 noatime,nodiratime,commit=1800 0 2

I do not have a UPS and yes I have the risk of losing up to 30 min of data upon power failure. But it is not like I am receiving tons of data on my websites every second. I have very few visits a day. If this screws up my server install that is OK. I can always reinstall/repair it.

This is the result I am hoping. I want my hard drive to idle for as long as possible. While idling green drives use about half the power as while working. By reducing writes to hard disk, I am hoping to increase the hard drives working time and increase the idle time. I did not change the hard drives sleep settings. Frequent sleep and wake can damage the hard disk.


CAUTION: I am no linux expert. The following changes can seriously affect your hard disk / performance. Do you due diligence before trying these methods.

Souces:
http://www.lesswatts.org/tips/disks.php (defunct)
http://ubuntuforums.org/showthread.php?t=1125285

Be the 1 in 200,000. Help us sustain what we do.
114 / 150 by Dec 31, 2024
Join Us (starting from just $1.67/month)

Anand

Anand is a self-learned computer enthusiast, hopeless tinkerer (if it ain't broke, fix it), a part-time blogger, and a Scientist during the day. He has been blogging since 2010 on Linux, Ubuntu, Home/Media/File Servers, Smart Home Automation, and related HOW-TOs.

Try Deployarr