Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Jeff Mahoney <jeffm@suse.com>
To: Chris Murphy <lists@colorremedies.com>
Cc: Andrei Borzenkov <arvidjaar@gmail.com>,
	Btrfs BTRFS <linux-btrfs@vger.kernel.org>
Subject: Re: bug? fstrim only trims unallocated space, not unused in bg's
Date: Mon, 20 Nov 2017 23:13:05 -0500	[thread overview]
Message-ID: <21f8dcf9-bc3c-c356-502a-789545a6f683@suse.com> (raw)
In-Reply-To: <CAJCQCtTDXfY=2=f+B-w81n7ZOPkLD5DXhwvrO7b4f3-g4RRURg@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 4330 bytes --]

On 11/20/17 11:04 PM, Chris Murphy wrote:
> On Mon, Nov 20, 2017 at 6:46 PM, Jeff Mahoney <jeffm@suse.com> wrote:
>> On 11/20/17 5:59 PM, Chris Murphy wrote:
>>> On Mon, Nov 20, 2017 at 1:40 PM, Jeff Mahoney <jeffm@suse.com> wrote:
>>>> On 11/20/17 3:01 PM, Jeff Mahoney wrote:
>>>>> On 11/20/17 3:00 PM, Jeff Mahoney wrote:
>>>>>> On 11/19/17 4:38 PM, Chris Murphy wrote:
>>>>>>> On Sat, Nov 18, 2017 at 11:27 PM, Andrei Borzenkov <arvidjaar@gmail.com> wrote:
>>>>>>>> 19.11.2017 09:17, Chris Murphy пишет:
>>>>>>>>> fstrim should trim free space, but it only trims unallocated. This is
>>>>>>>>> with kernel 4.14.0 and the entire 4.13 series. I'm pretty sure it
>>>>>>>>> behaved this way with 4.12 also.
>>>>>>>>>
>>>>>>>>
>>>>>>>> Well, I was told it should also trim free space ...
>>>>>>>>
>>>>>>>> https://www.spinics.net/lists/linux-btrfs/msg61819.html
>>>>>>>>
>>>>>>>
>>>>>>> It definitely isn't. If I do a partial balance, then fstrim, I get a
>>>>>>> larger trimmed value, corresponding exactly to unallocated space.
>>>>>>
>>>>>>
>>>>>> I've just tested with 4.14 and it definitely trims within block groups.
>>>>>
>>>>> Derp.  This should read 4.12.
>>>>>
>>>>>> I've attached my test script and the log of the run.  I'll build and
>>>>>> test a 4.14 kernel and see if I can reproduce there.  It may well be
>>>>>> that we're just misreporting the bytes trimmed.
>>>>
>>>> I get the same results on v4.14.  I wrote up a little script to parse
>>>> the btrfs-debug-tree extent tree dump and the discards that are issued
>>>> after the final sync (when the tree is dumped) match.
>>>>
>>>> The script output is also as expected:
>>>> /mnt2: 95.1 GiB (102082281472 bytes) trimmed
>>>> # remove every other 100MB file, totalling 1.5 GB
>>>> + sync
>>>> + killall blktrace
>>>> + wait
>>>> + echo 'after sync'
>>>> + sleep 1
>>>> + btrace -a discard /dev/loop0
>>>> + fstrim -v /mnt2
>>>> /mnt2: 96.6 GiB (103659962368 bytes) trimmed
>>>>
>>>> One thing that may not be apparent is that the byte count is from the
>>>> device(s)'s perspective.  If you have a file system with duplicate
>>>> chunks or a redundant RAID mode, the numbers will reflect that.
>>>>
>>>> The total byte count should be correct as well.  It's the total number
>>>> of bytes that we submit for discard and that were accepted by the block
>>>> layer.
>>>>
>>>> Do you have a test case that shows it being wrong and can you provide
>>>> the blktrace capture of the device(s) while the fstrim is running?
>>>
>>>
>>> Further,
>>>
>>> # fstrim -v /
>>> /: 38 GiB (40767586304 bytes) trimmed
>>>
>>> And then delete 10G worth of files, do not balance, and do nothing for
>>> a minute before:
>>>
>>> # fstrim -v /
>>> /: 38 GiB (40767586304 bytes) trimmed
>>>
>>> It's the same value. Free space according to fi us is +10 larger than
>>> before, and yet nothing additional is trimmed than before. So I don't
>>> know what's going on but it's not working for me.
>>
>> What happens if you sync before doing the fstrim again?  The code is
>> there to drop extents within block groups.  It works for me.  The big
>> thing is that the space must be freed entirely before we can trim.
> 
> I've sync'd and I've also rebooted, it's the same.
> 
> [root@f27h ~]# fstrim -v /
> /: 38 GiB (40767586304 bytes) trimmed
> [root@f27h ~]# btrfs fi us /
> Overall:
>     Device size:          70.00GiB
>     Device allocated:          32.03GiB
>     Device unallocated:          37.97GiB
>     Device missing:             0.00B
>     Used:              15.50GiB
>     Free (estimated):          52.93GiB    (min: 52.93GiB)
>     Data ratio:                  1.00
>     Metadata ratio:              1.00
>     Global reserve:          53.97MiB    (used: 192.00KiB)
> 
> Data,single: Size:30.00GiB, Used:15.04GiB
>    /dev/nvme0n1p8      30.00GiB
> 
> Metadata,single: Size:2.00GiB, Used:473.34MiB
>    /dev/nvme0n1p8       2.00GiB
> 
> System,single: Size:32.00MiB, Used:16.00KiB
>    /dev/nvme0n1p8      32.00MiB
> 
> Unallocated:
>    /dev/nvme0n1p8      37.97GiB
> [root@f27h ~]#

