Maximizing performance

From ArchWiki

Jump to: navigation, search
Image:Tango-view-fullscreen.png This article needs expansion.
Please help expand this article so the intended scope is covered in sufficient detail. (Discuss)

This article is a retrospective analysis and basic rundown about gaining performance in Arch Linux.

Contents

The basics

Know your system

The best way to tune a system is to target the bottlenecks. Is your hard drive the main problem, or the RAM, the network card, the CPU? Use your judgment and jump to the relevant sections of this page.

The first thing to do

The simplest and most efficient way of tuning a system is to run less and lighter applications. This can be achieved by:

  • Changing the desktop environment to a lighter one. Good choices are LXDE, Xfce, or a standalone window manager like Openbox.
  • Using lightweight applications. A good place to start to find them is Lightweight Software and the Light and Fast Applications Awards threads in the forum: 2007, 2008 and 2009
  • Removing unnecessary daemons in rc.conf

Compromise

Almost all tuning has a drawback. Lighter applications usually come with less features and some tweaks may make your system unstable, or simply require time to implement and maintain. This page tries to highlight those drawbacks, but the final judgment rests on the user.

Benchmarking

The effects of optimization are often difficult to judge. They can however be mesured by benchmarking tools

Storage devices

The hard drive speed is very often the main reason applications load slowly and the boot time is long. A hard drive usually costs little and can make a world of difference. Consider buying a Solid State Disk (SSD). Although they are far more expensive than conventional hard drives at equal capacity, they are much faster, consume less energy and are less prone to data loss. Their only drawback, except the price, is that they have less read/write cycles, and that means they will wear off faster, but this should not be a concern for a desktop computer. A low capacity SSD is a prime choice for a laptop computer. A cheaper alternative is to use SD or Compact Flash cards and a SD/CF to IDE/SATA converter. Those cards are slower than real SSDs, but this is still a very cheap and efficient solution for laptops.

Tuning for an SSD

This tutorial has some very simple tricks to fully harness the power of an SSD and to reduce disk read/write cycles to prolong its life. See also compcache.

Choosing and tuning your file-system

Choosing the best file-system for a specific system is very important because each has its own strenghts. You can find articles about each of them here. Those listed here are suitable for a desktop system:

Mount options

Mount options offer an easy way to improve speed without reformatting. They can be set using the mount command:

mount -o option1,option2 /dev/partition /mnt/partition

To set them permanently, you can modify /etc/fstab to make the relevant line look like this:

/dev/partition /mnt/partition partitiontype option1,option2 0 0

A couple of mount options improving performance on almost all file-systems is noatime,nodiratime. In rare cases, for example if you use mutt, it can cause minor problems. You can instead use the relatime option.

Ext3

The default file-system in Linux, ext3 is known for its stability, and has been tested and improved since a decade. However, it is not very fast, and if speed is your priority, you should consider another one. You can also check Ext3 Filesystem Tips. A factor to consider is that a driver for Windows exists, and you can therefore access your partition from any Windows installation.

Ext4

The Ext4 file-system is relatively new, and is basically an overall improvement over ext3, and that includes speed. It is also the new default for archlinux. Probably the best choice if stability is very important to you.

XFS

XFS offers excellent performance on large files and file-systems. In contrast, its average speed when dealing with large numbers of small files is poor. Therefore, if you choose Xfs, you should definitely consider using pacman-cage. Xfs offers on-line defragmentation ability and mounts quickly.

For optimal speed, create an XFS file-system with:

mkfs.xfs -l internal,size=128m -d agcount=2 /dev/thetargetpartition

An XFS specific mount option that may increase performance is logbufs=8.

BTRFS

Btrfs is a new very promising filesystem in linux world. It shall offer online defragmentation, optimised mode for SSDs, writable snapshots, changing size of partition without dataloss and more features. Btrfs is still in active development, and is avaliable in the kernel (marked experimental). See more info on the Btrfs homepage.

Pacman-cage

pacman-cage is a script that puts the pacman database, /var/lib/pacman, in a single loop file containing its own file-system. This very simple and permanent tweak improves by as much as a factor of ten all tasks relying on that database, like searching and updating. As the script makes a backup (at installation only) in case something goes wrong, there is no reason why anyone should not use it.

pacman-cage is now part of pactools on AUR and has been renamed pt-pacman-cage (with his brother pt-pacman-uncage)

Compressing /usr

A way to speed up reading from the hard drive is to compress the data, because there is less data to be read. It must however be decompressed, which means a greater CPU load. Some filesystems support transparent compression, most notably btrfs and reiserfs4, but their compression ratio is limited by the 4k block size. A good alternative is to compress /usr in a squashfs file, with a 64k block size, as instructed in this Gentoo forums thread. Squashfs is already in the kernel, and aufs2 is in the extra repository, so no kernel compilation is needed if using the stock kernel. What this tutorial does is basically to compress the /usr folder into a compressed squashfs file-system, then mounts it with aufs. A lot of space is saved, usually two thirds of the original size of /usr, and applications load faster. However, each time an application is installed or reinstalled, it is written uncompressed, so /usr must be re-compressed periodically.

