Page 1 of 1

How to make Linux faster

Posted: Mon Feb 22, 2010 6:08 pm
by Acid_1
I am going to start by saying a couple of things. First off, thanks Fred for helping me sort this out. Second is that don't do this if you're not comfortable messing with fstab or the command line. Third is I take no responsibility if it borks your PC. (It shouldn't though). Fourth, please read the tutorial completely and make sure you understand it. If you don't, either don't do this, or ask questions. Just make sure you know what's going on. And finally, if you have a desktop PC, make sure you have a battery backup. Turning off journaling and having a power failure=bad times. Laptops will likely be okay as they have their own battery...

To start off, I will tell you a bit about atime. Basically it writes to the file you have done anything with, whether it's creating it, modifying it, or reading it. This can cause slowdowns cause it makes the disk spin more than it needs to. So what we want to do is simply turn it off. This way when you open a file, it will not write the atime, saving you from having your disk spin (more than necessary). This is great if you have USB linux distributions installed, as it will minimize writing to the disk, saving the USB disk. If the prospect of noatime is too much for you, inserting relatime will be a good option. This way, it only writes to atime if permissions (chmod/grp) or last write is later than the atime currently recorded. So basically, if you open a file, close it, and open it again, it wouldn't adjust atime.

Another note, cause the examples are long they may go to the next line. If this is the case, use the code copy and place it in a text editor without line-wrap on. This will give you the proper view then.

Now to dig into the how to.

First, switch to a root terminal with

Code: Select all

sudo su
We're going to keep using the root terminal, so don't exit it.

Next we edit the fstab.

Code: Select all

cp /etc/fstab /etc/fstab.bak
gedit /etc/fstab
It should look something like this:

Code: Select all

# <file system> <mount point>   <type>             <options>                                 <dump>  <pass>
proc                     /proc             proc                defaults                                      0           0
/dev/sda1                 /               ext4                errors=remount-ro                       0           1
/dev/sda3           /home             ext4                defaults                                      0           2
/dev/sda2              none             swap               sw                                              0           0
/dev/scd0       /media/cdrom0   udf,iso9660      user,noauto,exec,utf8                0           0
Now anytime you see an ext4, change the types, add (for ext3 change it to barrier=0):

Code: Select all

noatime,data=writeback,commit=60,nobarrier
to it. I will demonstrate so you know where to stick it.

Code: Select all

# <file system> <mount point>   <type>             <options>                                                                                        <dump>  <pass>
proc                     /proc             proc                defaults                                                                                              0           0
/dev/sda1                 /               ext4                errors=remount-ro,noatime,data=writeback,commit=60,nobarrier         0           1
/dev/sda3           /home             ext4                defaults,noatime,data=writeback,commit=60,nobarrier                        0           2
/dev/sda2              none             swap               sw                                                                                                      0           0
/dev/scd0       /media/cdrom0   udf,iso9660      user,noauto,exec,utf8                                                                         0           0
Save it and close gedit.

Make sure that when you add ,noatime,data=writeback,commit=60,nobarrier that there are no spaces in between the comma and the option. This will not work otherwise, and I don't know if/how much it could screw your PC up.

Now we're almost done, but don't forget to add this last step, or you could render your OS unbootable. In the root terminal:

Code: Select all

tune2fs -o journal_data_writeback /dev/sdxx
and replace xx with the disk number.

For instance, since I did this to partition 1 and 3, I would have to do

Code: Select all

tune2fs -o journal_data_writeback /dev/sda1
tune2fs -o journal_data_writeback /dev/sda3
And finally, if you want to keep the partition in the future but install another distro on it, make sure you use

Code: Select all

sudo tune2fs -o journal_data_ordered /dev/sdxx
on those partitions to turn them back to normal.

Thanks for reading and good luck!

Re: How to make Linux faster

Posted: Mon Feb 22, 2010 6:21 pm
by remoulder
Good stuff, we'll blame you when everyone starts trashing their systems then! :lol:
Acid_1 wrote:when you open a file, it will not write the atime, saving you from having your disk spin
Bit unsure about this bit though. Surely the disk has to be spinning to read the file in the first place?

Re: How to make Linux faster

Posted: Mon Feb 22, 2010 6:28 pm
by Acid_1
remoulder wrote:Good stuff, we'll blame you when everyone starts trashing their systems then! :lol:
Acid_1 wrote:when you open a file, it will not write the atime, saving you from having your disk spin
Bit unsure about this bit though. Surely the disk has to be spinning to read the file in the first place?
You're correct. I suppose it would've been better worded as keeping the writes down.

Re: How to make Linux faster

Posted: Mon Feb 22, 2010 10:12 pm
by Fred
Acid_1,

A couple little points.
Now anytime you see an ext2/3/4, change the types, add

Code: Select all
noatime,data=writeback,commit=60,nobarrier
This is for ext4 only. For ext3 it has to be "barrier=0" instead of "nobarier." I know it is silly that they did that but they did. :-)

Also, ext2 doesn't have a journal so "data=writeback" and "nobarrier" are not options that are available in that file system.

To reiterate the cautions, when you are using writeback and/or nobarrier power failures are a big deal. Data corruption/lose is likely to occur if a power failure occurs. That is why UPS is recommended for desktops.

Fred

Re: How to make Linux faster

Posted: Wed Feb 24, 2010 12:02 am
by Acid_1
Thank you Fred. Your advice has been heeded and added to the tutorial.