News | About | Get Frugalware | Packages | Documentation | Discussion Forums | Bug Tracker | Wiki | Community | Development

Maximizing Performance

From FrugalWiki

Jump to: navigation, search



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

Contents

The basics

Know your system

The best way to tune a system is to target the bottlenecks, that is the subsystems that limit the overall speed. They usually can be identified by knowing the specifications of the system, but there are some basic indications:

  • If the computer becomes slow when big applications, like openoffice and firefox, are running at the same time, then there is a good chance the amount of RAM is insufficient. To verify available RAM, use this command, and check for the line beginning with -/+buffers:
User terminal 48px.png
$ free -m
  • If boot time is really slow, and if applications take a lot of time to load the first time they are launched, but run fine afterwards, then the hard drive is probably too slow. The speed of a hard drive can be measured using the hdparm command:
User terminal 48px.png
$ hdparm -t /dev/harddrive

This is only the pure read speed of the hard drive, and is not a valid benchmark, but a value superior to 40MB/s can be considered decent on an average system.

  • If the CPU load is consistently high even when RAM is available, then lowering CPU usage should be a priority. CPU load can be monitored in many ways, like using the top command:
User terminal 48px.png
$ top
  • If the only applications lagging are the ones using direct rendering, meaning they use the graphic card, like video players and games, then improving the graphic performance should help. First step would be to verify if direct rendering simply isn't enabled. This is indicated by the glxinfo command:
User terminal 48px.png
$ glxinfo

The first thing to do

The simplest and most efficient way of improving overall performance is to run lightweight environments and applications.

Compromise

Almost all tuning brings drawbacks. Lighter applications usually come with less features and some tweaks may make a 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 measured by benchmarking tools

Storage devices

Choosing and tuning your filesystem

Choosing the best filesystem for a specific system is very important because each has its own strengths.

Summary

  • XFS: Excellent performance with large files. Low speed with small files. A good choice for /home.
  • Reiserfs: Excellent performance with small files. A good choice for /var.
  • Ext3: Average performance, reliable.
  • Ext4: Great overall performance, reliable, has performance issues with sqlite and some other databases.
  • Btrfs: Great overall performance (better than ext4), reliable (once it becomes stable). Lots of features. Still in heavy development and considered as unstable. Do not use this filesystem yet unless you know what you are doing and are prepared for potential data loss.

Mount options

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

User terminal 48px.png
$ 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. The former is a superset of the latter (which applies to directories only -- noatime applies to both files and directories). In rare cases, for example if you use mutt, it can cause minor problems. You can instead use the relatime option (NB relatime is the default in >2.6.30)

Ext3

See Ext3 Filesystem Tips.

Ext4

See the Ext4 wiki page.

XFS

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

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

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

#/etc/fstab
LABEL=XFSHOME /home xfs noatime,logbufs=8 0 1

Reiserfs

The data=writeback mount option improves speed, but may corrupt data during power loss. The notail mount option increases the space used by the filesystem by about 5%, but also improves overall speed. You can also reduce disk load by putting the journal and data on separate drives. This is be done when creating the filesystem:

User terminal 48px.png
$ mkreiserfs –j /dev/hda1 /dev/hdb1

Replace /dev/hda1 with the partition reserved for the journal, and /dev/hdb1 with the partition for data. You can learn more about reiserfs with this article.

BTRFS

Btrfs is a new filesystem offering online defragmentation, optimized mode for SSDs, writable snapshots, changing size of partition without data loss and many other features. Btrfs is still in active development, and is available in the kernel (marked experimental). See more info on the Btrfs homepage.

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(128k) block size, as instructed in this Gentoo forums thread. 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. Squashfs is already in the kernel. Since the linked guide is for Gentoo the next commands outline the steps especially for Frugalware. Basically we have got install two packages to get it working:

Root terminal 48px.png
# pacman-g2 -S squashfs

This command installs the aufs-modules and some userspace-tools for the squash-filesystem. Now we need some extra directories where we can store the archive of /usr as read-only and another folder where we can store the data changed after the last compression as writeable:

Root terminal 48px.png
# mkdir -p /squashed/usr/{ro,rw

} Now that we got a rough setup you should perform a complete system-upgrade since every change of content in /usr after the compression will be excluded from this speedup. If you use prelink you should also perform a complete prelink before creating the archive. Now it is time to invoke the command to compress /usr:

Root terminal 48px.png
# mksquashfs /usr /squashed/usr/usr.sfs -b 65536

These parameters/options are the ones suggested by the Gentoo link but there might be some room for improvement using some of the options described here. Now to get the archive mounted together with the writeable folder it is necessary to edit fstab:

Root terminal 48px.png
# nano /etc/fstab

Add the following lines:

/squashed/usr/usr.sfs   /squashed/usr/ro   squashfs   loop,ro   0 0 
usr    /usr    aufs    udba=reval,br:/squashed/usr/rw:/squashed/usr/ro  0 0

Now you should be done and able to reboot. The original Author suggests to delete all the old content of /usr, but this might cause some problems if anything goes wrong during some later re-compression. It is more safe to leave the old files in place just to be on the safe side.

Tuning for an SSD

SSD#Tips_for_Maximizing_SSD_Performance

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 motherboards are notorious for disabling the capacity to overclock.

A way to modify performance (ref) 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).

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.


Ulatencyd

Ulatency is a daemon that controls how the Linux kernel will spend it's resources on the running processes. It uses dynamic cgroups to give the kernel hints and limitations on processes.


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=20
vm.vfs_cache_pressure=50

To test and more on why this may work, take a look at this article.

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 is therefore a good choice if using an SSD or if you have RAM to spare. Simply add this line to /etc/fstab and reboot:

tmpfs /tmp tmpfs defaults,noatime,nodev,nosuid,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 in the article Improve Boot Performance.

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. Also, 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.


Application-specific tips

Gcc/Makepkg

See Ccache.


SSH

See Speed up SSH.

Personal tools
Namespaces
Variants
Actions