CopyOnWrite 0.1.2
See the version list below for details.
dotnet add package CopyOnWrite --version 0.1.2
NuGet\Install-Package CopyOnWrite -Version 0.1.2
<PackageReference Include="CopyOnWrite" Version="0.1.2" />
paket add CopyOnWrite --version 0.1.2
#r "nuget: CopyOnWrite, 0.1.2"
// Install CopyOnWrite as a Cake Addin #addin nuget:?package=CopyOnWrite&version=0.1.2 // Install CopyOnWrite as a Cake Tool #tool nuget:?package=CopyOnWrite&version=0.1.2
This library provides a .NET layer on top of OS-specific logic that provides copy-on-write linking for files (a.k.a. CoW, file cloning, or reflinking). CoW linking provides the ability to copy a file without actually copying the original file's bytes from one disk location to another. The filesystem is in charge of ensuring that if the original file is modified or deleted, the CoW linked files remain unmodified by lazily copying the original file's bytes into each link. Unlike symlinks or hardlinks, writes to CoW links do not write through to the original file, as the filesystem breaks the link and copies in a lazy fashion. This enables scenarios like file caches where a single copy of a file held in a content-addressable or other store is safely linked to many locations in a filesystem with low I/O overhead.
This library allows a .NET developer to:
- Discover whether CoW links are allowed between two filesystem paths,
- Discover whether CoW links are allowed for a directory tree based at a specific root directory,
- Create CoW links.
- Find filesystem CoW link limits.
Discovery is important, as different operating systems and different filesystems available for those operating systems provide varying levels of CoW link support:
- Windows: The default NTFS filesystem does NOT support CoW, but the ReFS filesystem does.
- Linux: Btrfs, Xfs, Zfs support CoW while ext4 does not.
- Mac: AppleFS supports CoW by default.
When using this library you may need to create a wrapper that copies the file if CoW is not available.
Example
using Microsoft.CopyOnWrite;
ICopyOnWriteFilesystem cow = CopyOnWriteFilesystemFactory.GetInstance();
bool canCloneInCurrentDirectory = cow.CopyOnWriteLinkSupportedInDirectoryTree(Environment.CurrentDirectory);
if (canCloneInCurrentDirectory)
{
cow.CloneFile(existingFile, cowLinkFilePath);
}
Release History
- 0.1.2 October 2021: Performance fixes for Windows. Mac and Linux throw NotSupportedException.
- 0.1.1 October 2021: Bug fixes for Windows. Mac and Linux throw NotSupportedException.
- 0.1.0 July 2021: Windows ReFS support. Mac and Linux throw NotSupportedException.
Performance Comparisons
Windows
Generally, CoW links on ReFS save time over file copies except at file size zero. The savings is proportional to the file size, with 16MB files at about 35X performance, 1MB at 3.2X, and small sizes at about 1.3X.
Detailed numbers for a VHD formatted empty with ReFS for each iteration, comparing System.IO.File.Copy()
with CloneFile()
, 25 copies/clones of a single source file per measurement. See CoWComparisons.cs. Machine was an 8/16-core M.2 SSD, Win10 21H1 Enterprise.
Method | FileSize | Mean | Error | StdDev | Median | Ratio | RatioSD |
---|---|---|---|---|---|---|---|
File.Copy | 0 | 4.933 ms | 0.3274 ms | 0.9551 ms | 4.799 ms | 1.00 | 0.00 |
CoW | 0 | 5.002 ms | 0.2447 ms | 0.7100 ms | 4.885 ms | 1.04 | 0.21 |
File.Copy | 1 | 8.841 ms | 0.4976 ms | 1.4197 ms | 8.515 ms | 1.00 | 0.00 |
CoW | 1 | 6.499 ms | 0.3647 ms | 1.0579 ms | 6.169 ms | 0.75 | 0.13 |
File.Copy | 1024 | 8.614 ms | 0.4982 ms | 1.4374 ms | 8.471 ms | 1.00 | 0.00 |
CoW | 1024 | 6.678 ms | 0.3776 ms | 1.0834 ms | 6.269 ms | 0.79 | 0.14 |
File.Copy | 16384 | 8.950 ms | 0.5148 ms | 1.4770 ms | 8.454 ms | 1.00 | 0.00 |
CoW | 16384 | 6.774 ms | 0.3240 ms | 0.9137 ms | 6.622 ms | 0.77 | 0.12 |
File.Copy | 262144 | 12.700 ms | 0.6236 ms | 1.7993 ms | 12.140 ms | 1.00 | 0.00 |
CoW | 262144 | 7.036 ms | 0.3911 ms | 1.1470 ms | 6.882 ms | 0.56 | 0.10 |
File.Copy | 1048576 | 21.920 ms | 0.4359 ms | 1.1785 ms | 21.690 ms | 1.00 | 0.00 |
CoW | 1048576 | 6.940 ms | 0.3652 ms | 1.0711 ms | 6.743 ms | 0.32 | 0.05 |
File.Copy | 16777216 | 252.637 ms | 2.9167 ms | 2.5855 ms | 251.895 ms | 1.00 | 0.00 |
CoW | 16777216 | 7.272 ms | 0.2882 ms | 0.7987 ms | 7.136 ms | 0.03 | 0.00 |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on CopyOnWrite:
Package | Downloads |
---|---|
Microsoft.MSBuildCache.Common
A project cache plugin for MSBuild |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on CopyOnWrite:
Repository | Stars |
---|---|
microsoft/MSBuildSdks
MSBuild project SDKs
|
Version | Downloads | Last updated |
---|---|---|
0.4.2 | 140 | 11/4/2024 |
0.4.1 | 124 | 10/28/2024 |
0.4.0 | 94 | 10/14/2024 |
0.3.12 | 152 | 10/14/2024 |
0.3.11 | 217 | 9/24/2024 |
0.3.10 | 132 | 9/23/2024 |
0.3.9 | 110 | 9/23/2024 |
0.3.8 | 11,859 | 3/25/2024 |
0.3.7 | 8,116 | 9/11/2023 |
0.3.6 | 7,920 | 7/17/2023 |
0.3.5 | 202 | 7/13/2023 |
0.3.4 | 222 | 7/12/2023 |
0.3.3 | 208 | 7/11/2023 |
0.3.2 | 9,019 | 2/9/2023 |
0.3.1 | 339 | 2/8/2023 |
0.3.0 | 1,089 | 1/30/2023 |
0.2.2 | 406 | 1/27/2023 |
0.2.1 | 5,910 | 9/27/2022 |
0.2.0 | 477 | 9/15/2022 |
0.1.13 | 474 | 9/15/2022 |
0.1.12 | 485 | 9/15/2022 |
0.1.11 | 469 | 9/6/2022 |
0.1.10 | 428 | 9/3/2022 |
0.1.9 | 410 | 9/3/2022 |
0.1.8 | 522 | 4/19/2022 |
0.1.7 | 504 | 4/19/2022 |
0.1.6 | 444 | 4/19/2022 |
0.1.5 | 376 | 10/15/2021 |
0.1.4 | 366 | 10/14/2021 |
0.1.3 | 357 | 10/13/2021 |
0.1.2 | 351 | 10/13/2021 |
0.1.1 | 389 | 10/11/2021 |
0.1.0 | 406 | 7/10/2021 |