Friday, May 04, 2007
Tweaking Linux for speed
- Use hashed b-trees to speed up lookups in large directories when creating filesystems:
sudo mke2fs -j -O dir_index /dev/hda1 - Optimize directories.
e2fsck -fD /dev/hda1
man e2fsck:
-D Optimize directories in filesystem. This option causes e2fsck
to try to optimize all directories, either by reindexing them if
the filesystem supports directory indexing, or by sorting and
compressing directories for smaller directories, or for filesys‐
tems using traditional linear directories. - Use data=writeback and noatime when mounting ext3 partitions (/etc/fstab):
/dev/hda1 / ext3 defaults,data=writeback,noatime 0 1
sudo tune2fs -o journal_data_writeback /dev/hda1
From man mount:
writeback
Data ordering is not preserved - data may be written into
the main file system after its metadata has been commit‐
ted to the journal. This is rumoured to be the highest-
throughput option. It guarantees internal file system
integrity, however it can allow old data to appear in
files after a crash and journal recovery.
noatime
Do not update inode access times on this file system
(e.g, for faster access on the news spool to speed up
news servers). - Choose an I/O scheduler wisely. Although CFQ should be the default, it does no harm to force it by passing elevator=cfq to kernel command line (by editing /boot/grub/menu.lst and running update-grub).
Check your current scheduler:
cat /sys/block/hda/queue/scheduler # or
dmesg | grep scheduler
From http://www.redhat.com/magazine/008jun05/features/schedulers/ :The Completely Fair Queuing (CFQ) scheduler is the default algorthim in Red Hat Enterprise Linux 4. As the name implies, CFQ maintains a scalable per-process I/O queue and attempts to distribute the available I/O bandwidth equally among all I/O requests. CFQ is well suited for mid-to-large multi-processor systems and for systems which require balanced I/O performance over multiple LUNs and I/O controllers.
The Deadline elevator uses a deadline algorithm to minimize I/O latency for a given I/O request. The scheduler provides near real-time behavior and uses a round robin policy to attempt to be fair among multiple I/O requests and to avoid process starvation. Using five I/O queues, this scheduler will aggressively re-order requests to improve I/O performance.
The NOOP scheduler is a simple FIFO queue and uses the minimal amount of CPU/instructions per I/O to accomplish the basic merging and sorting functionality to complete the I/O. It assumes performance of the I/O has been or will be optimized at the block device (memory-disk) or with an intelligent HBA or externally attached controller.
The Anticipatory elevator introduces a controlled delay before dispatching the I/O to attempt to aggregate and/or re-order requests improving locality and reducing disk seek operations. This algorithm is intended to optimize systems with small or slow disk subsystems. One artifact of using the AS scheduler can be higher I/O latency.
Check that DMA is enabled.
dmesg | grep -i dma- Consider using readahead, prelink and preload. Prelink is generally a must. Readahead may cut boot times.
- Readahead allows the user to specify a set of files to be read into the page cache to accelerate first time loading of programs, typically during the boot sequence.
- The prelink package contains a utility which modifies ELF shared libraries and executables, so that far fewer relocations need to be resolved at runtime and thus programs come up faster.
- preload monitors applications that users run, and by analyzing this data, predicts what applications users might run, and fetches those binaries and their dependencies into memory for faster startup times.
sudo sed -i 's/PRELINK=.*/PRELINK=yes/' /etc/default/prelink
pass 'profile' option to kernel with grub on next boot, so that readahead can be reprofiled - Enable concurrent boot.
sudo sed -i 's/CONCURRENCY=.*/CONCURRENCY=shell/' /etc/init.d/rc - Place the swap partition wisely. Sectors are generally numbered starting from the outside of the disk, so either try to place swap close to sector 0 (on the outside of the drive, where read/write speed may or may not be higher) or in the middle. Let me quote:
Modern disks have more sectors in outer than in inner tracks but nevertheless placing swap partitions at the outer rim of the disk is questionable. The usage pattern of swap partitions involves short transfers between head movements. Therefore increasing throughput is less important then reducing seek time. It is better to place swap partitions at around the middle of the disk (but notice that the disk lies to fdisk about its true geometry and does not tell about outer tracks being bigger than inner ones so what looks to be the middle of the disk in fdisk is not the physical middle). - Control swapping according to your memory resources.
Quoting:- If you have a lot of memory and succeed in not using swap at all then set vm.swappiness to 0
- If your computer has little memory and needs to swap much set vm.swappiness to 100
- A good default in between is vm.swappiness=60
sudo sysctl vm.swappiness=0
sudo swapoff -a
sudo swapon -a
sudo su
echo 'vm.swappiness=0' >> /etc/sysctl.conf - Turn off IPv6:
sudo su
echo 'alias net-pf-10 off' >> /etc/modprobe.d/blacklist_ipv6
check after reboot:
lsmod | grep ipv6
Also turn off ipv6 in Firefox/Iceweasel:
about:config - Turn off filesystem checking for foreign filesystems and for filesystems that don't need to be checked (this will considerably speed up boot):
edit /etc/fstab and set last number to 0 for filesystems that don't need checking, e.g.
UUID=x /media/sda7 ntfs defaults,nls=utf8,umask=007,gid=46 0 0