diff --git a/src/native/libs/System.Native/pal_io.c b/src/native/libs/System.Native/pal_io.c index 4dd5c55dede84f..490f316e6b2077 100644 --- a/src/native/libs/System.Native/pal_io.c +++ b/src/native/libs/System.Native/pal_io.c @@ -1259,6 +1259,15 @@ int32_t SystemNative_CopyFile(intptr_t sourceFd, intptr_t destinationFd, int64_t copied = sourceLength == 0; } #endif + +#if HAVE_FALLOCATE // Linux + if (!copied && sourceLength > 81920) // BufferSize used by CopyFile_ReadWrite (would require more than 1 sys-call) + { + // try to pre-allocate disk space for large destination files + while ((ret = fallocate(outFd, FALLOC_FL_KEEP_SIZE, (off_t)0, (off_t)sourceLength)) == -1 && errno == EINTR); + } +#endif + #if HAVE_SENDFILE_4 // Try copying the data using sendfile. if (trySendFile && !copied && sourceLength != 0)