Skip to content

Commit

Permalink
c/self-test/diskcheck: Avoid large allocations
Browse files Browse the repository at this point in the history
`diskcheck_opts::request_size` is provided by the user.

To avoid very large allocations, split the request size into
at most 128KiB chunks, and read/write them via an iovec.

Preliminary testing shows very little difference in the
performance.

Fixes #10305

Signed-off-by: Ben Pope <ben@redpanda.com>
  • Loading branch information
BenPope committed Jun 2, 2023
1 parent 24dddb8 commit b4e2227
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/v/cluster/self_test/diskcheck.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,27 +193,33 @@ ss::future<metrics> diskcheck::do_run_benchmark(ss::file& file) {
template<diskcheck::read_or_write mode>
ss::future<> diskcheck::run_benchmark_fiber(
ss::lowres_clock::time_point start, ss::file& file, metrics& m) {
auto buf = ss::allocate_aligned_buffer<char>(
_opts.request_size, _opts.alignment());
random_generators::fill_buffer_randomchars(buf.get(), _opts.request_size);
const auto buf_len = std::min(_opts.request_size, 128_KiB);
auto buf = ss::allocate_aligned_buffer<char>(buf_len, _opts.alignment());
random_generators::fill_buffer_randomchars(buf.get(), buf_len);

std::vector<iovec> iov;
iov.reserve(_opts.request_size / buf_len);
for (size_t offset = 0; offset < _opts.request_size; offset += buf_len) {
size_t len = std::min(_opts.request_size - offset, buf_len);
iov.push_back(iovec{buf.get(), len});
}

auto stop = start + _opts.duration;
while (stop > ss::lowres_clock::now() && !_cancelled) {
if (unlikely(_as.abort_requested())) {
throw diskcheck_aborted_exception();
}
co_await m.measure([this, &buf, &file] {
co_await m.measure([this, &iov, &file] {
if constexpr (mode == read_or_write::write) {
return file.dma_write(
get_pos(),
buf.get(),
_opts.request_size,
iov,
ss::default_priority_class(),
&_intent);
} else {
return file.dma_read(
get_pos(),
buf.get(),
_opts.request_size,
iov,
ss::default_priority_class(),
&_intent);
}
Expand Down

0 comments on commit b4e2227

Please sign in to comment.