Skip to contentSkip to conversation

Reserve space for specific thin logical volumes

linux-lvm matthew patton 3 participants 6 messages Sep 12, 2017 – Sep 13, 2017 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 5 lines

Step-by-step example:
- create a 40 GB thin volume and subtract its size from the thin pool (USED 40 GB, FREE 60 GB, REFER 0 GB);
- overwrite the entire volume (USED 40 GB, FREE 60 GB, REFER 40 GB);
- snapshot the volume (USED 40 GB, FREE 60 GB, REFER 40 GB);

And 3 other threads also take snapshots against the same volume, or frankly any other volume in the pool. Since the next step (overwrite) hasn't happened yet or has written less than 20GB, all succeed.

Quoted 1 line

- completely overwrite the original volume (USED 80 GB, FREE 20 GB, REFER 40 GB);

4 threads all try to write their respective 40GB. Afterall, they got the green-light since their snapshot was allowed to be taken. Your thinLV blows up spectacularly.

Quoted 1 line

- a new snapshot creation will fails (REFER is higher then FREE).

nobody cares about new snapshot creation attempts at this point.

Quoted 1 line

When do you decide it ?  (you need to see this is total race-lend)

exactly!

#2 lore raw

Il 13-09-2017 01:22 matthew patton ha scritto:

Quoted 18 lines
Quoted 2 lines

Step-by-step example:
- create a 40 GB thin volume and subtract its size from the thin

pool (USED 40 GB, FREE 60 GB, REFER 0 GB);

Quoted 2 lines

- overwrite the entire volume (USED 40 GB, FREE 60 GB, REFER 40 GB);
- snapshot the volume (USED 40 GB, FREE 60 GB, REFER 40 GB);

And 3 other threads also take snapshots against the same volume, or frankly any other volume in the pool.
Since the next step (overwrite) hasn't happened yet or has written less than 20GB, all succeed.

Quoted 1 line

- completely overwrite the original volume (USED 80 GB, FREE 20 GB,

REFER 40 GB);

4 threads all try to write their respective 40GB. Afterall, they got the green-light since their snapshot was allowed to be taken. Your thinLV blows up spectacularly.

Quoted 7 lines
Quoted 1 line

- a new snapshot creation will fails (REFER is higher then FREE).

nobody cares about new snapshot creation attempts at this point.

Quoted 1 line

When do you decide it ?  (you need to see this is total race-lend)

exactly!

I all the examples I did, the snapshot are suppose to be read-only or at least never written. I thought that it was implicitly clear due to ZFS (used as example) being read-only by default. Sorry for not explicitly stating that.

However, the refreservation mechanism can protect the original volume even when snapshots are writeable. Here we go:

# Create a 400M ZVOL and fill it
[root@localhost ~]# zfs create -V 400M tank/vol1
[root@localhost ~]# dd if=/dev/zero of=/dev/zvol/tank/vol1 bs=1M oflag=direct
dd: error writing ‘/dev/zvol/tank/vol1’: No space left on device 401+0 records in
400+0 records out
419430400 bytes (419 MB) copied, 23.0573 s, 18.2 MB/s [root@localhost ~]# zfs list -t all

NAME        USED  AVAIL  REFER  MOUNTPOINT
tank        416M   464M    24K  /tank
tank/vol1   414M   478M   401M  -

# Create some snapshots (note how the USED value increased due to the snapshot reserving space for all "live" data in the ZVOL) [root@localhost ~]# zfs set snapdev=visible tank/vol1
[root@localhost ~]# zfs snapshot tank/vol1@snap1
[root@localhost ~]# zfs snapshot tank/vol1@snap2
[root@localhost ~]# zfs list -t all

NAME              USED  AVAIL  REFER  MOUNTPOINT
tank              816M  63.7M    24K  /tank
tank/vol1         815M   478M   401M  -
tank/vol1@snap1     0B      -   401M  -
tank/vol1@snap2     0B      -   401M  -

# Clone the snapshot (to be able to overwrite it) [root@localhost ~]# zfs clone tank/vol1@snap1 tank/cvol1 [root@localhost ~]# zfs list -t all

NAME              USED  AVAIL  REFER  MOUNTPOINT
tank              815M  64.6M    24K  /tank
tank/cvol1          1K  64.6M   401M  -
tank/vol1         815M   479M   401M  -
tank/vol1@snap1     0B      -   401M  -
tank/vol1@snap2     0B      -   401M  -

