# FreeBSD Kernel Optimizations for Dual Processing Power



## fbsduile (Jun 15, 2010)

Hello, FreeBSD developers and users. I have been running FreeBSD 8 in Oracle Virtual Box for quite a few weeks now and have decided that I like your operating system of choice. FreeBSD is fast, clean, efficient, and gets the job doneâ€”just what I need for my rig!

So I'm ready to migrate to real hardware, and I'd like to take advantage of compiling my own kernel with optimizations.

FreeBSD seems to have many kernel compile options, and I get the idea that the right mix of compile flags can make all the difference, and too many can be worse than none at all.

I had better talk about my system, though, so we know just what optimizations might be important.

We're working with an IBM PC 365, which originally came with a single 180 MHz Pentium Pro with 256 KiB L2 cache and 32 MiB RAM. Were that the current system, I would install stock FreeBSD and be done with it.

Since I discovered FreeBSD, though, I thought I'd splurge my operating system savings on hardware and did some pretty heavy-duty hardware upgrades to this baby (hence the need for kernel optimizations).

Currently she houses two overclocked 233 MHz Pentium Pros with 1 MiB L2 cache each and 512 (128x4) MiB RAM. (I know, I know, this might seem like overkill, but they were cheap and represent the best clock-to-performance ratio Intel had ever released until Core2 came along.)

In addition to thatâ€”as if that weren't enoughâ€”I also installed a 500 GiB hard disk optimized for 24/7 high-end media availability. Even though I'm not doing any video serving, and the controller can only see 128 GiB of it, I figure that if it's fast enough for multimedia then it's fast enough for me.

The RAM chips were $70/ea and the hard drive was $130. I bought the processors almost ten years ago, so I can't remember their exact cost, but it was something like $50 each, so call it a hundred.

All told that's just $500, money I think was well-spent.

So now back to the OS. What do I need to do to get it to run as fast as possible? Rest assured, I know how to use Google, so I have come across some literature about the topic, but therein lies the problem.

I keep coming across crap like optimization differences between FreeBSD kernel versions as well as optimizing for specific apps. Advice from one version of FreeBSD using some version or another of an app can be wildly different, and I have to say that this isn't very helpful.

But that's why I'm asking the true, died-in-the-wool, hardcore FreeBSD users who actually need to get something done with their systems everyday. I need to make this machine as efficient as possible and I know you know how to do it.

So tell me, FreeBSD-ers, how do I optimize my FreeBSD kernel and make this baby scream? Let's get'er done!


----------



## SirDice (Jun 15, 2010)

fbsduile said:
			
		

> FreeBSD seems to have many kernel compile options, and I get the idea that the right mix of compile flags can make all the difference, and too many can be worse than none at all.


Ok. You've seen them now forget about them. Unless you understand what you are doing it's best not to meddle with them. The default compiler options are good enough. Even if you know what you're doing the performance gained is marginal at best. Stability is the first thing to go out the window. When you do have problems first thing everybody will suggest is to remove the compiler options and recompile.



> So tell me, FreeBSD-ers, how do I optimize my FreeBSD kernel and make this baby scream? Let's get'er done!


Make a copy of the GENERIC config, remove all the drivers you don't need. Remove the debugging options. Compile. Forget about the compiler flags.


----------



## fbsduile (Jun 15, 2010)

So what're you giving meâ€”30% efficiency increase over the default? 25%? What?


----------



## SirDice (Jun 15, 2010)

fbsduile said:
			
		

> So what're you giving meâ€”30% efficiency increase over the default? 25%? What?


Disabling the debugging features will improve performance the most. No hard figures, just experience.


----------



## kdemidofff (Jun 15, 2010)

SirDice said:
			
		

> Ok. You've seen them now forget about them. ...
> Make a copy of the GENERIC config, remove all the drivers you don't need. Remove the debugging options. Compile. Forget about the compiler flags.



Hint: copy GENERIC to some file open it and replace all "device" with "nodevice" and then replace back on only needed devices
that's ur new kernel config 

make new kernel with 


```
include         GENERIC
ident           YOURKERNELNAME
nomakeoption   DEBUG
makeoptions     NO_MODULES
or
makeoptions    MODULES_OVERRIDE="modulename ... ..."
options ..
options ...
device ..

and all other stuff
nodevice ...
nodevice ...
nodevice ...
nodevice ...
```
all stuff u don't have
like SCSI controlers and unneeded NICs

this way u can end up with unbootable kernel but if u know what devices u need it will work
remember to include device for ur disk controller


for CPU optimizations add 

```
CPUTYPE?=native
and
KERNCONF=YOURKERNELNAME
```
to automate buildworld
to make.conf


----------



## fbsduile (Jun 16, 2010)

There's no way to run parts of the kernel or drivers out of my L2 cache? I have 2 MiB, as I pointed out. Overall your idea seems sound, but this is a little vanilla for me. I would like a list of optimization flags and which processors they're best for use with. Is there any such thing?


----------



## phoenix (Jun 16, 2010)

Search the forums for CFLAGS.  Note how every single one of them ends with "do not mess with CFLAGS".    Including this one.  

Set CPUTYPE in /etc/make.conf and be done with it.

The CPU will manage it's cache as needed to run programs.  Do you really expect to be able to monopolise the L2 just for the kernel, to the detriment of every other program you will be running?

Unless you are going to be digging around the source tree, with a heavy background of algorithms, and a large heap of golden horseshoes, there's nothing else to do but set CPUTYPE and enjoy the stability of FreeBSD.


----------



## dennylin93 (Jun 16, 2010)

