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