<br><div class="gmail_quote">On Tue, May 8, 2012 at 12:40 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="HOEnZb"><div class="h5">On Tue, May 08, 2012 at 11:24:52AM +0800, Zhu Han wrote:<br>
&gt; On Tue, May 8, 2012 at 7:59 AM, Dave Chinner &lt;<a href="mailto:david@fromorbit.com">david@fromorbit.com</a>&gt; wrote:<br>
&gt;<br>
&gt; &gt; On Mon, May 07, 2012 at 08:44:17PM +0800, Zhu Han wrote:<br>
&gt; &gt; &gt; Seems like xfs of CentOS 6.X occupies much more storage space than<br>
&gt; &gt; desired<br>
&gt; &gt; &gt; if fallocate is used against the file. Here is the step to reproduce it:<br>
&gt; &gt;<br>
&gt; &gt; You test case is not doing what you think it is doing.<br>
&gt;<br>
&gt; Thanks for pointing it out.<br>
&gt;<br>
&gt; &gt; &gt; By the way, is it normal when the file is moved around after the<br>
&gt; &gt; &gt; preallocated region is filled with data?<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; $ uname -r<br>
&gt; &gt; &gt; 2.6.32-220.7.1.el6.x86_64<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; $fallocate -n --offset 0 -l 1G file    ----&gt;Write a little more data than<br>
&gt; &gt; &gt; the preallocated size<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; $ xfs_bmap -p -vv file<br>
&gt; &gt; &gt; file:<br>
&gt; &gt; &gt;  EXT: FILE-OFFSET      BLOCK-RANGE            AG AG-OFFSET<br>
&gt; &gt; &gt; TOTAL FLAGS<br>
&gt; &gt; &gt;    0: [0..2097151]:    2593408088..2595505239 21 (29420144..31517295)<br>
&gt; &gt; &gt; 2097152 10000<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; $ dd if=/dev/zero of=/tmp/file bs=1M count=1026 conv=fsync<br>
&gt; &gt;<br>
&gt; &gt; That does a truncate first, removing all the preallocated space. Use<br>
&gt; &gt; conv=notrunc to avoid this. Hence the space allocated by this<br>
&gt; &gt; new write is different to the space allocated by the above<br>
&gt; &gt; preallocation. The file has not been moved, the filesystem just did<br>
&gt; &gt; what you asked it to do.<br>
&gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; $ xfs_bmap -p -vv file<br>
&gt; &gt; &gt; file:<br>
&gt; &gt; &gt;  EXT: FILE-OFFSET      BLOCK-RANGE            AG AG-OFFSET<br>
&gt; &gt; &gt; TOTAL FLAGS<br>
&gt; &gt; &gt;    0: [0..4194303]:    2709184016..2713378319 22 (23101408..27295711)<br>
&gt; &gt; &gt; 4194304 00000<br>
&gt; &gt;<br>
&gt; &gt; And so now you&#39;ve triggered the speculative delayed allocation<br>
&gt; &gt; beyond EOF, which is normal behaviour. Hence there are currently<br>
&gt; &gt; unused blocks beyond EOF which will get removed either when the next<br>
&gt; &gt; close(fd) occurs on the file or the inode is removed from the cache.<br>
&gt; &gt;<br>
&gt;<br>
&gt; Close(fd) should be invoked before dd quits. But why the extra blocks<br>
&gt; beyond EOF are not freed?<br>
<br>
</div></div>The removal is conditional on how many times the fd has been closed<br>
with dirty data on the inode.<br>
<div class="im"><br>
&gt; The only way I found to remove the extra blocks is truncate the file to its<br>
&gt; real size.<br>
<br>
</div>If the close() didn&#39;t remove them, they will be removed when the<br>
inode ages out of the cache. Why do you even care about them?<br></blockquote><div><br>Our distributed system depends on the real length of files to account the space usage. This behavior make the account inaccurate. <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>