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