Tookmund / Swapspace

A fork of Jeroen T. Vermeulen's excellent dynamic swap space manager
GNU General Public License v2.0
128 stars 12 forks source link

Warning: Could not disable COW '1': Invalid argument #32

Closed axet closed 2 years ago

axet commented 2 years ago

Hello!

Recent debian kernel version of linux-image-amd64 (5.14.9-2) causing following error in syslog:

Oct 12 19:42:54 axet-laptop swapspace[784]: Warning: Could not disable COW '1': Invalid argument
Oct 12 19:42:54 axet-laptop swapspace[3093]: Setting up swapspace version 1, size = 852.3 MiB (893706240 bytes)
Oct 12 19:42:54 axet-laptop swapspace[3093]: no label, UUID=9845f44a-6f59-4b46-a23e-2c77374db359
Oct 12 19:42:54 axet-laptop swapspace[784]: Error: Could not enable swapfile '1': Invalid argument
Oct 12 19:42:54 axet-laptop swapspace[784]: Warning: Could not disable COW '1': Invalid argument
Oct 12 19:42:54 axet-laptop kernel: [   54.712661] BTRFS warning (device dm-0): swapfile must not be copy-on-write
Oct 12 19:42:56 axet-laptop swapspace[3097]: Setting up swapspace version 1, size = 852.3 MiB (893706240 bytes)
Oct 12 19:42:56 axet-laptop swapspace[3097]: no label, UUID=4fd45e32-d2cc-46fb-9ad6-31fbea31388d
Oct 12 19:42:56 axet-laptop swapspace[784]: Error: Could not enable swapfile '1': Invalid argument
Oct 12 19:42:56 axet-laptop kernel: [   56.279310] BTRFS warning (device dm-0): swapfile must not be copy-on-write

This is unreleased and new debian (bookworm) with: swapspace 1.17-1

Tookmund commented 2 years ago

I'll have to look into this, that definitely shouldn't be happening.

As a temporary fix, you should be able to disable copy-on-write for the whole swapfile directory. The warning will probably still occur, but the swapfile should be successfully enabled.

chattr +C /var/lib/swapspace
axet commented 2 years ago
axet@axet-laptop:~$ sudo chattr +C /var/lib/swapspace
chattr: Invalid argument while setting flags on /var/lib/swapspace
axet@axet-laptop:~$ 

I guess this is 100% debian issue.

chungy commented 2 years ago

Basic question: is that directory actually on btrfs?

You can use df -T /var/lib/swapspace to verify.

axet commented 2 years ago

Not that simple ;)

axet@axet-laptop:~$ df -T /var/lib/swapspace
Filesystem       Type  1K-blocks     Used Available Use% Mounted on
/dev/mapper/luks btrfs 361487360 70731556 290052396  20% /
axet@axet-laptop:~$
Tookmund commented 2 years ago

I have not been able to reproduce this in a fresh Debian 11 install on BTRFS with the same kernel and Swapspace versions.

Do you know what BTRFS mount options you’re using? They should be in /etc/fstab

Jacob

On Oct 14, 2021, at 00:37, axet @.***> wrote:

 Not that simple ;)

@.:~$ df -T /var/lib/swapspace Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/mapper/luks btrfs 361487360 70731556 290052396 20% / @.:~$ — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

axet commented 2 years ago
UUID="a90dee0b-b4d0-429f-a078-8eda0b36abcd" /               btrfs    defaults 0       1
axet commented 2 years ago

I see:

axet@axet-laptop:~$ sudo lsattr /var/lib/|grep swap
--------c------------- /var/lib/swapspace
axet@axet-laptop:~$ sudo chattr -c /var/lib/swapspace
axet@axet-laptop:~$ sudo chattr +C /var/lib/swapspace
axet@axet-laptop:~$ 
axet commented 2 years ago

I suggest auto remove compression flag from /var/lib/swapspace folder automatically if present by swapspace service.

Tookmund commented 2 years ago

This approach has now been taken in the dir_attr branch. More testing is required before I can release it as is, but I can confirm that it fixes the problem seen in this issue.

axet commented 2 years ago

Removing '-c' from swaspace folder not necessary. You can just remove compression flag from file it self:

truncate -s 0 swapfile1 # create zero length file
chattr -c swapfile1 # drop compression flag
chattr +C swapfile1 # drop COW
btrfs property set swapfile1 compression none # force no compression
dd if=/dev/zero of=swapfile1 bs=1G count=1 # fill up
fallocate -l 5G swapfile1 # or use fallocate instead dd

EDIT: suggesting following patch:

@@ -452,6 +455,17 @@ int set_no_cow(int fd)
     }
     else return err;
   }
+  attr &= ~FS_COMPR_FL;
+  err = ioctl(fd, FS_IOC_SETFLAGS, &attr);
+  if (err != 0)
+  {
+    if (errno == ENOTSUP)
+    {
+      nocow_ok = false;
+      logm(LOG_NOTICE, "removing COMPR attribute not supported!");
+    }
+    else return err;
+  }
   attr |= FS_NOCOW_FL;
   err = ioctl(fd, FS_IOC_SETFLAGS, &attr);
   if (err != 0)

I've tested it. It works fine even with '+c' flag set on /var/lib/swapspace