⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 configtuning-kernel-limits.html

📁 这是很好的学习嵌入式LINUX的文章
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta name="generator" content="HTML Tidy, see www.w3.org" /><title>Tuning Kernel Limits</title><meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" /><link rel="HOME" title="FreeBSD Handbook" href="index.html" /><link rel="UP" title="Configuration and Tuning" href="config-tuning.html" /><link rel="PREVIOUS" title="Tuning Disks" href="configtuning-disk.html" /><link rel="NEXT" title="Adding Swap Space" href="adding-swap-space.html" /><link rel="STYLESHEET" type="text/css" href="docbook.css" /></head><body class="SECT1" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#840084"alink="#0000FF"><div class="NAVHEADER"><table summary="Header navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><th colspan="3" align="center">FreeBSD Handbook</th></tr><tr><td width="10%" align="left" valign="bottom"><a href="configtuning-disk.html"accesskey="P">Prev</a></td><td width="80%" align="center" valign="bottom">Chapter 11 Configuration and Tuning</td><td width="10%" align="right" valign="bottom"><a href="adding-swap-space.html"accesskey="N">Next</a></td></tr></table><hr align="LEFT" width="100%" /></div><div class="SECT1"><h1 class="SECT1"><a id="CONFIGTUNING-KERNEL-LIMITS"name="CONFIGTUNING-KERNEL-LIMITS">11.13 Tuning Kernel Limits</a></h1><div class="SECT2"><h2 class="SECT2"><a id="FILE-PROCESS-LIMITS" name="FILE-PROCESS-LIMITS">11.13.1File/Process Limits</a></h2><div class="SECT3"><h3 class="SECT3"><a id="KERN-MAXFILES" name="KERN-MAXFILES">11.13.1.1 <varclass="VARNAME">kern.maxfiles</var></a></h3><p><var class="VARNAME">kern.maxfiles</var> can be raised or lowered based upon yoursystem requirements. This variable indicates the maximum number of file descriptors onyour system. When the file descriptor table is full, ``<tt class="ERRORNAME">file: tableis full</tt>'' will show up repeatedly in the system message buffer, which can be viewedwith the <tt class="COMMAND">dmesg</tt> command.</p><p>Each open file, socket, or fifo uses one file descriptor. A large-scale productionserver may easily require many thousands of file descriptors, depending on the kind andnumber of services running concurrently.</p><p><var class="VARNAME">kern.maxfile</var>'s default value is dictated by the <varclass="OPTION">MAXUSERS</var> option in your kernel configuration file. <varclass="VARNAME">kern.maxfiles</var> grows proportionally to the value of <varclass="OPTION">MAXUSERS</var>. When compiling a custom kernel, it is a good idea to setthis kernel configuration option according to the uses of your system. From this number,the kernel is given most of its pre-defined limits. Even though a production machine maynot actually have 256 users connected at once, the resources needed may be similar to ahigh-scale web server.</p><div class="NOTE"><blockquote class="NOTE"><p><b>Note:</b> As of FreeBSD&nbsp;4.5, setting <var class="OPTION">MAXUSERS</var> to<var class="LITERAL">0</var> in your kernel configuration file will choose a reasonabledefault value based on the amount of RAM present in your system.</p></blockquote></div></div><div class="SECT3"><h3 class="SECT3"><a id="AEN16735" name="AEN16735">11.13.1.2 <varclass="VARNAME">kern.ipc.somaxconn</var></a></h3><p>The <var class="VARNAME">kern.ipc.somaxconn</var> sysctl variable limits the size ofthe listen queue for accepting new TCP connections. The default value of <varclass="LITERAL">128</var> is typically too low for robust handling of new connections ina heavily loaded web server environment. For such environments, it is recommended toincrease this value to <var class="LITERAL">1024</var> or higher. The service daemon mayitself limit the listen queue size (e.g. <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=sendmail&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">sendmail</span>(8)</span></a>, or <bclass="APPLICATION">Apache</b>) but will often have a directive in its configuration fileto adjust the queue size. Large listen queues also do a better job of avoiding Denial ofService (<abbr class="ABBREV">DoS</abbr>) attacks.</p></div></div><div class="SECT2"><h2 class="SECT2"><a id="AEN16750" name="AEN16750">11.13.2 Network Limits</a></h2><p>The <var class="LITERAL">NMBCLUSTERS</var> kernel configuration option dictates theamount of network Mbufs available to the system. A heavily-trafficked server with a lownumber of Mbufs will hinder FreeBSD's ability. Each cluster represents approximately2&nbsp;K of memory, so a value of 1024 represents 2 megabytes of kernel memory reservedfor network buffers. A simple calculation can be done to figure out how many are needed.If you have a web server which maxes out at 1000 simultaneous connections, and eachconnection eats a 16&nbsp;K receive and 16&nbsp;K send buffer, you need approximately32&nbsp;MB worth of network buffers to cover the web server. A good rule of thumb is tomultiply by 2, so 2x32&nbsp;MB&nbsp;/&nbsp;2&nbsp;KB&nbsp;=64&nbsp;MB&nbsp;/&nbsp;2&nbsp;kB&nbsp;= 32768. We recommend values between 4096 and 32768for machines with greater amounts of memory. Under no circumstances should you specify anarbitrarily high value for this parameter as it could lead to a boot time crash. The <varclass="OPTION">-m</var> option to <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=netstat&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">netstat</span>(1)</span></a> may be usedto observe network cluster use.</p><p><var class="VARNAME">kern.ipc.nmbclusters</var> loader tunable should be used to tunethis at boot time. Only older versions of FreeBSD will require you to use the <varclass="LITERAL">NMBCLUSTERS</var> kernel <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=config&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">config</span>(8)</span></a> option.</p><p>For busy servers that make extensive use of the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=sendfile&sektion=2"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">sendfile</span>(2)</span></a> systemcall, it may be necessary to increase the number of <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=sendfile&sektion=2"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">sendfile</span>(2)</span></a> buffersvia the <var class="LITERAL">NSFBUFS</var> kernel configuration option or by setting itsvalue in <tt class="FILENAME">/boot/loader.conf</tt> (see <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=loader&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">loader</span>(8)</span></a> fordetails). A common indicator that this parameter needs to be adjusted is when processesare seen in the <var class="LITERAL">sfbufa</var> state. The sysctl variable <varclass="VARNAME">kern.ipc.nsfbufs</var> is a read-only glimpse at the kernel configuredvariable. This parameter nominally scales with <var class="VARNAME">kern.maxusers</var>,however it may be necessary to tune accordingly.</p><div class="IMPORTANT"><blockquote class="IMPORTANT"><p><b>Important:</b> Even though a socket has been marked as non-blocking, calling <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=sendfile&sektion=2"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">sendfile</span>(2)</span></a> on thenon-blocking socket may result in the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=sendfile&sektion=2"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">sendfile</span>(2)</span></a> callblocking until enough <var class="LITERAL">struct sf_buf</var>'s are made available.</p></blockquote></div><div class="SECT3"><h3 class="SECT3"><a id="AEN16788" name="AEN16788">11.13.2.1 <varclass="VARNAME">net.inet.ip.portrange.*</var></a></h3><p>The <var class="VARNAME">net.inet.ip.portrange.*</var> sysctl variables control theport number ranges automatically bound to TCP and UDP sockets. There are three ranges: alow range, a default range, and a high range. Most network programs use the default rangewhich is controlled by the <var class="VARNAME">net.inet.ip.portrange.first</var> and<var class="VARNAME">net.inet.ip.portrange.last</var>, which default to 1024 and 5000,respectively. Bound port ranges are used for outgoing connections, and it is possible torun the system out of ports under certain circumstances. This most commonly occurs whenyou are running a heavily loaded web proxy. The port range is not an issue when runningservers which handle mainly incoming connections, such as a normal web server, or has alimited number of outgoing connections, such as a mail relay. For situations where youmay run yourself out of ports, it is recommended to increase <varclass="VARNAME">net.inet.ip.portrange.last</var> modestly. A value of <varclass="LITERAL">10000</var>, <var class="LITERAL">20000</var> or <varclass="LITERAL">30000</var> may be reasonable. You should also consider firewall effectswhen changing the port range. Some firewalls may block large ranges of ports (usuallylow-numbered ports) and expect systems to use higher ranges of ports for outgoingconnections -- for this reason it is recommended that <varclass="VARNAME">net.inet.ip.portrange.first</var> be lowered.</p></div><div class="SECT3"><h3 class="SECT3"><a id="AEN16802" name="AEN16802">11.13.2.2 TCP Bandwidth DelayProduct</a></h3><p>The TCP Bandwidth Delay Product Limiting is similar to TCP/Vegas in NetBSD. It can beenabled by setting <var class="VARNAME">net.inet.tcp.inflight_enable</var> sysctlvariable to <var class="LITERAL">1</var>. The system will attempt to calculate thebandwidth delay product for each connection and limit the amount of data queued to thenetwork to just the amount required to maintain optimum throughput.</p><p>This feature is useful if you are serving data over modems, Gigabit Ethernet, or evenhigh speed WAN links (or any other link with a high bandwidth delay product), especiallyif you are also using window scaling or have configured a large send window. If youenable this option, you should also be sure to set <varclass="VARNAME">net.inet.tcp.inflight_debug</var> to <var class="LITERAL">0</var>(disable debugging), and for production use setting <varclass="VARNAME">net.inet.tcp.inflight_min</var> to at least <varclass="LITERAL">6144</var> may be beneficial. However, note that setting high minimumsmay effectively disable bandwidth limiting depending on the link. The limiting featurereduces the amount of data built up in intermediate route and switch packet queues aswell as reduces the amount of data built up in the local host's interface queue. Withfewer packets queued up, interactive connections, especially over slow modems, will alsobe able to operate with lower <span class="emphasis"><i class="EMPHASIS">Round TripTimes</i></span>. However, note that this feature only effects data transmission(uploading / server side). It has no effect on data reception (downloading).</p><p>Adjusting <var class="VARNAME">net.inet.tcp.inflight_stab</var> is <spanclass="emphasis"><i class="EMPHASIS">not</i></span> recommended. This parameter defaultsto 20, representing 2 maximal packets added to the bandwidth delay product windowcalculation. The additional window is required to stabilize the algorithm and improveresponsiveness to changing conditions, but it can also result in higher ping times overslow links (though still much lower than you would get without the inflight algorithm).In such cases, you may wish to try reducing this parameter to 15, 10, or 5; and may alsohave to reduce <var class="VARNAME">net.inet.tcp.inflight_min</var> (for example, to3500) to get the desired effect. Reducing these parameters should be done as a lastresort only.</p></div></div></div><div class="NAVFOOTER"><hr align="LEFT" width="100%" /><table summary="Footer navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><td width="33%" align="left" valign="top"><a href="configtuning-disk.html"accesskey="P">Prev</a></td><td width="34%" align="center" valign="top"><a href="index.html"accesskey="H">Home</a></td><td width="33%" align="right" valign="top"><a href="adding-swap-space.html"accesskey="N">Next</a></td></tr><tr><td width="33%" align="left" valign="top">Tuning Disks</td><td width="34%" align="center" valign="top"><a href="config-tuning.html"accesskey="U">Up</a></td><td width="33%" align="right" valign="top">Adding Swap Space</td></tr></table></div><p align="center"><small>This, and other documents, can be downloaded from <ahref="ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/">ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/</a>.</small></p><p align="center"><small>For questions about FreeBSD, read the <ahref="http://www.FreeBSD.org/docs.html">documentation</a> before contacting &#60;<ahref="mailto:questions@FreeBSD.org">questions@FreeBSD.org</a>&#62;.<br />For questions about this documentation, e-mail &#60;<ahref="mailto:doc@FreeBSD.org">doc@FreeBSD.org</a>&#62;.</small></p></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -