Thank you so much for your kindly help.<br><br clear="all">best regards,<br>
韩竹(Zhu Han)<br>
<br><br><div class="gmail_quote">On Wed, May 9, 2012 at 6:31 AM, Dave Chinner <span dir="ltr">&lt;<a href="mailto:david@fromorbit.com" target="_blank">david@fromorbit.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On Tue, May 08, 2012 at 11:25:05PM +0800, Zhu Han wrote:<br>
&gt; On Tue, May 8, 2012 at 1:47 PM, Dave Chinner &lt;<a href="mailto:david@fromorbit.com">david@fromorbit.com</a>&gt; wrote:<br>
&gt;<br>
&gt; &gt; On Tue, May 08, 2012 at 01:10:55PM +0800, Zhu Han wrote:<br>
&gt; &gt; &gt; On Tue, May 8, 2012 at 12:40 PM, Dave Chinner &lt;<a href="mailto:david@fromorbit.com">david@fromorbit.com</a>&gt;<br>
&gt; &gt; wrote:<br>
&gt; &gt; &gt; &gt; On Tue, May 08, 2012 at 11:24:52AM +0800, Zhu Han wrote:<br>
&gt; &gt; &gt; &gt; &gt; On Tue, May 8, 2012 at 7:59 AM, Dave Chinner &lt;<a href="mailto:david@fromorbit.com">david@fromorbit.com</a>&gt;<br>
&gt; &gt; &gt; &gt; wrote:<br>
&gt; &gt; &gt; &gt; &gt; &gt; And so now you&#39;ve triggered the speculative delayed allocation<br>
&gt; &gt; &gt; &gt; &gt; &gt; beyond EOF, which is normal behaviour. Hence there are currently<br>
&gt; &gt; &gt; &gt; &gt; &gt; unused blocks beyond EOF which will get removed either when the<br>
&gt; &gt; next<br>
&gt; &gt; &gt; &gt; &gt; &gt; close(fd) occurs on the file or the inode is removed from the<br>
&gt; &gt; cache.<br>
&gt; &gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; Close(fd) should be invoked before dd quits. But why the extra blocks<br>
&gt; &gt; &gt; &gt; &gt; beyond EOF are not freed?<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; The removal is conditional on how many times the fd has been closed<br>
&gt; &gt; &gt; &gt; with dirty data on the inode.<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; The only way I found to remove the extra blocks is truncate the file<br>
&gt; &gt; to<br>
&gt; &gt; &gt; &gt; its<br>
&gt; &gt; &gt; &gt; &gt; real size.<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; If the close() didn&#39;t remove them, they will be removed when the<br>
&gt; &gt; &gt; &gt; inode ages out of the cache. Why do you even care about them?<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Our distributed system depends on the real length of files to account the<br>
&gt; &gt; &gt; space usage.<br>
&gt; &gt;<br>
&gt; &gt; That&#39;s ..... naive. It&#39;s never been valid to assume that the file<br>
&gt; &gt; size is an accurate reflection of space usage, especially as it will<br>
&gt; &gt; *always* be wrong for sparse files. In the same light, you also<br>
&gt; &gt; cannot assume that it is an accurate reflection for non-sparse files<br>
&gt; &gt; because we can do both explicit and speculative allocation beyond<br>
&gt; &gt; EOF which only du will show. Not to mention that metadata is not<br>
&gt; &gt; accounted in the file length, and that can consume a significant<br>
&gt; &gt; amount of space, too.<br>
&gt; &gt;<br>
&gt; &gt; &gt; This behavior make the account inaccurate.<br>
&gt; &gt;<br>
&gt; &gt; The block usage reported by XFS is both accurate and correct. The<br>
&gt; &gt; file size reported by XFS is both accurate and correct. You&#39;re<br>
&gt; &gt; &quot;account inaccuracy&quot; is assuming that they are the same. Perhaps you<br>
&gt; &gt; should be using quotas for accurate space usage accounting?<br>
&gt; &gt;<br>
&gt; &gt; Anyway, if you really want to stop speculative delayed allocation<br>
&gt; &gt; beyond EOF, then use the allocsize mount option to control it.<br>
&gt; &gt;<br>
&gt;<br>
&gt;<br>
&gt; Thanks for help.<br>
&gt;<br>
&gt; I can control the size of pre-allocation, so no data are written beyond the<br>
&gt; pre-allocated block range, so no speculative allocation is triggered.<br>
&gt; Besides it, our system can sync the accurate space usage of mount point<br>
&gt; periodically.<br>
&gt;<br>
&gt; Can you give any hints about the most lightweight approach to get the<br>
&gt; accurate block usage of whole file system?<br>
<br>
</div></div>If you are just after the whole filesystem, then statfs(2) will give<br>
you blocks used and free. If you are after a finer breakdown, then<br>
quotas are probably what you want - they can be used for accounting<br>
separately to the space limiting enforcement. Hence you get<br>
accurate, up-to-date per user, group or project space accounting<br>
without actually limiting space usage at all.<br>
<div class="HOEnZb"><div class="h5"><br>
Cheers,<br>
<br>
Dave.<br>
--<br>
Dave Chinner<br>
<a href="mailto:david@fromorbit.com">david@fromorbit.com</a><br>
</div></div></blockquote></div><br>