📄 configtuning-sysctl.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 with sysctl</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="Configuration Files" href="configtuning-configfiles.html" /><link rel="NEXT" title="Tuning Disks" href="configtuning-disk.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-configfiles.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="configtuning-disk.html"accesskey="N">Next</a></td></tr></table><hr align="LEFT" width="100%" /></div><div class="SECT1"><h1 class="SECT1"><a id="CONFIGTUNING-SYSCTL" name="CONFIGTUNING-SYSCTL">11.11 Tuningwith sysctl</a></h1><p><a href="http://www.FreeBSD.org/cgi/man.cgi?query=sysctl&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">sysctl</span>(8)</span></a> is aninterface that allows you to make changes to a running FreeBSD system. This includes manyadvanced options of the TCP/IP stack and virtual memory system that can dramaticallyimprove performance for an experienced system administrator. Over five hundred systemvariables can be read and set using <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=sysctl&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">sysctl</span>(8)</span></a>.</p><p>At its core, <a href="http://www.FreeBSD.org/cgi/man.cgi?query=sysctl&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">sysctl</span>(8)</span></a> serves twofunctions: to read and to modify system settings.</p><p>To view all readable variables:</p><pre class="SCREEN"><samp class="PROMPT">%</samp> <kbd class="USERINPUT">sysctl -a</kbd></pre><p>To read a particular variable, for example, <varclass="VARNAME">kern.maxproc</var>:</p><pre class="SCREEN"><samp class="PROMPT">%</samp> <kbd class="USERINPUT">sysctl kern.maxproc</kbd>kern.maxproc: 1044</pre><p>To set a particular variable, use the intuitive <varclass="REPLACEABLE">variable</var>=<var class="REPLACEABLE">value</var> syntax:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">sysctl kern.maxfiles=5000</kbd>kern.maxfiles: 2088 -> 5000</pre><p>Settings of sysctl variables are usually either strings, numbers, or booleans (aboolean being <var class="LITERAL">1</var> for yes or a <var class="LITERAL">0</var> forno).</p><p>If you want to set automatically some variables each time the machine boots, add themto the <tt class="FILENAME">/etc/sysctl.conf</tt> file. For more information see the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=sysctl.conf&sektion=5"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">sysctl.conf</span>(5)</span></a> manualpage and the <a href="configtuning-configfiles.html#CONFIGTUNING-SYSCTLCONF">Section11.10.4</a>.</p><div class="SECT2"><h2 class="SECT2"><a id="SYSCTL-READONLY" name="SYSCTL-READONLY">11.11.1 <spanclass="CITEREFENTRY">sysctl(8)</span> Read-only</a></h2><i class="AUTHORGROUP"><span class="CONTRIB">Contributed by</span> Tom Rhodes.</i> <p>In some cases it may be desirable to modify read-only <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=sysctl&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">sysctl</span>(8)</span></a> values.While this is not recommended, it is also sometimes unavoidable.</p><p>For instance on some laptop models the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=cardbus&sektion=4"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">cardbus</span>(4)</span></a> device willnot probe memory ranges, and fail with errors which look similar to:</p><pre class="SCREEN">cbb0: Could not map register memorydevice_probe_and_attach: cbb0 attach returned 12</pre><p>Cases like the one above usually require the modification of some default <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=sysctl&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">sysctl</span>(8)</span></a> settingswhich are set read only. To overcome these situations a user can put <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=sysctl&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">sysctl</span>(8)</span></a> ``OIDs'' intheir local <tt class="FILENAME">/boot/loader.conf</tt>. Default settings are located inthe <tt class="FILENAME">/boot/defaults/loader.conf</tt> file.</p><p>Fixing the problem mentioned above would require a user to set <varclass="OPTION">hw.pci.allow_unsupported_io_range=1</var> in the aforementioned file. Now<a href="http://www.FreeBSD.org/cgi/man.cgi?query=cardbus&sektion=4"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">cardbus</span>(4)</span></a> will workproperly.</p></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-configfiles.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="configtuning-disk.html"accesskey="N">Next</a></td></tr><tr><td width="33%" align="left" valign="top">Configuration Files</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">Tuning Disks</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 <<ahref="mailto:questions@FreeBSD.org">questions@FreeBSD.org</a>>.<br />For questions about this documentation, e-mail <<ahref="mailto:doc@FreeBSD.org">doc@FreeBSD.org</a>>.</small></p></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -