iwm: Fix S:N reporting in ifconfig(8)
[dragonfly.git] / share / man / man7 / tuning.7
1 .\" Copyright (c) 2001 Matthew Dillon.  Terms and conditions are those of
2 .\" the BSD Copyright as specified in the file "/usr/src/COPYRIGHT" in
3 .\" the source tree.
4 .\"
5 .Dd August 24, 2018
6 .Dt TUNING 7
7 .Os
8 .Sh NAME
9 .Nm tuning
10 .Nd performance tuning under DragonFly
11 .Sh SYSTEM SETUP
12 Modern
13 .Dx
14 systems typically have just three partitions on the main drive.
15 In order, a UFS
16 .Pa /boot ,
17 .Pa swap ,
18 and a HAMMER or HAMMER2
19 .Pa root .
20 In prior years the installer created separate PFSs for half a dozen
21 directories, but now we just put (almost) everything in the root.
22 The installer will separate stuff that doesn't need to be backed up into
23 a /build subdirectory and create null-mounts for things like /usr/obj, but it
24 no longer creates separate PFSs for these.
25 If desired, you can make /build its own mount to separate-out the
26 components of the filesystem which do not need to be persistent.
27 .Pp
28 Generally speaking the
29 .Pa /boot
30 partition should be 1GB in size.  This is the minimum recommended
31 size, giving you room for backup kernels and alternative boot schemes.
32 .Dx
33 always installs debug-enabled kernels and modules and these can take
34 up quite a bit of disk space (but will not take up any extra ram).
35 .Pp
36 In the old days we recommended that swap be sized to at least 2x main
37 memory.  These days swap is often used for other activities, including
38 .Xr tmpfs 5
39 and
40 .Xr swapcache 8 .
41 We recommend that swap be sized to the larger of 2x main memory or
42 1GB if you have a fairly small disk and 16GB or more if you have a
43 modestly endowed system.
44 If you have a modest SSD + large HDD combination, we recommend
45 a large dedicated swap partition on the SSD.  For example, if
46 you have a 128GB SSD and 2TB or more of HDD storage, dedicating
47 upwards of 64GB of the SSD to swap and using
48 .Xr swapcache 8
49 will significantly improve your HDD's performance.
50 .Pp
51 In an all-SSD or mostly-SSD system,
52 .Xr swapcache 8
53 is not normally used and should be left disabled (the default), but you
54 may still want to have a large swap partition to support
55 .Xr tmpfs 5
56 use.
57 Our synth/poudriere build machines run with at least 200GB of
58 swap and use tmpfs for all the builder jails.  50-100 GB
59 is swapped out at the peak of the build.  As a result, actual
60 system storage bandwidth is minimized and performance increased.
61 .Pp
62 If you are on a minimally configured machine you may, of course,
63 configure far less swap or no swap at all but we recommend at least
64 some swap.
65 The kernel's VM paging algorithms are tuned to perform best when there is
66 swap space configured.
67 Configuring too little swap can lead to inefficiencies in the VM
68 page scanning code as well as create issues later on if you add
69 more memory to your machine, so don't be shy about it.
70 Swap is a good idea even if you don't think you will ever need it as it
71 allows the
72 machine to page out completely unused data and idle programs (like getty),
73 maximizing the ram available for your activities.
74 .Pp
75 If you intend to use the
76 .Xr swapcache 8
77 facility with a SSD + HDD combination we recommend configuring as much
78 swap space as you can on the SSD.
79 However, keep in mind that each 1GByte of swapcache requires around
80 1MByte of ram, so don't scale your swap beyond the equivalent ram
81 that you reasonably want to eat to support it.
82 .Pp
83 Finally, on larger systems with multiple drives, if the use
84 of SSD swap is not in the cards or if it is and you need higher-than-normal
85 swapcache bandwidth, you can configure swap on up to four drives and
86 the kernel will interleave the storage.
87 The swap partitions on the drives should be approximately the same size.
88 The kernel can handle arbitrary sizes but
89 internal data structures scale to 4 times the largest swap partition.
90 Keeping
91 the swap partitions near the same size will allow the kernel to optimally
92 stripe swap space across the N disks.
93 Do not worry about overdoing it a
94 little, swap space is the saving grace of
95 .Ux
96 and even if you do not normally use much swap, having some allows the system
97 to move idle program data out of ram and allows the machine to more easily
98 handle abnormal runaway programs.
99 However, keep in mind that any sort of swap space failure can lock the
100 system up.
101 Most machines are configured with only one or two swap partitions.
102 .Pp
103 Most
104 .Dx
105 systems have a single HAMMER or HAMMER2 root.
106 PFSs can be used to administratively separate domains for backup purposes
107 but tend to be a hassle otherwise so if you don't need the administrative
108 separation you don't really need to use multiple PFSs.
109 All the PFSs share the same allocation layer so there is no longer a need
110 to size each individual mount.
111 Instead you should review the
112 .Xr hammer 8
113 manual page and use the 'hammer viconfig' facility to adjust snapshot
114 retention and other parameters.
115 By default
116 HAMMER1 keeps 60 days worth of snapshots, and HAMMER2 keeps none.
117 By convention
118 .Pa /build
119 is not backed up and contained only directory trees that do not need
120 to be backed-up or snapshotted.
121 .Pp
122 If a very large work area is desired it is often beneficial to
123 configure it as its own filesystem in a completely independent partition
124 so allocation blowouts (if they occur) do not affect the main system.
125 By convention a large work area is named
126 .Pa /build .
127 Similarly if a machine is going to have a large number of users
128 you might want to separate your
129 .Pa /home
130 out as well.
131 .Pp
132 A number of run-time
133 .Xr mount 8
134 options exist that can help you tune the system.
135 The most obvious and most dangerous one is
136 .Cm async .
137 Do not ever use it; it is far too dangerous.
138 A less dangerous and more
139 useful
140 .Xr mount 8
141 option is called
142 .Cm noatime .
143 .Ux
144 filesystems normally update the last-accessed time of a file or
145 directory whenever it is accessed.
146 However, neither HAMMER nor HAMMER2 implement atime so there is usually
147 no need to mess with this option.
148 The lack of atime updates can create issues with certain programs
149 such as when detecting whether unread mail is present, but
150 applications for the most part no longer depend on it.
151 .Sh SSD SWAP
152 The single most important thing you can do to improve performance is to`
153 have at least one solid-state drive in your system, and to configure your
154 swap space on that drive.
155 If you are using a combination of a smaller SSD and a very larger HDD,
156 you can use
157 .Xr swapcache 8
158 to automatically cache data from your HDD.
159 But even if you do not, having swap space configured on your SSD will
160 significantly improve performance under even modest paging loads.
161 It is particularly useful to configure a significant amount of swap
162 on a workstation, 32GB or more is not uncommon, to handle bloated
163 leaky applications such as browsers.
164 .Sh SYSCTL TUNING
165 .Xr sysctl 8
166 variables permit system behavior to be monitored and controlled at
167 run-time.
168 Some sysctls simply report on the behavior of the system; others allow
169 the system behavior to be modified;
170 some may be set at boot time using
171 .Xr rc.conf 5 ,
172 but most will be set via
173 .Xr sysctl.conf 5 .
174 There are several hundred sysctls in the system, including many that appear
175 to be candidates for tuning but actually are not.
176 In this document we will only cover the ones that have the greatest effect
177 on the system.
178 .Pp
179 The
180 .Va kern.gettimeofday_quick
181 sysctl defaults to 0 (off).  Setting this sysctl to 1 causes
182 .Fn gettimeofday
183 calls in libc to use a tick-granular time from the kpmap instead of making
184 a system call.  Setting this feature can be useful when running benchmarks
185 which make large numbers of
186 .Fn gettimeofday
187 calls, such as postgres.
188 .Pp
189 The
190 .Va kern.ipc.shm_use_phys
191 sysctl defaults to 1 (on) and may be set to 0 (off) or 1 (on).
192 Setting
193 this parameter to 1 will cause all System V shared memory segments to be
194 mapped to unpageable physical RAM.
195 This feature only has an effect if you
196 are either (A) mapping small amounts of shared memory across many (hundreds)
197 of processes, or (B) mapping large amounts of shared memory across any
198 number of processes.
199 This feature allows the kernel to remove a great deal
200 of internal memory management page-tracking overhead at the cost of wiring
201 the shared memory into core, making it unswappable.
202 .Pp
203 The
204 .Va vfs.write_behind
205 sysctl defaults to 1 (on).  This tells the filesystem to issue media
206 writes as full clusters are collected, which typically occurs when writing
207 large sequential files.  The idea is to avoid saturating the buffer
208 cache with dirty buffers when it would not benefit I/O performance.  However,
209 this may stall processes and under certain circumstances you may wish to turn
210 it off.
211 .Pp
212 The
213 .Va vfs.lorunningspace
214 and
215 .Va vfs.hirunningspace
216 sysctls determines how much outstanding write I/O may be queued to
217 disk controllers system wide at any given moment.  The default is
218 usually sufficient, particularly when SSDs are part of the mix.
219 Note that setting too high a value can lead to extremely poor
220 clustering performance.  Do not set this value arbitrarily high!  Also,
221 higher write queueing values may add latency to reads occurring at the same
222 time.
223 The
224 .Va vfs.bufcache_bw
225 controls data cycling within the buffer cache.  I/O bandwidth less than
226 this specification (per second) will cycle into the much larger general
227 VM page cache while I/O bandwidth in excess of this specification will
228 be recycled within the buffer cache, reducing the load on the rest of
229 the VM system at the cost of bypassing normal VM caching mechanisms.
230 The default value is 200 megabytes/s (209715200), which means that the
231 system will try harder to cache data coming off a slower hard drive
232 and less hard trying to cache data coming off a fast SSD.
233 .Pp
234 This parameter is particularly important if you have NVMe drives in
235 your system as these storage devices are capable of transferring
236 well over 2GBytes/sec into the system and can blow normal VM paging
237 and caching algorithms to bits.
238 .Pp
239 There are various other buffer-cache and VM page cache related sysctls.
240 We do not recommend modifying their values.
241 .Pp
242 The
243 .Va net.inet.tcp.sendspace
244 and
245 .Va net.inet.tcp.recvspace
246 sysctls are of particular interest if you are running network intensive
247 applications.
248 They control the amount of send and receive buffer space
249 allowed for any given TCP connection.
250 However,
251 .Dx
252 now auto-tunes these parameters using a number of other related
253 sysctls (run 'sysctl net.inet.tcp' to get a list) and usually
254 no longer need to be tuned manually.
255 We do not recommend
256 increasing or decreasing the defaults if you are managing a very large
257 number of connections.
258 Note that the routing table (see
259 .Xr route 8 )
260 can be used to introduce route-specific send and receive buffer size
261 defaults.
262 .Pp
263 As an additional management tool you can use pipes in your
264 firewall rules (see
265 .Xr ipfw 8 )
266 to limit the bandwidth going to or from particular IP blocks or ports.
267 For example, if you have a T1 you might want to limit your web traffic
268 to 70% of the T1's bandwidth in order to leave the remainder available
269 for mail and interactive use.
270 Normally a heavily loaded web server
271 will not introduce significant latencies into other services even if
272 the network link is maxed out, but enforcing a limit can smooth things
273 out and lead to longer term stability.
274 Many people also enforce artificial
275 bandwidth limitations in order to ensure that they are not charged for
276 using too much bandwidth.
277 .Pp
278 Setting the send or receive TCP buffer to values larger than 65535 will result
279 in a marginal performance improvement unless both hosts support the window
280 scaling extension of the TCP protocol, which is controlled by the
281 .Va net.inet.tcp.rfc1323
282 sysctl.
283 These extensions should be enabled and the TCP buffer size should be set
284 to a value larger than 65536 in order to obtain good performance from
285 certain types of network links; specifically, gigabit WAN links and
286 high-latency satellite links.
287 RFC 1323 support is enabled by default.
288 .Pp
289 The
290 .Va net.inet.tcp.always_keepalive
291 sysctl determines whether or not the TCP implementation should attempt
292 to detect dead TCP connections by intermittently delivering
293 .Dq keepalives
294 on the connection.
295 By default, this is now enabled for all applications.
296 We do not recommend turning it off.
297 The extra network bandwidth is minimal and this feature will clean-up
298 stalled and long-dead connections that might not otherwise be cleaned
299 up.
300 In the past people using dialup connections often did not want to
301 use this feature in order to be able to retain connections across
302 long disconnections, but in modern day the only default that makes
303 sense is for the feature to be turned on.
304 .Pp
305 The
306 .Va net.inet.tcp.delayed_ack
307 TCP feature is largely misunderstood.  Historically speaking this feature
308 was designed to allow the acknowledgement to transmitted data to be returned
309 along with the response.  For example, when you type over a remote shell
310 the acknowledgement to the character you send can be returned along with the
311 data representing the echo of the character.   With delayed acks turned off
312 the acknowledgement may be sent in its own packet before the remote service
313 has a chance to echo the data it just received.  This same concept also
314 applies to any interactive protocol (e.g. SMTP, WWW, POP3) and can cut the
315 number of tiny packets flowing across the network in half.   The
316 .Dx
317 delayed-ack implementation also follows the TCP protocol rule that
318 at least every other packet be acknowledged even if the standard 100ms
319 timeout has not yet passed.  Normally the worst a delayed ack can do is
320 slightly delay the teardown of a connection, or slightly delay the ramp-up
321 of a slow-start TCP connection.  While we aren't sure we believe that
322 the several FAQs related to packages such as SAMBA and SQUID which advise
323 turning off delayed acks may be referring to the slow-start issue.
324 .Pp
325 The
326 .Va net.inet.tcp.inflight_enable
327 sysctl turns on bandwidth delay product limiting for all TCP connections.
328 This feature is now turned on by default and we recommend that it be
329 left on.
330 It will slightly reduce the maximum bandwidth of a connection but the
331 benefits of the feature in reducing packet backlogs at router constriction
332 points are enormous.
333 These benefits make it a whole lot easier for router algorithms to manage
334 QOS for multiple connections.
335 The limiting feature reduces the amount of data built up in intermediate
336 router and switch packet queues as well as reduces the amount of data built
337 up in the local host's interface queue.  With fewer packets queued up,
338 interactive connections, especially over slow modems, will also be able
339 to operate with lower round trip times.  However, note that this feature
340 only affects data transmission (uploading / server-side).  It does not
341 affect data reception (downloading).
342 .Pp
343 The system will attempt to calculate the bandwidth delay product for each
344 connection and limit the amount of data queued to the network to just the
345 amount required to maintain optimum throughput.  This feature is useful
346 if you are serving data over modems, GigE, or high speed WAN links (or
347 any other link with a high bandwidth*delay product), especially if you are
348 also using window scaling or have configured a large send window.
349 .Pp
350 For production use setting
351 .Va net.inet.tcp.inflight_min
352 to at least 6144 may be beneficial.  Note, however, that setting high
353 minimums may effectively disable bandwidth limiting depending on the link.
354 .Pp
355 Adjusting
356 .Va net.inet.tcp.inflight_stab
357 is not recommended.
358 This parameter defaults to 50, representing +5% fudge when calculating the
359 bwnd from the bw.  This fudge is on top of an additional fixed +2*maxseg
360 added to bwnd.  The fudge factor is required to stabilize the algorithm
361 at very high speeds while the fixed 2*maxseg stabilizes the algorithm at
362 low speeds.  If you increase this value excessive packet buffering may occur.
363 .Pp
364 The
365 .Va net.inet.ip.portrange.*
366 sysctls control the port number ranges automatically bound to TCP and UDP
367 sockets.  There are three ranges:  A low range, a default range, and a
368 high range, selectable via an IP_PORTRANGE
369 .Fn setsockopt
370 call.
371 Most network programs use the default range which is controlled by
372 .Va net.inet.ip.portrange.first
373 and
374 .Va net.inet.ip.portrange.last ,
375 which defaults to 1024 and 5000 respectively.  Bound port ranges are
376 used for outgoing connections and it is possible to run the system out
377 of ports under certain circumstances.  This most commonly occurs when you are
378 running a heavily loaded web proxy.  The port range is not an issue
379 when running serves which handle mainly incoming connections such as a
380 normal web server, or has a limited number of outgoing connections such
381 as a mail relay.  For situations where you may run yourself out of
382 ports we recommend increasing
383 .Va net.inet.ip.portrange.last
384 modestly.  A value of 10000 or 20000 or 30000 may be reasonable.  You should
385 also consider firewall effects when changing the port range.  Some firewalls
386 may block large ranges of ports (usually low-numbered ports) and expect systems
387 to use higher ranges of ports for outgoing connections.  For this reason
388 we do not recommend that
389 .Va net.inet.ip.portrange.first
390 be lowered.
391 .Pp
392 The
393 .Va kern.ipc.somaxconn
394 sysctl limits the size of the listen queue for accepting new TCP connections.
395 The default value of 128 is typically too low for robust handling of new
396 connections in a heavily loaded web server environment.
397 For such environments,
398 we recommend increasing this value to 1024 or higher.
399 The service daemon
400 may itself limit the listen queue size (e.g.\&
401 .Xr sendmail 8 ,
402 apache) but will
403 often have a directive in its configuration file to adjust the queue size up.
404 Larger listen queues also do a better job of fending off denial of service
405 attacks.
406 .Pp
407 The
408 .Va kern.maxvnodes
409 specifies how many vnodes and related file structures the kernel will
410 cache.
411 The kernel uses a modestly generous default for this parameter based on
412 available physical memory.
413 You generally do not want to mess with this parameter as it directly
414 effects how well the kernel can cache not only file structures but also
415 the underlying file data.
416 .Pp
417 However, situations may crop up where you wish to cache less filesystem
418 data in order to make more memory available for programs.  Not only will
419 this reduce kernel memory use for vnodes and inodes, it will also have a
420 tendency to reduce the impact of the buffer cache on main memory because
421 recycling a vnode also frees any underlying data that has been cached for
422 that vnode.
423 .Pp
424 It is, in fact, possible for the system to have more files open than the
425 value of this tunable, but as files are closed the system will try to
426 reduce the actual number of cached vnodes to match this value.
427 The read-only
428 .Va kern.openfiles
429 sysctl may be interrogated to determine how many files are currently open
430 on the system.
431 .Pp
432 The
433 .Va vm.swap_idle_enabled
434 sysctl is useful in large multi-user systems where you have lots of users
435 entering and leaving the system and lots of idle processes.
436 Such systems
437 tend to generate a great deal of continuous pressure on free memory reserves.
438 Turning this feature on and adjusting the swapout hysteresis (in idle
439 seconds) via
440 .Va vm.swap_idle_threshold1
441 and
442 .Va vm.swap_idle_threshold2
443 allows you to depress the priority of pages associated with idle processes
444 more quickly than the normal pageout algorithm.
445 This gives a helping hand
446 to the pageout daemon.
447 Do not turn this option on unless you need it,
448 because the tradeoff you are making is to essentially pre-page memory sooner
449 rather than later, eating more swap and disk bandwidth.
450 In a small system
451 this option will have a detrimental effect but in a large system that is
452 already doing moderate paging this option allows the VM system to stage
453 whole processes into and out of memory more easily.
454 .Sh LOADER TUNABLES
455 Some aspects of the system behavior may not be tunable at runtime because
456 memory allocations they perform must occur early in the boot process.
457 To change loader tunables, you must set their values in
458 .Xr loader.conf 5
459 and reboot the system.
460 .Pp
461 .Va kern.maxusers
462 is automatically sized at boot based on the amount of memory available in
463 the system.  The value can be read (but not written) via sysctl.
464 .Pp
465 You can change this value as a loader tunable if the default resource
466 limits are not sufficient.
467 This tunable works primarily by adjusting
468 .Va kern.maxproc ,
469 so you can opt to override that instead.
470 It is generally easier formulate an adjustment to
471 .Va kern.maxproc
472 instead of
473 .Va kern.maxusers .
474 .Pp
475 .Va kern.maxproc
476 controls most kernel auto-scaling components.  If kernel resource limits
477 are not scaled high enough, setting this tunables to a higher value is
478 usually sufficient.
479 Generally speaking you will want to set this tunable to the upper limit
480 for the number of process threads you want the kernel to be able to handle.
481 The kernel may still decide to cap maxproc at a lower value if there is
482 insufficient ram to scale resources as desired.
483 .Pp
484 Only set this tunable if the defaults are not sufficient.
485 Do not use this tunable to try to trim kernel resource limits, you will
486 not actually save much memory by doing so and you will leave the system
487 more vulnerable to DOS attacks and runaway processes.
488 .Pp
489 Setting this tunable will scale the maximum number processes, pipes and
490 sockets, total open files the system can support, and increase mbuf
491 and mbuf-cluster limits.  These other elements can also be separately
492 overridden to fine-tune the setup.  We rcommend setting this tunable
493 first to create a baseline.
494 .Pp
495 Setting a high value presumes that you have enough physical memory to
496 support the resource utilization.  For example, your system would need
497 approximately 128GB of ram to reasonably support a maxproc value of
498 4 million (4000000).  The default maxproc given that much ram will
499 typically be in the 250000 range.
500 .Pp
501 Note that the PID is currently limited to 6 digits, so a system cannot
502 have more than a million processes operating anyway (though the aggregate
503 number of threads can be far greater).
504 And yes, there is in fact no reason why a very well-endowed system
505 couldn't have that many processes.
506 .Pp
507 .Va kern.nbuf
508 sets how many filesystem buffers the kernel should cache.
509 Filesystem buffers can be up to 128KB each.
510 UFS typically uses an 8KB blocksize while HAMMER and HAMMER2 typically
511 uses 64KB.  The system defaults usually suffice for this parameter.
512 Cached buffers represent wired physical memory so specifying a value
513 that is too large can result in excessive kernel memory use, and is also
514 not entirely necessary since the pages backing the buffers are also
515 cached by the VM page cache (which does not use wired memory).
516 The buffer cache significantly improves the hot path for cached file
517 accesses and dirty data.
518 .Pp
519 The kernel reserves (128KB * nbuf) bytes of KVM.  The actual physical
520 memory use depends on the filesystem buffer size.
521 It is generally more flexible to manage the filesystem cache via
522 .Va kern.maxfiles
523 than via
524 .Va kern.nbuf ,
525 but situations do arise where you might want to increase or decrease
526 the latter.
527 .Pp
528 The
529 .Va kern.dfldsiz
530 and
531 .Va kern.dflssiz
532 tunables set the default soft limits for process data and stack size
533 respectively.
534 Processes may increase these up to the hard limits by calling
535 .Xr setrlimit 2 .
536 The
537 .Va kern.maxdsiz ,
538 .Va kern.maxssiz ,
539 and
540 .Va kern.maxtsiz
541 tunables set the hard limits for process data, stack, and text size
542 respectively; processes may not exceed these limits.
543 The
544 .Va kern.sgrowsiz
545 tunable controls how much the stack segment will grow when a process
546 needs to allocate more stack.
547 .Pp
548 .Va kern.ipc.nmbclusters
549 and
550 .Va kern.ipc.nmbjclusters
551 may be adjusted to increase the number of network mbufs the system is
552 willing to allocate.
553 Each normal cluster represents approximately 2K of memory,
554 so a value of 1024 represents 2M of kernel memory reserved for network
555 buffers.
556 Each 'j' cluster is typically 4KB, so a value of 1024 represents 4M of
557 kernel memory.
558 You can do a simple calculation to figure out how many you need but
559 keep in mind that tcp buffer sizing is now more dynamic than it used to
560 be.
561 .Pp
562 The defaults usually suffice but you may want to bump it up on service-heavy
563 machines.
564 Modern machines often need a large number of mbufs to operate services
565 efficiently, values of 65536, even upwards of 262144 or more are common.
566 If you are running a server, it is better to be generous than to be frugal.
567 Remember the memory calculation though.
568 .Pp
569 Under no circumstances
570 should you specify an arbitrarily high value for this parameter, it could
571 lead to a boot-time crash.
572 The
573 .Fl m
574 option to
575 .Xr netstat 1
576 may be used to observe network cluster use.
577 .Sh KERNEL CONFIG TUNING
578 There are a number of kernel options that you may have to fiddle with in
579 a large-scale system.
580 In order to change these options you need to be
581 able to compile a new kernel from source.
582 The
583 .Xr build 7
584 manual page and the handbook are good starting points for learning how to
585 do this.
586 Generally speaking, removing options to trim the size of the kernel
587 is not going to save very much memory on a modern system.
588 In the grand scheme of things, saving a megabyte or two is in the noise
589 on a system that likely has multiple gigabytes of memory.
590 .Pp
591 If your motherboard is AHCI-capable then we strongly recommend turning
592 on AHCI mode in the BIOS if it is not already the default.
593 .Sh CPU, MEMORY, DISK, NETWORK
594 The type of tuning you do depends heavily on where your system begins to
595 bottleneck as load increases.
596 If your system runs out of CPU (idle times
597 are perpetually 0%) then you need to consider upgrading the CPU or moving to
598 an SMP motherboard (multiple CPU's), or perhaps you need to revisit the
599 programs that are causing the load and try to optimize them.
600 If your system
601 is paging to swap a lot you need to consider adding more memory.
602 If your
603 system is saturating the disk you typically see high CPU idle times and
604 total disk saturation.
605 .Xr systat 1
606 can be used to monitor this.
607 There are many solutions to saturated disks:
608 increasing memory for caching, mirroring disks, distributing operations across
609 several machines, and so forth.
610 .Pp
611 Finally, you might run out of network suds.
612 Optimize the network path
613 as much as possible.
614 If you are operating a machine as a router you may need to
615 setup a
616 .Xr pf 4
617 firewall (also see
618 .Xr firewall 7 .
619 .Dx
620 has a very good fair-share queueing algorithm for QOS in
621 .Xr pf 4 .
622 .Sh BULK BUILDING MACHINE SETUP
623 Generally speaking memory is at a premium when doing bulk compiles.
624 Machines dedicated to bulk building usually reduce
625 .Va kern.maxvnodes
626 to 1000000 (1 million) vnodes or lower.  Don't get too cocky here, this
627 parameter should never be reduced below around 100000 on reasonably well
628 endowed machines.
629 .Pp
630 Bulk build setups also often benefit from a relatively large amount
631 of SSD swap, allowing the system to 'burst' high-memory-usage situations
632 while still maintaining optimal concurrency for other periods during the
633 build which do not use as much run-time memory and prefer more parallelism.
634 .Sh SOURCE OF KERNEL MEMORY USAGE
635 The primary sources of kernel memory usage are:
636 .Bl -tag -width ".Va kern.maxvnodes"
637 .It Va kern.maxvnodes
638 The maximum number of cached vnodes in the system.
639 These can eat quite a bit of kernel memory, primarily due to auxiliary
640 structures tracked by the HAMMER filesystem.
641 It is relatively easy to configure a smaller value, but we do not
642 recommend reducing this parameter below 100000.
643 Smaller values directly impact the number of discrete files the
644 kernel can cache data for at once.
645 .It Va kern.ipc.nmbclusters , Va kern.ipc.nmbjclusters
646 Calculate approximately 2KB per normal cluster and 4KB per jumbo
647 cluster.
648 Do not make these values too low or you risk deadlocking the network
649 stack.
650 .It Va kern.nbuf
651 The number of filesystem buffers managed by the kernel.
652 The kernel wires the underlying cached VM pages, typically 8KB (UFS) or
653 64KB (HAMMER) per buffer.
654 .It swap/swapcache
655 Swap memory requires approximately 1MB of physical ram for each 1GB
656 of swap space.
657 When swapcache is used, additional memory may be required to keep
658 VM objects around longer (only really reducable by reducing the
659 value of
660 .Va kern.maxvnodes
661 which you can do post-boot if you desire).
662 .It tmpfs
663 Tmpfs is very useful but keep in mind that while the file data itself
664 is backed by swap, the meta-data (the directory topology) requires
665 wired kernel memory.
666 .It mmu page tables
667 Even though the underlying data pages themselves can be paged to swap,
668 the page tables are usually wired into memory.
669 This can create problems when a large number of processes are
670 .Fn mmap Ns ing
671 very large files.
672 Sometimes turning on
673 .Va machdep.pmap_mmu_optimize
674 suffices to reduce overhead.
675 Page table kernel memory use can be observed by using 'vmstat -z'
676 .It Va kern.ipc.shm_use_phys
677 It is sometimes necessary to force shared memory to use physical memory
678 when running a large database which uses shared memory to implement its
679 own data caching.
680 The use of sysv shared memory in this regard allows the database to
681 distinguish between data which it knows it can access instantly (i.e.
682 without even having to page-in from swap) verses data which it might require
683 and I/O to fetch.
684 .Pp
685 If you use this feature be very careful with regards to the database's
686 shared memory configuration as you will be wiring the memory.
687 .El
688 .Sh SEE ALSO
689 .Xr netstat 1 ,
690 .Xr systat 1 ,
691 .Xr dm 4 ,
692 .Xr dummynet 4 ,
693 .Xr nata 4 ,
694 .Xr pf 4 ,
695 .Xr login.conf 5 ,
696 .Xr pf.conf 5 ,
697 .Xr rc.conf 5 ,
698 .Xr sysctl.conf 5 ,
699 .Xr build 7 ,
700 .Xr firewall 7 ,
701 .Xr hier 7 ,
702 .Xr boot 8 ,
703 .Xr ccdconfig 8 ,
704 .Xr disklabel 8 ,
705 .Xr fsck 8 ,
706 .Xr ifconfig 8 ,
707 .Xr ipfw 8 ,
708 .Xr loader 8 ,
709 .Xr mount 8 ,
710 .Xr newfs 8 ,
711 .Xr route 8 ,
712 .Xr sysctl 8 ,
713 .Xr tunefs 8
714 .Sh HISTORY
715 The
716 .Nm
717 manual page was inherited from
718 .Fx
719 and first appeared in
720 .Fx 4.3 ,
721 May 2001.
722 .Sh AUTHORS
723 The
724 .Nm
725 manual page was originally written by
726 .An Matthew Dillon .