streda 7. marca 2012

FreeBSD system upgrade/kernel upgrade 3


1.make.conf

The "make.conf" is configuration file with options for every compilation used via "make" command. So basically for compilation ports and system source.
Some point outs which seem interesting:
*MAKEOBJDIRPREFIX - this is used when compiling the source. Default is "/usr/obj". Its directory used as working directory during compilation. You can change it to yours. For example to ramdisk.
*CPUTYPE?=nocona - I have this value even I have core 2 duo. According /usr/src/share/mk/bsd.cpu.mk, they are the same. Check man for make.conf.
*CFLAGS= -O -pipe - according article, "-O" is faster than "-O2", defines optimization. "-pipe" defines pipes instead of files, more memory / less disk space, faster.
*COPTFLAGS= -O -pipe - the same as previous but for kernel compilation.

*LOADER_TFTP_SUPPORT= YES - than you recompile /usr/src/sys/boot and you will get new pxeboot file with TFTP support. PXE has default NFS support.

###
#SUP=            /usr/bin/csup
#SUPFLAGS=       -L 2
#SUPHOST=        cvsup.sk.FreeBSD.org
#SUPFILE=        /usr/share/examples/cvsup/standard-supfile
#PORTSSUPFILE=   /usr/share/examples/cvsup/ports-supfile
#DOCSUPFILE=     /usr/share/examples/cvsup/doc-supfile
###
#-fill up these files if you want to use "make update" in "/usr/src" as a "general" update for ports,docs,src. I prefer to run each manually.

*NO_MODULES= - leave it without "yes" or "true". It will cause skip the module compilation within kernel build. By default, with kernel compilation also modules are compiled.
*MODULES_OVERRIDE= - list modules you want to compile
*WITHOUT_MODULES= - like previous but in opposite meaning

During your system maintenance you can find more options to put into "make.conf" accordingly to specific situation.
If you observe problems like compilations ends with errors etc., the reason may be the CPU optimization flags, so comment them out and try again. Do not forget if you put something to "exclude" options for modules, so than you are not wondering that your module is not or wrong compiled or working due to version mismatch.

2.Separate compilation
As you can notice, with "NO_MODULES=" option, just the kernel will be build.
If you want to have it like this and manually compile modules afterwards, go to "/usr/src/sys/modules" and do "make". It will compile all modules. You can type "make install" to install them to "/boot" directory.
Another way, if you want just particular module, go to appropriate sub-directory in above path and do "make" and "make install" or instead of "make install" copy compiled module manually.
Choosing modules just you need saves time. Hardened kernel compilation takes about 1,45 minute for me (Acer 8930g with Core 2 Duo T9600 @ 2,8 GHz, 6GB RAM) without modules and with multi-thread compilation.

Don't forget to have modules with same version as kernel, otherwise mismatch errors can appear during module loading.


3.Multi-threaded compilation
Are you wondering you have a fast hardware and the compilation is still slow? Try to check top during kernel compilation. See example.
I have computer as above (section 2). If I run standard "make" of kernel and check top during compilation, I can see CPU idle around 50% and load average in last minute (first value, second is for 5, third for 15 minutes) around 1,0.  That means my CPU is about half sleeping. So lets burn the CPU.
We want to achieve 0,0% idle all the time. The magic is to add "-j [num]" flag to "make" command. By default it seems just one thread is working. I made a little test with "num" value which means number of jobs during compilation.
It seems to have a balanced, use this (my own) calc.: number of CPUx2 + 1.
In my case I have two CPUs so the result is 5.
Compare your own compilation with command:
time make buildkernel KERNCONF=MY_OWN_KERNEL 
and than
time make -j 5 buildkernel KERNCONF=MY_OWN_KERNEL
In my case it's 2min 45s minute for first and 1min 40s minute for second way.

What about making ports? You use "make" command as well right?
In ports, using "-j" flag causes breaking of compilation frequently. So if you want to try this flag do partial compilation as "make", "make install", "make clean" and for plain "make" use this flag. Sometimes it's possible to run make, run it for a while ( 20sec ) than Ctrl+C so all directories and links are created and start again with flagged "make". Yes these ways are not normal, so rather don't use it. There is some normal workaround with flagged compilation for ports, but this is for another article.

4.Compilation using Ramdisk
There is not a huge improvement to compile source code in Ramdisk, but anyway it's possible and you can use it for anything else.
Why there is not huge improvement?
I use 7200rpm disk. You probably too. As you can notice in previous section, with multi-threaded compilation, we have 0,0% idle CPU. Already with this value, we can say that CPU is limiting factor of compilation. You can prove it with "iostat" command, (etc. iostat -c 50). The disk activity is almost nothing during compilation. So with Ramdisk we won't get much better read/write spead in this case, only noticeable improvement is access time, for RAM almost zero compared to disk. So at all, there is a little performance improvement. In my case I have improvement 5~6s for above kernel compilation. I think would be greater for bigger compilation.
I prefer to create two Ramdisks, one for soure and one for "/usr/obj".
mdmfs -s 600M md /mnt - will create and mount Ramdisk to /mnt for source
mdmfs -s 200M md /usr/obj 
cp -R /usr/src/ /mnt
df or mount - check the mounted disks (should be md0 and md1)
do "make" in "/mnt" directory
after operation remove files, umount directories and:
mdconfig -d -u 0 - to remove Ramdisk md0
mdconfig -d -u 1 - to remove Ramdisk md1

One negative of doing this is, you need to have a lot of RAM memory. I mean, for whole compilation (with world and modules), you need around 1600MB Ramdisk size total. For only kernel compilation the space you need is arround 800MB. 

Žiadne komentáre:

Zverejnenie komentára