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

📄 configtuning-disk.html

📁 FreeBSD操作系统的详细使用手册
💻 HTML
📖 第 1 页 / 共 2 页
字号:
class="CITEREFENTRY"><span class="REFENTRYTITLE">tunefs</span>(8)</span></a> while it ismounted. A good time to enable Soft Updates is before any partitions have been mounted,in single-user mode.</p><div class="NOTE"><blockquote class="NOTE"><p><b>Note:</b> As of FreeBSD&nbsp;4.5, it is possible to enable Soft Updates atfilesystem creation time, through use of the <var class="LITERAL">-U</var> option to <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=newfs&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">newfs</span>(8)</span></a>.</p></blockquote></div><p>Soft Updates drastically improves meta-data performance, mainly file creation anddeletion, through the use of a memory cache. We recommend to use Soft Updates on all ofyour file systems. There are two downsides to Soft Updates that you should be aware of:First, Soft Updates guarantees filesystem consistency in the case of a crash but couldvery easily be several seconds (even a minute!) behind updating the physical disk. Ifyour system crashes you may lose more work than otherwise. Secondly, Soft Updates delaysthe freeing of filesystem blocks. If you have a filesystem (such as the root filesystem)which is almost full, performing a major update, such as <tt class="COMMAND">makeinstallworld</tt>, can cause the filesystem to run out of space and the update tofail.</p><div class="SECT3"><h3 class="SECT3"><a id="AEN16662" name="AEN16662">11.12.2.1 More Details about SoftUpdates</a></h3><p>There are two traditional approaches to writing a file systems meta-data back to disk.(Meta-data updates are updates to non-content data like inodes or directories.)</p><p>Historically, the default behavior was to write out meta-data updates synchronously.If a directory had been changed, the system waited until the change was actually writtento disk. The file data buffers (file contents) were passed through the buffer cache andbacked up to disk later on asynchronously. The advantage of this implementation is thatit operates safely. If there is a failure during an update, the meta-data are always in aconsistent state. A file is either created completely or not at all. If the data blocksof a file did not find their way out of the buffer cache onto the disk by the time of thecrash, <a href="http://www.FreeBSD.org/cgi/man.cgi?query=fsck&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">fsck</span>(8)</span></a> is able torecognize this and repair the filesystem by setting the file length to 0. Additionally,the implementation is clear and simple. The disadvantage is that meta-data changes areslow. An <tt class="COMMAND">rm -r</tt>, for instance, touches all the files in adirectory sequentially, but each directory change (deletion of a file) will be writtensynchronously to the disk. This includes updates to the directory itself, to the inodetable, and possibly to indirect blocks allocated by the file. Similar considerationsapply for unrolling large hierarchies (<tt class="COMMAND">tar -x</tt>).</p><p>The second case is asynchronous meta-data updates. This is the default forLinux/ext2fs and <tt class="COMMAND">mount -o async</tt> for *BSD ufs. All meta-dataupdates are simply being passed through the buffer cache too, that is, they will beintermixed with the updates of the file content data. The advantage of thisimplementation is there is no need to wait until each meta-data update has been writtento disk, so all operations which cause huge amounts of meta-data updates work much fasterthan in the synchronous case. Also, the implementation is still clear and simple, sothere is a low risk for bugs creeping into the code. The disadvantage is that there is noguarantee at all for a consistent state of the filesystem. If there is a failure duringan operation that updated large amounts of meta-data (like a power failure, or someonepressing the reset button), the filesystem will be left in an unpredictable state. Thereis no opportunity to examine the state of the filesystem when the system comes up again;the data blocks of a file could already have been written to the disk while the updatesof the inode table or the associated directory were not. It is actually impossible toimplement a <tt class="COMMAND">fsck</tt> which is able to clean up the resulting chaos(because the necessary information is not available on the disk). If the filesystem hasbeen damaged beyond repair, the only choice is to use <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=newfs&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">newfs</span>(8)</span></a> on it andrestore it from backup.</p><p>The usual solution for this problem was to implement <span class="emphasis"><iclass="EMPHASIS">dirty region logging</i></span>, which is also referred to as <spanclass="emphasis"><i class="EMPHASIS">journaling</i></span>, although that term is notused consistently and is occasionally applied to other forms of transaction logging aswell. Meta-data updates are still written synchronously, but only into a small region ofthe disk. Later on they will be moved to their proper location. Because the logging areais a small, contiguous region on the disk, there are no long distances for the disk headsto move, even during heavy operations, so these operations are quicker than synchronousupdates. Additionally the complexity of the implementation is fairly limited, so the riskof bugs being present is low. A disadvantage is that all meta-data are written twice(once into the logging region and once to the proper location) so for normal work, aperformance ``pessimization'' might result. On the other hand, in case of a crash, allpending meta-data operations can be quickly either rolled-back or completed from thelogging area after the system comes up again, resulting in a fast filesystem startup.</p><p>Kirk McKusick, the developer of Berkeley FFS, solved this problem with Soft Updates:all pending meta-data updates are kept in memory and written out to disk in a sortedsequence (``ordered meta-data updates''). This has the effect that, in case of heavymeta-data operations, later updates to an item ``catch'' the earlier ones if the earlierones are still in memory and have not already been written to disk. So all operations on,say, a directory are generally performed in memory before the update is written to disk(the data blocks are sorted according to their position so that they will not be on thedisk ahead of their meta-data). If the system crashes, this causes an implicit ``logrewind'': all operations which did not find their way to the disk appear as if they hadnever happened. A consistent filesystem state is maintained that appears to be the one of30 to 60 seconds earlier. The algorithm used guarantees that all resources in use aremarked as such in their appropriate bitmaps: blocks and inodes. After a crash, the onlyresource allocation error that occurs is that resources are marked as ``used'' which areactually ``free''. <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=fsck&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">fsck</span>(8)</span></a> recognizesthis situation, and frees the resources that are no longer used. It is safe to ignore thedirty state of the filesystem after a crash by forcibly mounting it with <ttclass="COMMAND">mount -f</tt>. In order to free resources that may be unused, <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=fsck&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">fsck</span>(8)</span></a> needs to berun at a later time. This is the idea behind the <span class="emphasis"><iclass="EMPHASIS">background fsck</i></span>: at system startup time, only a <spanclass="emphasis"><i class="EMPHASIS">snapshot</i></span> of the filesystem is recorded.The <tt class="COMMAND">fsck</tt> can be run later on. All file systems can then bemounted ``dirty'', so the system startup proceeds in multiuser mode. Then, background <ttclass="COMMAND">fsck</tt>s will be scheduled for all file systems where this is required,to free resources that may be unused. (File systems that do not use Soft Updates stillneed the usual foreground <tt class="COMMAND">fsck</tt> though.)</p><p>The advantage is that meta-data operations are nearly as fast as asynchronous updates(i.e. faster than with <span class="emphasis"><i class="EMPHASIS">logging</i></span>,which has to write the meta-data twice). The disadvantages are the complexity of the code(implying a higher risk for bugs in an area that is highly sensitive regarding loss ofuser data), and a higher memory consumption. Additionally there are some idiosyncrasiesone has to get used to. After a crash, the state of the filesystem appears to be somewhat``older''. In situations where the standard synchronous approach would have caused somezero-length files to remain after the <tt class="COMMAND">fsck</tt>, these files do notexist at all with a Soft Updates filesystem because neither the meta-data nor the filecontents have ever been written to disk. Disk space is not released until the updateshave been written to disk, which may take place some time after running <ttclass="COMMAND">rm</tt>. This may cause problems when installing large amounts of data ona filesystem that does not have enough free space to hold all the files twice.</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-sysctl.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-kernel-limits.html"accesskey="N">Next</a></td></tr><tr><td width="33%" align="left" valign="top">Tuning with sysctl</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 Kernel Limits</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 + -