Wednesday, August 18, 2010

Make Linux faster

With just a few tweaks, your Linux box can be lighter, sprightlier and quicker than ever before. Read on for the best ways to speed up your boot sequence, optimise KDE and Gnome, and get better performance from your favourite apps. We've also got some top tips from our favourite free software gurus...

Gone are the days when you could make a cup of tea and drink it in the time it takes your computer's operating system to boot (with one notable exception). On that basis, you might think that your Linux machines are already performing at the fastest possible speed, right?

Sadly, this is not always the case. Communities developing mainstream Linux distributions have to appeal to the widest possible audience and ensure compatibility with the widest range of hardware. This means that someone running a mainstream distro on a netbook or a low-end PC may well be using many of the same settings as someone with a high-end gaming machine. But it doesn't have to be this way!

With just a few tweaks and some experimentation, your Linux system can realise your machine's untapped potential. Do you have a dual-core processor? Take advantage of this by running boot processes in parallel. Do you have more memory than you know what to do with? You could try caching data in memory rather than swapping space for faster access.

The great strength of everyone's favourite free OS is that it can be customised from the ground up, so Linux is the ideal tool to tailor to your needs. But once you have an ultrafast system, how can you become more productive? We've consulted prominent members of the free software community for their favourite tips that make their systems more productive - and they could do the same for you.


Make Linux boot faster

Any productive machine needs to be up and running as soon as possible, and a sluggish boot can hinder your efforts – which is why boot times were the first thing we thought about improving. One word of warning before you begin: we recommend that you make a backup before you make these alterations, as a bug in your bootloader can render your Linux box unbootable!

Remove the timeout

You may notice that each time you boot there's a small count-down from three to zero, which is great if you regularly select a different OS or Linux kernel at boot time, but useless if you always boot into the same distro. Fortunately, it's easy to remove by opening /boot/grub/menu.lst in a text editor with root permissions and finding the line showing:

timeout=3

Once you've found it, change the value to zero. Save and exit then reboot and you should notice you have just knocked three seconds off your boot time.

Improve disk performance

If you have a DMA-compatible (Direct Memory Access) hard drive, you can increase data throughput threefold with a simple tweak. This will improve boot times because read times will be reduced, and overall performance will increase whenever the hard disk is accessed.

Start by installing hdparm through your package manager, then fire up a root terminal and type: hdparm -d1 /dev/hda1replacing /dev/hda1 with the location of your boot partition to increase startup times or the root partition to increase general performance. Gnome users can have this run automatically each startup by heading to System > Administration > Services. You can then add this line as an entry with gksudo at the start to ensure it runs with root permissions without requiring additional authentication.

Run boot processes in parallel

Parallelism can lead to big performance boosts, because running two processes at once will take half the time of running them sequentially (at least in theory). You can take advantage of this technique in Grub by firing up /etc/init.d/rc in a text editor with root permissions and finding the following line:

CONCURRENCY=none

You would then replace none with shell before saving and closing your text editor. When you reboot you should see a noticeable decrease in your boot times (around one or two seconds in most cases). If you don't see an increase, this is because this tweak is aimed primarily at systems with multi-core processors. If you have a solo-core processor you could actually increase your boot time if you use this tweak, which was the case with our test system where we saw a 2.4-second increase.

You could edit a text file and restart your machine to profile your system, or just click a few buttons in Grub.

Optimise memory

One great way to improve performance is to define how swap space is used. A swap partition is where the Linux kernel caches data in virtual memory to quickly swap into RAM as and when it's needed. A dedicated partition isn't compulsory, but the space is also used to store your machine state if you choose to hibernate. The effects of this tip depend on your system and whether you have a swap partition, but if you have plenty of RAM you'll find that reducing swappiness will give you a noticeable performance boost.

This will allow the kernel to cache data in memory for faster access and reduces the amount of data being swapped in and out of swap space at any given time. Simply open /etc/sysctl.conf in a text editor with root permissions, then append the following line to the bottom of the file:

vm.swappiness=10

(You will need to restart the session in order for your changes to take effect.) You can tweak this value to see how performance improves. The lower the value, the less you use swap space and the more data is cached to memory. This was the value that seemed to work best with our test system using 512MB RAM. However, this tip isn't just restricted to systems with large amounts of memory - systems with 256MB of RAM or less may see a performance boost if swappiness is increased, as this will cache more data to swap space and free up more memory for day-to-day applications.

The precise values vary from system to system so this will require some trial and error, especially as reading data from swap space still takes longer than reading it from memory, but the end results are usually worth the effort.

Speed up ext3

You can gain some significant performance benefits by enabling write-back operation in ext3. This tweak isn't restricted to systems running KDE, but it is disabled by default in almost every distro. This is primarily because older hard drives don't support this feature, though newer hard drives can achieve a minor speed boost. This won't affect your day-to-day disk operations, so it is not recommended you try this tweak on a typical home system, but you will see an improvement for the high intensity disk operations that are typically the preserve of servers.

After making a back up of the file, open /etc/fstab in a text editor with root permissions and look for a line with the following section of text:

relatime,errors=remount-ro

and replace it with this:

noatime,nodiratime,errors=remount-ro,data=writeback

If there is no text either side of this snippet, you have done it wrong! Save and exit this file then open /boot/grub/menu.lstand find the following two lines:

# defoptions quiet splash #altoptions=(recoverymode) single

They won't be next to each other, but once you find them append the following at the end of both those lines:

rootflags=data=writeback

then save and exit. Open up a root terminal and run update grub. You then have the option of simply restarting to apply these changes to your file system, or you can apply them on the fly by installing tune2fs from your package manager. If you choose the latter option you would then type the following into a root terminal:

tune2fs -o journal_data_writeback /dev/hda1

substituting /dev/hda1 with your root partition. Be warned: write-back mode puts you at a little risk of losing data if you machine suddenly powers off, ie if you kick the power cord out, if there's a major system crash or if you get a general power outage


Optimise Gnome

Along with KDE, Gnome is one of the two most widely used desktop environments in the Linux ecosystem, but it's quickly being overtaken by Xfce and other more lightweight alternatives when it comes to performance and speed. However, with just a few of our tweaks, Gnome can keep up with the rest of the pack...

Install preload

Preload is a daemon that analyses what you do on a day-to-day basis and fetches the binaries and files you're most likely to need to boost startup times and general performance. In Ubuntu you just need to search for 'preload' in the package manager, but on other distros it's worth checking that the service is running. To activate the service, type:

service preload on

After enabling automatic login and installing preload we initiated two restarts on our test machine to give the daemon a chance to monitor the startups. After comparing the two times, we found that preload had trimmed a second off the time it took to get a usable desktop. This doesn't sound a lot, but if it's used in conjunction with your new fast boot time then it's well worth the effort.

Enable automatic login

Yes, we know we're always telling you how important security is, but if you live on your own in a castle that doesn't have internet access then you're probably safe to enable automatic logins. The time saved is the time it would otherwise take you to type your password.

The GUI method is by far the easiest. Simply head to System > Administration > Login Window. After authenticating yourself, head to the Security tab and check the box next to Automatic Login. You can then choose from the list of users in the drop-down menu who gets logged in automatically.

Unfortunately for users of Fedora, this option isn't available, so you need to make the necessary changes manually. To enable automatic login you need to open /etc/gdm/custom.conf in a text editor with root permissions and then append the following to the bottom of the file:

[daemon] TimedLoginEnable=True TimedLogin=UserName TimedLoginDelay=0

replacing UserName with the user you would like to log in.

Use wire frames

A common problem with low-powered systems is the lag generated when you click and drag a window. Gnome renders the window as it moves, which can slow performance down, but it has a built-in method to reduce the demand on system resources this causes, which you can activate by typing the following into a terminal:

gconftool-2 --type bool --set /apps/metacity/general/ reduced_resources true

Now when you click and drag windows you will see wire frames instead of the window contents, which drastically improves performance on under-powered systems (but has little or no effect on others). Note that this trick won't work if you are using Compiz or an alternative window decorator.


Gnome's wireframe mode eliminates the overhead of showing window contents whilst resizing or moving them.

Make menus faster

If your menus are starting to feel sluggish, the most likely cause is the icon delay. Every time you open the Gnome menu for the first time the icons have to be loaded from their source files. On slower systems this can look a little messy, so there is a timeout deliberately set to ensure the icons are loaded in time for you to see them. However, with modern hardware this is not generally necessary, so the option can safely be adjusted. Create a new file in your home directory named .gtkrc-2.0then open this file in your favourite text editor to type:

gtk-menu-popup-delay=0

