Merge branch 'vendor/OPENSSL'
[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 October 24, 2010
6 .Dt TUNING 7
7 .Os
8 .Sh NAME
9 .Nm tuning
10 .Nd performance tuning under DragonFly
11 .Sh SYSTEM SETUP - DISKLABEL, NEWFS, TUNEFS, SWAP
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
19 .Pa / .
20 The installer usually creates a multitude of PFSs (pseudo filesystems) on
21 the HAMMER partition for /var, /tmp, and numerous other sub-trees.
22 These PFSs exist to ease the management of snapshots and backups.
23 .Pp
24 Generally speaking the
25 .Pa /boot
26 partition should be around 768MB in size.  The minimum recommended
27 is around 350MB, giving you room for backup kernels and alternative
28 boot schemes.
29 .Pp
30 In the old days we recommended that swap be sized to at least 2x main
31 memory.  These days swap is often used for other activities, including
32 .Xr tmpfs 5 .
33 We recommend that swap be sized to the larger of 2x main memory or
34 1GB if you have a fairly small disk and up to 16GB if you have a
35 moderately endowed system and a large drive.
36 If you are on a minimally configured machine you may, of course,
37 configure far less swap or no swap at all but we recommend at least
38 some swap.
39 The kernel's VM paging algorithms are tuned to perform best when there is
40 at least 2x swap versus main memory.
41 Configuring too little swap can lead to inefficiencies in the VM
42 page scanning code as well as create issues later on if you add
43 more memory to your machine.
44 Swap is a good idea even if you don't think you will ever need it as it allows the
45 machine to page out completely unused data from idle programs (like getty),
46 maximizing the ram available for your activities.
47 .Pp
48 If you intend to use the
49 .Xr swapcache 8
50 facility with a SSD we recommend the SSD be configured with at
51 least a 32G swap partition.
52 If you are on a moderately well configured 64-bit system you can
53 size swap even larger.
54 .Pp
55 Finally, on larger systems with multiple drives, if the use
56 of SSD swap is not in the cards, we recommend that you
57 configure swap on each drive (up to four drives).
58 The swap partitions on the drives should be approximately the same size.
59 The kernel can handle arbitrary sizes but
60 internal data structures scale to 4 times the largest swap partition.
61 Keeping
62 the swap partitions near the same size will allow the kernel to optimally
63 stripe swap space across the N disks.
64 Do not worry about overdoing it a
65 little, swap space is the saving grace of
66 .Ux
67 and even if you do not normally use much swap, it can give you more time to
68 recover from a runaway program before being forced to reboot.
69 .Pp
70 Most
71 .Dx
72 systems have a single HAMMER root and use PFSs to break it up into
73 various administrative domains.
74 All the PFSs share the same allocation layer so there is no longer a need
75 to size each individual mount.
76 Instead you should review the
77 .Xr hammer 8
78 manual page and use the 'hammer viconfig' facility to adjust snapshot
79 retention and other parameters.
80 By default
81 HAMMER keeps 60 days worth of snapshots.
82 Usually snapshots are not desired on PFSs such as
83 .Pa /usr/obj
84 or
85 .Pa /tmp
86 since data on these partitions cycles a lot.
87 .Pp
88 If a very large work area is desired it is often beneficial to
89 configure it as a separate HAMMER mount.  If it is integrated into
90 the root mount it should at least be its own HAMMER PFS.
91 We recommend naming the large work area
92 .Pa /build .
93 Similarly if a machine is going to have a large number of users
94 you might want to separate your
95 .Pa /home
96 out as well.
97 .Pp
98 A number of run-time
99 .Xr mount 8
100 options exist that can help you tune the system.
101 The most obvious and most dangerous one is
102 .Cm async .
103 Do not ever use it; it is far too dangerous.
104 A less dangerous and more
105 useful
106 .Xr mount 8
107 option is called
108 .Cm noatime .
109 .Ux
110 filesystems normally update the last-accessed time of a file or
111 directory whenever it is accessed.
112 This operation is handled in
113 .Dx
114 with a delayed write and normally does not create a burden on the system.
115 However, if your system is accessing a huge number of files on a continuing
116 basis the buffer cache can wind up getting polluted with atime updates,
117 creating a burden on the system.
118 For example, if you are running a heavily
119 loaded web site, or a news server with lots of readers, you might want to
120 consider turning off atime updates on your larger partitions with this
121 .Xr mount 8
122 option.
123 You should not gratuitously turn off atime updates everywhere.
124 For example, the
125 .Pa /var
126 filesystem customarily
127 holds mailboxes, and atime (in combination with mtime) is used to
128 determine whether a mailbox has new mail.
129 .Sh STRIPING DISKS
130 In larger systems you can stripe partitions from several drives together
131 to create a much larger overall partition.
132 Striping can also improve
133 the performance of a filesystem by splitting I/O operations across two
134 or more disks.
135 The
136 .Xr vinum 8 ,
137 .Xr lvm 8 ,
138 and
139 .Xr dm 8
140 subsystems may be used to create simple striped filesystems.
141 We have deprecated
142 .Xr ccd 4 .
143 Generally
144 speaking, striping smaller partitions such as the root and
145 .Pa /var/tmp ,
146 or essentially read-only partitions such as
147 .Pa /usr
148 is a complete waste of time.
149 You should only stripe partitions that require serious I/O performance.
150 We recommend that such partitions be completely separate mounts
151 and not use the same storage media as your root mount.
152 .Pp
153 I should reiterate that last comment.  Do not stripe your boot+root.
154 Just about everything in there will be cached in system memory anyway.
155 Neither would I recommend RAIDing your root.
156 If robustness is needed placing your boot, swap, and root on a SSD
157 which has about the same MTBF as your motherboard, then RAIDing everything
158 which requires significant amounts of storage, should be sufficient.
159 There isn't much point making the boot/swap/root storage even more redundant
160 when the motherboard itself has no redundancy.
161 When a high level of total system redundancy is required you need to be
162 thinking more about having multiple physical machines that back each
163 other up.
164 .Pp
165 When striping multiple disks always partition in multiples of at
166 least 8 megabytes and use at least a 128KB stripe.
167 A 256KB stripe is probably even better.
168 This will avoid mis-aligning HAMMER big-blocks (which are 8MB)
169 or causing a single I/O cluster from crossing a stripe boundary.
170 .Dx
171 will issue a significant amount of read-ahead, upwards of a megabyte
172 or more if it determines accesses are linear enough, which is
173 sufficient to issue concurrent I/O across multiple stripes.
174 .Sh SYSCTL TUNING
175 .Xr sysctl 8
176 variables permit system behavior to be monitored and controlled at
177 run-time.
178 Some sysctls simply report on the behavior of the system; others allow
179 the system behavior to be modified;
180 some may be set at boot time using
181 .Xr rc.conf 5 ,
182 but most will be set via
183 .Xr sysctl.conf 5 .
184 There are several hundred sysctls in the system, including many that appear
185 to be candidates for tuning but actually are not.
186 In this document we will only cover the ones that have the greatest effect
187 on the system.
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.hirunningspace
214 sysctl determines how much outstanding write I/O may be queued to
215 disk controllers system wide at any given instance.  The default is
216 usually sufficient but on machines with lots of disks you may want to bump
217 it up to four or five megabytes.  Note that setting too high a value
218 (exceeding the buffer cache's write threshold) can lead to extremely
219 bad clustering performance.  Do not set this value arbitrarily high!  Also,
220 higher write queueing values may add latency to reads occurring at the same
221 time.
222 .Pp
223 There are various other buffer-cache and VM page cache related sysctls.
224 We do not recommend modifying these values.
225 As of
226 .Fx 4.3 ,
227 the VM system does an extremely good job tuning itself.
228 .Pp
229 The
230 .Va net.inet.tcp.sendspace
231 and
232 .Va net.inet.tcp.recvspace
233 sysctls are of particular interest if you are running network intensive
234 applications.
235 They control the amount of send and receive buffer space
236 allowed for any given TCP connection.
237 The default sending buffer is 32K; the default receiving buffer
238 is 64K.
239 You can often
240 improve bandwidth utilization by increasing the default at the cost of
241 eating up more kernel memory for each connection.
242 We do not recommend
243 increasing the defaults if you are serving hundreds or thousands of
244 simultaneous connections because it is possible to quickly run the system
245 out of memory due to stalled connections building up.
246 But if you need
247 high bandwidth over a fewer number of connections, especially if you have
248 gigabit Ethernet, increasing these defaults can make a huge difference.
249 You can adjust the buffer size for incoming and outgoing data separately.
250 For example, if your machine is primarily doing web serving you may want
251 to decrease the recvspace in order to be able to increase the
252 sendspace without eating too much kernel memory.
253 Note that the routing table (see
254 .Xr route 8 )
255 can be used to introduce route-specific send and receive buffer size
256 defaults.
257 .Pp
258 As an additional management tool you can use pipes in your
259 firewall rules (see
260 .Xr ipfw 8 )
261 to limit the bandwidth going to or from particular IP blocks or ports.
262 For example, if you have a T1 you might want to limit your web traffic
263 to 70% of the T1's bandwidth in order to leave the remainder available
264 for mail and interactive use.
265 Normally a heavily loaded web server
266 will not introduce significant latencies into other services even if
267 the network link is maxed out, but enforcing a limit can smooth things
268 out and lead to longer term stability.
269 Many people also enforce artificial
270 bandwidth limitations in order to ensure that they are not charged for
271 using too much bandwidth.
272 .Pp
273 Setting the send or receive TCP buffer to values larger than 65535 will result
274 in a marginal performance improvement unless both hosts support the window
275 scaling extension of the TCP protocol, which is controlled by the
276 .Va net.inet.tcp.rfc1323
277 sysctl.
278 These extensions should be enabled and the TCP buffer size should be set
279 to a value larger than 65536 in order to obtain good performance from
280 certain types of network links; specifically, gigabit WAN links and
281 high-latency satellite links.
282 RFC 1323 support is enabled by default.
283 .Pp
284 The
285 .Va net.inet.tcp.always_keepalive
286 sysctl determines whether or not the TCP implementation should attempt
287 to detect dead TCP connections by intermittently delivering
288 .Dq keepalives
289 on the connection.
290 By default, this is disabled for all applications, only applications
291 that specifically request keepalives will use them.
292 In most environments, TCP keepalives will improve the management of
293 system state by expiring dead TCP connections, particularly for
294 systems serving dialup users who may not always terminate individual
295 TCP connections before disconnecting from the network.
296 However, in some environments, temporary network outages may be
297 incorrectly identified as dead sessions, resulting in unexpectedly
298 terminated TCP connections.
299 In such environments, setting the sysctl to 0 may reduce the occurrence of
300 TCP session disconnections.
301 .Pp
302 The
303 .Va net.inet.tcp.delayed_ack
304 TCP feature is largely misunderstood.  Historically speaking this feature
305 was designed to allow the acknowledgement to transmitted data to be returned
306 along with the response.  For example, when you type over a remote shell
307 the acknowledgement to the character you send can be returned along with the
308 data representing the echo of the character.   With delayed acks turned off
309 the acknowledgement may be sent in its own packet before the remote service
310 has a chance to echo the data it just received.  This same concept also
311 applies to any interactive protocol (e.g. SMTP, WWW, POP3) and can cut the
312 number of tiny packets flowing across the network in half.   The
313 .Dx
314 delayed-ack implementation also follows the TCP protocol rule that
315 at least every other packet be acknowledged even if the standard 100ms
316 timeout has not yet passed.  Normally the worst a delayed ack can do is
317 slightly delay the teardown of a connection, or slightly delay the ramp-up
318 of a slow-start TCP connection.  While we aren't sure we believe that
319 the several FAQs related to packages such as SAMBA and SQUID which advise
320 turning off delayed acks may be referring to the slow-start issue.
321 .Pp
322 The
323 .Va net.inet.tcp.inflight_enable
324 sysctl turns on bandwidth delay product limiting for all TCP connections.
325 The system will attempt to calculate the bandwidth delay product for each
326 connection and limit the amount of data queued to the network to just the
327 amount required to maintain optimum throughput.  This feature is useful
328 if you are serving data over modems, GigE, or high speed WAN links (or
329 any other link with a high bandwidth*delay product), especially if you are
330 also using window scaling or have configured a large send window.  If
331 you enable this option you should also be sure to set
332 .Va net.inet.tcp.inflight_debug
333 to 0 (disable debugging), and for production use setting
334 .Va net.inet.tcp.inflight_min
335 to at least 6144 may be beneficial.  Note, however, that setting high
336 minimums may effectively disable bandwidth limiting depending on the link.
337 The limiting feature reduces the amount of data built up in intermediate
338 router and switch packet queues as well as reduces the amount of data built
339 up in the local host's interface queue.  With fewer packets queued up,
340 interactive connections, especially over slow modems, will also be able
341 to operate with lower round trip times.  However, note that this feature
342 only affects data transmission (uploading / server-side).  It does not
343 affect data reception (downloading).
344 .Pp
345 Adjusting
346 .Va net.inet.tcp.inflight_stab
347 is not recommended.
348 This parameter defaults to 50, representing +5% fudge when calculating the
349 bwnd from the bw.  This fudge is on top of an additional fixed +2*maxseg
350 added to bwnd.  The fudge factor is required to stabilize the algorithm
351 at very high speeds while the fixed 2*maxseg stabilizes the algorithm at
352 low speeds.  If you increase this value excessive packet buffering may occur.
353 .Pp
354 The
355 .Va net.inet.ip.portrange.*
356 sysctls control the port number ranges automatically bound to TCP and UDP
357 sockets.  There are three ranges:  A low range, a default range, and a
358 high range, selectable via an IP_PORTRANGE
359 .Fn setsockopt
360 call.
361 Most network programs use the default range which is controlled by
362 .Va net.inet.ip.portrange.first
363 and
364 .Va net.inet.ip.portrange.last ,
365 which defaults to 1024 and 5000 respectively.  Bound port ranges are
366 used for outgoing connections and it is possible to run the system out
367 of ports under certain circumstances.  This most commonly occurs when you are
368 running a heavily loaded web proxy.  The port range is not an issue
369 when running serves which handle mainly incoming connections such as a
370 normal web server, or has a limited number of outgoing connections such
371 as a mail relay.  For situations where you may run yourself out of
372 ports we recommend increasing
373 .Va net.inet.ip.portrange.last
374 modestly.  A value of 10000 or 20000 or 30000 may be reasonable.  You should
375 also consider firewall effects when changing the port range.  Some firewalls
376 may block large ranges of ports (usually low-numbered ports) and expect systems
377 to use higher ranges of ports for outgoing connections.  For this reason
378 we do not recommend that
379 .Va net.inet.ip.portrange.first
380 be lowered.
381 .Pp
382 The
383 .Va kern.ipc.somaxconn
384 sysctl limits the size of the listen queue for accepting new TCP connections.
385 The default value of 128 is typically too low for robust handling of new
386 connections in a heavily loaded web server environment.
387 For such environments,
388 we recommend increasing this value to 1024 or higher.
389 The service daemon
390 may itself limit the listen queue size (e.g.\&
391 .Xr sendmail 8 ,
392 apache) but will
393 often have a directive in its configuration file to adjust the queue size up.
394 Larger listen queues also do a better job of fending off denial of service
395 attacks.
396 .Pp
397 The
398 .Va kern.maxfiles
399 sysctl determines how many open files the system supports.
400 The default is
401 typically a few thousand but you may need to bump this up to ten or twenty
402 thousand if you are running databases or large descriptor-heavy daemons.
403 The read-only
404 .Va kern.openfiles
405 sysctl may be interrogated to determine the current number of open files
406 on the system.
407 .Pp
408 The
409 .Va vm.swap_idle_enabled
410 sysctl is useful in large multi-user systems where you have lots of users
411 entering and leaving the system and lots of idle processes.
412 Such systems
413 tend to generate a great deal of continuous pressure on free memory reserves.
414 Turning this feature on and adjusting the swapout hysteresis (in idle
415 seconds) via
416 .Va vm.swap_idle_threshold1
417 and
418 .Va vm.swap_idle_threshold2
419 allows you to depress the priority of pages associated with idle processes
420 more quickly than the normal pageout algorithm.
421 This gives a helping hand
422 to the pageout daemon.
423 Do not turn this option on unless you need it,
424 because the tradeoff you are making is to essentially pre-page memory sooner
425 rather than later, eating more swap and disk bandwidth.
426 In a small system
427 this option will have a detrimental effect but in a large system that is
428 already doing moderate paging this option allows the VM system to stage
429 whole processes into and out of memory more easily.
430 .Sh LOADER TUNABLES
431 Some aspects of the system behavior may not be tunable at runtime because
432 memory allocations they perform must occur early in the boot process.
433 To change loader tunables, you must set their values in
434 .Xr loader.conf 5
435 and reboot the system.
436 .Pp
437 .Va kern.maxusers
438 controls the scaling of a number of static system tables, including defaults
439 for the maximum number of open files, sizing of network memory resources, etc.
440 On
441 .Dx ,
442 .Va kern.maxusers
443 is automatically sized at boot based on the amount of memory available in
444 the system, and may be determined at run-time by inspecting the value of the
445 read-only
446 .Va kern.maxusers
447 sysctl.
448 Some sites will require larger or smaller values of
449 .Va kern.maxusers
450 and may set it as a loader tunable; values of 64, 128, and 256 are not
451 uncommon.
452 We do not recommend going above 256 unless you need a huge number
453 of file descriptors; many of the tunable values set to their defaults by
454 .Va kern.maxusers
455 may be individually overridden at boot-time or run-time as described
456 elsewhere in this document.
457 .Pp
458 The
459 .Va kern.dfldsiz
460 and
461 .Va kern.dflssiz
462 tunables set the default soft limits for process data and stack size
463 respectively.
464 Processes may increase these up to the hard limits by calling
465 .Xr setrlimit 2 .
466 The
467 .Va kern.maxdsiz ,
468 .Va kern.maxssiz ,
469 and
470 .Va kern.maxtsiz
471 tunables set the hard limits for process data, stack, and text size
472 respectively; processes may not exceed these limits.
473 The
474 .Va kern.sgrowsiz
475 tunable controls how much the stack segment will grow when a process
476 needs to allocate more stack.
477 .Pp
478 .Va kern.ipc.nmbclusters
479 may be adjusted to increase the number of network mbufs the system is
480 willing to allocate.
481 Each cluster represents approximately 2K of memory,
482 so a value of 1024 represents 2M of kernel memory reserved for network
483 buffers.
484 You can do a simple calculation to figure out how many you need.
485 If you have a web server which maxes out at 1000 simultaneous connections,
486 and each connection eats a 16K receive and 16K send buffer, you need
487 approximately 32MB worth of network buffers to deal with it.
488 A good rule of
489 thumb is to multiply by 2, so 32MBx2 = 64MB/2K = 32768.
490 So for this case
491 you would want to set
492 .Va kern.ipc.nmbclusters
493 to 32768.
494 We recommend values between
495 1024 and 4096 for machines with moderates amount of memory, and between 4096
496 and 32768 for machines with greater amounts of memory.
497 Under no circumstances
498 should you specify an arbitrarily high value for this parameter, it could
499 lead to a boot-time crash.
500 The
501 .Fl m
502 option to
503 .Xr netstat 1
504 may be used to observe network cluster use.
505 .Sh KERNEL CONFIG TUNING
506 There are a number of kernel options that you may have to fiddle with in
507 a large-scale system.
508 In order to change these options you need to be
509 able to compile a new kernel from source.
510 The
511 .Xr config 8
512 manual page and the handbook are good starting points for learning how to
513 do this.
514 Generally the first thing you do when creating your own custom
515 kernel is to strip out all the drivers and services you do not use.
516 Removing things like
517 .Dv INET6
518 and drivers you do not have will reduce the size of your kernel, sometimes
519 by a megabyte or more, leaving more memory available for applications.
520 .Pp
521 If your motherboard is AHCI-capable then we strongly recommend turning
522 on AHCI mode.
523 .Sh CPU, MEMORY, DISK, NETWORK
524 The type of tuning you do depends heavily on where your system begins to
525 bottleneck as load increases.
526 If your system runs out of CPU (idle times
527 are perpetually 0%) then you need to consider upgrading the CPU or moving to
528 an SMP motherboard (multiple CPU's), or perhaps you need to revisit the
529 programs that are causing the load and try to optimize them.
530 If your system
531 is paging to swap a lot you need to consider adding more memory.
532 If your
533 system is saturating the disk you typically see high CPU idle times and
534 total disk saturation.
535 .Xr systat 1
536 can be used to monitor this.
537 There are many solutions to saturated disks:
538 increasing memory for caching, mirroring disks, distributing operations across
539 several machines, and so forth.
540 If disk performance is an issue and you
541 are using IDE drives, switching to SCSI can help a great deal.
542 While modern
543 IDE drives compare with SCSI in raw sequential bandwidth, the moment you
544 start seeking around the disk SCSI drives usually win.
545 .Pp
546 Finally, you might run out of network suds.
547 The first line of defense for
548 improving network performance is to make sure you are using switches instead
549 of hubs, especially these days where switches are almost as cheap.
550 Hubs
551 have severe problems under heavy loads due to collision backoff and one bad
552 host can severely degrade the entire LAN.
553 Second, optimize the network path
554 as much as possible.
555 For example, in
556 .Xr firewall 7
557 we describe a firewall protecting internal hosts with a topology where
558 the externally visible hosts are not routed through it.
559 Use 100BaseT rather
560 than 10BaseT, or use 1000BaseT rather than 100BaseT, depending on your needs.
561 Most bottlenecks occur at the WAN link (e.g.\&
562 modem, T1, DSL, whatever).
563 If expanding the link is not an option it may be possible to use the
564 .Xr dummynet 4
565 feature to implement peak shaving or other forms of traffic shaping to
566 prevent the overloaded service (such as web services) from affecting other
567 services (such as email), or vice versa.
568 In home installations this could
569 be used to give interactive traffic (your browser,
570 .Xr ssh 1
571 logins) priority
572 over services you export from your box (web services, email).
573 .Sh SEE ALSO
574 .Xr netstat 1 ,
575 .Xr systat 1 ,
576 .Xr dummynet 4 ,
577 .Xr nata 4 ,
578 .Xr login.conf 5 ,
579 .Xr rc.conf 5 ,
580 .Xr sysctl.conf 5 ,
581 .Xr firewall 7 ,
582 .Xr hier 7 ,
583 .Xr boot 8 ,
584 .Xr ccdconfig 8 ,
585 .Xr config 8 ,
586 .Xr disklabel 8 ,
587 .Xr fsck 8 ,
588 .Xr ifconfig 8 ,
589 .Xr ipfw 8 ,
590 .Xr loader 8 ,
591 .Xr mount 8 ,
592 .Xr newfs 8 ,
593 .Xr route 8 ,
594 .Xr sysctl 8 ,
595 .Xr tunefs 8 ,
596 .Xr vinum 8
597 .Sh HISTORY
598 The
599 .Nm
600 manual page was originally written by
601 .An Matthew Dillon
602 and first appeared
603 in
604 .Fx 4.3 ,
605 May 2001.