05.05.2019 10:50, Maksim Fomin пишет: > Good day. > > Since 5.0 btrfs supports swap files. Does it support hibernation into > a swap file? > > With kernel version 5.0.10 (archlinux) and btrfs-progs 4.20.2 > (unlikely to be relevant, but still) when I try to hibernate with > systemctl or by directly manipulating '/sys/power/resume' and > '/sys/power/resume_offset', the kernel logs: > > PM: Cannot find swap device, try swapon -a PM: Cannot get swap > writer >
How exactly do you compute resume_offset? What are exact commands you ise to initiate hibernation? systemctl will likely not work anyway as systemd is using FIEMAP which returns logical offset of file extents in btrfs address space, not physical offset on containing device. You will need to jump from extent vaddr to device offset manually. > After digging into this issue I suspect that currently btrfs does not > support hibernation into swap file (or does it?). Furthermore, I > suspect that kernel mechanism of accessing swap file via > 'resume_offset' is unreliable in btrfs case because it is more likely > (comparing to other fs) to move files across filesystem which > invalidates swap file offset, so the whole idea is dubious. So, > > 1) does btrfs supports hibernation into swap file? 2) is there > mechanism to lock swap file? > btrfs performs some checks before allowing file as swap and it also implicitly locks it during swap usage. Note that btrfs will disable snapshots of subvolume with swapfile. File also must be using single allocation profile. There is no way to force allocation profile for individual file I am aware of in case filesytem defaults to something else. Also for multi-device btrfs I am not aware of any way to force allocation of file on specific physical device, and this is required to use file as swap on btrfs. So you are likely restricted to single device single data profile. Finally you are not allowed to mount any filesystem read-write (or replay any pending log/journal) before doing resume. Does btrfs support "true" read-only mount, which is guaranteed to not change filesystem state in any way?