Initial import from FreeBSD RELENG_4:
[games.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 .\" $FreeBSD: src/share/man/man7/tuning.7,v 1.1.2.30 2002/12/17 19:32:08 dillon Exp $
6 .\"
7 .Dd May 25, 2001
8 .Dt TUNING 7
9 .Os
10 .Sh NAME
11 .Nm tuning
12 .Nd performance tuning under FreeBSD
13 .Sh SYSTEM SETUP - DISKLABEL, NEWFS, TUNEFS, SWAP
14 When using
15 .Xr disklabel 8
16 or
17 .Xr sysinstall 8
18 to lay out your filesystems on a hard disk it is important to remember
19 that hard drives can transfer data much more quickly from outer tracks
20 than they can from inner tracks.
21 To take advantage of this you should
22 try to pack your smaller filesystems and swap closer to the outer tracks,
23 follow with the larger filesystems, and end with the largest filesystems.
24 It is also important to size system standard filesystems such that you
25 will not be forced to resize them later as you scale the machine up.
26 I usually create, in order, a 128M root, 1G swap, 128M
27 .Pa /var ,
28 128M
29 .Pa /var/tmp ,
30 3G
31 .Pa /usr ,
32 and use any remaining space for
33 .Pa /home .
34 .Pp
35 You should typically size your swap space to approximately 2x main memory.
36 If you do not have a lot of RAM, though, you will generally want a lot
37 more swap.
38 It is not recommended that you configure any less than
39 256M of swap on a system and you should keep in mind future memory
40 expansion when sizing the swap partition.
41 The kernel's VM paging algorithms are tuned to perform best when there is
42 at least 2x swap versus main memory.
43 Configuring too little swap can lead
44 to inefficiencies in the VM page scanning code as well as create issues
45 later on if you add more memory to your machine.
46 Finally, on larger systems
47 with multiple SCSI disks (or multiple IDE disks operating on different
48 controllers), we strongly recommend that you configure swap on each drive
49 (up to four drives).
50 The swap partitions on the drives should be approximately the same size.
51 The kernel can handle arbitrary sizes but
52 internal data structures scale to 4 times the largest swap partition.
53 Keeping
54 the swap partitions near the same size will allow the kernel to optimally
55 stripe swap space across the N disks.
56 Do not worry about overdoing it a
57 little, swap space is the saving grace of
58 .Ux
59 and even if you do not normally use much swap, it can give you more time to
60 recover from a runaway program before being forced to reboot.
61 .Pp
62 How you size your
63 .Pa /var
64 partition depends heavily on what you intend to use the machine for.
65 This
66 partition is primarily used to hold mailboxes, the print spool, and log
67 files.
68 Some people even make
69 .Pa /var/log
70 its own partition (but except for extreme cases it is not worth the waste
71 of a partition ID).
72 If your machine is intended to act as a mail
73 or print server,
74 or you are running a heavily visited web server, you should consider
75 creating a much larger partition \(en perhaps a gig or more.
76 It is very easy
77 to underestimate log file storage requirements.
78 .Pp
79 Sizing
80 .Pa /var/tmp
81 depends on the kind of temporary file usage you think you will need.
82 128M is
83 the minimum we recommend.
84 Also note that sysinstall will create a
85 .Pa /tmp
86 directory.
87 Dedicating a partition for temporary file storage is important for
88 two reasons: first, it reduces the possibility of filesystem corruption
89 in a crash, and second it reduces the chance of a runaway process that
90 fills up
91 .Oo Pa /var Oc Ns Pa /tmp
92 from blowing up more critical subsystems (mail,
93 logging, etc).
94 Filling up
95 .Oo Pa /var Oc Ns Pa /tmp
96 is a very common problem to have.
97 .Pp
98 In the old days there were differences between
99 .Pa /tmp
100 and
101 .Pa /var/tmp ,
102 but the introduction of
103 .Pa /var
104 (and
105 .Pa /var/tmp )
106 led to massive confusion
107 by program writers so today programs haphazardly use one or the
108 other and thus no real distinction can be made between the two.
109 So it makes sense to have just one temporary directory and
110 softlink to it from the other tmp directory locations.
111 However you handle
112 .Pa /tmp ,
113 the one thing you do not want to do is leave it sitting
114 on the root partition where it might cause root to fill up or possibly
115 corrupt root in a crash/reboot situation.
116 .Pp
117 The
118 .Pa /usr
119 partition holds the bulk of the files required to support the system and
120 a subdirectory within it called
121 .Pa /usr/local
122 holds the bulk of the files installed from the
123 .Xr ports 7
124 hierarchy.
125 If you do not use ports all that much and do not intend to keep
126 system source
127 .Pq Pa /usr/src
128 on the machine, you can get away with
129 a 1 gigabyte
130 .Pa /usr
131 partition.
132 However, if you install a lot of ports
133 (especially window managers and Linux-emulated binaries), we recommend
134 at least a 2 gigabyte
135 .Pa /usr
136 and if you also intend to keep system source
137 on the machine, we recommend a 3 gigabyte
138 .Pa /usr .
139 Do not underestimate the
140 amount of space you will need in this partition, it can creep up and
141 surprise you!
142 .Pp
143 The
144 .Pa /home
145 partition is typically used to hold user-specific data.
146 I usually size it to the remainder of the disk.
147 .Pp
148 Why partition at all?
149 Why not create one big
150 .Pa /
151 partition and be done with it?
152 Then I do not have to worry about undersizing things!
153 Well, there are several reasons this is not a good idea.
154 First,
155 each partition has different operational characteristics and separating them
156 allows the filesystem to tune itself to those characteristics.
157 For example,
158 the root and
159 .Pa /usr
160 partitions are read-mostly, with very little writing, while
161 a lot of reading and writing could occur in
162 .Pa /var
163 and
164 .Pa /var/tmp .
165 By properly
166 partitioning your system fragmentation introduced in the smaller more
167 heavily write-loaded partitions will not bleed over into the mostly-read
168 partitions.
169 Additionally, keeping the write-loaded partitions closer to
170 the edge of the disk (i.e. before the really big partitions instead of after
171 in the partition table) will increase I/O performance in the partitions
172 where you need it the most.
173 Now it is true that you might also need I/O
174 performance in the larger partitions, but they are so large that shifting
175 them more towards the edge of the disk will not lead to a significant
176 performance improvement whereas moving
177 .Pa /var
178 to the edge can have a huge impact.
179 Finally, there are safety concerns.
180 Having a small neat root partition that
181 is essentially read-only gives it a greater chance of surviving a bad crash
182 intact.
183 .Pp
184 Properly partitioning your system also allows you to tune
185 .Xr newfs 8 ,
186 and
187 .Xr tunefs 8
188 parameters.
189 Tuning
190 .Xr newfs 8
191 requires more experience but can lead to significant improvements in
192 performance.
193 There are three parameters that are relatively safe to tune:
194 .Em blocksize , bytes/i-node ,
195 and
196 .Em cylinders/group .
197 .Pp
198 .Fx
199 performs best when using 8K or 16K filesystem block sizes.
200 The default filesystem block size is 16K,
201 which provides best performance for most applications,
202 with the exception of those that perform random access on large files
203 (such as database server software).
204 Such applications tend to perform better with a smaller block size,
205 although modern disk characteristics are such that the performance
206 gain from using a smaller block size may not be worth consideration.
207 Using a block size larger than 16K
208 can cause fragmentation of the buffer cache and
209 lead to lower performance.
210 .Pp
211 The defaults may be unsuitable
212 for a filesystem that requires a very large number of i-nodes
213 or is intended to hold a large number of very small files.
214 Such a filesystem should be created with an 8K or 4K block size.
215 This also requires you to specify a smaller
216 fragment size.
217 We recommend always using a fragment size that is 1/8
218 the block size (less testing has been done on other fragment size factors).
219 The
220 .Xr newfs 8
221 options for this would be
222 .Dq Li "newfs -f 1024 -b 8192 ..." .
223 .Pp
224 If a large partition is intended to be used to hold fewer, larger files, such
225 as database files, you can increase the
226 .Em bytes/i-node
227 ratio which reduces the number of i-nodes (maximum number of files and
228 directories that can be created) for that partition.
229 Decreasing the number
230 of i-nodes in a filesystem can greatly reduce
231 .Xr fsck 8
232 recovery times after a crash.
233 Do not use this option
234 unless you are actually storing large files on the partition, because if you
235 overcompensate you can wind up with a filesystem that has lots of free
236 space remaining but cannot accommodate any more files.
237 Using 32768, 65536, or 262144 bytes/i-node is recommended.
238 You can go higher but
239 it will have only incremental effects on
240 .Xr fsck 8
241 recovery times.
242 For example,
243 .Dq Li "newfs -i 32768 ..." .
244 .Pp
245 .Xr tunefs 8
246 may be used to further tune a filesystem.
247 This command can be run in
248 single-user mode without having to reformat the filesystem.
249 However, this is possibly the most abused program in the system.
250 Many people attempt to
251 increase available filesystem space by setting the min-free percentage to 0.
252 This can lead to severe filesystem fragmentation and we do not recommend
253 that you do this.
254 Really the only
255 .Xr tunefs 8
256 option worthwhile here is turning on
257 .Em softupdates
258 with
259 .Dq Li "tunefs -n enable /filesystem" .
260 (Note: in
261 .Fx 4.5
262 and later, softupdates can be turned on using the
263 .Fl U
264 option to
265 .Xr newfs 8 ,
266 and
267 .Xr sysinstall 8
268 will typically enable softupdates automatically for non-root filesystems).
269 Softupdates drastically improves meta-data performance, mainly file
270 creation and deletion.
271 We recommend enabling softupdates on most filesystems; however, there
272 are two limitations to softupdates that you should be aware of when
273 determining whether to use it on a filesystem.
274 First, softupdates guarantees filesystem consistency in the
275 case of a crash but could very easily be several seconds (even a minute!)
276 behind on pending writes to the physical disk.
277 If you crash you may lose more work
278 than otherwise.
279 Secondly, softupdates delays the freeing of filesystem
280 blocks.
281 If you have a filesystem (such as the root filesystem) which is
282 close to full, doing a major update of it, e.g.\&
283 .Dq Li "make installworld" ,
284 can run it out of space and cause the update to fail.
285 For this reason, softupdates will not be enabled on the root filesystem
286 during a typical install.  There is no loss of performance since the root
287 filesystem is rarely written to.
288 .Pp
289 A number of run-time
290 .Xr mount 8
291 options exist that can help you tune the system.
292 The most obvious and most dangerous one is
293 .Cm async .
294 Do not ever use it; it is far too dangerous.
295 A less dangerous and more
296 useful
297 .Xr mount 8
298 option is called
299 .Cm noatime .
300 .Ux
301 filesystems normally update the last-accessed time of a file or
302 directory whenever it is accessed.
303 This operation is handled in
304 .Fx
305 with a delayed write and normally does not create a burden on the system.
306 However, if your system is accessing a huge number of files on a continuing
307 basis the buffer cache can wind up getting polluted with atime updates,
308 creating a burden on the system.
309 For example, if you are running a heavily
310 loaded web site, or a news server with lots of readers, you might want to
311 consider turning off atime updates on your larger partitions with this
312 .Xr mount 8
313 option.
314 However, you should not gratuitously turn off atime
315 updates everywhere.
316 For example, the
317 .Pa /var
318 filesystem customarily
319 holds mailboxes, and atime (in combination with mtime) is used to
320 determine whether a mailbox has new mail.
321 You might as well leave
322 atime turned on for mostly read-only partitions such as
323 .Pa /
324 and
325 .Pa /usr
326 as well.
327 This is especially useful for
328 .Pa /
329 since some system utilities
330 use the atime field for reporting.
331 .Sh STRIPING DISKS
332 In larger systems you can stripe partitions from several drives together
333 to create a much larger overall partition.
334 Striping can also improve
335 the performance of a filesystem by splitting I/O operations across two
336 or more disks.
337 The
338 .Xr vinum 8
339 and
340 .Xr ccdconfig 8
341 utilities may be used to create simple striped filesystems.
342 Generally
343 speaking, striping smaller partitions such as the root and
344 .Pa /var/tmp ,
345 or essentially read-only partitions such as
346 .Pa /usr
347 is a complete waste of time.
348 You should only stripe partitions that require serious I/O performance,
349 typically
350 .Pa /var , /home ,
351 or custom partitions used to hold databases and web pages.
352 Choosing the proper stripe size is also
353 important.
354 Filesystems tend to store meta-data on power-of-2 boundaries
355 and you usually want to reduce seeking rather than increase seeking.
356 This
357 means you want to use a large off-center stripe size such as 1152 sectors
358 so sequential I/O does not seek both disks and so meta-data is distributed
359 across both disks rather than concentrated on a single disk.
360 If
361 you really need to get sophisticated, we recommend using a real hardware
362 RAID controller from the list of
363 .Fx
364 supported controllers.
365 .Sh SYSCTL TUNING
366 .Xr sysctl 8
367 variables permit system behavior to be monitored and controlled at
368 run-time.
369 Some sysctls simply report on the behavior of the system; others allow
370 the system behavior to be modified;
371 some may be set at boot time using
372 .Xr rc.conf 5 ,
373 but most will be set via
374 .Xr sysctl.conf 5 .
375 There are several hundred sysctls in the system, including many that appear
376 to be candidates for tuning but actually are not.
377 In this document we will only cover the ones that have the greatest effect
378 on the system.
379 .Pp
380 The
381 .Va kern.ipc.shm_use_phys
382 sysctl defaults to 0 (off) and may be set to 0 (off) or 1 (on).
383 Setting
384 this parameter to 1 will cause all System V shared memory segments to be
385 mapped to unpageable physical RAM.
386 This feature only has an effect if you
387 are either (A) mapping small amounts of shared memory across many (hundreds)
388 of processes, or (B) mapping large amounts of shared memory across any
389 number of processes.
390 This feature allows the kernel to remove a great deal
391 of internal memory management page-tracking overhead at the cost of wiring
392 the shared memory into core, making it unswappable.
393 .Pp
394 The
395 .Va vfs.vmiodirenable
396 sysctl defaults to 1 (on).
397 This parameter controls how directories are cached
398 by the system.
399 Most directories are small and use but a single fragment
400 (typically 1K) in the filesystem and even less (typically 512 bytes) in
401 the buffer cache.
402 However, when operating in the default mode the buffer
403 cache will only cache a fixed number of directories even if you have a huge
404 amount of memory.
405 Turning on this sysctl allows the buffer cache to use
406 the VM Page Cache to cache the directories.
407 The advantage is that all of
408 memory is now available for caching directories.
409 The disadvantage is that
410 the minimum in-core memory used to cache a directory is the physical page
411 size (typically 4K) rather than 512 bytes.
412 We recommend turning this option off in memory-constrained environments;
413 however, when on, it will substantially improve the performance of services
414 that manipulate a large number of files.
415 Such services can include web caches, large mail systems, and news systems.
416 Turning on this option will generally not reduce performance even with the
417 wasted memory but you should experiment to find out.
418 .Pp
419 The
420 .Va vfs.write_behind
421 sysctl defaults to 1 (on).  This tells the filesystem to issue media
422 writes as full clusters are collected, which typically occurs when writing
423 large sequential files.  The idea is to avoid saturating the buffer
424 cache with dirty buffers when it would not benefit I/O performance.  However,
425 this may stall processes and under certain circumstances you may wish to turn
426 it off.
427 .Pp
428 The
429 .Va vfs.hirunningspace
430 sysctl determines how much outstanding write I/O may be queued to
431 disk controllers system wide at any given instance.  The default is
432 usually sufficient but on machines with lots of disks you may want to bump
433 it up to four or five megabytes.  Note that setting too high a value
434 (exceeding the buffer cache's write threshold) can lead to extremely
435 bad clustering performance.  Do not set this value arbitrarily high!  Also,
436 higher write queueing values may add latency to reads occuring at the same
437 time.
438 .Pp
439 There are various other buffer-cache and VM page cache related sysctls.
440 We do not recommend modifying these values.
441 As of
442 .Fx 4.3 ,
443 the VM system does an extremely good job tuning itself.
444 .Pp
445 The
446 .Va net.inet.tcp.sendspace
447 and
448 .Va net.inet.tcp.recvspace
449 sysctls are of particular interest if you are running network intensive
450 applications.
451 They control the amount of send and receive buffer space
452 allowed for any given TCP connection.
453 The default sending buffer is 32K; the default receiving buffer
454 is 64K.
455 You can often
456 improve bandwidth utilization by increasing the default at the cost of
457 eating up more kernel memory for each connection.
458 We do not recommend
459 increasing the defaults if you are serving hundreds or thousands of
460 simultaneous connections because it is possible to quickly run the system
461 out of memory due to stalled connections building up.
462 But if you need
463 high bandwidth over a fewer number of connections, especially if you have
464 gigabit Ethernet, increasing these defaults can make a huge difference.
465 You can adjust the buffer size for incoming and outgoing data separately.
466 For example, if your machine is primarily doing web serving you may want
467 to decrease the recvspace in order to be able to increase the
468 sendspace without eating too much kernel memory.
469 Note that the routing table (see
470 .Xr route 8 )
471 can be used to introduce route-specific send and receive buffer size
472 defaults.
473 .Pp
474 As an additional management tool you can use pipes in your
475 firewall rules (see
476 .Xr ipfw 8 )
477 to limit the bandwidth going to or from particular IP blocks or ports.
478 For example, if you have a T1 you might want to limit your web traffic
479 to 70% of the T1's bandwidth in order to leave the remainder available
480 for mail and interactive use.
481 Normally a heavily loaded web server
482 will not introduce significant latencies into other services even if
483 the network link is maxed out, but enforcing a limit can smooth things
484 out and lead to longer term stability.
485 Many people also enforce artificial
486 bandwidth limitations in order to ensure that they are not charged for
487 using too much bandwidth.
488 .Pp
489 Setting the send or receive TCP buffer to values larger then 65535 will result
490 in a marginal performance improvement unless both hosts support the window
491 scaling extension of the TCP protocol, which is controlled by the
492 .Va net.inet.tcp.rfc1323
493 sysctl.
494 These extensions should be enabled and the TCP buffer size should be set
495 to a value larger than 65536 in order to obtain good performance from
496 certain types of network links; specifically, gigabit WAN links and
497 high-latency satellite links.
498 RFC1323 support is enabled by default.
499 .Pp
500 The
501 .Va net.inet.tcp.always_keepalive
502 sysctl determines whether or not the TCP implementation should attempt
503 to detect dead TCP connections by intermittently delivering
504 .Dq keepalives
505 on the connection.
506 By default, this is enabled for all applications; by setting this
507 sysctl to 0, only applications that specifically request keepalives
508 will use them.
509 In most environments, TCP keepalives will improve the management of
510 system state by expiring dead TCP connections, particularly for
511 systems serving dialup users who may not always terminate individual
512 TCP connections before disconnecting from the network.
513 However, in some environments, temporary network outages may be
514 incorrectly identified as dead sessions, resulting in unexpectedly
515 terminated TCP connections.
516 In such environments, setting the sysctl to 0 may reduce the occurrence of
517 TCP session disconnections.
518 .Pp
519 The
520 .Va net.inet.tcp.delayed_ack
521 TCP feature is largly misunderstood.  Historically speaking this feature
522 was designed to allow the acknowledgement to transmitted data to be returned
523 along with the response.  For example, when you type over a remote shell
524 the acknowledgement to the character you send can be returned along with the
525 data representing the echo of the character.   With delayed acks turned off
526 the acknowledgement may be sent in its own packet before the remote service
527 has a chance to echo the data it just received.  This same concept also
528 applies to any interactive protocol (e.g. SMTP, WWW, POP3) and can cut the
529 number of tiny packets flowing across the network in half.   The FreeBSD
530 delayed-ack implementation also follows the TCP protocol rule that
531 at least every other packet be acknowledged even if the standard 100ms
532 timeout has not yet passed.  Normally the worst a delayed ack can do is
533 slightly delay the teardown of a connection, or slightly delay the ramp-up
534 of a slow-start TCP connection.  While we aren't sure we believe that
535 the several FAQs related to packages such as SAMBA and SQUID which advise
536 turning off delayed acks may be refering to the slow-start issue.  In FreeBSD
537 it would be more beneficial to increase the slow-start flightsize via
538 the
539 .Va net.inet.tcp.slowstart_flightsize
540 sysctl rather then disable delayed acks.
541 .Pp
542 The
543 .Va net.inet.tcp.inflight_enable
544 sysctl turns on bandwidth delay product limiting for all TCP connections.
545 The system will attempt to calculate the bandwidth delay product for each
546 connection and limit the amount of data queued to the network to just the
547 amount required to maintain optimum throughput.  This feature is useful
548 if you are serving data over modems, GigE, or high speed WAN links (or
549 any other link with a high bandwidth*delay product), especially if you are
550 also using window scaling or have configured a large send window.  If
551 you enable this option you should also be sure to set
552 .Va net.inet.tcp.inflight_debug
553 to 0 (disable debugging), and for production use setting
554 .Va net.inet.tcp.inflight_min
555 to at least 6144 may be beneficial.  Note, however, that setting high
556 minimums may effectively disable bandwidth limiting depending on the link.
557 The limiting feature reduces the amount of data built up in intermediate
558 router and switch packet queues as well as reduces the amount of data built
559 up in the local host's interface queue.  With fewer packets queued up,
560 interactive connections, especially over slow modems, will also be able
561 to operate with lower round trip times.  However, note that this feature
562 only effects data transmission (uploading / server-side).  It does not
563 effect data reception (downloading).
564 .Pp
565 Adjusting
566 .Va net.inet.tcp.inflight_stab
567 is not recommended.
568 This parameter defaults to 20, representing 2 maximal packets added   
569 to the bandwidth delay product window calculation.  The additional
570 window is required to stabilize the algorithm and improve responsiveness
571 to changing conditions, but it can also result in higher ping times
572 over slow links (though still much lower then you would get without 
573 the inflight algorithm).  In such cases you may
574 wish to try reducing this parameter to 15, 10, or 5, and you may also
575 have to reduce
576 .Va net.inet.tcp.inflight_min
577 (for example, to 3500) to get the desired effect.  Reducing these parameters
578 should be done as a last resort only.
579 .Pp
580 The
581 .Va net.inet.ip.portrange.*
582 sysctls control the port number ranges automatically bound to TCP and UDP
583 sockets.  There are three ranges:  A low range, a default range, and a
584 high range, selectable via an IP_PORTRANGE setsockopt() call.  Most 
585 network programs use the default range which is controlled by
586 .Va net.inet.ip.portrange.first
587 and
588 .Va net.inet.ip.portrange.last ,
589 which defaults to 1024 and 5000 respectively.  Bound port ranges are
590 used for outgoing connections and it is possible to run the system out
591 of ports under certain circumstances.  This most commonly occurs when you are
592 running a heavily loaded web proxy.  The port range is not an issue
593 when running serves which handle mainly incoming connections such as a
594 normal web server, or has a limited number of outgoing connections such
595 as a mail relay.  For situations where you may run yourself out of
596 ports we recommend increasing
597 .Va net.inet.ip.portrange.last
598 modestly.  A value of 10000 or 20000 or 30000 may be reasonable.  You should
599 also consider firewall effects when changing the port range.  Some firewalls
600 may block large ranges of ports (usually low-numbered ports) and expect systems
601 to use higher ranges of ports for outgoing connections.  For this reason
602 we do not recommend that
603 .Va net.inet.ip.portrange.first
604 be lowered.
605 .Pp
606 The
607 .Va kern.ipc.somaxconn
608 sysctl limits the size of the listen queue for accepting new TCP connections.
609 The default value of 128 is typically too low for robust handling of new
610 connections in a heavily loaded web server environment.
611 For such environments,
612 we recommend increasing this value to 1024 or higher.
613 The service daemon
614 may itself limit the listen queue size (e.g.\&
615 .Xr sendmail 8 ,
616 apache) but will
617 often have a directive in its configuration file to adjust the queue size up.
618 Larger listen queues also do a better job of fending off denial of service
619 attacks.
620 .Pp
621 The
622 .Va kern.maxfiles
623 sysctl determines how many open files the system supports.
624 The default is
625 typically a few thousand but you may need to bump this up to ten or twenty
626 thousand if you are running databases or large descriptor-heavy daemons.
627 The read-only
628 .Va kern.openfiles
629 sysctl may be interrogated to determine the current number of open files
630 on the system.
631 .Pp
632 The
633 .Va vm.swap_idle_enabled
634 sysctl is useful in large multi-user systems where you have lots of users
635 entering and leaving the system and lots of idle processes.
636 Such systems
637 tend to generate a great deal of continuous pressure on free memory reserves.
638 Turning this feature on and adjusting the swapout hysteresis (in idle
639 seconds) via
640 .Va vm.swap_idle_threshold1
641 and
642 .Va vm.swap_idle_threshold2
643 allows you to depress the priority of pages associated with idle processes
644 more quickly then the normal pageout algorithm.
645 This gives a helping hand
646 to the pageout daemon.
647 Do not turn this option on unless you need it,
648 because the tradeoff you are making is to essentially pre-page memory sooner
649 rather then later, eating more swap and disk bandwidth.
650 In a small system
651 this option will have a detrimental effect but in a large system that is
652 already doing moderate paging this option allows the VM system to stage
653 whole processes into and out of memory more easily.
654 .Sh LOADER TUNABLES
655 Some aspects of the system behavior may not be tunable at runtime because
656 memory allocations they perform must occur early in the boot process.
657 To change loader tunables, you must set their values in
658 .Xr loader.conf 5
659 and reboot the system.
660 .Pp
661 .Va kern.maxusers
662 controls the scaling of a number of static system tables, including defaults
663 for the maximum number of open files, sizing of network memory resources, etc.
664 As of
665 .Fx 4.5 ,
666 .Va kern.maxusers
667 is automatically sized at boot based on the amount of memory available in
668 the system, and may be determined at run-time by inspecting the value of the
669 read-only
670 .Va kern.maxusers
671 sysctl.
672 Some sites will require larger or smaller values of
673 .Va kern.maxusers
674 and may set it as a loader tunable; values of 64, 128, and 256 are not
675 uncommon.
676 We do not recommend going above 256 unless you need a huge number
677 of file descriptors; many of the tunable values set to their defaults by
678 .Va kern.maxusers
679 may be individually overridden at boot-time or run-time as described
680 elsewhere in this document.
681 Systems older than
682 .Fx 4.4
683 must set this value via the kernel
684 .Xr config 8
685 option
686 .Cd maxusers
687 instead.
688 .Pp
689 .Va kern.ipc.nmbclusters
690 may be adjusted to increase the number of network mbufs the system is
691 willing to allocate.
692 Each cluster represents approximately 2K of memory,
693 so a value of 1024 represents 2M of kernel memory reserved for network
694 buffers.
695 You can do a simple calculation to figure out how many you need.
696 If you have a web server which maxes out at 1000 simultaneous connections,
697 and each connection eats a 16K receive and 16K send buffer, you need
698 approximately 32MB worth of network buffers to deal with it.
699 A good rule of
700 thumb is to multiply by 2, so 32MBx2 = 64MB/2K = 32768.
701 So for this case
702 you would want to set
703 .Va kern.ipc.nmbclusters
704 to 32768.
705 We recommend values between
706 1024 and 4096 for machines with moderates amount of memory, and between 4096
707 and 32768 for machines with greater amounts of memory.
708 Under no circumstances
709 should you specify an arbitrarily high value for this parameter, it could
710 lead to a boot-time crash.
711 The
712 .Fl m
713 option to
714 .Xr netstat 1
715 may be used to observe network cluster use.
716 Older versions of
717 .Fx
718 do not have this tunable and require that the
719 kernel
720 .Xr config 8
721 option
722 .Dv NMBCLUSTERS
723 be set instead.
724 .Pp
725 More and more programs are using the
726 .Xr sendfile 2
727 system call to transmit files over the network.
728 The
729 .Va kern.ipc.nsfbufs
730 sysctl controls the number of filesystem buffers
731 .Xr sendfile 2
732 is allowed to use to perform its work.
733 This parameter nominally scales
734 with
735 .Va kern.maxusers
736 so you should not need to modify this parameter except under extreme
737 circumstances.
738 .Sh KERNEL CONFIG TUNING
739 There are a number of kernel options that you may have to fiddle with in
740 a large-scale system.
741 In order to change these options you need to be
742 able to compile a new kernel from source.
743 The
744 .Xr config 8
745 manual page and the handbook are good starting points for learning how to
746 do this.
747 Generally the first thing you do when creating your own custom
748 kernel is to strip out all the drivers and services you do not use.
749 Removing things like
750 .Dv INET6
751 and drivers you do not have will reduce the size of your kernel, sometimes
752 by a megabyte or more, leaving more memory available for applications.
753 .Pp
754 .Dv SCSI_DELAY
755 and
756 .Dv IDE_DELAY
757 may be used to reduce system boot times.
758 The defaults are fairly high and
759 can be responsible for 15+ seconds of delay in the boot process.
760 Reducing
761 .Dv SCSI_DELAY
762 to 5 seconds usually works (especially with modern drives).
763 Reducing
764 .Dv IDE_DELAY
765 also works but you have to be a little more careful.
766 .Pp
767 There are a number of
768 .Dv *_CPU
769 options that can be commented out.
770 If you only want the kernel to run
771 on a Pentium class CPU, you can easily remove
772 .Dv I386_CPU
773 and
774 .Dv I486_CPU ,
775 but only remove
776 .Dv I586_CPU
777 if you are sure your CPU is being recognized as a Pentium II or better.
778 Some clones may be recognized as a Pentium or even a 486 and not be able
779 to boot without those options.
780 If it works, great!
781 The operating system
782 will be able to better-use higher-end CPU features for MMU, task switching,
783 timebase, and even device operations.
784 Additionally, higher-end CPUs support
785 4MB MMU pages, which the kernel uses to map the kernel itself into memory,
786 increasing its efficiency under heavy syscall loads.
787 .Sh IDE WRITE CACHING
788 .Fx 4.3
789 flirted with turning off IDE write caching.
790 This reduced write bandwidth
791 to IDE disks but was considered necessary due to serious data consistency
792 issues introduced by hard drive vendors.
793 Basically the problem is that
794 IDE drives lie about when a write completes.
795 With IDE write caching turned
796 on, IDE hard drives will not only write data to disk out of order, they
797 will sometimes delay some of the blocks indefinitely under heavy disk
798 load.
799 A crash or power failure can result in serious filesystem
800 corruption.
801 So our default was changed to be safe.
802 Unfortunately, the
803 result was such a huge loss in performance that we caved in and changed the
804 default back to on after the release.
805 You should check the default on
806 your system by observing the
807 .Va hw.ata.wc
808 sysctl variable.
809 If IDE write caching is turned off, you can turn it back
810 on by setting the
811 .Va hw.ata.wc
812 loader tunable to 1.
813 More information on tuning the ATA driver system may be found in the
814 .Xr ata 4
815 man page.
816 .Pp
817 There is a new experimental feature for IDE hard drives called
818 .Va hw.ata.tags
819 (you also set this in the boot loader) which allows write caching to be safely
820 turned on.
821 This brings SCSI tagging features to IDE drives.
822 As of this
823 writing only IBM DPTA and DTLA drives support the feature.
824 Warning!
825 These
826 drives apparently have quality control problems and I do not recommend
827 purchasing them at this time.
828 If you need performance, go with SCSI.
829 .Sh CPU, MEMORY, DISK, NETWORK
830 The type of tuning you do depends heavily on where your system begins to
831 bottleneck as load increases.
832 If your system runs out of CPU (idle times
833 are perpetually 0%) then you need to consider upgrading the CPU or moving to
834 an SMP motherboard (multiple CPU's), or perhaps you need to revisit the
835 programs that are causing the load and try to optimize them.
836 If your system
837 is paging to swap a lot you need to consider adding more memory.
838 If your
839 system is saturating the disk you typically see high CPU idle times and
840 total disk saturation.
841 .Xr systat 1
842 can be used to monitor this.
843 There are many solutions to saturated disks:
844 increasing memory for caching, mirroring disks, distributing operations across
845 several machines, and so forth.
846 If disk performance is an issue and you
847 are using IDE drives, switching to SCSI can help a great deal.
848 While modern
849 IDE drives compare with SCSI in raw sequential bandwidth, the moment you
850 start seeking around the disk SCSI drives usually win.
851 .Pp
852 Finally, you might run out of network suds.
853 The first line of defense for
854 improving network performance is to make sure you are using switches instead
855 of hubs, especially these days where switches are almost as cheap.
856 Hubs
857 have severe problems under heavy loads due to collision backoff and one bad
858 host can severely degrade the entire LAN.
859 Second, optimize the network path
860 as much as possible.
861 For example, in
862 .Xr firewall 7
863 we describe a firewall protecting internal hosts with a topology where
864 the externally visible hosts are not routed through it.
865 Use 100BaseT rather
866 than 10BaseT, or use 1000BaseT rather then 100BaseT, depending on your needs.
867 Most bottlenecks occur at the WAN link (e.g.\&
868 modem, T1, DSL, whatever).
869 If expanding the link is not an option it may be possible to use the
870 .Xr dummynet 4
871 feature to implement peak shaving or other forms of traffic shaping to
872 prevent the overloaded service (such as web services) from affecting other
873 services (such as email), or vice versa.
874 In home installations this could
875 be used to give interactive traffic (your browser,
876 .Xr ssh 1
877 logins) priority
878 over services you export from your box (web services, email).
879 .Sh SEE ALSO
880 .Xr netstat 1 ,
881 .Xr systat 1 ,
882 .Xr ata 4 ,
883 .Xr dummynet 4 ,
884 .Xr login.conf 5 ,
885 .Xr rc.conf 5 ,
886 .Xr sysctl.conf 5 ,
887 .Xr firewall 7 ,
888 .Xr hier 7 ,
889 .Xr ports 7 ,
890 .Xr boot 8 ,
891 .Xr ccdconfig 8 ,
892 .Xr config 8 ,
893 .Xr disklabel 8 ,
894 .Xr fsck 8 ,
895 .Xr ifconfig 8 ,
896 .Xr ipfw 8 ,
897 .Xr loader 8 ,
898 .Xr mount 8 ,
899 .Xr newfs 8 ,
900 .Xr route 8 ,
901 .Xr sysctl 8 ,
902 .Xr sysinstall 8 ,
903 .Xr tunefs 8 ,
904 .Xr vinum 8
905 .Sh HISTORY
906 The
907 .Nm
908 manual page was originally written by
909 .An Matthew Dillon
910 and first appeared
911 in
912 .Fx 4.3 ,
913 May 2001.