xref: /freebsd/share/man/man7/tuning.7 (revision aa77200569e397d6ff1fdb4d255d0fa254d0a128)
1.\" Copyright (C) 2001 Matthew Dillon. All rights reserved.
2.\"
3.\" Redistribution and use in source and binary forms, with or without
4.\" modification, are permitted provided that the following conditions
5.\" are met:
6.\" 1. Redistributions of source code must retain the above copyright
7.\"    notice, this list of conditions and the following disclaimer.
8.\" 2. Redistributions in binary form must reproduce the above copyright
9.\"    notice, this list of conditions and the following disclaimer in the
10.\"    documentation and/or other materials provided with the distribution.
11.\"
12.\" THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15.\" ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
16.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22.\" SUCH DAMAGE.
23.\"
24.\" $FreeBSD$
25.\"
26.Dd October 20, 2012
27.Dt TUNING 7
28.Os
29.Sh NAME
30.Nm tuning
31.Nd performance tuning under FreeBSD
32.Sh SYSTEM SETUP - DISKLABEL, NEWFS, TUNEFS, SWAP
33The swap partition should typically be approximately 2x the size of
34main memory
35for systems with less than 4GB of RAM, or approximately equal to
36the size of main memory
37if you have more.
38Keep in mind future memory
39expansion when sizing the swap partition.
40Configuring too little swap can lead
41to inefficiencies in the VM page scanning code as well as create issues
42later on if you add more memory to your machine.
43On larger systems
44with multiple SCSI disks (or multiple IDE disks operating on different
45controllers), configure swap on each drive.
46The swap partitions on the drives should be approximately the same size.
47The kernel can handle arbitrary sizes but
48internal data structures scale to 4 times the largest swap partition.
49Keeping
50the swap partitions near the same size will allow the kernel to optimally
51stripe swap space across the N disks.
52Do not worry about overdoing it a
53little, swap space is the saving grace of
54.Ux
55and even if you do not normally use much swap, it can give you more time to
56recover from a runaway program before being forced to reboot.
57.Pp
58It is not a good idea to make one large partition.
59First,
60each partition has different operational characteristics and separating them
61allows the file system to tune itself to those characteristics.
62For example,
63the root and
64.Pa /usr
65partitions are read-mostly, with very little writing, while
66a lot of reading and writing could occur in
67.Pa /var/tmp .
68By properly
69partitioning your system fragmentation introduced in the smaller more
70heavily write-loaded partitions will not bleed over into the mostly-read
71partitions.
72.Pp
73Properly partitioning your system also allows you to tune
74.Xr newfs 8 ,
75and
76.Xr tunefs 8
77parameters.
78The only
79.Xr tunefs 8
80option worthwhile turning on is
81.Em softupdates
82with
83.Dq Li "tunefs -n enable /filesystem" .
84Softupdates drastically improves meta-data performance, mainly file
85creation and deletion.
86We recommend enabling softupdates on most file systems; however, there
87are two limitations to softupdates that you should be aware of when
88determining whether to use it on a file system.
89First, softupdates guarantees file system consistency in the
90case of a crash but could very easily be several seconds (even a minute!\&)
91behind on pending write to the physical disk.
92If you crash you may lose more work
93than otherwise.
94Secondly, softupdates delays the freeing of file system
95blocks.
96If you have a file system (such as the root file system) which is
97close to full, doing a major update of it, e.g.,\&
98.Dq Li "make installworld" ,
99can run it out of space and cause the update to fail.
100For this reason, softupdates will not be enabled on the root file system
101during a typical install.
102There is no loss of performance since the root
103file system is rarely written to.
104.Pp
105A number of run-time
106.Xr mount 8
107options exist that can help you tune the system.
108The most obvious and most dangerous one is
109.Cm async .
110Only use this option in conjunction with
111.Xr gjournal 8 ,
112as it is far too dangerous on a normal file system.
113A less dangerous and more
114useful
115.Xr mount 8
116option is called
117.Cm noatime .
118.Ux
119file systems normally update the last-accessed time of a file or
120directory whenever it is accessed.
121This operation is handled in
122.Fx
123with a delayed write and normally does not create a burden on the system.
124However, if your system is accessing a huge number of files on a continuing
125basis the buffer cache can wind up getting polluted with atime updates,
126creating a burden on the system.
127For example, if you are running a heavily
128loaded web site, or a news server with lots of readers, you might want to
129consider turning off atime updates on your larger partitions with this
130.Xr mount 8
131option.
132However, you should not gratuitously turn off atime
133updates everywhere.
134For example, the
135.Pa /var
136file system customarily
137holds mailboxes, and atime (in combination with mtime) is used to
138determine whether a mailbox has new mail.
139You might as well leave
140atime turned on for mostly read-only partitions such as
141.Pa /
142and
143.Pa /usr
144as well.
145This is especially useful for
146.Pa /
147since some system utilities
148use the atime field for reporting.
149.Sh STRIPING DISKS
150In larger systems you can stripe partitions from several drives together
151to create a much larger overall partition.
152Striping can also improve
153the performance of a file system by splitting I/O operations across two
154or more disks.
155The
156.Xr gstripe 8 ,
157.Xr gvinum 8 ,
158and
159.Xr ccdconfig 8
160utilities may be used to create simple striped file systems.
161Generally
162speaking, striping smaller partitions such as the root and
163.Pa /var/tmp ,
164or essentially read-only partitions such as
165.Pa /usr
166is a complete waste of time.
167You should only stripe partitions that require serious I/O performance,
168typically
169.Pa /var , /home ,
170or custom partitions used to hold databases and web pages.
171Choosing the proper stripe size is also
172important.
173File systems tend to store meta-data on power-of-2 boundaries
174and you usually want to reduce seeking rather than increase seeking.
175This
176means you want to use a large off-center stripe size such as 1152 sectors
177so sequential I/O does not seek both disks and so meta-data is distributed
178across both disks rather than concentrated on a single disk.
179If
180you really need to get sophisticated, we recommend using a real hardware
181RAID controller from the list of
182.Fx
183supported controllers.
184.Sh SYSCTL TUNING
185.Xr sysctl 8
186variables permit system behavior to be monitored and controlled at
187run-time.
188Some sysctls simply report on the behavior of the system; others allow
189the system behavior to be modified;
190some may be set at boot time using
191.Xr rc.conf 5 ,
192but most will be set via
193.Xr sysctl.conf 5 .
194There are several hundred sysctls in the system, including many that appear
195to be candidates for tuning but actually are not.
196In this document we will only cover the ones that have the greatest effect
197on the system.
198.Pp
199The
200.Va vm.overcommit
201sysctl defines the overcommit behaviour of the vm subsystem.
202The virtual memory system always does accounting of the swap space
203reservation, both total for system and per-user.
204Corresponding values
205are available through sysctl
206.Va vm.swap_total ,
207that gives the total bytes available for swapping, and
208.Va vm.swap_reserved ,
209that gives number of bytes that may be needed to back all currently
210allocated anonymous memory.
211.Pp
212Setting bit 0 of the
213.Va vm.overcommit
214sysctl causes the virtual memory system to return failure
215to the process when allocation of memory causes
216.Va vm.swap_reserved
217to exceed
218.Va vm.swap_total .
219Bit 1 of the sysctl enforces
220.Dv RLIMIT_SWAP
221limit
222(see
223.Xr getrlimit 2 ) .
224Root is exempt from this limit.
225Bit 2 allows to count most of the physical
226memory as allocatable, except wired and free reserved pages
227(accounted by
228.Va vm.stats.vm.v_free_target
229and
230.Va vm.stats.vm.v_wire_count
231sysctls, respectively).
232.Pp
233The
234.Va kern.ipc.maxpipekva
235loader tunable is used to set a hard limit on the
236amount of kernel address space allocated to mapping of pipe buffers.
237Use of the mapping allows the kernel to eliminate a copy of the
238data from writer address space into the kernel, directly copying
239the content of mapped buffer to the reader.
240Increasing this value to a higher setting, such as `25165824' might
241improve performance on systems where space for mapping pipe buffers
242is quickly exhausted.
243This exhaustion is not fatal; however, and it will only cause pipes
244to fall back to using double-copy.
245.Pp
246The
247.Va kern.ipc.shm_use_phys
248sysctl defaults to 0 (off) and may be set to 0 (off) or 1 (on).
249Setting
250this parameter to 1 will cause all System V shared memory segments to be
251mapped to unpageable physical RAM.
252This feature only has an effect if you
253are either (A) mapping small amounts of shared memory across many (hundreds)
254of processes, or (B) mapping large amounts of shared memory across any
255number of processes.
256This feature allows the kernel to remove a great deal
257of internal memory management page-tracking overhead at the cost of wiring
258the shared memory into core, making it unswappable.
259.Pp
260The
261.Va vfs.vmiodirenable
262sysctl defaults to 1 (on).
263This parameter controls how directories are cached
264by the system.
265Most directories are small and use but a single fragment
266(typically 2K) in the file system and even less (typically 512 bytes) in
267the buffer cache.
268However, when operating in the default mode the buffer
269cache will only cache a fixed number of directories even if you have a huge
270amount of memory.
271Turning on this sysctl allows the buffer cache to use
272the VM Page Cache to cache the directories.
273The advantage is that all of
274memory is now available for caching directories.
275The disadvantage is that
276the minimum in-core memory used to cache a directory is the physical page
277size (typically 4K) rather than 512 bytes.
278We recommend turning this option off in memory-constrained environments;
279however, when on, it will substantially improve the performance of services
280that manipulate a large number of files.
281Such services can include web caches, large mail systems, and news systems.
282Turning on this option will generally not reduce performance even with the
283wasted memory but you should experiment to find out.
284.Pp
285The
286.Va vfs.write_behind
287sysctl defaults to 1 (on).
288This tells the file system to issue media
289writes as full clusters are collected, which typically occurs when writing
290large sequential files.
291The idea is to avoid saturating the buffer
292cache with dirty buffers when it would not benefit I/O performance.
293However,
294this may stall processes and under certain circumstances you may wish to turn
295it off.
296.Pp
297The
298.Va vfs.hirunningspace
299sysctl determines how much outstanding write I/O may be queued to
300disk controllers system-wide at any given time.
301It is used by the UFS file system.
302The default is self-tuned and
303usually sufficient but on machines with advanced controllers and lots
304of disks this may be tuned up to match what the controllers buffer.
305Configuring this setting to match tagged queuing capabilities of
306controllers or drives with average IO size used in production works
307best (for example: 16 MiB will use 128 tags with IO requests of 128 KiB).
308Note that setting too high a value
309(exceeding the buffer cache's write threshold) can lead to extremely
310bad clustering performance.
311Do not set this value arbitrarily high!
312Higher write queuing values may also add latency to reads occurring at
313the same time.
314.Pp
315The
316.Va vfs.read_max
317sysctl governs VFS read-ahead and is expressed as the number of blocks
318to pre-read if the heuristics algorithm decides that the reads are
319issued sequentially.
320It is used by the UFS, ext2fs and msdosfs file systems.
321With the default UFS block size of 32 KiB, a setting of 64 will allow
322speculatively reading up to 2 MiB.
323This setting may be increased to get around disk I/O latencies, especially
324where these latencies are large such as in virtual machine emulated
325environments.
326It may be tuned down in specific cases where the I/O load is such that
327read-ahead adversely affects performance or where system memory is really
328low.
329.Pp
330The
331.Va vfs.ncsizefactor
332sysctl defines how large VFS namecache may grow.
333The number of currently allocated entries in namecache is provided by
334.Va debug.numcache
335sysctl and the condition
336debug.numcache < kern.maxvnodes * vfs.ncsizefactor
337is adhered to.
338.Pp
339The
340.Va vfs.ncnegfactor
341sysctl defines how many negative entries VFS namecache is allowed to create.
342The number of currently allocated negative entries is provided by
343.Va debug.numneg
344sysctl and the condition
345vfs.ncnegfactor * debug.numneg < debug.numcache
346is adhered to.
347.Pp
348There are various other buffer-cache and VM page cache related sysctls.
349We do not recommend modifying these values.
350As of
351.Fx 4.3 ,
352the VM system does an extremely good job tuning itself.
353.Pp
354The
355.Va net.inet.tcp.sendspace
356and
357.Va net.inet.tcp.recvspace
358sysctls are of particular interest if you are running network intensive
359applications.
360They control the amount of send and receive buffer space
361allowed for any given TCP connection.
362The default sending buffer is 32K; the default receiving buffer
363is 64K.
364You can often
365improve bandwidth utilization by increasing the default at the cost of
366eating up more kernel memory for each connection.
367We do not recommend
368increasing the defaults if you are serving hundreds or thousands of
369simultaneous connections because it is possible to quickly run the system
370out of memory due to stalled connections building up.
371But if you need
372high bandwidth over a fewer number of connections, especially if you have
373gigabit Ethernet, increasing these defaults can make a huge difference.
374You can adjust the buffer size for incoming and outgoing data separately.
375For example, if your machine is primarily doing web serving you may want
376to decrease the recvspace in order to be able to increase the
377sendspace without eating too much kernel memory.
378Note that the routing table (see
379.Xr route 8 )
380can be used to introduce route-specific send and receive buffer size
381defaults.
382.Pp
383As an additional management tool you can use pipes in your
384firewall rules (see
385.Xr ipfw 8 )
386to limit the bandwidth going to or from particular IP blocks or ports.
387For example, if you have a T1 you might want to limit your web traffic
388to 70% of the T1's bandwidth in order to leave the remainder available
389for mail and interactive use.
390Normally a heavily loaded web server
391will not introduce significant latencies into other services even if
392the network link is maxed out, but enforcing a limit can smooth things
393out and lead to longer term stability.
394Many people also enforce artificial
395bandwidth limitations in order to ensure that they are not charged for
396using too much bandwidth.
397.Pp
398Setting the send or receive TCP buffer to values larger than 65535 will result
399in a marginal performance improvement unless both hosts support the window
400scaling extension of the TCP protocol, which is controlled by the
401.Va net.inet.tcp.rfc1323
402sysctl.
403These extensions should be enabled and the TCP buffer size should be set
404to a value larger than 65536 in order to obtain good performance from
405certain types of network links; specifically, gigabit WAN links and
406high-latency satellite links.
407RFC1323 support is enabled by default.
408.Pp
409The
410.Va net.inet.tcp.always_keepalive
411sysctl determines whether or not the TCP implementation should attempt
412to detect dead TCP connections by intermittently delivering
413.Dq keepalives
414on the connection.
415By default, this is enabled for all applications; by setting this
416sysctl to 0, only applications that specifically request keepalives
417will use them.
418In most environments, TCP keepalives will improve the management of
419system state by expiring dead TCP connections, particularly for
420systems serving dialup users who may not always terminate individual
421TCP connections before disconnecting from the network.
422However, in some environments, temporary network outages may be
423incorrectly identified as dead sessions, resulting in unexpectedly
424terminated TCP connections.
425In such environments, setting the sysctl to 0 may reduce the occurrence of
426TCP session disconnections.
427.Pp
428The
429.Va net.inet.tcp.delayed_ack
430TCP feature is largely misunderstood.
431Historically speaking, this feature
432was designed to allow the acknowledgement to transmitted data to be returned
433along with the response.
434For example, when you type over a remote shell,
435the acknowledgement to the character you send can be returned along with the
436data representing the echo of the character.
437With delayed acks turned off,
438the acknowledgement may be sent in its own packet, before the remote service
439has a chance to echo the data it just received.
440This same concept also
441applies to any interactive protocol (e.g.,\& SMTP, WWW, POP3), and can cut the
442number of tiny packets flowing across the network in half.
443The
444.Fx
445delayed ACK implementation also follows the TCP protocol rule that
446at least every other packet be acknowledged even if the standard 100ms
447timeout has not yet passed.
448Normally the worst a delayed ACK can do is
449slightly delay the teardown of a connection, or slightly delay the ramp-up
450of a slow-start TCP connection.
451While we are not sure we believe that
452the several FAQs related to packages such as SAMBA and SQUID which advise
453turning off delayed acks may be referring to the slow-start issue.
454In
455.Fx ,
456it would be more beneficial to increase the slow-start flightsize via
457the
458.Va net.inet.tcp.slowstart_flightsize
459sysctl rather than disable delayed acks.
460.Pp
461The
462.Va net.inet.tcp.inflight.enable
463sysctl turns on bandwidth delay product limiting for all TCP connections.
464The system will attempt to calculate the bandwidth delay product for each
465connection and limit the amount of data queued to the network to just the
466amount required to maintain optimum throughput.
467This feature is useful
468if you are serving data over modems, GigE, or high speed WAN links (or
469any other link with a high bandwidth*delay product), especially if you are
470also using window scaling or have configured a large send window.
471If you enable this option, you should also be sure to set
472.Va net.inet.tcp.inflight.debug
473to 0 (disable debugging), and for production use setting
474.Va net.inet.tcp.inflight.min
475to at least 6144 may be beneficial.
476Note however, that setting high
477minimums may effectively disable bandwidth limiting depending on the link.
478The limiting feature reduces the amount of data built up in intermediate
479router and switch packet queues as well as reduces the amount of data built
480up in the local host's interface queue.
481With fewer packets queued up,
482interactive connections, especially over slow modems, will also be able
483to operate with lower round trip times.
484However, note that this feature
485only affects data transmission (uploading / server-side).
486It does not
487affect data reception (downloading).
488.Pp
489Adjusting
490.Va net.inet.tcp.inflight.stab
491is not recommended.
492This parameter defaults to 20, representing 2 maximal packets added
493to the bandwidth delay product window calculation.
494The additional
495window is required to stabilize the algorithm and improve responsiveness
496to changing conditions, but it can also result in higher ping times
497over slow links (though still much lower than you would get without
498the inflight algorithm).
499In such cases you may
500wish to try reducing this parameter to 15, 10, or 5, and you may also
501have to reduce
502.Va net.inet.tcp.inflight.min
503(for example, to 3500) to get the desired effect.
504Reducing these parameters
505should be done as a last resort only.
506.Pp
507The
508.Va net.inet.ip.portrange.*
509sysctls control the port number ranges automatically bound to TCP and UDP
510sockets.
511There are three ranges: a low range, a default range, and a
512high range, selectable via the
513.Dv IP_PORTRANGE
514.Xr setsockopt 2
515call.
516Most
517network programs use the default range which is controlled by
518.Va net.inet.ip.portrange.first
519and
520.Va net.inet.ip.portrange.last ,
521which default to 49152 and 65535, respectively.
522Bound port ranges are
523used for outgoing connections, and it is possible to run the system out
524of ports under certain circumstances.
525This most commonly occurs when you are
526running a heavily loaded web proxy.
527The port range is not an issue
528when running a server which handles mainly incoming connections, such as a
529normal web server, or has a limited number of outgoing connections, such
530as a mail relay.
531For situations where you may run out of ports,
532we recommend decreasing
533.Va net.inet.ip.portrange.first
534modestly.
535A range of 10000 to 30000 ports may be reasonable.
536You should also consider firewall effects when changing the port range.
537Some firewalls
538may block large ranges of ports (usually low-numbered ports) and expect systems
539to use higher ranges of ports for outgoing connections.
540By default
541.Va net.inet.ip.portrange.last
542is set at the maximum allowable port number.
543.Pp
544The
545.Va kern.ipc.somaxconn
546sysctl limits the size of the listen queue for accepting new TCP connections.
547The default value of 128 is typically too low for robust handling of new
548connections in a heavily loaded web server environment.
549For such environments,
550we recommend increasing this value to 1024 or higher.
551The service daemon
552may itself limit the listen queue size (e.g.,\&
553.Xr sendmail 8 ,
554apache) but will
555often have a directive in its configuration file to adjust the queue size up.
556Larger listen queues also do a better job of fending off denial of service
557attacks.
558.Pp
559The
560.Va kern.maxfiles
561sysctl determines how many open files the system supports.
562The default is
563typically a few thousand but you may need to bump this up to ten or twenty
564thousand if you are running databases or large descriptor-heavy daemons.
565The read-only
566.Va kern.openfiles
567sysctl may be interrogated to determine the current number of open files
568on the system.
569.Pp
570The
571.Va vm.swap_idle_enabled
572sysctl is useful in large multi-user systems where you have lots of users
573entering and leaving the system and lots of idle processes.
574Such systems
575tend to generate a great deal of continuous pressure on free memory reserves.
576Turning this feature on and adjusting the swapout hysteresis (in idle
577seconds) via
578.Va vm.swap_idle_threshold1
579and
580.Va vm.swap_idle_threshold2
581allows you to depress the priority of pages associated with idle processes
582more quickly then the normal pageout algorithm.
583This gives a helping hand
584to the pageout daemon.
585Do not turn this option on unless you need it,
586because the tradeoff you are making is to essentially pre-page memory sooner
587rather than later, eating more swap and disk bandwidth.
588In a small system
589this option will have a detrimental effect but in a large system that is
590already doing moderate paging this option allows the VM system to stage
591whole processes into and out of memory more easily.
592.Sh LOADER TUNABLES
593Some aspects of the system behavior may not be tunable at runtime because
594memory allocations they perform must occur early in the boot process.
595To change loader tunables, you must set their values in
596.Xr loader.conf 5
597and reboot the system.
598.Pp
599.Va kern.maxusers
600controls the scaling of a number of static system tables, including defaults
601for the maximum number of open files, sizing of network memory resources, etc.
602As of
603.Fx 4.5 ,
604.Va kern.maxusers
605is automatically sized at boot based on the amount of memory available in
606the system, and may be determined at run-time by inspecting the value of the
607read-only
608.Va kern.maxusers
609sysctl.
610Some sites will require larger or smaller values of
611.Va kern.maxusers
612and may set it as a loader tunable; values of 64, 128, and 256 are not
613uncommon.
614We do not recommend going above 256 unless you need a huge number
615of file descriptors; many of the tunable values set to their defaults by
616.Va kern.maxusers
617may be individually overridden at boot-time or run-time as described
618elsewhere in this document.
619Systems older than
620.Fx 4.4
621must set this value via the kernel
622.Xr config 8
623option
624.Cd maxusers
625instead.
626.Pp
627The
628.Va kern.dfldsiz
629and
630.Va kern.dflssiz
631tunables set the default soft limits for process data and stack size
632respectively.
633Processes may increase these up to the hard limits by calling
634.Xr setrlimit 2 .
635The
636.Va kern.maxdsiz ,
637.Va kern.maxssiz ,
638and
639.Va kern.maxtsiz
640tunables set the hard limits for process data, stack, and text size
641respectively; processes may not exceed these limits.
642The
643.Va kern.sgrowsiz
644tunable controls how much the stack segment will grow when a process
645needs to allocate more stack.
646.Pp
647.Va kern.ipc.nmbclusters
648may be adjusted to increase the number of network mbufs the system is
649willing to allocate.
650Each cluster represents approximately 2K of memory,
651so a value of 1024 represents 2M of kernel memory reserved for network
652buffers.
653You can do a simple calculation to figure out how many you need.
654If you have a web server which maxes out at 1000 simultaneous connections,
655and each connection eats a 16K receive and 16K send buffer, you need
656approximately 32MB worth of network buffers to deal with it.
657A good rule of
658thumb is to multiply by 2, so 32MBx2 = 64MB/2K = 32768.
659So for this case
660you would want to set
661.Va kern.ipc.nmbclusters
662to 32768.
663We recommend values between
6641024 and 4096 for machines with moderates amount of memory, and between 4096
665and 32768 for machines with greater amounts of memory.
666Under no circumstances
667should you specify an arbitrarily high value for this parameter, it could
668lead to a boot-time crash.
669The
670.Fl m
671option to
672.Xr netstat 1
673may be used to observe network cluster use.
674Older versions of
675.Fx
676do not have this tunable and require that the
677kernel
678.Xr config 8
679option
680.Dv NMBCLUSTERS
681be set instead.
682.Pp
683More and more programs are using the
684.Xr sendfile 2
685system call to transmit files over the network.
686The
687.Va kern.ipc.nsfbufs
688sysctl controls the number of file system buffers
689.Xr sendfile 2
690is allowed to use to perform its work.
691This parameter nominally scales
692with
693.Va kern.maxusers
694so you should not need to modify this parameter except under extreme
695circumstances.
696See the
697.Sx TUNING
698section in the
699.Xr sendfile 2
700manual page for details.
701.Sh KERNEL CONFIG TUNING
702There are a number of kernel options that you may have to fiddle with in
703a large-scale system.
704In order to change these options you need to be
705able to compile a new kernel from source.
706The
707.Xr config 8
708manual page and the handbook are good starting points for learning how to
709do this.
710Generally the first thing you do when creating your own custom
711kernel is to strip out all the drivers and services you do not use.
712Removing things like
713.Dv INET6
714and drivers you do not have will reduce the size of your kernel, sometimes
715by a megabyte or more, leaving more memory available for applications.
716.Pp
717.Dv SCSI_DELAY
718may be used to reduce system boot times.
719The defaults are fairly high and
720can be responsible for 5+ seconds of delay in the boot process.
721Reducing
722.Dv SCSI_DELAY
723to something below 5 seconds could work (especially with modern drives).
724.Pp
725There are a number of
726.Dv *_CPU
727options that can be commented out.
728If you only want the kernel to run
729on a Pentium class CPU, you can easily remove
730.Dv I486_CPU ,
731but only remove
732.Dv I586_CPU
733if you are sure your CPU is being recognized as a Pentium II or better.
734Some clones may be recognized as a Pentium or even a 486 and not be able
735to boot without those options.
736If it works, great!
737The operating system
738will be able to better use higher-end CPU features for MMU, task switching,
739timebase, and even device operations.
740Additionally, higher-end CPUs support
7414MB MMU pages, which the kernel uses to map the kernel itself into memory,
742increasing its efficiency under heavy syscall loads.
743.Sh CPU, MEMORY, DISK, NETWORK
744The type of tuning you do depends heavily on where your system begins to
745bottleneck as load increases.
746If your system runs out of CPU (idle times
747are perpetually 0%) then you need to consider upgrading the CPU
748or perhaps you need to revisit the
749programs that are causing the load and try to optimize them.
750If your system
751is paging to swap a lot you need to consider adding more memory.
752If your
753system is saturating the disk you typically see high CPU idle times and
754total disk saturation.
755.Xr systat 1
756can be used to monitor this.
757There are many solutions to saturated disks:
758increasing memory for caching, mirroring disks, distributing operations across
759several machines, and so forth.
760If disk performance is an issue and you
761are using IDE drives, switching to SCSI can help a great deal.
762While modern
763IDE drives compare with SCSI in raw sequential bandwidth, the moment you
764start seeking around the disk SCSI drives usually win.
765.Pp
766Finally, you might run out of network suds.
767Optimize the network path
768as much as possible.
769For example, in
770.Xr firewall 7
771we describe a firewall protecting internal hosts with a topology where
772the externally visible hosts are not routed through it.
773Use 1000BaseT rather
774than 100BaseT, depending on your needs.
775Most bottlenecks occur at the WAN link (e.g.,\&
776modem, T1, DSL, whatever).
777If expanding the link is not an option it may be possible to use the
778.Xr dummynet 4
779feature to implement peak shaving or other forms of traffic shaping to
780prevent the overloaded service (such as web services) from affecting other
781services (such as email), or vice versa.
782In home installations this could
783be used to give interactive traffic (your browser,
784.Xr ssh 1
785logins) priority
786over services you export from your box (web services, email).
787.Sh SEE ALSO
788.Xr netstat 1 ,
789.Xr systat 1 ,
790.Xr sendfile 2 ,
791.Xr ata 4 ,
792.Xr dummynet 4 ,
793.Xr login.conf 5 ,
794.Xr rc.conf 5 ,
795.Xr sysctl.conf 5 ,
796.Xr firewall 7 ,
797.Xr eventtimers 7 ,
798.Xr hier 7 ,
799.Xr ports 7 ,
800.Xr boot 8 ,
801.Xr bsdinstall 8 ,
802.Xr bsdlabel 8 ,
803.Xr ccdconfig 8 ,
804.Xr config 8 ,
805.Xr fsck 8 ,
806.Xr gjournal 8 ,
807.Xr gstripe 8 ,
808.Xr gvinum 8 ,
809.Xr ifconfig 8 ,
810.Xr ipfw 8 ,
811.Xr loader 8 ,
812.Xr mount 8 ,
813.Xr newfs 8 ,
814.Xr route 8 ,
815.Xr sysctl 8 ,
816.Xr tunefs 8
817.Sh HISTORY
818The
819.Nm
820manual page was originally written by
821.An Matthew Dillon
822and first appeared
823in
824.Fx 4.3 ,
825May 2001.
826The manual page was greatly modified by
827.An Eitan Adler Aq eadler@FreeBSD.org
828