Subject: Re: [PATCH] copy.c: use `sendfile()` for in-kernel file copying on Linux

From: Jeff King <[email-masked]>
Date: Sun, 15 Feb 2026 02:43:06 -0500

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
    packfile

To 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