# Writing to the cloned ZVOL fails (after only 66 MB written) *without* impacting the original volume [root@localhost ~]# dd if=/dev/zero of=/dev/zvol/tank/cvol1 bs=1M oflag=direct
dd: error writing ‘/dev/zvol/tank/cvol1’: Input/output error
64+0 records in
63+0 records out
66060288 bytes (66 MB) copied, 25.9189 s, 2.5 MB/s

After the last write, the cloned cvol1 is clearly corrputed, but the original volume has not problem at all.

Now, I am *not* advocating switching thinp to a ZFS-like things (ie: note the write speed, which is low even for my super-slow notebook HDD). However, a mechanism with which we can tell LVM "hey, this volume should have all its space as reserved, don't worry about preventing snapshots and/or freezing them when free space runs out".

This was more or less the case with classical, fat LVM: a snapshot runnig out of space *will* fail, but the original volume remains unaffected.

Thanks.

Signature · 5 lines
Danti Gionatan
Supporto Tecnico
Assyoma S.r.l. - www.assyoma.it
email: [email protected] - [email protected]
GPG public key ID: FF5F32A8
#3 lore raw

Dne 13.9.2017 v 09:53 Gionatan Danti napsal(a):

Quoted 23 lines

Il 13-09-2017 01:22 matthew patton ha scritto:

Quoted 22 lines
Quoted 1 line

Step-by-step example:

 > - create a 40 GB thin volume and subtract its size from the thin pool (USED 40 GB, FREE 60 GB, REFER 0 GB);
 > - overwrite the entire volume (USED 40 GB, FREE 60 GB, REFER 40 GB); > - snapshot the volume (USED 40 GB, FREE 60 GB, REFER 40 GB);

And 3 other threads also take snapshots against the same volume, or frankly any other volume in the pool.
Since the next step (overwrite) hasn't happened yet or has written less than 20GB, all succeed.

 > - completely overwrite the original volume (USED 80 GB, FREE 20 GB, REFER 40 GB);

4 threads all try to write their respective 40GB. Afterall, they got the green-light since their snapshot was allowed to be taken. Your thinLV blows up spectacularly.

 > - a new snapshot creation will fails (REFER is higher then FREE). nobody cares about new snapshot creation attempts at this point.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

When do you decide it ?  (you need to see this is total race-lend)

exactly!

I all the examples I did, the snapshot are suppose to be read-only or at least never written. I thought that it was implicitly clear due to ZFS (used as example) being read-only by default. Sorry for not explicitly stating that.

Ohh this is pretty major constrain ;)

But as pointed out multiple times - with scripting around various fullness moments of thin-pool - several different actions can be programmed around, starting from fstrim, ending with plain erase of unneeded snapshot.
(Maybe erasing unneeded files....)

To get most secure application - such app should actually avoid using page-cache (using direct-io) in such case you are always guaranteed to get exact error at the exact time (i.e. even without journaled mounting option for ext4....)

Quoted 1 line

After the last write, the cloned cvol1 is clearly corrputed, but the original volume has not problem at all.

Surely there is good reason we keep 'old snapshots' still with us - although everyone knows it's implementation has aged :)

There are cases where this copying into separate COW areas simply works better - especially for temporary living object with low number of 'small' changes.

We even support old-snapshot for thin-volumes for this reason - so you can use 'bigger' thin-pool chunks - but for temporary snapshot for taking backups you can take old snapshot of thin volume...

Quoted 2 lines

This was more or less the case with classical, fat LVM: a snapshot runnig out of space *will* fail, but the original volume remains unaffected.

Partially this might get solved in 'some' cases with fully provisioned thinLVs within thin-pool...

What comes to my mind as possible supporting solution is -
adding possible enhancement on LVM2 side could be 'forcible' removal of running volumes (aka lvm2 equivalent of 'dmsetup remove --force')

ATM lvm2 prevents you to remove 'running/mounted' volumes.

I can well imagine LVM will let you forcible replace such LV with error target - so instead of thinLV - you will have single 'error' target snapshot - which could be possibly even auto-cleaned once the volume use-count drops bellow 0 (lvmpolld/dmeventd monitoring whatever...)

