bcachefs-tools icon indicating copy to clipboard operation
bcachefs-tools copied to clipboard

bcachefs format --discard scope

Open jpsollie opened this issue 4 years ago • 8 comments

The--discard parameter scope does not start at the begin of a new group:

linuxserver /home/janpieter # bcachefs format -g SSD --discard /dev/disk/by-partuuid/f8d16ed7-eddc-4ef1-84b7-bc3b74e8b3ca -g HDD /dev/sdd --foreground_target=SSD --promote_target=SSD --background_target=HDD                        External UUID:4ad9b6a6-4911-4b9c-9d05-3c4091e973b4
Internal UUID:df5a0103-6c83-4193-abf3-9602ca9e1b96
Label:
Version:11
Created:Sat Jun 13 07:21:38 2020
Block_size:512
Btree node size:256.0K
Error action:remount-ro
Clean:0
Features:
Metadata replicas:1
Data replicas:1
Metadata checksum type:crc32c (1)
Data checksum type:crc32c (1)
Compression type:none (0)
Foreground write target:Group 0 (SSD)
Background write target:Group 1 (HDD)
Promote target:Group 0 (SSD)
String hash type:siphash (2)
32 bit inodes:0
GC reserve percentage:8%
Root reserve percentage:0%
Devices:2 live, 2 total
Sections:members,disk_groups
Superblock size:976

Members (size 120):
  Device 0:
    UUID:9c41e5d3-979a-467d-b9f5-ac0a31e1d57a
    Size:107.3G
    Bucket size:256.0K
    First bucket:0
    Buckets:439556
    Last mount:(never)
    State:readwrite
    Group:SSD (0)
    Data allowed:journal,btree,data
    Has data:(none)
    Replacement policy:lru
    Discard:1
  Device 1:
    UUID:c2f801f4-b323-4947-bf0b-9921ba482b39
    Size:3.6T
    Bucket size:512.0K
    First bucket:0
    Buckets:7618540
    Last mount:(never)
    State:readwrite
    Group:HDD (1)
    Data allowed:journal,btree,data
    Has data:(none)
    Replacement policy:lru
    Discard:1
initializing new filesystem
mounted with opts: foreground_target=SSD,background_target=HDD,promote_target=SSD
linuxserver /home/janpieter # bcachefs format -g HDD /dev/sdd -g SSD --discard /dev/disk/by-partuuid/f8d16ed7-eddc-4ef1-84b7-bc3b74e8b3ca --foreground_target=SSD --promote_target=SSD --background_target=HDD
External UUID:5044a9f4-27e4-4b73-bb89-4e104ab370eb
Internal UUID:b916dfed-a454-4d55-ac63-c79733474949
Label:
Version:11
Created:Sat Jun 13 07:23:34 2020
Block_size:512
Btree node size:256.0K
Error action:remount-ro
Clean:0
Features:
Metadata replicas:1
Data replicas:1
Metadata checksum type:crc32c (1)
Data checksum type:crc32c (1)
Compression type:none (0)
Foreground write target:Group 1 (SSD)
Background write target:Group 0 (HDD)
Promote target:Group 1 (SSD)
String hash type:siphash (2)
32 bit inodes:0
GC reserve percentage:8%
Root reserve percentage:0%
Devices:2 live, 2 total
Sections:members,disk_groups
Superblock size:976

Members (size 120):
  Device 0:
    UUID:bcce3afc-d31b-49d5-b9f0-bb3231e6431f
    Size:3.6T
    Bucket size:512.0K
    First bucket:0
    Buckets:7618540
    Last mount:(never)
    State:readwrite
    Group:HDD (0)
    Data allowed:journal,btree,data
    Has data:(none)
    Replacement policy:lru
    Discard:0
  Device 1:
    UUID:000c018b-05a0-46e1-b535-e04ae00f70b6
    Size:107.3G
    Bucket size:256.0K
    First bucket:0
    Buckets:439556
    Last mount:(never)
    State:readwrite
    Group:SSD (1)
    Data allowed:journal,btree,data
    Has data:(none)
    Replacement policy:lru
    Discard:1
initializing new filesystem
mounted with opts: foreground_target=SSD,background_target=HDD,promote_target=SSD
linuxserver /home/janpieter #

As a result, all SSD devices have to be specified as the final ones, otherwise the discard flag is taken over by the HDD group.

jpsollie avatar Jun 13 '20 05:06 jpsollie

I'm not seeing the problem, the way you want to do it seems more confusing to me. Discard, like all other per device options (-g included!) are scoped to devices that come after that option

koverstreet avatar Jun 30 '20 17:06 koverstreet

Discard, like all other per device options (-g included!) are scoped to devices that come after that option

Exactly. When I create group 1, enable discard, and then create group 2, the discard option is promoted to group 2 while I only wanted it for group 1. This is what issue #33 is all about. When we need to consider resetting device options when a group is created, it may be useful to create a feature where you have a global flag when you do not include it in a group. The logic behind "is a global flag" (and thus does not need to be reset for each group) is somewhat confusing, but that's more or less what I'm doing here

jpsollie avatar Jun 30 '20 18:06 jpsollie

so let's just add a --nodiscard option if you want discards off for group 2...

koverstreet avatar Jun 30 '20 18:06 koverstreet

I think you might be confusing yourself by thinking of the discard option as applying to a group. it doesn't, it applies to a disk.

koverstreet avatar Jun 30 '20 18:06 koverstreet

I think you might be confusing yourself by thinking of the discard option as applying to a group. it doesn't, it applies to a disk.

now I am confused indeed: I usually format like --group=ssd --discard <dev1> <dev2> .... --group=hdd <dev3><dev4> ... so the discard option should apply only for dev1?

jpsollie avatar Jun 30 '20 18:06 jpsollie

No, it applies to all devices that come after it, until another option overrides (which won't happen since we don't have --nodiscard) - it'll apply to all devices in your example.

On Tue, Jun 30, 2020 at 2:56 PM jpsollie [email protected] wrote:

I think you might be confusing yourself by thinking of the discard option as applying to a group. it doesn't, it applies to a disk.

now I am confused indeed: I usually format like --group=ssd --discard .... --group=hdd ... so the discard option should apply only for dev1?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/koverstreet/bcachefs-tools/issues/33#issuecomment-651981405, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPGX3WEK6CZJUURUFPJ3N3RZIYOBANCNFSM4N42XNZQ .

koverstreet avatar Jun 30 '20 19:06 koverstreet

ok, now rebase and squash your fixup commits so I can see what's actually going on... I don't want to change the discard option and make it inconsistent, but I'll take the other stuff

koverstreet avatar Jun 30 '20 20:06 koverstreet

Here you go, I hope it's clear to you

jpsollie avatar Jul 01 '20 13:07 jpsollie