Re: [PATCH] copy.c: use `sendfile()` for in-kernel file copying on Linux
- From
Jeff King <peff@peff.net>
- Date
- Feb 15, 2026, 07:43 UTC
- Message-ID
- <20260215074306.GA86282@coredump.intra.peff.net>
- In-Reply-To
- <20260213124656.218396-1-integral@archlinux.org>
On Fri, Feb 13, 2026 at 08:46:56PM +0800, George Hu wrote:
> The `sendfile()` system call copies data between one file descriptor > and another within the kernel, which is more efficient than the > combination of `read()` and `write()`.
OK, but...does this efficiency matter for the callers of copy_file() and friends? Just skimming over grep results, it mostly seems to be used with files we'd expect to be small. Some possible exceptions I can see:
- bundle-uri with a file:// uri will use it (so this could be a big
packfile) - in "clone --local" mode without hardlinks available, we might copy a
packfileTo some degree, if it's easy to use sendfile(), we should just do so if it might be a bit faster. But as responses from others showed, there are some complications we'd have to deal with (portability, fallback, etc). So I think it would be a lot more compelling if we could show a measurable speedup for some real world operation.
-Peff