From: Eric Sandeen <sandeen@redhat.com>
To: "Richard W.M. Jones" <rjones@redhat.com>
Cc: linux-ext4@vger.kernel.org
Subject: Re: fstrim has no effect on a just-mounted filesystem
Date: Tue, 11 Mar 2014 17:08:19 -0500 [thread overview]
Message-ID: <531F8953.1030702@redhat.com> (raw)
In-Reply-To: <20140311220013.GV1346@redhat.com>
On 3/11/14, 5:00 PM, Richard W.M. Jones wrote:
> [The context of this is trying to get virt-sparsify to work in place
> on disks.]
>
> On Tue, Mar 11, 2014 at 04:47:02PM -0500, Eric Sandeen wrote:
>> On 3/11/14, 4:39 PM, Richard W.M. Jones wrote:
>>>
>>> Here's a problem I can't work out:
>>>
>>> I have a filesystem (in a VM) that I know has at least 100MB of
>>> deleted files on it.
>>
>> Was it mounted with -o discard at the time the files were deleted?
>
> No, it was not.
Ok, worth asking. :)
> I know that the original 'rm' command didn't recover any space because
> the disk image grew by ~100 MB.
>> If so, then the trim is already done during the unlink process,
>> and there's no more work to do.
>>
>> So that's my first thought, but ...
>>
>>> Doing this in a script:
>>>
>>> mount -o discard /dev/sda1 /mnt
>>> fstrim /mnt
>>>
>>> ... does nothing. Also the fstrim is almost instantaneous -- there's
>>> no way it could be scanning the disk.
>>
>> blktrace would be a better tool to find out whether or not discards
>> are actually getting issued to storage...
blktrace is probably the place to start. Do you see discard
requests? then ext4 is doing its job. If not, we can trace
ext4 to see why it's not issuing them, assuming there really
is work to do.
>> And if you strace it what does the ioctl return?
>
> I'll try that in a few minutes.
>
> In the mean time I captured the fstrim -v output:
>
> fstrim -v /
> /: 124 MiB (130039808 bytes) trimmed
>
> 124 MB is (within 25%) the amount of data I would expect needs to be
> trimmed.
Ok, so it says that it did do what you expected...
>> Enabling the trace_ext4_trim_all_free tracepoint might be interesting too.
>
> That a systemtap thing? It's tricky to get systemtap working in a
> virtual machine, but I guess I can try if nothing else works.
# trace-cmd record -e &
# <run test>
# fg
<ctrl-c>
# trace-cmd report > trace_report.txt
should do it.
>>> However, if I start with the same filesystem, mounted with -o discard,
>>> and create and rm large files, while observing the size of the
>>> underlying virtual disk, then discard is obviously working fine. 'rm'
>>> of large files makes the underlying disk shrink.
(backing up, that's the "-o discard" option at work)
>>> Any ideas here?
>>
>> first of all, I should point out that "-o discard" is not necessary for
>> fstrim / FITRIM ioctl to work. The former tries to trim as soon
>> as files are unlinked; FITRIM goes looking for free blocks to trim.
>>
>> If you're mounting with -o discard, then fstrim should never find any
>> work to do.
>
> Useful to know.
>
> I thought I had to use -o discard in order for the ext4 module to send
> discard commands at all to the block layer.
nope. That just makes it do it every time a block is freed, instead
of in batches via fstrim:
discard Controls whether ext4 should issue discard/TRIM
nodiscard(*) commands to the underlying block device when
blocks are freed.
the FITRIM ioctl works fine w/o the mount option, and in fact as I said,
should have no work to do if the mount option is there - every freed block
shouid get discarded (well, maybe modulo some size thresholds, I don't
remember for sure).
-Eric
> Thanks,
>
> Rich.
>
next prev parent reply other threads:[~2014-03-11 22:08 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-11 21:39 fstrim has no effect on a just-mounted filesystem Richard W.M. Jones
2014-03-11 21:47 ` Eric Sandeen
2014-03-11 22:00 ` Richard W.M. Jones
2014-03-11 22:04 ` Richard W.M. Jones
2014-03-11 22:08 ` Eric Sandeen [this message]
2014-03-11 22:59 ` Richard W.M. Jones
2014-03-11 23:07 ` Richard W.M. Jones
2014-03-11 23:09 ` Eric Sandeen
2014-03-11 23:30 ` Richard W.M. Jones
2014-03-12 10:17 ` Richard W.M. Jones
2014-03-12 13:42 ` Richard W.M. Jones
2014-03-12 18:10 ` Paolo Bonzini
2014-03-12 18:24 ` Richard W.M. Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=531F8953.1030702@redhat.com \
--to=sandeen@redhat.com \
--cc=linux-ext4@vger.kernel.org \
--cc=rjones@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).