Yes, there are, but stay away from all the optimization flags. They bring more trouble than they're worth, so it's rare that people running FreeBSD will use them.

Some optimizations are already done (such as using -O2 or -O3), so the defaults should be fine.

If you really insist on using them though, just set CPUTYPE.


----------



## danbi (Jun 16, 2010)

Come on people, some CFLAGS, like -pipe are real useful!

By the way, the appropriate CPUTYPE for Pentium Pro processors is


```
CPUTYPE?=pentiumpro
```

Too bad Intel did not make a 5GHz version of these...


----------



## Alt (Jun 16, 2010)

set /etc/make.conf to your cpu type, maybe add -O2 (man says -O3 may be dangerous);
Rebuild kernel with no debug symbols, no unused drivers;
tune sysctls, sortware caches for your server reasons
compile software from ports by your own, no use for pre-compiled pkgs, try threaded versions


----------



## SirDice (Jun 16, 2010)

danbi said:
			
		

> Come on people, some CFLAGS, like -pipe are real useful!





			
				Alt said:
			
		

> maybe add -O2 (man says -O3 may be dangerous)]
> Already used by default. No need to specify.
> 
> /usr/share/mk/sys.mk:
> ...


----------



## kdemidofff (Jun 16, 2010)

fbsduile said:
			
		

> There's no way to run parts of the kernel or drivers out of my L2 cache? I have 2 MiB, as I pointed out. Overall your idea seems sound, but this is a little vanilla for me. I would like a list of optimization flags and which processors they're best for use with. Is there any such thing?



Cache is yet another marketing feature just use 

```
CPUTYPE?=
```


----------



## fbsduile (Jun 16, 2010)

danbi said:
			
		

> ```
> CPUTYPE?=pentiumpro
> ```
> 
> Too bad Intel did not make a 5GHz version of these...



Hell yeah buddy. Imagine a pair of 2 GHz Pros in yer chassis. Only thing that could stand against it would be Nahelem.


----------



## phoenix (Jun 16, 2010)

A 2 GHz PPro is called an over-clocked P3 or an over-clocked Pentium-M or an over-clocked Core.    The PPro, P2, and P3 are all based on the same CPU core architecture (known as the P6).  The only real differences were that the PPro was optimised for 32-bit code while the dominant OS (Win9x) was a mix of 16-bit and 32-bit code and didn't run too well on it.  The P2 was optimised for 16-bit/32-bit code, and ran Win9x better than the PPro, which is why it became popular.  And the P2/P3 added MMX, SSE, SSE2, etc.

The P4 is an abomination, and based on a different core architecture.  Thankfully, this architecture is now dead and buried.

The Pentium-M was based on the P6 core.  The Core (not Core2) architecture is an evolution of the Pentium-M core, which is an evolution of the P6 core.

The Core2 was based on a new CPU architecture.

And the Core i-series is based on a new CPU architecture.

IOW, the PPro lives on!!


----------



## fbsduile (Jun 17, 2010)

So in other words, Intel Core is the latest version of the Pentium Proâ€¦ Interesting. Anyone know how FreeBSD runs on a Core T2700? The Pentium Pro rides again!

So I think I'll buy the last great PCI graphics card ever released to compliment my systemâ€¦ The GeForce 9500 GT 1 GiB. Too bad FreeBSD can't assign the second Pentium Pro to process graphics like most other modern operating systems can.

Another $100 in this bad boy to crank up its graphics ability ain't bad. Then I'll be able to see what it's really capable of. Maybe FreeBSD can quit limping after that and we can see what it's really capable ofâ€¦


----------



## phoenix (Jun 17, 2010)

fbsduile said:
			
		

> So in other words, Intel Core is the latest version of the Pentium Proâ€¦ Interesting. Anyone know how FreeBSD runs on a Core T2700? The Pentium Pro rides again!



Note:  Core, Core2, Core i are all different.  Intel likes to reuse names (like how a "Pentium" is now a Core2-based CPU).  Core (the original architecture based on Pentium-M) is no longer available, AFAICT.  Most of them went to Apple (Core Solo), or were used in laptops.  You'd be hard pressed to find an original desktop system using a Core CPU nowadays.

You'll want to lookup on the Intel website whether or not that Core T-whatever is actually a Core product, and not a Core2, or something else.

It's pretty sad that you have to resort to a product matrix (actually, several) in order to figure out which product name refers to which CPU architecture.    Intel is really doing themselves a disservice by keeping their "product naming manager" employed.



> So I think I'll buy the last great PCI graphics card ever released to compliment my systemâ€¦ The GeForce 9500 GT 1 GiB. Too bad FreeBSD can't assign the second Pentium Pro to process graphics like most other modern operating systems can.



What?  Name a single OS that can use the CPU as a graphics core.  Most systems go the other way:  running general purpose code on a GPU core.


----------



## fbsduile (Jun 18, 2010)

Which graphics card do you suggest then? What does FreeBSD run the most fast on? I figured the one above since it has, you know, 1 GiB RAM and 32 shaders, etc.


----------



## phoenix (Jun 18, 2010)

You're asking the wrong fella about graphics cards.    I'm lamenting the loss of consumer Matrox cards, still using pre-AMD ATi AGP cards, and couldn't tell you the difference between a shader, a texturizer, or a rasterizer.


----------



## fbsduile (Jun 21, 2010)

So my system crashed and burned when I installed the video card. I think it's the power supply, but the motherboard might be fried. I'll know in a day or two when the new one arrives.

Now that I'm thinking of it, this couldn't be FreeBSD's fault, could it? I'm plugged into a grounded outlet.


----------