After saving the file, press Ctrl+Alt+Backspace to reinitialise xserver and your menus should open considerably faster.


Optimise KDE

KDE has received a mixed press lately. Though there's no doubting that its good looks and the new plasmoids set it apart from the competition, KDE 4 still can't match KDE 3 (or even Gnome) for speed and performance. Though this area is in heavy development, a few tweaks can trim valuable seconds off your startup time and make the desktop as a whole much more responsive.

Disable IPv6

Until IPv6 is more implemented, Konqueror has to translate between IPv4 and IPv6 - so if you can get a speed boost by turning off IPv6. The methods are slightly different between distros. For instance, in Kubuntu you need to edit/etc/environment as root and add the following line to the file:

KDE_NO_IPV6=True

In openSUSE, edit /etc/sysconfig/windowmanager with root permissions and find this line:

KDE_USE_IPV6="yes"

then change the answer to no. In both cases you will need to save the file and exit before restarting the session for the changes to take effect.

Enable automatic login

Gnome isn't the only desktop that can benefit from you setting up an automatic login: KDE 4 users can do much the same thing by heading to System Settings and clicking on the Advanced tab. Here you can run the login manager and enable automatic login from the Convenience tab. You'll also need to choose the user you want to log in automatically from the drop-down menu below the checkbox. When you reboot you should miss the login screen altogether and launch straight into the KDE 4 splash screen.

Start with an empty session

By default KDE 4 saves volumes of data about your current session, such as which windows are open and which processes were running so that next time you log in your session is exactly as you left it. This is very convenient, but it also slows your boot time down as this data has to be reloaded on each boot. We can avoid this problem by ensuring that we start with a fresh session. Select System Settings (or Configure Desktop in OpenSUSE) from the KDE menu and in the Advanced tab start the session manager. Towards the bottom of the form select the radio button next to Start With An Empty Session then click Apply.

Start Konqueror faster

We can make Konqueror run much faster by enabling preloading. This uses some memory, but means that the next time you fire up Konqueror it will open in around half the time and in the same place you left it. If you used the previous tweak to start KDE with an empty session then there's no need to panic, as we will configure preloading to run automatically when KDE starts.

To enable Konqueror preloading, open up the browser and head to Settings > Configure Konqueror. In the Performance section check the box next to Preload An Instance After KDE Startup. You can also set how many instances of Konqueror are preloaded at startup depending on how many Konqueror windows you tend to run at any one given time.


Boost your network

You've tweaked your router, optimised your server and replaced all your broadband filters in your house - and you still have a slow connection. Before you make an angry phone call to your ISP, there's a possibility that the client machine may be the bottleneck. With just a few of these tweaks you can improve your connections, or at the very least eliminate your client machine as the single point of failure.

Use hostname 'localhost'

This doesn't cause a drastic improvement on its own, but in conjunction with the other network tricks here can improve your local machine's network performance. Simply open /etc/hosts in a text editor with root permissions and change the top two lines to:

127.0.0.1 localhost yourhost 127.0.1.1 yourhost

where yourhost is the name of the machine (ie bobdesktop). Ensure you keep a backup of your /etc/hosts file, as not all distros are compatible with this!

Optimise TCP settings

Distros come preconfigured for "average" internet users, but in a world of 3G, dial-up and ADSL there is no such thing as an average user. Now edit /etc/sysctl.conf as root and append the following:

net.ipv4.tcp_timestamps = 0 net.ipv4.tcp_sack = 1

(This may take some trial and error, so keep a backup of the files you edit.) The top line removes timestamps and so relieves all incoming and outgoing packets of a 12k overhead. The bottom line enables selective acknowledgements, which means fewer checks are initiated on each packet so they are delivered quicker. We don't recommend the latter tweak for dial-up connections as this increases the number of packets which need to be resent.

Metrics and backlogs

You can further optimise your TCP settings by appending the following lines to the same text file:

net.ipv4.tcp_no_metrics_save = 1 net.core.netdev_max_backlog = 2500

The top line speeds up connections by ensuring that TCP metrics are not saved for each individual packet. The second line dictates the backlog of packets allowed. To give an idea of the scale of the figure you should use for your backlog, around 2,000 is recommended for wireless or older Ethernet connections, and around 5,000 for a 1GB Ethernet cable to broadband connection. On the other hand, this figure can rise up to 30,000 for an expensive 10GB Ethernet cable. The slower the connection, the lower your backlog should be, as the aim of this tweak is to clear outstanding packets as soon as possible in order to boost connection speeds.