What's the discard granularity on that device?

grep . /sys/block/nvme0n1/queue/discard_*
cat /sys/block/nvme0n1/discard*

-Jeff


-- 
Jeff Mahoney
SUSE Labs


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2017-11-21  4:13 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-19  6:17 bug? fstrim only trims unallocated space, not unused in bg's Chris Murphy
2017-11-19  6:27 ` Andrei Borzenkov
2017-11-19 21:38   ` Chris Murphy
     [not found]     ` <3114a78e-485a-daea-f8b1-48cc330f4209@suse.com>
2017-11-20 20:01       ` Jeff Mahoney
2017-11-20 20:40         ` Jeff Mahoney
2017-11-20 21:56           ` Chris Murphy
2017-11-20 22:59           ` Chris Murphy
2017-11-21  1:46             ` Jeff Mahoney
2017-11-21  4:04               ` Chris Murphy
2017-11-21  4:13                 ` Jeff Mahoney [this message]
2017-11-21  4:15                   ` Chris Murphy
2017-11-20  2:13 ` Qu Wenruo
2017-11-20  2:24   ` Chris Murphy
2017-11-20  2:30     ` Chris Murphy
2017-11-20  2:42     ` Qu Wenruo
2017-11-20 22:23       ` Chris Murphy
2017-11-21  1:16         ` Qu Wenruo
2017-11-21  4:06           ` Chris Murphy
2017-11-21  4:09             ` Chris Murphy
2017-11-21  4:29             ` Qu Wenruo
2017-11-21  4:34               ` Chris Murphy
2017-11-21  4:43                 ` Qu Wenruo
2017-11-21  4:46                   ` Chris Murphy
2017-11-21  4:49                   ` Chris Murphy
2017-11-21  4:58                     ` Qu Wenruo
2017-11-21  5:58                       ` Chris Murphy
2017-11-21  6:10                         ` Qu Wenruo
2018-04-01  3:28                           ` Chris Murphy
2018-04-01 10:34                             ` Qu Wenruo
2018-04-01 23:30                               ` Chris Murphy

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=21f8dcf9-bc3c-c356-502a-789545a6f683@suse.com \
    --to=jeffm@suse.com \
    --cc=arvidjaar@gmail.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=lists@colorremedies.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