Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Chris Murphy <lists@colorremedies.com>
Cc: Btrfs BTRFS <linux-btrfs@vger.kernel.org>
Subject: Re: bug? fstrim only trims unallocated space, not unused in bg's
Date: Tue, 21 Nov 2017 14:10:56 +0800	[thread overview]
Message-ID: <a95813ad-d87e-bd5a-a258-c3d241fa5181@gmx.com> (raw)
In-Reply-To: <CAJCQCtSezvyBGBQJRwQ+aeJH+8_8QsihkFD-iZaEVFeoL-00+Q@mail.gmail.com>


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



On 2017年11月21日 13:58, Chris Murphy wrote:
> On Mon, Nov 20, 2017 at 9:58 PM, Qu Wenruo <quwenruo.btrfs@gmx.com> wrote:
>>
>>
>> On 2017年11月21日 12:49, Chris Murphy wrote:
>>> On Mon, Nov 20, 2017 at 9:43 PM, Qu Wenruo <quwenruo.btrfs@gmx.com> wrote:
>>>>
>>>>
>>>>>
>>>>> Apply in addition to previous patch? Or apply to clean v4.14?
>>>>
>>>> On previous patch.
>>>
>>> Refuses to apply with or without previous patch.
>>>
>>> $ git apply -v ~/qufstrim3.patch
>>> Checking patch fs/btrfs/extent-tree.c...
>>> error: while searching for:
>>>        int dev_ret = 0;
>>>        int ret = 0;
>>>
>>>        /*
>>>         * try to trim all FS space, our block group may start from non-zero.
>>>         */
>>>
>>> error: patch failed: fs/btrfs/extent-tree.c:10972
>>> error: fs/btrfs/extent-tree.c: patch does not apply
>>>
>>
>> Please try this branch.
>>
>> It's just previous patch and diff merged together and applied on v4.14
>> tag from torvalds.
>>
>> https://github.com/adam900710/linux/tree/tmp
> 
> # fstrim -v /
> /: 38 GiB (40767586304 bytes) trimmed
> # dmesg
> 
> ..snip...
> [   46.408792] BTRFS info (device nvme0n1p8): trimming btrfs, start=0
> len=75161927680 minlen=512
> [   46.408800] BTRFS info (device nvme0n1p8): bg start=140882477056
> len=1073741824
> [   46.433867] BTRFS info (device nvme0n1p8): trimming done

Great (for the output, not for the trimming failure).

And the problem is very obvious now.
140882477056 << First chunk start
75161927680  << length of fstrim_range passed in

Obviously, fstrim_range passed in is using the filesystem size it
assumes to be.

While we stupidly use the range in fstrim_range without considering the
fact that, we're dealing with *btrfs logical address space*.
Where our chunk can start from any bytenr (well, at least aligned with
sectorsize).
When I read the code I also think the range check has nothing wrong at all.

So the truth here is, we should not ever try to check the range from
fstrim_range.

And the problem means that, a normal btrfs with some usage and after
several full balance, fstrim will only trim the unallocated space for btrfs.

Now the fix should not be a hard to craft.

Great thanks for all your help to locate the problem.

Thanks,
Qu
> 
> Attaching 'btrfs-debug -b /' to get an idea about the block groups present.
> 
> 
> 


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

  reply	other threads:[~2017-11-21  6:11 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
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 [this message]
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=a95813ad-d87e-bd5a-a258-c3d241fa5181@gmx.com \
    --to=quwenruo.btrfs@gmx.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