TCP window scaling

The TCP window settings define the minimum and maximum size of packets we can send and recieve. Dial-up users will see a speed boost with smaller packet sizes while broadband users will see a speed boost with larger packet sizes. Edit/etc/sysctl.conf as root, and append this:

net.ipv4.tcp_window_scaling = 1 net.ipv4.tcp_wmem = 10240 87380 16777216 net.ipv4.tcp_rmem = 10240 87380 16777216 net.ipv4.tcp_mem = 16777216 16777216 16777216 net.core.rmem_max = 16777216 net.core wmem_max = 16777216

Those figures are optimised for a 2Mbps connection on Sky broadband over a wireless connection, but the packet size recommendation for any given connection is usually maximum bandwidth divided by latency. You can find these figures by heading to www.speedtest.net, and you can also analyse how your changes are affecting your connection viawww.speedguide.net:8080.

www.speedguide.net can give you an indication of which values and tweaks will improve your network connection.

www.speedguide.net can give you an indication of which values and tweaks will improve your network connection.


Faster Firefox

Continuing with the networking theme, you can optimise much more than just your TCP settings. Mozilla Firefox has a raft of options cunningly hidden from users that can untap the browser's potential...

Disable IPv6 (again!)

With this tweak we will simply amend an existing value. Type the following into the search bar: network.dns.disableIPv6

You shouldn't have to type out the whole thing, as the listings change dynamically as you're typing. Simply double-click on the entry to change the default value of "False" to "True".

Render pages faster

Create a new integer value in about:config named content.notify.backoffcount and set the value to 5 so that Firefox won't wait for the entire page to download before rendering. You can also create a value with the namenglayout.initialpaint.delay and set the value to zero. This ensures that Firefox doesn't wait for the page layout information to be fully downloaded before rendering.

Optimise your history

If you reduce the amount of web history that Firefox stores, it will load faster and also save you some disk space. Type the following in the search bar: browser.history and change browser.history_expires_days andbrowser.history_expires_min to zero. You can also use low numbers if you want to keep some browser history.

More TCP tweaks

Change the network.http.pipelining and network.http.proxy.pipelining values to "True" and then setnetwork.http.pipelining.maxrequests to 8 instead of 4. These tweaks boost performance for broadband users as we use a TCP technique known as pipelining, which allows Firefox to make multiple requests on a single connection.


Any mistakes here could break Firefox, so once you've made a backup and a vow of honour you can unleash the power hidden in your browser.

Speed up menus

Start by typing about:config and accepting the warning that comes up (you will need to do this for all these Firefox tips). The listing you see is much like the Firefox equivalent of the Windows registry, which means that though this is a very powerful way to tweak your browser you can cause serious stability problems if you get it wrong.

We can make our Firefox menus load faster by adding our own value to the listing. Right-click anywhere in the listing and then click New > Integer. Use ui.submenuDelay as the name and then set the value to zero. When you restart Firefox you should notice that your menus load noticeably faster, as you have removed the delay for the menu popups.


Speed up your software

Almost all mature applications have options hidden away in the GUI that can boost their performance on your system, so if we've given you the tweaking bug there's plenty of scope for further experimentation. Whether you're shaving a few seconds of boot time off OpenOffice.org or improving the backbone of your system, the applications that make up your Linux system are what it's all about.

The fastest mirror

Open a root terminal and type: yum install yum-fastestmirror. This well-known Yum plugin ensures that you always download packages from the fastest mirror, which could save minutes on large distro downloads.

Avoid rechecking

Every time you update or install a package Yum has a tendancy to re-download all the metadata packages from each server, which isn't ideal for users with slow connections. You can resolve this by downloading the entire cache in one go and allowing Yum to then refer to this rather than the online sources. Fire up a root terminal and type:

yum checkcache

We recommend you run this command at least once a week to keep the list up to date.

Faster OpenOffice.org

We often harp on about how slow OpenOffice.org is, but it doesn't have to be like that. With just one tweak you can remedy the problem, and with further alterations the latest OpenOffice.org can run on much older hardware. So, before you ditch this office suite forever and use AbiWord and Gnumeric instead, try monkeying with the settings under Tools > Options > Memory to reduce the amount of RAM that OOo chews up.

