|
cuDDL
|
Writes a file from a thread of its own, so the caller produces the next bytes while earlier ones reach storage. More...
#include <file_writer.hpp>
Public Member Functions | |
| file_writer (std::filesystem::path const &path, bool durable, size_t queued_limit=size_t{1}<< 30) | |
| file_writer (file_writer const &)=delete | |
| file_writer & | operator= (file_writer const &)=delete |
| ~file_writer () | |
| Stops writing without flushing; finish reports whether every byte arrived. | |
| std::span< char > | reserve (size_t bytes) |
Space for the next bytes of the file, for the caller to fill and then hand back with commit, sparing append's copy. | |
| void | commit () |
| Queues the bytes of the last reserve. | |
| void | append (std::initializer_list< std::span< char const > > chunks) |
Copies chunks, which reach the file together and in order; waits while the queued bytes reach the limit. | |
| void | append (std::span< char const > bytes) |
| void | finish () |
| Writes everything appended and closes the file, flushing it to storage first if durable. | |
| bool | direct () const noexcept |
| Whether writes bypass the page cache. | |
| bool | asynchronous () const noexcept |
| Whether writes go through io_uring. | |
Static Public Attributes | |
| static constexpr size_t | block_bytes = size_t{8} << 20 |
| static constexpr unsigned | depth = 4 |
| Writes in flight with io_uring. | |
| static constexpr size_t | probe_window = size_t{64} << 20 |
| Bytes timed per route before a writer that need not be durable picks one; it leaves the page cache only after 16 such windows through it ran too slow. | |
Writes a file from a thread of its own, so the caller produces the next bytes while earlier ones reach storage.
Bytes are copied into page-aligned memory by append, or produced there in place through reserve, and written with O_DIRECT in requests of up to 8 MiB, bypassing the page cache. Buffered writes stall in page-cache copies and writeback: on a Samsung 9100 PRO, one buffered stream plus fsync wrote 2.4-3.1 GB/s and O_DIRECT 8 MiB writes 12.9-13.6 GB/s, the drive's rated 13.4 GB/s; 1 MiB writes reached only 9.1-9.7 GB/s. There the copy itself, 11 GB/s on one core, held a 159 GB all-to-all output below the drive. Where io_uring is available, four requests are in flight at once: on a btrfs file system that wrote 2.9-4.4 GB/s against 1.9-2.6 GB/s for synchronous writes. Elsewhere one request is written at a time, which on ext4 already reached the drive's rate.
File systems without O_DIRECT (tmpfs) and network file systems get buffered writes: direct writes to Lustre wait for the server on every request (8 streams reached 28 MB/s).
Definition at line 49 of file file_writer.hpp.
|
inline |
| durable | Whether finish flushes the file to storage before returning. |
| queued_limit | Bytes reserved or appended but not yet written before reserve and append wait; a larger reservation waits only for all but one other. |
Definition at line 61 of file file_writer.hpp.
|
delete |
|
inline |
Stops writing without flushing; finish reports whether every byte arrived.
Definition at line 105 of file file_writer.hpp.
|
inline |
Copies chunks, which reach the file together and in order; waits while the queued bytes reach the limit.
Throws if an earlier write failed.
Definition at line 133 of file file_writer.hpp.
|
inline |
Definition at line 144 of file file_writer.hpp.
|
inlinenoexcept |
Whether writes go through io_uring.
Definition at line 180 of file file_writer.hpp.
|
inline |
Queues the bytes of the last reserve.
A direct write covers whole sectors, so the last partial sector waits for the next bytes.
Definition at line 126 of file file_writer.hpp.
|
inlinenoexcept |
Whether writes bypass the page cache.
Definition at line 175 of file file_writer.hpp.
|
inline |
Writes everything appended and closes the file, flushing it to storage first if durable.
Bytes left in the page cache otherwise reach storage after the caller moves on, as with any buffered write.
Definition at line 151 of file file_writer.hpp.
|
delete |
|
inline |
Space for the next bytes of the file, for the caller to fill and then hand back with commit, sparing append's copy.
Waits while the queued bytes reach the limit; throws if an earlier write failed. One reservation at a time.
Definition at line 114 of file file_writer.hpp.
|
staticconstexpr |
Definition at line 51 of file file_writer.hpp.
|
staticconstexpr |
Writes in flight with io_uring.
Definition at line 53 of file file_writer.hpp.
|
staticconstexpr |
Bytes timed per route before a writer that need not be durable picks one; it leaves the page cache only after 16 such windows through it ran too slow.
Definition at line 56 of file file_writer.hpp.