Seastar
High performance C++ framework for concurrent servers
fstream.hh
Go to the documentation of this file.
1/*
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
6 *
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18/*
19 * Copyright (C) 2015 Cloudius Systems, Ltd.
20 */
21
22#pragma once
23
25
26// File <-> streams adapters
27//
28// Seastar files are block-based due to the reliance on DMA - you must read
29// on sector boundaries. The adapters in this file provide a byte stream
30// interface to files, while retaining the zero-copy characteristics of
31// seastar files.
32#include <seastar/core/file.hh>
33#include <seastar/core/iostream.hh>
34#include <seastar/core/shared_ptr.hh>
35#include <seastar/core/internal/api-level.hh>
36#include <seastar/util/modules.hh>
37
38#ifndef SEASTAR_MODULE
39#include <cstdint>
40#endif
41
42namespace seastar {
43
44SEASTAR_MODULE_EXPORT_BEGIN
45
47 static constexpr uint64_t window_size = 4 * 1024 * 1024;
48 struct window {
49 uint64_t total_read = 0;
50 uint64_t unused_read = 0;
51 };
52 window current_window;
53 window previous_window;
54 unsigned read_ahead = 1;
55
56 friend class file_data_source_impl;
57};
58
61 size_t buffer_size = 8192;
62 unsigned read_ahead = 0;
64};
65
76 file file, uint64_t offset, uint64_t len, file_input_stream_options options = {});
77
86 file file, uint64_t offset, file_input_stream_options = {});
87
95
97 // For small files, setting preallocation_size can make it impossible for XFS to find
98 // an aligned extent. On the other hand, without it, XFS will divide the file into
99 // file_size/buffer_size extents. To avoid fragmentation, we set the default buffer_size
100 // to 64k (so each extent will be a minimum of 64k) and preallocation_size to 0 (to avoid
101 // extent allocation problems).
102 //
103 // Large files should increase both buffer_size and preallocation_size.
104 unsigned buffer_size = 65536;
105 unsigned preallocation_size = 0;
106 unsigned write_behind = 1;
107};
108
114 file file,
115 uint64_t buffer_size = 8192) noexcept;
116
122 file file,
123 file_output_stream_options options) noexcept;
124
129
130SEASTAR_MODULE_EXPORT_END
131
132}
Definition: iostream.hh:163
Definition: fstream.hh:46
Definition: file.hh:177
A representation of a possibly not-yet-computed value.
Definition: future.hh:1240
Definition: shared_ptr.hh:268
Definition: iostream.hh:393
Seastar API namespace.
Definition: abort_on_ebadf.hh:26
future< output_stream< char > > make_file_output_stream(file file, uint64_t buffer_size=8192) noexcept
future< data_sink > make_file_data_sink(file, file_output_stream_options) noexcept
unsigned write_behind
Number of buffers to write in parallel.
Definition: fstream.hh:106
size_t buffer_size
I/O buffer size.
Definition: fstream.hh:61
unsigned preallocation_size
Preallocate extents. For large files, set to a large number (a few megabytes) to reduce fragmentation...
Definition: fstream.hh:105
unsigned read_ahead
Maximum number of extra read-ahead operations.
Definition: fstream.hh:62
input_stream< char > make_file_input_stream(file file, uint64_t offset, uint64_t len, file_input_stream_options options={})
Creates an input_stream to read a portion of a file.
lw_shared_ptr< file_input_stream_history > dynamic_adjustments
Input stream history, if null dynamic adjustments are disabled.
Definition: fstream.hh:63
Data structure describing options for opening a file input stream.
Definition: fstream.hh:60
Definition: fstream.hh:96