UNIX System Administration Handbook - Evi Nemeth [151]
disk fd0 at fdc0 drive 0
disk fd1 at fdc0 drive 1
# IDE controller and disks
controller wdc0 at isa? port "IO_WD1" bio irq 14
disk wd0 at wdc0 drive 0
disk wd1 at wdc0 drive 1
controller wdc1 at isa? port "IO_WD2" bio irq 15
disk wd2 at wdc1 drive 0
disk wd3 at wdc1 drive 1
Here we declare the controllers and disks for our example system: a floppy controller, two floppy drives (even though only one is used, declaring them both doesn’t hurt), and two IDE controllers with corresponding disks.
options ATAPI # Enable ATAPI support for IDE bus
options ATAPI_STATIC # Don't do it as an LKM
device acd0 # IDE CD-ROM
Under FreeBSD, we need to include these special options to enable IDE devices. Although IDE can be configured as a loadable kernel module (the “LKM” referred to in the comment), it must be statically configured if you’re using an IDE disk as your root partition. Otherwise, the system cannot recognize your root disk at boot time.
pseudo-device loop # Network loopback
pseudo-device ether # Ethernet support
pseudo-device bpfilter 4 # Berkeley packet filter
Of these pseudo-devices, only loop is mandatory. In general, you should retain all the pseudo-devices in the GENERIC configuration. Obviously, you need the ether pseudo-device to use Ethernet devices. You need the bpfilter pseudo-device to run tcpdump and DHCP clients, so keep it.
You may want to leave out bpfilter support to prevent people from sniffing the network. However, if you omit bpfilter, you won’t be able to legitimately snoop to diagnose problems.
Tuning the FreeBSD kernel
The GENERIC kernel is not tuned for high performance, as you will notice especially if you are building a high-volume web server. Here are some suggestions for building a better FreeBSD kernel.
To some extent, you can dynamically tune the FreeBSD kernel with the sysctl command, which provides a user-level interface to many of the kernel’s internal data structures. sysctl lets you dynamically change selected kernel parameters; it’s a powerful (and dangerous) command.
sysctl -a lists the kernel variables you can look at and possibly change. Almost all the parameters described in Table 12.7 can be changed dynamically. Documentation on what each variable does is typically meager, although the variable names usually give a hint. Be careful when tuning your kernel with sysctl because you can easily break things.
Table 12.7 Interesting FreeBSD kernel variables accessible through sysctl
The changes that sysctl makes to kernel variables are not remembered across reboots. A useful paradigm is to first test changes by using sysctl, then make them permanent by changing the kernel config file and recompiling the kernel. This procedure has the advantage of safety, since you can simply reboot to reset the system no matter how much you’ve screwed things up.
Table 12.7 lists the most commonly tuned sysctl variables, their default values, and their meanings.
Note that in the default configuration, a single user can consume all but one of the system’s process slots. Even if only one person will actually use the system, these defaults create a potential problem because no headroom is reserved for starting system processes. You should make the gap between maxproc and maxprocperuid much larger than the default.
Below, we describe some simple parameters you might change in your kernel config to get better performance out of the GENERIC kernel. These tweaks are designed specifically for use on a web server, although they should increase performance for most network servers.
maxusers 256
The maxusers keyword adjusts many other variables in the kernel, such as the maximum number of processes, the maximum number of processes per user, the system-wide limit on open files, the per-process limit on open files, and the maximum number of network buffers. Be generous when configuring a server.
options NMBCLUSTERS=4096
Here, we set the number of network buffers to a more reasonable value. The default is 256, which is laughably