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

<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>