One easy tweak here that we recommend is to reduce the number of undo steps from the default value of 100 to somewhere between 20 and 30. That way you use less memory than before but still gain the benefits of having an undo function. Another thing you can do is to enable the Systray quick starter (in the bottom of the window). This enables you to keep an instance of OOo in the cache, so you can restart more quickly.


Make OOo more efficient in Tools > Options > Memory.

Increase graphics cache

On systems with under 512MB RAM, use a graphics cache of between 32MB and 64MB, but for systems with 512MB or over we recommend a cache size of at least 128MB, as the additional memory will help large apps such as OOo run that little bit faster.

Remove items from memory

Also in the OpenOffice.org Memory dialog we can define how long OOo leaves things before refreshing its cache. On a system with 256MB RAM or less we recommend setting the refresh to 0:30 (every 30 minutes) as more frequent reloads will cause OOo to lock up or become sluggish. For users of higher-end systems, the 10-minute default is usually fine.

Clean out Yum

For peace of mind and more disk space it makes sense to ensure that Yum's cache doesn't contain any redundant packages. To do so, open a root terminal and type: yum clean all. Ensure you run this before you do any other optimisations for Yum, as this operation will reset them.

Try Opera

It may only be free as in beer and not as in speech, but Opera is a lightweight and very capable alternative to Firefox that's fast enough already even without any optimisation tweaks. It integrates additional tools to handle mail, file sharing and even IRC chats. The Opera community has developed thousands of skins and plugins, and with recent releases personal web space and even a personal web server have been included free of charge.


Opera - not free as in freedom, but still a great, memory-friendly web browser.

Install apt-fast

The apt-fast script can provide a huge speed boost to package management, as we use Axel as a drop-in replacement download manager for Aptitude rather than the traditional wget. You will need to install Axel through Aptitude and then open a text-editor with root permissions and paste the shell code from here directly into the file. Then we recommend you save it as /usr/local/bin/apt-fast (no extension) and close the text editor before opening a root terminal and typing:

chmod +x /usr/local/bin/apt-fast

To use the script, try this as root: apt-fast install packagename or simply use apt-fast update and apt-fast upgrade to update all your packages. The script may be slow in some cases, as the tweaks you made to Aptitude will not apply to the script, and Axel does not use Aptitude's cache.

Get a better download mirror

Head to System > Administration > Software Sources in Gnome and select Other from the drop-down menu next to Server Location. Then click Select Best Server and wait for the checks to finish. When this is finished, close the window and let your distro update its sources.

A common problem with this method is that the update window can freeze and go grey. (This is a known issue with older versions of Ubuntu.) This can be resolved by closing the window (using the Force Quit Gnome applet if necessary by right-clicking the panel and selecting Add to Panel) and then running Add/Remove Software to update the sources.

Halt Java

The JRE in OpenOffice.org is the main culprit for the slow startups. You don't need the JRE to run in a day to day environment, so you can safely disable it, and in the event you do need the JRE you can quickly re-enable it. Simply head to Tools > Options and select Java in the left-hand box. To disable the JRE simply uncheck the box next to Use A Java Runtime Environment.

Remove old packages

Run this to remove orphaned dependancies with APT:

apt-get autoremove

and to remove all package files from the cache:

apt-get clean

Use autoclean rather than clean to remove old versions of packages. Make sure you're root!

Reduce history

By reducing the amount of history that Opera keeps we can reduce the time it takes to initialise it and also curtail Opera reloading its history every five hours. This is achieved by heading to Tools > Preferences and clicking on the Advancedtab. Select History from the left-hand side and then click Clear in the Addresses section. Then set the value as anything from 0 to 1,000, which will be considerably less than the default. You can also uncheck Remember Content On Visited Pages to save further disk space.

Hey Presto

Sometimes updates vary very little from their previous download, especially if it's just a bug fix. If you want to download only the changes, run this as root to install the Presto plugin for Yum:

yum install yum-presto

Disable name completion

Users with low-end systems may find that pictures and the auto-completing navigation bar in Opera can be a little sluggish at times. We can remedy the first issue by disabling Turbo, which pre-draws images before they are loaded. Look inabout:config for the Turbo Mode option in User Prefs, then uncheck it. To disable name completion, choose Tools > Preferences > Advanced > Network > Server name completion, then uncheck Look For Local Network Machine

source: tuxradar.com/content/make-linux-faster-and-lighter

No comments:

Post a Comment