From b65f6b865044bffc4db07551caff9e81d6fa8f28 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Tue, 15 Dec 2020 14:56:02 -0500 Subject: [PATCH] librbd: explicitly disable readahead for writearound cache The readahead IOs would be wasted effort since the writearound cache does not service reads. Fixes: https://tracker.ceph.com/issues/48486 Signed-off-by: Jason Dillaman --- src/librbd/ImageCtx.cc | 8 ++++++-- src/librbd/ImageCtx.h | 4 ++-- src/librbd/image/OpenRequest.cc | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/librbd/ImageCtx.cc b/src/librbd/ImageCtx.cc index c1856a0bf87b1..99e00644b6d1a 100644 --- a/src/librbd/ImageCtx.cc +++ b/src/librbd/ImageCtx.cc @@ -769,8 +769,6 @@ librados::IoCtx duplicate_io_ctx(librados::IoCtx& io_ctx) { ASSIGN_OPTION(non_blocking_aio, bool); ASSIGN_OPTION(cache, bool); ASSIGN_OPTION(sparse_read_threshold_bytes, Option::size_t); - ASSIGN_OPTION(readahead_max_bytes, Option::size_t); - ASSIGN_OPTION(readahead_disable_after_bytes, Option::size_t); ASSIGN_OPTION(clone_copy_on_read, bool); ASSIGN_OPTION(enable_alloc_hint, bool); ASSIGN_OPTION(mirroring_replay_delay, uint64_t); @@ -780,6 +778,12 @@ librados::IoCtx duplicate_io_ctx(librados::IoCtx& io_ctx) { ASSIGN_OPTION(discard_granularity_bytes, uint64_t); ASSIGN_OPTION(blkin_trace_all, bool); + auto cache_policy = config.get_val("rbd_cache_policy"); + if (cache_policy == "writethrough" || cache_policy == "writeback") { + ASSIGN_OPTION(readahead_max_bytes, Option::size_t); + ASSIGN_OPTION(readahead_disable_after_bytes, Option::size_t); + } + #undef ASSIGN_OPTION if (sparse_read_threshold_bytes == 0) { diff --git a/src/librbd/ImageCtx.h b/src/librbd/ImageCtx.h index 99bce5961aee0..cc7a914a0e78e 100644 --- a/src/librbd/ImageCtx.h +++ b/src/librbd/ImageCtx.h @@ -214,8 +214,8 @@ namespace librbd { bool non_blocking_aio; bool cache; uint64_t sparse_read_threshold_bytes; - uint64_t readahead_max_bytes; - uint64_t readahead_disable_after_bytes; + uint64_t readahead_max_bytes = 0; + uint64_t readahead_disable_after_bytes = 0; bool clone_copy_on_read; bool enable_alloc_hint; uint32_t alloc_hint_flags = 0U; diff --git a/src/librbd/image/OpenRequest.cc b/src/librbd/image/OpenRequest.cc index 9b8e098108339..d34dd9ec89793 100644 --- a/src/librbd/image/OpenRequest.cc +++ b/src/librbd/image/OpenRequest.cc @@ -576,6 +576,8 @@ Context *OpenRequest::send_init_cache(int *result) { auto cache = cache::WriteAroundObjectDispatch::create( m_image_ctx, max_dirty, writethrough_until_flush); cache->init(); + + m_image_ctx->readahead.set_max_readahead_size(0); } else if (cache_policy == "writethrough" || cache_policy == "writeback") { if (cache_policy == "writethrough") { max_dirty = 0; -- 2.39.5