(Of course - we are not solving what happens to application using/running out of such error target - hopefully something not completely bad....)

This way - you get very 'powerful' weapon to be used in those 'scriplets' so you can drop uneeded volumes ANYTIME you need to and reclaim its resources...

Regards

Zdenek

#4 lore raw

Il 13-09-2017 10:15 Zdenek Kabelac ha scritto:

Quoted 1 line

Ohh this is pretty major constrain ;)

Sure :p
Sorry for not explicitly stating that before.

Quoted 7 lines

But as pointed out multiple times - with scripting around various fullness moments of thin-pool - several different actions can be programmed around,
starting from fstrim, ending with plain erase of unneeded snapshot. (Maybe erasing unneeded files....)

Quoted 6 lines

To get most secure application - such app should actually avoid using page-cache (using direct-io) in such case you are always guaranteed to get exact error at the exact time (i.e. even without journaled mounting option for ext4....)

True, but pagecache exists for a reason. Anyway, this is not anything you can "fix" in device mapper/lvm, I 100% agree with that.

Quoted 15 lines

Partially this might get solved in 'some' cases with fully provisioned thinLVs within thin-pool...

What comes to my mind as possible supporting solution is - adding possible enhancement on LVM2 side could be 'forcible' removal of running volumes (aka lvm2 equivalent of 'dmsetup remove --force')

ATM lvm2 prevents you to remove 'running/mounted' volumes.

I can well imagine LVM will let you forcible replace such LV with error target - so instead of thinLV - you will have single 'error' target snapshot - which could be possibly even auto-cleaned once the volume use-count drops bellow 0 (lvmpolld/dmeventd monitoring whatever...)

Quoted 7 lines

(Of course - we are not solving what happens to application using/running out of such error target - hopefully something not completely bad....)

This way - you get very 'powerful' weapon to be used in those 'scriplets' so you can drop uneeded volumes ANYTIME you need to and reclaim its resources...

This would be *really* great. I played with dm-setup remove/error target and, while working, it often freezed LVM. An integrated forced volume removal/swith to error target would be great.

Thank.

Signature · 5 lines
Danti Gionatan
Supporto Tecnico
Assyoma S.r.l. - www.assyoma.it
email: [email protected] - [email protected]
GPG public key ID: FF5F32A8
#5 lore raw

Dne 13.9.2017 v 10:28 Gionatan Danti napsal(a):

Quoted 14 lines

Il 13-09-2017 10:15 Zdenek Kabelac ha scritto:

Quoted 13 lines

Ohh this is pretty major constrain ;)

I can well imagine� LVM will let you forcible� replace such LV with error target� - so instead of� thinLV� - you will have� single 'error' target snapshot - which could be possibly even� auto-cleaned once the volume use-count drops bellow 0� (lvmpolld/dmeventd monitoring whatever...)

(Of course - we are not solving what happens to application using/running out of such error target - hopefully something not completely bad....)

Quoted 7 lines
Quoted 3 lines

This way - you get very 'powerful' weapon to be used in those 'scriplets' so you can drop uneeded volumes ANYTIME you need to and reclaim its resources...

This would be *really* great. I played with dm-setup remove/error target and, while working, it often freezed LVM. An integrated forced volume removal/swith to error target would be great.

Forcible remove (with some reasonable locking - so i.e. 2 processes are not playing with same device :) 'dmsetup remove --force' - is replacing
existing device with 'error' target (with built-in noflush)

Anyway - if you see a reproducible problem with forcible removal - it needs to be reported as this is a real bug then and BZ shall be opened...

Regards

Zdenek

#6 lore raw

Il 13-09-2017 10:44 Zdenek Kabelac ha scritto:

Quoted 5 lines

Forcible remove (with some reasonable locking - so i.e. 2 processes
are not playing with same device :) 'dmsetup remove --force' - is
replacing
existing device with 'error' target (with built-in noflush)

Quoted 7 lines

Anyway - if you see a reproducible problem with forcible removal - it needs to be reported as this is a real bug then and BZ shall be opened...

Regards

Zdenek

Ok, I'll do some more test and in case problems arise I'll open the BZ :) Thanks.

Signature · 5 lines
Danti Gionatan
Supporto Tecnico
Assyoma S.r.l. - www.assyoma.it
email: [email protected] - [email protected]
GPG public key ID: FF5F32A8