All of lore.kernel.org
 help / color / mirror / Atom feed
* btrfs and hibernation to swap file on it?
@ 2022-09-27 15:45 Christoph Anton Mitterer
  2022-09-28 19:12 ` Andrei Borzenkov
  2022-09-30 12:12 ` Forza
  0 siblings, 2 replies; 5+ messages in thread
From: Christoph Anton Mitterer @ 2022-09-27 15:45 UTC (permalink / raw)
  To: linux-btrfs

Hey.

Maybe someone could help me with that question:

I'd like to set up hibernation, using a swapfile on btrfs (which itself
is on dm-crypt).

Now I'm aware of the section on swaptfiles in btrfs(5) and their
restrictions... and I think these should be fine for me.


What I don't quite get is:

a) Hibernate seems to want an offset parameter for the swapfile. How is
that used respectively why is it needed.

Does that mean that hibernation directly writes/reads to/from the block
device?
And wouldn't that be kind of fragile (if something internally moves in
the fs... or if it's split in several extents and not one big
contiguous space)?

Guess I would be kinda scared to get some corruptions if something
writes directly to the btrfs' block device - other than btrfs.

Are there any suggestions with respect to btrfs? Like not using a
swapfile for hibernation, or is it considered safe?


b) Internet resources say that for btrfs one cannot use filefrag to get
the offset.
I found Omar's tool, but wondered whether the same had been directly
integrated into btrfs-progs in the meantime?



Thanks,
Chris.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: btrfs and hibernation to swap file on it?
  2022-09-27 15:45 btrfs and hibernation to swap file on it? Christoph Anton Mitterer
@ 2022-09-28 19:12 ` Andrei Borzenkov
  2022-10-23 21:19   ` Christoph Anton Mitterer
  2022-09-30 12:12 ` Forza
  1 sibling, 1 reply; 5+ messages in thread
From: Andrei Borzenkov @ 2022-09-28 19:12 UTC (permalink / raw)
  To: Christoph Anton Mitterer, linux-btrfs

On 27.09.2022 18:45, Christoph Anton Mitterer wrote:
> Hey.
> 
> Maybe someone could help me with that question:
> 
> I'd like to set up hibernation, using a swapfile on btrfs (which itself
> is on dm-crypt).
> 
> Now I'm aware of the section on swaptfiles in btrfs(5) and their
> restrictions... and I think these should be fine for me.
> 
> 
> What I don't quite get is:
> 
> a) Hibernate seems to want an offset parameter for the swapfile. How is
> that used respectively why is it needed.
> 
> Does that mean that hibernation directly writes/reads to/from the block
> device?

Correct.

> And wouldn't that be kind of fragile (if something internally moves in
> the fs... or if it's split in several extents and not one big
> contiguous space)?
> 

There are quite some restrictions for using swapfile on btrfs, in
particular, it must be preallocated and btrfs will refuse relocation of
extents in this file.

kernel supports swapfile with multiple extents.

> Guess I would be kinda scared to get some corruptions if something
> writes directly to the btrfs' block device - other than btrfs.
> 
> Are there any suggestions with respect to btrfs? Like not using a
> swapfile for hibernation, or is it considered safe?
> 
> 
> b) Internet resources say that for btrfs one cannot use filefrag to get
> the offset.
> I found Omar's tool, but wondered whether the same had been directly
> integrated into btrfs-progs in the meantime?
> 
> 
> 
> Thanks,
> Chris.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: btrfs and hibernation to swap file on it?
  2022-09-27 15:45 btrfs and hibernation to swap file on it? Christoph Anton Mitterer
  2022-09-28 19:12 ` Andrei Borzenkov
@ 2022-09-30 12:12 ` Forza
  2022-10-23 21:25   ` Christoph Anton Mitterer
  1 sibling, 1 reply; 5+ messages in thread
From: Forza @ 2022-09-30 12:12 UTC (permalink / raw)
  To: Christoph Anton Mitterer, linux-btrfs



On 2022-09-27 17:45, Christoph Anton Mitterer wrote:
> Hey.
> 
> Maybe someone could help me with that question:
> 
> I'd like to set up hibernation, using a swapfile on btrfs (which itself
> is on dm-crypt).
> 
> Now I'm aware of the section on swaptfiles in btrfs(5) and their
> restrictions... and I think these should be fine for me.
> 
> 
> What I don't quite get is:
> 
> a) Hibernate seems to want an offset parameter for the swapfile. How is
> that used respectively why is it needed.
> 
> Does that mean that hibernation directly writes/reads to/from the block
> device?

