Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Eric Levy <contact@ericlevy.name>,
	"linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>
Subject: Re: "hardware-assisted zeroing"
Date: Wed, 5 Jan 2022 06:37:10 +0800	[thread overview]
Message-ID: <09ee7152-a650-32a8-a036-e322a1afe177@gmx.com> (raw)
In-Reply-To: <faa7edb08a5cf68e8668546facbb8c60ae5a22e7.camel@ericlevy.name>



On 2022/1/4 18:50, Eric Levy wrote:
> On Mon, 2022-01-03 at 19:51 +0800, Qu Wenruo wrote:
>
>> The filesystem (normally) doesn't maintain such info, what a
>> filesystem
>> really care is the unused/used space.
>>
>> For fstrim case, the filesystem will issue such discard comand to
>> most
>> (if not all) unused space.
>>
>> And one can call fstrim multiple times to do the same work again and
>> again, the filesystem won't really care.
>> (even the operation can be very time consuming)
>>
>> The special thing in btrfs is, there is a cache to record which
>> blocks
>> have been trimmed. (only in memory, thus after unmount, such cache is
>> lost, and on next mount will need to be rebuilt)
>>
>> This is to reduce the trim workload with recent async-discard
>> optimization.
>
> So in the general case (i.e. no session cache), the trim operation
> scans all the allocation structures, to process all non-allocated
> space?

Yes, and that's almost for all filesystems supporting trim.

All filesystems supporing read-write need to maintain such info anyway.
IIRC for filesystems like ext4, there is a bitmap storing which sector
is used and which is not.

Btrfs has a more complex one (extent tree), not only recording which
range is used, but also which tree is using it.

>
>>> Why is the
>>> command not sent instantly, as soon as the space is freed by the
>>> file
>>> system?
>>
>> If you use discard mount option, then most filesystems will send the
>> discard command to the underlying device when some space is freed.
>>
>> But please keep in mind that, how such discard command gets handled
>> is
>> hardware/storage stack dependent.
>>
>> Some disk firmware may choose to do discard synchronously, which can
>> hugely slow down other operations.
>> (That's why btrfs has async-discard optimization, and also why fstrim
>> is
>> preferred, to avoid unexpected slow down).
>
> Yes, but of course as I have used "instantly", I meant, not necessarily
> synchronously, but simply near in time.
>
> The trim operation is not avoiding bottlenecks, even if it is non-
> blocking, because it operates at the level of the entire file system,
> in a single operation. If Btrfs is able to process discard operations
> asynchronously, then mounting with the discard option seems preferable,
> as it requires no redundant work, adds no serious delay until until the
> calls are made, and depends on no activity (not even automatic
> activity) from the admin.

IIRC this async discard is currently only specific to btrfs, thus it's
not really generic.

Another thing is, just as Zygo said, there is not much benefit from
discarding some frequently used/freed metadata.

But the overhead is always there for discard mount option, thus that's
why we don't recommend discard mount option, even we have async-discard
behavior.

Thanks,
Qu

>
> I fail to see a reason for preferring trim over discard.
>

  parent reply	other threads:[~2022-01-04 22:37 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-03 11:08 "hardware-assisted zeroing" Eric Levy
2022-01-03 11:17 ` Qu Wenruo
2022-01-03 11:24   ` Eric Levy
2022-01-03 11:51     ` Qu Wenruo
2022-01-04 10:50       ` Eric Levy
2022-01-04 20:49         ` Zygo Blaxell
2022-01-04 22:37           ` Eric Levy
2022-01-04 22:46             ` Qu Wenruo
2022-01-05  0:38               ` Paul Jones
2022-01-05  0:44                 ` Eric Levy
2022-01-05  1:12                   ` Paul Jones
2022-01-05  1:20                     ` Eric Levy
2022-01-05  1:21                   ` Zygo Blaxell
2022-01-05  1:26                     ` Eric Levy
2022-01-05  1:33                       ` Zygo Blaxell
2022-01-05  1:37                         ` Eric Levy
2022-01-05  2:20                           ` Zygo Blaxell
2022-01-05  1:32             ` Zygo Blaxell
2022-01-04 22:37         ` Qu Wenruo [this message]
2022-01-03 11:46 ` David Disseldorp
2022-01-03 11:57   ` Qu Wenruo

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=09ee7152-a650-32a8-a036-e322a1afe177@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=contact@ericlevy.name \
    --cc=linux-btrfs@vger.kernel.org \
    /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