CPU

The only way to directly improve CPU speed is overclocking. As it is a complicated and risky task, it is not recommended for anyone except experts. The best way to overclock is through the BIOS. When purchasing your system, keep in mind that most Intel chip-sets are notorious for disabling the capacity to overclock.

Another way to improve CPU performance is to use Con Kolivas' desktop-centric kernel patchset, which, among other things, replaces the Completely Fair Scheduler(CFS) with the Brain Fuck Scheduler(BFS). To install from the AUR using yaourt:

$ yaourt -S kernel26-ck
Warning: Currently (20 Dec 2009) you must comment out line 5 and uncomment line 6 of the pkgbuild for the install to work correctly.

Or for just BFS:

$ yaourt -S kernel26-bfs
Note: BFS/CK are designed for desktop/laptop use and not servers. They provide low latency and work well for 16 CPUs or less. Also, Con Kolivas suggests setting HZ to 1000. For more information, see the BFS FAQ and ck patches.

Network

Speeding up DNS

By tuning DNS querying, you can noticeably speed up web browsing. This tutorial explains a very easy and permanent way of doing it.

Graphics

Xorg.conf configuration

Graphic performance heavily depends on the settings in /etc/X11/xorg.conf. There are tutorials for Nvidia, ATI and Intel cards. Some settings may stop Xorg from booting, so caution is advised.

Driconf

Driconf is a small utility that allows you to change the direct rendering settings for open source drivers. Enabling HyperZ can drastically improve performance.

Overclocking

Overclocking a graphic card is much simpler that with a CPU. For ATI users, get rovclock, and Nvidia users should get nvclock in the extra repository. The best settings are the highest values your card will take before artifacts appear. The changes can be made permanent, by running the appropriate command after X boots, for example by adding it to ~/.xinitrc. A safer approach would be to only apply the settings when needed.

RAM and swap

Swappiness

The swappiness represent how much the kernel prefers swap to RAM. Setting it to a very low value, meaning the kernel will almost always use RAM, is known to improve responsiveness on many systems. To do that, simply add those line to /etc/sysctl.conf:

vm.swappiness=1
vm.vfs_cache_pressure=10

Compcache

Compcache is a kernel module that allow you put your swap into your RAM and compress it. That means that part of your RAM can hold much more information, at the cost of a little more CPU usage, and is still much quicker than a hard drive swap. If your system falls back to swap every now and then, this can help make your system more responsive. Simply install compcache from AUR after each kernel upgrade and add it to the DAEMONS array. Your can also tell compcache to fall back on the hard drive swap when full. This is also a good way to reduce disk read/write cycles on SSDs.

Mounting /tmp to RAM

This will make your system a tiny bit faster, but will take up some of your RAM. It also reduces disk read/write cycles, and so is a good choice if you use a SSD or if you have some RAM to spare. Simply add this line to /etc/fstab and reboot:

tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0

Using the graphic card's RAM

In the unlikely case that you have very little RAM and a surplus of video RAM, you can use the latter as swap. See: Swap on video ram.

Boot time

You can find tutorials with good tips here and here.

Suspend to ram

The best way to reduce boot time is not booting at all. Consider suspending your system to ram instead.

Kernel boot options

Some boot options can decrease kernel boot time. The fastboot option usually can take off one second or so. If you see a message saying "Waiting 8s for device XXX" at boot, adding rootdelay=1 can reduce the waiting time, but be careful, as it may break the booting process. Those options are set in /boot/grub/menu.lst or /etc/lilo.conf, depending on which bootloader you use.

Custom kernel

Compiling a custom kernel will reduce boot time and memory usage, but can be long, complicated and even painful. It usually is not worth the effort, but can be very interesting and a great learning experience. If you really know what you are doing, start here.

Application-specific tips

Pacman

You can find tips on improving pacman here.

Mkinitcpio

User josh_ from the forum as made impressive changes to the mkinitcpio script, making it two or three times faster. While waiting for these changes to be implemented, you can get them here.

Firefox

Many other relevant tips can be found here.

Disabling pango

Rendering is much slower when using pango. To disable it, add this line to ~/.bashrc or /etc/profile:

export MOZ_DISABLE_PANGO=1

Cleaning sqlite database

This command will reduce the size of Firefox's sqlite files, which will improve its loading time and responsivenes. Only run it when firefox is closed. Backing up ~/.mozilla is recommended, as the command can break the database.

find $HOME/.mozilla/ \( -name "*.sqlite" \) -exec sqlite3 {} "vacuum" \;
Personal tools