unionfs-fuse icon indicating copy to clipboard operation
unionfs-fuse copied to clipboard

Use clone copy for copy-up operation on APFS file systems on MacOS

Open WaterJuice opened this issue 2 years ago • 5 comments

The APFS filesystem for MacOS has a built in COW feature which is implemented at the block level. Performing a copy up operation using the file clone would dramatically improve the performance with very little extra required to implement it. It would just involve changing the existing copy function to use the macOS clone when it can. The APFS COW is performed at the block level, and the initial clone in instant as no data is copied at that point. And only as blocks are changed are those individual blocks copied.

WaterJuice avatar May 01 '22 01:05 WaterJuice

What exactly would you have to add? Any documentation?

DUOLabs333 avatar May 16 '22 16:05 DUOLabs333

You can probably change cow.c at copy_file to say if __APPLE__ is defined, use clonefile(from,to,flags), else use copy_file as a preprocessor directive. Shouldn't be too hard.

DUOLabs333 avatar May 16 '22 16:05 DUOLabs333

Well, patches welcome I guess. But note that unionfs does full file copies, while it looks like you want to use block level cow. Not impossible, but quite some work for full block level cow...

bsbernd avatar May 23 '22 13:05 bsbernd

Well, patches welcome I guess. But note that unionfs does full file copies, while it looks like you want to use block level cow. Not impossible, but quite some work for full block level cow...

The point is its not work at all because the block level COW is performed by APFS. It is just a change from doing an actual file copy to a "clone copy" at the point it does the copy-up. On the command line its as simple as adding -c to the copy command.

WaterJuice avatar May 23 '22 22:05 WaterJuice

So what is the "-c" option actually doing - which system call switches it to? Please check with strace what changes.... I guess you could then easily update the code to add this in.

bsbernd avatar Aug 12 '22 18:08 bsbernd