Yes. The kernel stores Hibernation information (RAM contents) in the file.

> And wouldn't that be kind of fragile (if something internally moves in
> the fs... or if it's split in several extents and not one big
> contiguous space)?
> 

Btrfs will not move the swap-file once it is created, so it is ok.

> Guess I would be kinda scared to get some corruptions if something
> writes directly to the btrfs' block device - other than btrfs.
> 
> Are there any suggestions with respect to btrfs? Like not using a
> swapfile for hibernation, or is it considered safe?

Swapfile should work fine. Btrfs tells the kernel on what blocks it can 
write to. This brings the limitations as you already mentionee; no 
snapshots, no datacow, no compression and also no DUP/RAID profile.

For those reasons I usually prefer to have a separate swap partition so 
that I am free to use snapshots and other Btrfs features. If you use 
dm-crypt you can setup another lv or another partition for swap.

> 
> 
> b) Internet resources say that for btrfs one cannot use filefrag to get
> the offset.
> I found Omar's tool, but wondered whether the same had been directly
> integrated into btrfs-progs in the meantime?
> 
> 
> 
> Thanks,
> Chris.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: btrfs and hibernation to swap file on it?
  2022-09-28 19:12 ` Andrei Borzenkov
@ 2022-10-23 21:19   ` Christoph Anton Mitterer
  0 siblings, 0 replies; 5+ messages in thread
From: Christoph Anton Mitterer @ 2022-10-23 21:19 UTC (permalink / raw)
  To: Andrei Borzenkov, linux-btrfs

Hey Andrei.

Thanks for your replies and sorry for my late answer but first I had
been on some diving trip and then had a cold until few days ago.


On Wed, 2022-09-28 at 22:12 +0300, Andrei Borzenkov wrote:
> There are quite some restrictions for using swapfile on btrfs, in
> particular, it must be preallocated and btrfs will refuse relocation
> of
> extents in this file.

I assume it only does so (refuse relocation) while it's actually an
active swap area (how would it know otherwise that the file is a swap
file)?


> kernel supports swapfile with multiple extents.

Ah, I see.


So, with the btrfsprogs, is there a way to get the offset?

The whole interface with specifying an offset seems to be quite unhandy
anyway (would be better for users IMO, if one could specify a pathname
and the kernel would find out the offset by itself)... but having to
download/compile a "3rd party" tool makes it even more cumbersome.


Cheers,
Chris.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: btrfs and hibernation to swap file on it?
  2022-09-30 12:12 ` Forza
@ 2022-10-23 21:25   ` Christoph Anton Mitterer
  0 siblings, 0 replies; 5+ messages in thread
From: Christoph Anton Mitterer @ 2022-10-23 21:25 UTC (permalink / raw)
  To: Forza, linux-btrfs

Hey Forza.

On Fri, 2022-09-30 at 14:12 +0200, Forza wrote:
> Btrfs will not move the swap-file once it is created, so it is ok.

Well, at least as long every current (and future) part of btrfs
remembers that ;-)



>  This brings the limitations as you already mentionee; no 
> snapshots, no datacow, no compression and also no DUP/RAID profile.

But effectively one can make a separate subvolume and just have the
restrictions there? Well at least no snapshots, nodatacow and
nocompression.


> For those reasons I usually prefer to have a separate swap partition
> so 
> that I am free to use snapshots and other Btrfs features.

I'm also kinda inclined to to that, but less because of the feature
limitations and more because I'm a bit wary on how stable or fragile
the concept of the kernel bypassing the fs and directly writing to the
block device is.

OTOH, not having to "waste" considerable amount of storage just for the
hibernation file, would be quite nice.


> If you use 
> dm-crypt you can setup another lv or another partition for swap.

Sure, but again I'd have preferred not to add another DM layer.

And didn't some users recently report some issues with dm-
crypt+lvm+btrfs here?!
But maybe I mix something up and that was something else.



Thanks,
Chris.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-23 21:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-27 15:45 btrfs and hibernation to swap file on it? Christoph Anton Mitterer
2022-09-28 19:12 ` Andrei Borzenkov
2022-10-23 21:19   ` Christoph Anton Mitterer
2022-09-30 12:12 ` Forza
2022-10-23 21:25   ` Christoph Anton Mitterer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.