On Wed, Apr 29, 2020 at 12:30 PM Stefanie Leisestreichler <stefanie.leisestreichler@xxxxxxxxxxxxxx> wrote: > > Hi. > From the chattr man page: > A file with the 'C' attribute set will not be subject to copy-on-write > updates. This flag is only supported on file systems which perform > copy-on-write. (Note: For btrfs, the 'C' flag should be set on new or > empty files. 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. If > the 'C' flag is set on a directory, it will have no effect on the > directory, but new files created in that directory will have the No_COW > attribute set.) > > Question 1) > If /var/lib/mysql is a own subvolume and chattr +C /var/lib/mysql is set > and mysql is configured to use one directory for every database, will > nodatacow apply for a new dir which is created when a new db is created? > Just asking, because the last sentence of the man above which states > "...new files created in that directory...". Is a dir a file in the > context of chattr? Yes. $ btrfs sub create haha Create subvolume './haha' $ chattr +C haha $ mkdir haha/test $ lsattr haha ---------------C---- haha/test $ > > Question 2) > I guess CoW will still happen, if I hold a snapshot of the subvolume > which will be mounted to /var/lib/mysql. Is this correct? Yes, initial changes will COW to new extents, subsequent changes for changed extents are nocow until there's another snapshot. > Question 3) > How to solve this and avoid defragmentation if my assumption in 2) is > correct? I'm not sure what the problem is you want solved. I'm not certain the behavior is identical on XFS but I expect that reflink copy of a database file on XFS causes any initial changed extent to be COW and subsequent changes to the same extent to be an overwrite. -- Chris Murphy
