How to fly with gentoo

HOW TO OPTIMIZE AND ACCELERATE YOUR SYSTEM
讓你的 Gentoo 加速~ 要如何最佳化自己的系統呢?..
從以下幾點來做. 深入的就看看 這篇文章 吧~
0. How to make tests without being in danger
1. Optimization of the init scripts
2. Using rc-update
3. Cflags and ldflags
4. Using hdparm
5. Should you.. prelink?
6. Managing the Swap
7. Ccache
8. Distcc
9. USE's
10. Modifying ebuilds and injecting packages
11. Halt vs Suspend
12. Xdelta - Deltup
13. NPTL
14. GCC
15. Filesystems [data safety vs speed]
16. i/o and tasks schedulers
17. Useful Scripts


以下轉載自: HOW TO OPTIMIZE AND ACCELERATE YOUR SYSTEM
also known as how to fly with gentoo
This is guide is a sum of a lot of posts here in the forum and some investigations i have done in my boxes by trying out several programs and options. Some of them are completely safe, but some other could damage your system. Please make backups of your important data, try this guide in testing boxes, and then move the optimizations to the production boxes.
This improvements will obviously have a greater effect on a old computer, if you have a very good computer this will have a minor impact, as your system should already be pretty fast Wink
INDEX
0. How to make tests without being in danger
1. Optimization of the init scripts
2. Using rc-update
3. Cflags and ldflags
4. Using hdparm
5. Should you.. prelink?
6. Managing the Swap
7. Ccache
8. Distcc
9. USE's
10. Modifying ebuilds and injecting packages
11. Halt vs Suspend
12. Xdelta - Deltup
13. NPTL
14. GCC
15. Filesystems [data safety vs speed]
16. i/o and tasks schedulers
17. Useful Scripts
0. How to make tests without being in danger
To test new ebuilds and try new configurations I did an instalation inside a chroot to be completely safe. There's is a guide HERE to make a similar thing, and be able to test this howto without damaging your system. You could also use vmware or uml, but this seems a fastest way.
Once I did the chroot install, I made a compressed image, so that everytime I broke the sub-system with my tests i can extract it and go on testing with a new installed system (and my system keeps clean).
1. Optimization of the init scripts
Some of the operations performed when you boot the system are not always needed. Let's modify the scripts so that we only do them if they are really needed.
/etc/init.d/modules
change:
Code:
ebegin "Calculating module dependencies"
/sbin/modules-update &>/dev/null
eend $? "Failed to calculate dependencies"
for:
Code:
if [ /etc/modules.d -nt /etc/modules.conf ]
then
ebegin "Calculating module dependencies"
/sbin/modules-update &>/dev/null
eend $? "Failed to calculate dependencies"
else
einfo "Module dependencies are up-to-date"
fi
Doing this, modules-update will only run if it愀 really needed because you made changes in the system.
/etc/init.d/localmount
change:
Code:
mount -at nocoda,nonfs,noproc,noncpfs,nosmbfs,noshm >/dev/null
for:
Code:
mount -aFt nocoda,nonfs,noproc,noncpfs,nosmbfs,noshm >/dev/null
The will start all the local mounts at the same moment, not one after the other.
/etc/init.d/bootmisc
change:
Code:
if [ -x /sbin/env-update.sh ]
then
ebegin "Updating environment"
/sbin/env-update.sh >/dev/null
eend 0
fi
for:
Code:
if [ -x /sbin/env-update.sh ]
then
if [ /etc/env.d -nt /etc/profile.env ]
then
ebegin "Updating environment"
/sbin/env-update.sh >/dev/null
eend 0
else
einfo "Environment up-to-date"
fi
fi
Doing this, env-update will only run if it愀 really needed because you made changes in the system.
/etc/conf.d/rc
change:
Code:
RC_PARALLEL_STARTUP="no"
for:
Code:
RC_PARALLEL_STARTUP="yes"
This will start all the services at the same moment, not one after the other.
note: could some devel explain if this tweaks are dangeorus, and if not why they are not in portage by default?
2. Using rc-update
Managing the runlevels is very easy thanks to rc-update, that makes easy this job:
to see how we have currently configured the boot runlevels:
Code:
# rc-update show
to remove a service from the system start:
Code:
# rc-update del aplicacion runlevel
note: change runlevel for boot or default (you could also create more), if you omit the runlevel it will search in all of them and remove the service.
to add an application:
Code:
# rc-update add application runlevel
I have some service in the boot runlevel and some in the default runlevel, please note that some services need to be started after some other (this means that some services depends on some other.
You can check the depends editing the /etc/init.d/service file and checking the first lines, where the depends are declared. For example, if you want to start sshd, you will need the net services started before.
I have recently created a new runlevel (battery) where i added all i want to have running when i don愒 have AC. Then, with acpid's help I configured the runlevel so that when i unplug the AC, it changes to battery runlevel, and the when i plug it again it gets back to default runlevel. This way, when I switch to the battery level i use speedfreq, hdparm and iwconfig to reduce the power consumption of the hardisk, the wireless card and the processor.
You can check the actual runlevel using rc-status:
Code:
# rc-status
Runlevel: battery
acpid started
alsasound started
domainname started
gpm started
hdparm.battery started
local started
metalog started
speedfreq.battery started
vixie-cron started
wireless.baterry started
more information about the RC- HERE.
For those who boot directly into X (xdm, gdm, kdm,..) i have read that you can put xdm and it's dependencies in boot runlevel, so that it will load X while loading the rest of services in the background. If someone have this running please comment so that the rest can use it.
3. cflags and ldflags
CFLAGS (you can set them at /etc/make.conf) are parameters we pass to gcc when we compile a package when emerging it. You can be more or less risky here, in THIS webpage and THIS one there is a lot of info on recommended configurations for CFLAGS. My CFLAGS for my pentium4 box are the following:
Code:
CHOST="i686-pc-linux-gnu"
CFLAGS="-march=pentium4 -mcpu=pentium4 -O3 -pipe -fforce-addr -falign-functions=4 -fprefetch-loop-arrays -fomit-frame-pointer"
note: cflags changed a little bit in gcc 3.4.X and -mcpu is deprecated, you should use -mtune instead. Moreover, pentium-m is accepted for centrino laptops. The CFLAGS of my centrino laptop are the following:
Code:
CFLAGS="-O3 -march=pentium-m -mtune=pentium-m -pipe -ftracer -fomit-frame-pointer -ffast-math -momit-leaf-frame-pointers"
As for the CXXFLAGS, -fvisibility-inlines-hidden has been reported as a good flag to improve the C++ compiles (thx teutzz).
Frepo has also been reported as a good cxxflag, but it does not perform very well on my system.
The ldflags are also interesting, they are discussed HERE and HERE. Ldflags are optimizations for the dinamyc loader (ld), so it's more or less the same way prelink would go. I am using them already and didn't have any problem when emerging new packages:
Code:
LDFLAGS="-Wl,-O1 -Wl,--enable-new-dtags -Wl,--sort-common -s"
Something more "stable" would be
Code:
LDFLAGS="-Wl,-O1"
note: those in the ldflags are "L", not "1" (in the -W)
note: some users reported errors using ldflags, if you have problems compiling a package try to remove them (and post ldflags/package in this thread).
NOTE: Cflags and Ldflags are and will be always a subject in which everybody has his opinion. The best way is to test them yourself, do somebenchmarks, and keep the flags you find optimal for your system. Also check the differents posts in the forums talking about this so that you can get an idea. A useful program to determine what cflags you should use, is ACOVEA (already in portage), which is a benchmarking tool that will do several tests on your machine (the standard test will run for more than 15 hours) to help you pick the best cflags for your machine. See THIS thread for acovea scripts and results.
4. Using hdparm
Another important application is hdparm. It allows us to configure our hard disk parameters, so get the maximum performance:
Code:
# emerge hdparm
# rc-update add hdparm default
See /etc/conf.d/hdparm
see actual configuration:
Code:
# hdparm -i /dev/hda
testing the speed:
Code:
# hdparm -Tt /dev/hda
In my computer I modifified /etc/conf.d/hdparm to get the maximum of my hard disk:
Code:
hda_args="-d1 -X69 -c1"
cdrom0_args="-d1"
If you need more information the man page is pretty good
Code:
# man hdparm
Also check THIS for a little tutorial.
5. Should you.. prelink?
Prelink is a powerful application, it allows us to pre-link the libraries needed for a binary before using it. So instead of looking for which libraries the binary will need when we launch it, prelink will modify the binary addind a little descriptions of the libs it nees to run. This get rid of the search for shared libraries everytime we launch the binary, so it makes it faster.
Important: Everytime that you upgrade the libraries that are needed for the binaries, (for example glibc) you have to re-run prelink on the system.
This is a little optimization that we will thank when launching big applications like KDE (moreover, if you prelink your system KDE will not need to launch kdeinit, so it will also run faster). The little binaries are already pretty fast, so will not appreciate the difference.
Requirements: it is a must to have compiled the binaries with binutils-2.13.90.0.xx and gcc-3.2 or higher, and also have installed glibc-2.3.1-r2 or higher. The size of the binaries will be bigger with prelink, and to run the process you need enough free space on the hard disk.
Way to go:
Code:
# emerge prelink
Find config file at /etc/prelink.conf
Code:
# prelink -afmR
This is the common use of prelink, that will prelink ALL the binaries, and also will look if the binaries were already prelinked, and prelink them again if needed.
It is possible that you get some errors when running prelink, because some binaries can not be prelinked (the ones compressed with upx, for example).
More information HERE, and/or man prelink.
6. Managing the swap
In this section I just wanted to mention some things that can help us.
First of all, if you have two harddisks it is better to put the swap partition on the second disk (having the root partition in the first one) as this will improve the read/write times.
Also you should NOT use a file as swap. I tried it once in an old computer, deleted the swap partition and set a file as ./swap of 256 MB.� and modified fstab. This method is slower, as it has to find the file, open the file, find were it was writting to it, writte to it, save, and close the
file. With a partition in the disc this process is pretty much faster.
Another concept to know about is swappiness (kernel 2.6+). When an application needs memory and the RAM is full, there are two options: or the RAM gets empties a little bit cleaning out old used memory, or swap memory gets used (slower than ram). In the new kernels, you can set a variable to define if the kernel should empty some ram or use the swap partition.
/etc/sysctl.conf
Code:
vm.swappiness = 40
This value can be between 0 and 100. Close to 0 will mean that the kernel should empty some ram, and a higher value close to 100 will tell the kernel to use the swap memory more often.
The default value is 60. I set this to 25 in my laptop, so that i can reduce the disk access. You can use 惠ree -m� to see the stats of your memory useage.
7. Ccache
ccache is an application (included en portage and on by default when emerging (if you emerge ccache)) that acts as a cache for the compiler.
With this little prog we will be able to compile in a faster way when compiling packages, specially with the big make's (you could think that using a cache when compiling has no use, but it speeds up some instructions like the make clean)
Just emerge it and set the default cache size (read the einfo after the emerge), and it will be on by default. You can check it with:
Code:
# emerge info | grep ccache
ccache version 2.3 [enabled]
You can check the ccache stats by doing:
Code:
# ccache -s
8. Distcc
distcc is an application that will make our life easier when installing gentoo in several computers, or if our computer is very slow but have another fast computer. It can be combined with ccache, optimizing the compiling time. I won't explaint this
feature a lot, because it's not used by everyone. Just that you know about it, because you can use cross-compiling with different computers with different processors, they will just share the compiling tasks.
More information HERE.
9. USE's
The USE flags are a useful tool that gentoo provides us with to configure our packages as we want them.
For example, imagine that you want to compile apache:
Code:
# emerge -pv apache
[ebuild N ] net-www/apache-2.0.50 -debug -doc -ipv6 +ssl 6,197 kB
The (+/-) options that appear after the name of the program we are going to install (-v flag) are the USE vars we can use to configure the package we are installing. If, for example, we don't want our apache to use ssl, we can do this:
Code:
# USE="-ssl" emerge -pv apache
[ebuild N ] net-www/apache-2.0.50 -debug -doc -ipv6 -ssl 6,197 kB
We can see that ssl is now off, and apache won't be compiled with ssl support.
In this example we set the USE var directly on the propmt, but this is not the correct way to do it if you want the system to remember the USE flags everytime you compile that package. You can set your USE flags in the /etc/make.conf file, or also use /etc/portage/package.use to set them for
individual packages.
It is the same for the "x86" flag (to tell portage to use the latest version available of every package), it's not recommended to just set the flag on the prompt, you should set it on /etc/make.conf to use it for all the packages, or set it individually:
Code:
# echo "app-editors/nano ~x86" >> /etc/portage/package.keywords
It is important to take a look at the USE flags of the packages before installing them, so that we can turn off features we won't be needing saving space and sometimes dependencies.
For example, if we want to emerge the console irc client BitchX, portage want to install xmms, X, and some other dependencies that could be useless for some of us. Setting -xxms and -X for xmms in the /etc/portage/package.use will allow us to install BitchX without the xmms and X support, and we won't need to install all those packages.
You can see that this is a powerful tool to use when emerging, it gives us a lot of control of how the packages will be installed in our system.
You have a little description of the USE flags in /usr/portage/profiles/use.desc
10. Modifying ebuilds and injecting packages
Always keep a backup of your files before modifying them (also note that emerge sync will fix if you mess an ebuild).
獨hat's injecting a package and what's the use of it?
Remember that time when you wanted to install package X, and as a dependency portage asked to install package Y? For example, a lot of users manage the kernel manually instead of using portage to do it (gentoo-sources, gentoo-dev-sources, vanilla-sources, and so on). Then, when you emerge some package that needs the kernel-sources (like alsa, or ipw2X00) installed portage will try to install some kernel-sources. Why would you do that if you already have your kernel at /usr/src?
note: injecting has been deprecated, now you should use package.provided and virtuals as explained
- using package.provided:
package.provided tells portage that a package is installed (even if it's not)
You can use this file to put all the packages you want to tell portage you installed by hand.
Code:
echo "sys-kernel/ck-sources" >> /etc/portage/profile/package.provided
package.provided doesn't affect virtuals, virtuals are used to tell portage what packages should install for a given category:
For example, you could tell portage that you want to satisfy x11 with xorg, and not xfree anymore (which is not a valid example anymore, but it is useful to understand the use of it)
Code:
echo "virtual/x11 x11-base/xorg-x11" >> /etc/portage/profile/virtuals
more information on this and /etc/portage management -> man portage
11. Halt vs Suspend
Have you never asked yourself why you shutdown you computer, when you can suspend it to ram or disk?
If you suspend to ram, it has the handicap that it will still need AC input in order to keep the system alive. But suspending to disk is very useful (specially for laptops), because the laptop will "shutdown", but we will keep our sesion.
Doing it this way we avoid to boot all the system services everytime (it not an instant recuperation from the "sleep", but seems faster).
I have used swsusp2 in my laptop and works fine, but you have to patch the kernel sources. You can find info in THIS post on how to do this. Try it and you won't regret.
12. Xdelta - Deltup
In THIS post Deltup is discussed, because a new version is available. The point is that everytime portage needs to download a file, deltup will look for an older version of the file (/usr/portage/distfiles) and try to download only the
difference between the two files, and create the new file on-the-fly.
This can be a big improvement for all those 56k users who keep their /usr/portage/distfiles in order to only download patches when new "revisions" are released, because this can lower the mb to download everytime they want to emerge new versions of the installed packages.
13. Native POSIX Thread Library
This library, know as NPTL, can improve our system, because it's up to 4 times faster than the standard LinuxThreads when creating new threads. You *should* use 2.6 linux headers, and a new version of glibc and gcc (~x86). To use ntpl you just have to recompile glibc with the USE flag
"nptl" turned on.
note: in order to use nptl you need gcc 3.x or higher installed.
HERE you can get more information and benchmarkings.
14. GCC
GCC is very important, specially in a distro like gentoo in which the users look to optimize their system by compiling theirselves the packages they install. Using an actual version of gcc has some advantages, because all the code we create when compiling will be more optimized (from version 3.4.x you can already use the -march=pentium-m for the centrino
processors).
To install the latest gcc, just emerge gcc with ~x86 turned on (rmember to change your profile also):
Code:
# echo "sys-devel/gcc ~x86" >> /etc/portage/package.keywords
# emerge -u gcc
15. Filesystems [data safety vs speed]
After trying out some filesystems, i use reiser4 because it's the fastest filesystem available. I think that it is very useful to use a fast filesystem, but you have to keep backups of your data just in case you have corruption issues.
Also point that, after using ext2, ext3, reiserfs, xfs, reiserfs and som other encripted filesystems i have never had corruption issues with my data. Just keep backups of your data and you will be all set.
Note that you need a version of the kernel with the reiser4 patches, so it will have to be a development patched release.
To convert your / partition to reiser4 you will need a livecd with reiser4 support like THIS one, and install a kernel with that support also.
NOTA: Some people have problems because they can't find the Reiser4 submenu in the Filesystems tree of the kernel, make sure that you have deactivated the option "use 4kb for kernel stacks instead of 8kb) under the kernel hacking submenu, and then you will find the Reiser4 option.
16. i/o and tasks schedulers
coming soon
17. Useful Scripts and tips
There are some useful scripts in the forums and the portage tree to manage our system:
1- esearch
This one is included in the portage tree (you can just emerge esearch), and it's an utility to search trought the portage package database. The good thing is that it's very fast (faster than emerge -sS).
Note that after every emerge sync we have to update de esearch database by running eupdatedb, or you can just use esync to update the portage tree (esync will emerge sync, and then show a list with the changes (new packages) from the last sync).
2- eix
The same concept as esearch, but it's faster (and it is also faster to update the package database).
It's a young project, but works pretty fine.
More info HERE.
3- Cruft
This script from will generate a list with all the files in our system that could be deleted because they don't belong to any installed package. You have to be careful when using it, because it can generase false positives.
Usage:
Code:
# ./cruft > cruft.log
Then you can check the list, and remove from it the files you want to keep.
Then you can run this command to get rid of the files:
Code:
# cat cruft.log | xargs rm -rf
You could also just take a look at the list and delete them yourself.
More info HERE.
4- Stale
Interesting script that will help us to keep /usr/portage/distfiles with an optimal size. The script will search in that dir, and delete (when invoked with the --nopretend option) the old files, not the actual ones.
For example, if we have libtool-1.3.5.tar.gz and libtool-1.5.2.tar.gz, it would delete libtool-1.3.5.tar.gz
It gets messed with files like font-arial-iso-8859-1 and font-arial-iso-8859-2, in which the numeration doesn't not correspond to the versioning of the package (the same with gtk and glib in their versions 1.x and 2.x)
More info HERE.
5- Porthole
Portage frontend made in python (+gtk), that offers us a visual way to configure portage, and it makes easier to configure the packages and emerges. It's already in portage, so you just have to "emerge porthole".
6- kuroo
Another portage frontend, this one is made with Qt (for the kde-lovers). It's a young project, but works fine.
More info HERE.
You can also find more useful scripts and programs related to Portage in THIS thread.
7- portage cdb
This is not a script itself, but it's a nice tip to improve the portage speed. Try it, you wont be disappointed!
8- mounting / in ram
very nice article, worth a read Smile http://forums.gentoo.org/viewtopic-t-296892.html
-under construction-
_________________
gentoo sex is updatedb; locate; talk; date; cd; strip; look; touch; finger; unzip; uptime; gawk; head; emerge --oneshot condom; mount; fsck; gasp; more; yes; yes; yes; more; umount; emerge -C condom; make clean; sleep


關於 Tsung

對新奇的事物都很有興趣, 喜歡簡單的東西, 過簡單的生活.
本篇發表於 OS-Linux_BSD。將永久鏈結加入書籤。

發表迴響

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料