Squeezing performance out of NetBSD: tuning sysctl for the kernel, VM, and network, monitoring the system with systat and top, and comparing FFS with ZFS as a storage option.

In episode 18 we took NetBSD into the virtualization world. Now it's time to make sure the running system runs as fast and efficiently as possible. In this episode we'll dissect performance and optimization on NetBSD — tuning sysctl for the kernel, VM, and network, monitoring the system with systat and top, and comparing FFS with ZFS as a storage option.
sysctl hw.ncpu
sysctl hw.physmemhw.ncpu = 8
hw.physmem = 8471793664top shows processes and resource usage in real time:
topload averages: 0.13, 0.08, 0.05
10 processes: 9 running, 1 idle
CPU states: 2.4% user, 0.0% nice, 1.8% system, 0.0% interrupt, 95.8% idle
Memory: 4096M Act, 340M Inact, 370M Wired, 30M Exec, 3056M Freesystat is NetBSD's deeper monitoring tool. Some of its views:
| View | Function |
|---|---|
systat vmstat | Memory and paging statistics |
systat netstat | Network traffic |
systat iostat | Disk I/O statistics |
systat swap | Swap usage |
systat iostat disk0 disk1
KB/t tps KB/t tps
32.5 12.3 12.1 3.4Basic parameters that are often adjusted:
sysctl kern.maxvnodes
sysctl kern.maxfileskern.maxvnodes = 52326
kern.maxfiles = 10480sysctl -w kern.maxfiles=524288
sysctl -w kern.maxvnodes=262144NetBSD manages memory diligently. For read/write-heavy workloads, watch caching and paging:
sysctl vm.vm.vm_page_free_min
sysctl vm.vm.vm_page_free_targetvm.vm.vm_page_free_min = 512
vm.vm.vm_page_free_target = 2048The most influential network parameter is the buffer — too small causes retransmits, too large eats memory:
sysctl net.inet.tcp.sendspace
sysctl net.inet.tcp.recvspacenet.inet.tcp.sendspace = 32768
net.inet.tcp.recvspace = 65536For high-speed links (1 Gbps and up), raise sendspace:
sysctl -w net.inet.tcp.sendspace=131072The rule of thumb for TCP buffers: about Bandwidth x RTT (the bandwidth-delay product). To determine the RTT, use ping:
ping -c 5 10.0.0.2round-trip min/avg/max/stddev = 0.421/0.513/0.672/0.079 msWarning
Only raise network buffers if you truly need to — large buffers consume kernel memory per connection. With thousands of connections, a 128 KB buffer each means hundreds of MB of memory. Tuning must be proportional to the scale of the workload.
sysctl -w changes vanish on reboot. For permanence, write them in /etc/sysctl.conf — this file is read at boot:
kern.maxfiles=524288
kern.maxvnodes=262144
net.inet.tcp.sendspace=131072FFS accepts mount options that affect performance. Viewing the active options:
mount | grep ffs/dev/wd0e on /usr type ffs (local, nodevmtime, noatime)Options commonly considered:
| Option | Effect |
|---|---|
noatime | Doesn't update access times — reduces write I/O |
nodevmtime | Doesn't write times to the device — similar to noatime |
norelatime | Disables relatime (the default) |
Example of adding noatime in /etc/fstab for a frequently-read /var partition:
/dev/wd0f /var ffs rw,noatime 1 2ZFS is available on NetBSD as a package (zfs). Both have different strengths:
| Aspect | FFS | ZFS |
|---|---|---|
| Maturity on NetBSD | Default, very mature | Port, stable for general use |
| Data checksums | Not automatic | Yes (corruption detection) |
| Snapshots | Via fsck -t | Built-in, very easy |
| RAID/volume | Needs cciss/cgd + raframe | Built-in (mirror, raidz) |
| Complexity | Simple | More complex |
cd /usr/pkgsrc/filesystems/zfs
make install clean| Step | Action |
|---|---|
| 1 | Measure the baseline with top, systat iostat, systat netstat |
| 2 | Identify the dominant bottleneck |
| 3 | Change one parameter in /etc/sysctl.conf, then reboot or sysctl -w |
| 4 | Measure again and compare |
| 5 | Keep only the changes proven to help |
In this episode 19, you've squeezed performance out of NetBSD: monitoring the system with top and systat, tuning sysctl for the kernel, VM, and network, making tuning permanent in /etc/sysctl.conf, and comparing FFS with ZFS for storage needs.
Key takeaways:
top (processes) and systat iostat/netstat (I/O, network).kern.maxfiles, net.inet.tcp.sendspace — match buffers to the bandwidth-delay product./etc/sysctl.conf.In the next episode, episode 20, we'll dive into the soul of NetBSD: embedded, ARM, and a portability deep-dive — exploring architecture support like arm64, riscv, and evbarm, cross-arch building, and use on SBCs and legacy hardware. See you in episode 20!