2 ms·
All of this relies on the rest of the system playing well and only using POSIX rename() to replace files. So to do it safely, you need to make a swap file copy
by audidude 9y ago
All of this relies on the rest of the system playing well and only using POSIX rename() to replace files. So to do it safely, you need to make a swap file copy (a'la vim) to do the paginated mmap() + page-replacement cache on the swap file.
However, often times you also need to do encoding conversion, and you can do this at the same time as the copy to the swap file.
If you detect you have btrfs/xfs w/ reflink support, and no encoding change is necessary, you can cheat and just do a CoW of the underlying block ranges and let the FS garbage collect it afterwards (just unlink() your reflink copy immediately).
Another convenient thing you can do with the swap file, is use the tail of it for a write ahead log of the changes in a piecetable and crash recovery.
- wrycoder 9y agoBelieve me, I'm not bored.