LWN: Comments on "The Linux "copy problem"" https://lwn.net/Articles/789623/ This is a special feed containing comments posted to the individual LWN article titled "The Linux "copy problem"". en-us Thu, 16 Oct 2025 12:46:03 +0000 Thu, 16 Oct 2025 12:46:03 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net The Linux "copy problem" https://lwn.net/Articles/844695/ https://lwn.net/Articles/844695/ oliwer <div class="FormattedComment"> Note that GNU cp(1) recently added support for copy_file_range(2).<br> <a rel="nofollow" href="https://git.savannah.gnu.org/cgit/coreutils.git/commit/src/copy.c?id=4b04a0c3b792d27909670a81d21f2a3b3e0ea563">https://git.savannah.gnu.org/cgit/coreutils.git/commit/sr...</a><br> </div> Mon, 01 Feb 2021 13:18:12 +0000 The Linux "copy problem" https://lwn.net/Articles/791854/ https://lwn.net/Articles/791854/ nix <div class="FormattedComment"> Reflinking does, inevitably, reduce the fragmentation-resistance of the filesystem if you use it a lot and tend to keep the post-reflinked files for longer than the pre-reflinked ones. (That's the whole point, after all: the new blocks are necessarily going to be fragmented wrt the old ones, even if this is reduced by writing more than strictly needed in the CoW phase.)<br> <p> Ideally, a background preen phase would rewrite such things after a while so they are non-fragmented again. I guess one could call xfs_fsr from cron to do that... on an SSD this matters not at all, of course, and not very much if there's a caching layer like LVM's or bcache in the way either. But it's a real concern on unintermediated spinning rust.<br> </div> Mon, 24 Jun 2019 14:28:47 +0000 The Linux "copy problem" https://lwn.net/Articles/791532/ https://lwn.net/Articles/791532/ jezuch <div class="FormattedComment"> I think people were concerned with loss of redundancy. Some claimed that they make a copy because they want to *really* have an actual copy and making it COW by default is surprising to the user by basically changing the contract of the command.<br> <p> That's how I remember it at least.<br> <p> Anyway, when I copy something it's mostly because I screwed up and I am restoring things from a btrfs backup snapshot. Making a real copy would cause unnecessary duplication in the backup - and would be unnecessarily slow and drive-thrashing. But that's just my use case.<br> </div> Thu, 20 Jun 2019 06:51:50 +0000 The copy problem is really the backup problem https://lwn.net/Articles/791513/ https://lwn.net/Articles/791513/ nix <div class="FormattedComment"> btrfs send and receive are not regular I/O, so they work fine. (Though I'm not sure what happens in conjunction with O_DIRECT, which is a bit... hard to grasp the semantics of on a CoW filesystem in any case.)<br> <p> (You don't get -ETXTBSY if you read a file in any case, only if you try to modify it.)<br> </div> Wed, 19 Jun 2019 21:32:21 +0000 The Linux "copy problem" https://lwn.net/Articles/791227/ https://lwn.net/Articles/791227/ nevyn <div class="FormattedComment"> Why is this not the default?<br> </div> Sun, 16 Jun 2019 17:40:19 +0000 The Linux "copy problem" https://lwn.net/Articles/790839/ https://lwn.net/Articles/790839/ smfrench <div class="FormattedComment"> This is great news - looking forward to trying it. Am also very excited about the work Andreas at RedHat did, enabling GCM crypto for SMB3.1.1 mounts, which can more than double performance copying files to server when on encrypted mounts (in conjunction with two cifs.ko client patches that I recently merged into for-next that enable GCM on the client).<br> </div> Mon, 10 Jun 2019 21:58:01 +0000 The copy problem is really the backup problem https://lwn.net/Articles/790239/ https://lwn.net/Articles/790239/ mcr <div class="FormattedComment"> What happens if a file is open (TXTBUSY)? or open O_DIRECT, or any of these other things that might be mutually exclusive with regular I/O?<br> </div> Tue, 04 Jun 2019 14:06:36 +0000 The copy problem is really the backup problem https://lwn.net/Articles/790232/ https://lwn.net/Articles/790232/ jezuch <div class="FormattedComment"> At least on btrfs that's:<br> <p> btrfs subvolume snapshot -r<br> btrfs send<br> btrfs receive<br> <p> But it does not work on per-file basis, unfortunately. And yes, btrfs defines its own serialization format.<br> </div> Tue, 04 Jun 2019 09:18:20 +0000 The Linux "copy problem" https://lwn.net/Articles/790079/ https://lwn.net/Articles/790079/ desbma <div class="FormattedComment"> You are right, I'm using ZSH and didn't realize that line was not portable across other shells.<br> <p> curl -v --compressed '<a href="https://lwn.net/">https://lwn.net/</a>' -o /dev/null 2&gt;&amp;1 | grep gzip<br> <p> also works<br> </div> Sun, 02 Jun 2019 12:45:37 +0000 The Linux "copy problem" https://lwn.net/Articles/790077/ https://lwn.net/Articles/790077/ Jandar <div class="FormattedComment"> <font class="QuotedText">&gt; curl -v --compressed '<a href="https://lwn.net/">https://lwn.net/</a>' &gt; /dev/null 2&gt;&amp;1 | grep gzip</font><br> <p> This command is obviously without any output.<br> <p> $ curl -v --compressed '<a href="https://lwn.net/">https://lwn.net/</a>' &gt; /dev/null 2&gt;&amp;1 | wc<br> 0 0 0<br> <p> Perhaps you meant: curl -v --compressed '<a href="https://lwn.net/">https://lwn.net/</a>' 2&gt;&amp;1 &gt; /dev/null | grep gzip<br> </div> Sun, 02 Jun 2019 12:20:52 +0000 The Linux "copy problem" https://lwn.net/Articles/790075/ https://lwn.net/Articles/790075/ desbma <div class="FormattedComment"> My browser (and curl) both disagree with you:<br> curl -v --compressed '<a href="https://lwn.net/">https://lwn.net/</a>' &gt; /dev/null 2&gt;&amp;1 | grep gzip<br> <font class="QuotedText">&gt; Accept-Encoding: deflate, gzip</font><br> &lt; Content-Encoding: gzip<br> </div> Sun, 02 Jun 2019 10:27:17 +0000 The Linux "copy problem" https://lwn.net/Articles/790072/ https://lwn.net/Articles/790072/ tarkasteve <div class="FormattedComment"> So inspired by all this, I've updated xcp with the ability to do parallel copies (at the per-file level). The results are fairly good; I'm seeing 30%-60% speed-ups depending on caching.<br> </div> Sun, 02 Jun 2019 05:12:03 +0000 The Linux "copy problem" https://lwn.net/Articles/790069/ https://lwn.net/Articles/790069/ scientes <div class="FormattedComment"> <font class="QuotedText">&gt; (including when your browser decompresses this very page).</font><br> <p> Compression is disabled for https sites due to various attacks on the file size information leak.<br> </div> Sun, 02 Jun 2019 03:07:27 +0000 The Linux "copy problem" https://lwn.net/Articles/790067/ https://lwn.net/Articles/790067/ scientes <div class="FormattedComment"> I myself was using inotail until I reported the problem (tail -f didn't support inotify) to coreutils and it was actually fixed.<br> </div> Sun, 02 Jun 2019 03:02:57 +0000 The Linux "copy problem" https://lwn.net/Articles/790064/ https://lwn.net/Articles/790064/ desbma <div class="FormattedComment"> This is most likely the infamous "dirty writeback" problem, best described in this LWN article: <a href="https://lwn.net/Articles/572911/">https://lwn.net/Articles/572911/</a><br> <p> On my systems, I fix it permanently with:<br> echo "vm.dirty_background_bytes=$((48 * 1024 * 1024))<br> vm.dirty_ratio=10" | sudo tee /etc/sysctl.d/99-dirty-writeback.conf<br> sudo sysctl --system<br> <p> That way the writeback kicks in with at most 48MB of dirty data, and also stalls the writer process before there is more than 10% of all memory consumed by dirty writeback pages.<br> </div> Sat, 01 Jun 2019 21:13:17 +0000 The Linux "copy problem" https://lwn.net/Articles/790060/ https://lwn.net/Articles/790060/ jmclnx <div class="FormattedComment"> Speeding up things is always good, but the one thing I have noticed in the last few years. Once in a great while, if I cp a large file from one local fs to another local fs, the whole system would freeze for multiple 10s of seconds when a sync happens. <br> <p> In the early days I never saw this and we use to make fun of Microsoft for having that freeze issue. I would rather have a slower cp and not have that sync freeze :)<br> <p> <p> </div> Sat, 01 Jun 2019 16:11:36 +0000 The Linux "copy problem" https://lwn.net/Articles/790054/ https://lwn.net/Articles/790054/ desbma <div class="FormattedComment"> Thanks for the link.<br> <p> It joins the list of great little tools that have taken inspiration from classic Unix command line tools, but rewritten them in Rust with many improvements along the way: grep -&gt; ripgrep, find -&gt; fd, hexdump -&gt; hexyl, cat -&gt; bat, du -&gt; diskus, cloc -&gt; tokei...<br> <p> I'll be sure to look into xcp, and probably open a few issues along the way :)<br> </div> Sat, 01 Jun 2019 13:04:38 +0000 The Linux "copy problem" https://lwn.net/Articles/790041/ https://lwn.net/Articles/790041/ tarkasteve <div class="FormattedComment"> I'd also humbly suggest `xcp`:<br> <p> <a href="https://crates.io/crates/xcp">https://crates.io/crates/xcp</a><br> <p> * Uses copy_file_range() where possible, falls back to userspace if not.<br> * Supports sparse files (with lseek; I wasn't aware of fiemap, is there any advantage to one over the other?)<br> * Partially parallel (recursive read is separate from copy operations; I have an todo for parallel copy as it seems to have advantages on nvme drives).<br> * Optional progress bar.<br> * Written in Rust<br> * Cross platform (well, Linux + other unix-like OSs; Windows may work, I've never managed to get Rust to work on it).<br> <p> It doesn't support much in the way of permissions/ACLs ATM, it's still an intermittent WIP.<br> <p> I did look at using O_DIRECT, but I get EINVAL. The open manpage lists a whole series of caveats and warnings about using it, including a disparaging quote from Linus.<br> <p> Thanks for the discussion/article, it's given me some things to look into.<br> <p> </div> Sat, 01 Jun 2019 01:40:21 +0000 The Linux "copy problem" https://lwn.net/Articles/790011/ https://lwn.net/Articles/790011/ rahulsundaram <div class="FormattedComment"> Yes. Enabled by default in recent Fedora and RHEL 8 as well. <br> </div> Fri, 31 May 2019 15:46:00 +0000 The Linux "copy problem" https://lwn.net/Articles/790007/ https://lwn.net/Articles/790007/ jhoblitt <div class="FormattedComment"> Doesn't XFS has reflink() support?<br> </div> Fri, 31 May 2019 14:44:39 +0000 The Linux "copy problem" https://lwn.net/Articles/789970/ https://lwn.net/Articles/789970/ LtWorf <div class="FormattedComment"> Some of us don't use experimental filesystems.<br> </div> Fri, 31 May 2019 09:33:48 +0000 The Linux "copy problem" https://lwn.net/Articles/789909/ https://lwn.net/Articles/789909/ jmgao <div class="FormattedComment"> <font class="QuotedText">&gt; He does think that there should be a way to create files with all of their attributes atomically, however.</font><br> <p> Isn't there already a solution to this? You can open a file on the filesystem you want to create the file on with O_TMPFILE to hide it until you've done all of your attribute twiddling, do your fsetfilecon, fsetxattr, etc. on the file descriptor, and then use linkat to put it into place.<br> </div> Thu, 30 May 2019 18:56:29 +0000 The Linux "copy problem" https://lwn.net/Articles/789886/ https://lwn.net/Articles/789886/ boutcher <div class="FormattedComment"> I had to laugh that you brought up OS/2<br> </div> Thu, 30 May 2019 16:20:05 +0000 The Linux "copy problem" https://lwn.net/Articles/789885/ https://lwn.net/Articles/789885/ desbma <div class="FormattedComment"> Unfortunately, there are many other example of cases like this.<br> <p> For example zlib, one the most widely used software library in the world, has several forks (Intel, Cloudflare, zlib-ng...) with optimizations that improve compression/decompression speed.<br> <p> Yet the changes have never been merged back in zlib, and everybody still uses the historic version, and happily wastes CPU cycles (including when your browser decompresses this very page).<br> </div> Thu, 30 May 2019 16:17:30 +0000 The Linux "copy problem" https://lwn.net/Articles/789882/ https://lwn.net/Articles/789882/ KAMiKAZOW <div class="FormattedComment"> <font class="QuotedText">&gt; It seems like it would be worth at least diving into `cp` and making sure it's as good as can be, since that gets used so much.</font><br> <p> I find it insane that cp was fixed a decade ago by NASA and in all that time neither them nor anybody else thought about upstreaming the changes.<br> </div> Thu, 30 May 2019 16:00:23 +0000 The copy problem is really the backup problem https://lwn.net/Articles/789869/ https://lwn.net/Articles/789869/ mcr <div class="FormattedComment"> In the old says of Unix, with a single file system, we used "dump" to get a good copy. It had all sorts ridiculous issues of having a userspace program trying to decipher file system contents from raw reads of the disk. On the other hand, when it worked, it got all the metadata, did it without destroying the buffer cache, and often was able to backup disks which were in the process of dying. When it failed, it failed, and the backups were sometimes garbage. And it didn't work for many things. So people mostly use tar for backup. And that's should be the most common copy problem, which is not just about data centers or cluster environments. And tar fails for any file system that does something innovative.<br> My claim is that our VFS layer is incomplete: it should include an atomic backup and an atomic restore operation, at least on a file level, but optionally on a directory basis. If we had that, then cp would always usefully be backup file | restore file2. This means that file systems have to serialize file contents and meta data, and have to deserialize it too. We Linux a microkernel architecture, then probably much of this deserialization could be done in some system-provided, non-ring0 context. Should we pick tar for serialization, or something more modern like CBOR, that's a bike shed for a design team.<br> I would just be happy if we could agree that we need this functionality.<br> <p> </div> Thu, 30 May 2019 15:01:45 +0000 The Linux "copy problem" https://lwn.net/Articles/789854/ https://lwn.net/Articles/789854/ desbma <div class="FormattedComment"> <font class="QuotedText">&gt; I haven't actually tried this, but in theory it should enable the kernel to do a zero-copy copy where the underlying files support that.</font><br> <p> This is exactly what sendfile does, with a single system call, instead of 3 for your example.<br> </div> Thu, 30 May 2019 14:00:36 +0000 The Linux "copy problem" https://lwn.net/Articles/789853/ https://lwn.net/Articles/789853/ ecree <div class="FormattedComment"> <font class="QuotedText">&gt; &gt; one of the file descriptors must refer to a pipe</font><br> Yes, so you make two splice calls:<br> <p> int p[2];<br> pipe(p);<br> splice(fd_in, NULL, p[1], NULL, len, flags);<br> splice(p[0], NULL, fd_out, NULL, len, flags);<br> <p> I haven't actually tried this, but in theory it should enable the kernel to do a zero-copy copy where the underlying files support that. The pipe is really no more than a way to associate a userspace handle with a kernel buffer; see <a href="https://yarchive.net/comp/linux/splice.html">https://yarchive.net/comp/linux/splice.html</a> for details.<br> </div> Thu, 30 May 2019 13:54:00 +0000 The Linux "copy problem" https://lwn.net/Articles/789852/ https://lwn.net/Articles/789852/ desbma <div class="FormattedComment"> According to `man splice`:<br> <font class="QuotedText">&gt; splice() moves data between two file descriptors [...] where one of the file descriptors must refer to a pipe</font><br> <p> sendfile does not have this restriction (it can also work if the destination fd is a socket), so it is the ideal candidate for copying files.<br> <p> Apparently, someone proposed to update coreutil's cp to use sendfile in 2012, but it was rejected: <a href="https://lists.gnu.org/archive/html/coreutils/2012-10/msg00026.html">https://lists.gnu.org/archive/html/coreutils/2012-10/msg0...</a><br> <p> A while ago I did some benchmarks in Python to compare "read/write chunk" vs "sendfile" based copy, and it let to a 30-50% speedup : <a href="https://github.com/desbma/pyfastcopy#performance">https://github.com/desbma/pyfastcopy#performance</a><br> <p> </div> Thu, 30 May 2019 13:38:06 +0000 The Linux "copy problem" https://lwn.net/Articles/789851/ https://lwn.net/Articles/789851/ ecree <div class="FormattedComment"> I was wondering about splice(). Wouldn't that be a more efficient way to do copies?<br> </div> Thu, 30 May 2019 13:22:33 +0000 The Linux "copy problem" https://lwn.net/Articles/789818/ https://lwn.net/Articles/789818/ jezuch <div class="FormattedComment"> I don't cp often but when I do I cp --reflink<br> <p> :)<br> </div> Thu, 30 May 2019 10:35:46 +0000 The Linux "copy problem" https://lwn.net/Articles/789805/ https://lwn.net/Articles/789805/ k3ninho <div class="FormattedComment"> I had a range of responses to this 'build the interfaces' thing. <br> <p> How people use those interfaces is something that needs guidance, always: you form a symbiotic loop in reliance on each other. <br> <p> Conway's Law hasn't gone away and is implications about interacting with the users of your interfaces still stand. I think that Chris Mason's comment here is misguided and that we need to help people work together and communicate better. I think we need to balance this view of APIs with criticism of xattrs being difficult to copy and racy (with security implications).<br> <p> K3n.<br> </div> Thu, 30 May 2019 07:29:03 +0000 The Linux "copy problem" https://lwn.net/Articles/789776/ https://lwn.net/Articles/789776/ roc <div class="FormattedComment"> That makes sense, but you also want to the default to be as good as can be.<br> </div> Wed, 29 May 2019 23:05:10 +0000 The Linux "copy problem" https://lwn.net/Articles/789760/ https://lwn.net/Articles/789760/ ewen <div class="FormattedComment"> The sendfile system call was my thought too. If a copy tool used sendfile, eg, for within a file system copying then the kernel has lots more information on the high level goal with which to optimise the approach taken. And even between file systems it could potentially make use of file system internal knowledge (block layout, etc) and buffer access.<br> <p> If copy tools just do read/write in a loop, the kernel is left guessing the high level intent (including read ahead and whether to cache it in the kernel buffers),<br> <p> Ewen<br> </div> Wed, 29 May 2019 21:38:32 +0000 The Linux "copy problem" https://lwn.net/Articles/789755/ https://lwn.net/Articles/789755/ smfrench <div class="FormattedComment"> In the presentation I listed seven options that could be added (e.g. to cp and rsync). Other copy tools (like robocopy for Windows) have these (as well as others that may be less important for us on Linux) and may be useful examples.<br> <p> For example some options which other tools like robocopy let the user select:<br> - parallel i/o (especially for the uncached copy case)<br> - allow setting file size first (to reduce the number of metadata updates during the copy operation)<br> - allow calling the copy system call (copy_file_range API) for file systems which support it<br> - allow copying additional metadata (e..g xattr and ACLs)<br> - allow choosing larger i/o (overriding the block size). For some filesystems i/o &gt; 1MB can be much faster than small I/O (some tools will default to 4K or smaller which can be more than 10 times slower)<br> <p> And then following up on other discussions at the sumimt:<br> - allow options like encryption or compression (which could be supported over SMB3 for example and probably other filesystems).<br> </div> Wed, 29 May 2019 21:05:45 +0000 The Linux "copy problem" https://lwn.net/Articles/789749/ https://lwn.net/Articles/789749/ roc <div class="FormattedComment"> <font class="QuotedText">&gt; Mason pointed out that kernel developers are not ambassadors to go fix applications across the open-source world, however; "our job is to build the interfaces", so that is where the focus of the discussion should be.</font><br> <p> It seems like it would be worth at least diving into `cp` and making sure it's as good as can be, since that gets used so much. Then you can point developers of those other applications at `cp` as an example of how to do things right.<br> </div> Wed, 29 May 2019 20:20:52 +0000 The Linux "copy problem" https://lwn.net/Articles/789744/ https://lwn.net/Articles/789744/ desbma <div class="FormattedComment"> No mention of the sendfile system call?<br> It does not work for every case, but when it does, it is much more efficient than doing chunk based copy, and it solves the "what is the optimal I/O size" dilemma.<br> </div> Wed, 29 May 2019 19:57:27 +0000