-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added storage preallocation for the target file in copy_file on Linux.
Use Linux fallocate system call to preallocate storage for the target file in copy_file backends based on sendfile and copy_file_range. These backends are only used when the file size is known beforehand, and preallocating storage allows to reduce filesystem fragmentation and get an early error if there's not enough free space on the target filesystem. Preallocation is only done as an optimization/hint. On filesystems that do not support it we continue the data copying process as before. This is why we aren't using posix_fallocate, because glibc contains an emulation path that is used when the filesystem doesn't support the functionality. We don't want this emulation, as it would effectively double the amount of written data.
- Loading branch information
Showing
6 changed files
with
78 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2024 Andrey Semashev | ||
|
||
// Distributed under the Boost Software License, Version 1.0. | ||
// See http://www.boost.org/LICENSE_1_0.txt | ||
|
||
// See library home page at http://www.boost.org/libs/filesystem | ||
|
||
#include "platform_config.hpp" | ||
|
||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
|
||
int main() | ||
{ | ||
int fd = open("file.txt", O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); | ||
int err = fallocate(fd, FALLOC_FL_KEEP_SIZE, 0, 4096); | ||
return err != 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters