Btrfs : compress and nodatacow priority + automation
2
votes
0
answers
596
views
I have a btrfs partition mounted on
/
with compression enabled:
mount -o subvol=@,defaults,noatime,nodiratime,compress=zstd,space_cache=v2 /dev/mapper/archlinux /mnt
I want to disable the CoW mecanism on some folders such as:
- The folder which contains my VM disks
- Any folder that might contain SQLite databases (mostly for browsers)
Here's what [btrfs documentation](https://btrfs.readthedocs.io/en/latest/Administration.html#mount-options) states :
> If compression is enabled, nodatacow and nodatasum are disabled.
But it also states
> If nodatacow or nodatasum are enabled, compression is disabled.
I'm ok with the fact that they are mutually exclusive, however I do wonder which one will take priority if I set chattr +C
to a folder. Will my change remain permanent ? Or will it be overriden during the next boot when my partition is remounted with the compress
option ? My guts tell me that chattr +C
will take precedence, but I've been unable to find any documentation that would confirm that.
Second question is: is there a way to automatically disable CoW on all newly created SQLite databases ? At first I wanted to write a systemd timer which would scan the whole file system to look for SQLite databases and set chattr +C
on it. But then in the [chattr man page](https://man7.org/linux/man-pages/man1/chattr.1.html) I read the following:
> If it is set on a file which already has data blocks, it is undefined when the blocks assigned to the file will be fully stable.
So basically I should not use chattr +C
on existing non-empty files. Is there a way to hook into the filesystem so that any file that ends with \.(sqlite|db)
or has the SQLite magic bytes won't use CoW ? Or do I have no other choice but to manually create the NoCoW folder before I install the targetted application ? I don't necessarily know if X or Y app is using an SQLite backend, it would be very inconvenient to remove all the app data to set NoCoW every time I realise an app is using SQLite. What would you recommend to somehow automate this process ?
EDIT:
Do you think it should be distributions maintainers responsibility to set chattr +C
during installation of packages that use SQLite ?
Asked by ShellCode
(235 rep)
Mar 2, 2023, 12:43 PM
Last activity: Mar 4, 2023, 12:50 PM
Last activity: Mar 4, 2023, 12:50 PM