Thursday, 30 January 2025

Comparison: Kernel-Space vs User-Space Copying

 

Comparison: Kernel-Space vs User-Space Copying

MethodSystem Calls UsedUser-Space Copying?Zero-Copy?
Files.copy()read() + write()✅ Yes❌ No
ByteBuffer (NIO)read() + write()✅ Yes❌ No
Memory-Mapped File (mmap)mmap() + memcpy() + msync()🚫 No (but may cause page faults)✅ Yes (after mapping)
transferTo() (sendfile)sendfile()🚫 No✅ Yes
transferFrom()sendfile()🚫 No✅ Yes
Buffered Streams (I/O)read() + write()✅ Yes❌ No
Apache FileUtils.copyFile()read()/write() OR sendfile()✅ Yes (if using streams) / 🚫 No (if using sendfile)✅ Possible
InputStream.transferTo()read() + write()✅ Yes❌ No