Skip to content

Commit 801186f

Browse files
authored
Merge pull request ceph#60668 from ronen-fr/wip-rf-mconf
osd/scrub: cache frequently used configuration parameters Reviewed-by: Radoslaw Zarzynski <[email protected]> Reviewed-by: Samuel Just <[email protected]>
2 parents c1646dd + f920428 commit 801186f

File tree

5 files changed

+72
-41
lines changed

5 files changed

+72
-41
lines changed

src/common/config_cacher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class md_config_cacher_t : public md_config_obs_t {
5050
conf.remove_observer(this);
5151
}
5252

53-
operator ValueT() const {
53+
ValueT operator*() const {
5454
return value_cache.load();
5555
}
5656
};

src/common/options/osd.yaml.in

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ options:
346346
default: 5
347347
see_also:
348348
- osd_scrub_chunk_max
349-
with_legacy: true
349+
with_legacy: false
350350
- name: osd_scrub_chunk_max
351351
type: int
352352
level: advanced
@@ -357,7 +357,7 @@ options:
357357
default: 15
358358
see_also:
359359
- osd_scrub_chunk_min
360-
with_legacy: true
360+
with_legacy: false
361361
- name: osd_shallow_scrub_chunk_min
362362
type: int
363363
level: advanced
@@ -369,7 +369,7 @@ options:
369369
see_also:
370370
- osd_shallow_scrub_chunk_max
371371
- osd_scrub_chunk_min
372-
with_legacy: true
372+
with_legacy: false
373373
- name: osd_shallow_scrub_chunk_max
374374
type: int
375375
level: advanced
@@ -380,7 +380,7 @@ options:
380380
see_also:
381381
- osd_shallow_scrub_chunk_min
382382
- osd_scrub_chunk_max
383-
with_legacy: true
383+
with_legacy: false
384384
# sleep between [deep]scrub ops
385385
- name: osd_scrub_sleep
386386
type: float

src/osd/PrimaryLogPG.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6006,7 +6006,7 @@ int PrimaryLogPG::do_osd_ops(OpContext *ctx, vector<OSDOp>& ops)
60066006
object_info_t& oi = obs.oi;
60076007
const hobject_t& soid = oi.soid;
60086008
const bool skip_data_digest = osd->store->has_builtin_csum() &&
6009-
osd->osd_skip_data_digest;
6009+
*osd->osd_skip_data_digest;
60106010

60116011
PGTransaction* t = ctx->op_t.get();
60126012

@@ -6069,9 +6069,9 @@ int PrimaryLogPG::do_osd_ops(OpContext *ctx, vector<OSDOp>& ops)
60696069
// munge ZERO -> TRUNCATE? (don't munge to DELETE or we risk hosing attributes)
60706070
if (op.op == CEPH_OSD_OP_ZERO &&
60716071
obs.exists &&
6072-
op.extent.offset < static_cast<Option::size_t>(osd->osd_max_object_size) &&
6072+
op.extent.offset < *osd->osd_max_object_size &&
60736073
op.extent.length >= 1 &&
6074-
op.extent.length <= static_cast<Option::size_t>(osd->osd_max_object_size) &&
6074+
op.extent.length <= *osd->osd_max_object_size &&
60756075
op.extent.offset + op.extent.length >= oi.size) {
60766076
if (op.extent.offset >= oi.size) {
60776077
// no-op
@@ -6781,7 +6781,7 @@ int PrimaryLogPG::do_osd_ops(OpContext *ctx, vector<OSDOp>& ops)
67816781
}
67826782
result = check_offset_and_length(
67836783
op.extent.offset, op.extent.length,
6784-
static_cast<Option::size_t>(osd->osd_max_object_size), get_dpp());
6784+
*osd->osd_max_object_size, get_dpp());
67856785
if (result < 0)
67866786
break;
67876787

@@ -6838,7 +6838,7 @@ int PrimaryLogPG::do_osd_ops(OpContext *ctx, vector<OSDOp>& ops)
68386838
}
68396839
result = check_offset_and_length(
68406840
0, op.extent.length,
6841-
static_cast<Option::size_t>(osd->osd_max_object_size), get_dpp());
6841+
*osd->osd_max_object_size, get_dpp());
68426842
if (result < 0)
68436843
break;
68446844

@@ -6888,7 +6888,7 @@ int PrimaryLogPG::do_osd_ops(OpContext *ctx, vector<OSDOp>& ops)
68886888
{ // zero
68896889
result = check_offset_and_length(
68906890
op.extent.offset, op.extent.length,
6891-
static_cast<Option::size_t>(osd->osd_max_object_size), get_dpp());
6891+
*osd->osd_max_object_size, get_dpp());
68926892
if (result < 0)
68936893
break;
68946894

@@ -6953,7 +6953,7 @@ int PrimaryLogPG::do_osd_ops(OpContext *ctx, vector<OSDOp>& ops)
69536953

69546954
result = check_offset_and_length(
69556955
op.extent.offset, op.extent.length,
6956-
static_cast<Option::size_t>(osd->osd_max_object_size), get_dpp());
6956+
*osd->osd_max_object_size, get_dpp());
69576957
if (result < 0)
69586958
break;
69596959

src/osd/scrubber/pg_scrubber.cc

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
#include "./pg_scrubber.h" // '.' notation used to affect clang-format order
55

6+
#include <fmt/ranges.h>
7+
68
#include <cmath>
79
#include <iostream>
810
#include <span>
911
#include <vector>
1012

11-
#include <fmt/ranges.h>
12-
1313
#include "debug.h"
1414

1515
#include "common/ceph_time.h"
@@ -824,21 +824,21 @@ namespace {
824824
* an aux function to be used in select_range() below, to
825825
* select the correct chunk size based on the type of scrub
826826
*/
827-
int size_from_conf(
827+
int64_t size_from_conf(
828828
bool is_deep,
829829
const ceph::common::ConfigProxy& conf,
830-
std::string_view deep_opt,
831-
std::string_view shallow_opt)
830+
const md_config_cacher_t<int64_t>& deep_opt,
831+
const md_config_cacher_t<int64_t>& shallow_opt)
832832
{
833833
if (!is_deep) {
834-
auto sz = conf.get_val<int64_t>(shallow_opt);
834+
auto sz = *shallow_opt;
835835
if (sz != 0) {
836836
// assuming '0' means that no distinction was yet configured between
837837
// deep and shallow scrubbing
838-
return static_cast<int>(sz);
838+
return sz;
839839
}
840840
}
841-
return static_cast<int>(conf.get_val<int64_t>(deep_opt));
841+
return *deep_opt;
842842
}
843843
} // anonymous namespace
844844

@@ -917,16 +917,16 @@ std::optional<uint64_t> PgScrubber::select_range()
917917
dout(20) << fmt::format(
918918
"{} {} mins: {}d {}s, max: {}d {}s", __func__,
919919
(m_is_deep ? "D" : "S"),
920-
conf.get_val<int64_t>("osd_scrub_chunk_min"),
921-
conf.get_val<int64_t>("osd_shallow_scrub_chunk_min"),
922-
conf.get_val<int64_t>("osd_scrub_chunk_max"),
923-
conf.get_val<int64_t>("osd_shallow_scrub_chunk_max"))
920+
*osd_scrub_chunk_min,
921+
*osd_shallow_scrub_chunk_min,
922+
*osd_scrub_chunk_max,
923+
*osd_shallow_scrub_chunk_max)
924924
<< dendl;
925925

926-
const int min_from_conf = size_from_conf(
927-
m_is_deep, conf, "osd_scrub_chunk_min", "osd_shallow_scrub_chunk_min");
928-
const int max_from_conf = size_from_conf(
929-
m_is_deep, conf, "osd_scrub_chunk_max", "osd_shallow_scrub_chunk_max");
926+
const int min_from_conf = static_cast<int>(size_from_conf(
927+
m_is_deep, conf, osd_scrub_chunk_min, osd_shallow_scrub_chunk_min));
928+
const int max_from_conf = static_cast<int>(size_from_conf(
929+
m_is_deep, conf, osd_scrub_chunk_max, osd_shallow_scrub_chunk_max));
930930

931931
const int divisor = static_cast<int>(preemption_data.chunk_divisor());
932932
const int min_chunk_sz = std::max(3, min_from_conf / divisor);
@@ -1640,7 +1640,7 @@ void PgScrubber::replica_scrub_op(OpRequestRef op)
16401640
advance_token();
16411641
const auto& conf = m_pg->get_cct()->_conf;
16421642
const int max_from_conf = size_from_conf(
1643-
m_is_deep, conf, "osd_scrub_chunk_max", "osd_shallow_scrub_chunk_max");
1643+
m_is_deep, conf, osd_scrub_chunk_max, osd_shallow_scrub_chunk_max);
16441644
auto cost = get_scrub_cost(max_from_conf);
16451645
m_osds->queue_for_rep_scrub(m_pg,
16461646
m_replica_request_priority,
@@ -2546,6 +2546,16 @@ PgScrubber::PgScrubber(PG* pg)
25462546
, m_pg_id{pg->pg_id}
25472547
, m_osds{m_pg->osd}
25482548
, m_pg_whoami{pg->pg_whoami}
2549+
, osd_scrub_chunk_max{m_osds->cct->_conf, "osd_scrub_chunk_max"}
2550+
, osd_shallow_scrub_chunk_max{m_osds->cct->_conf,
2551+
"osd_shallow_scrub_chunk_max"}
2552+
, osd_scrub_chunk_min{m_osds->cct->_conf, "osd_scrub_chunk_min"}
2553+
, osd_shallow_scrub_chunk_min{m_osds->cct->_conf,
2554+
"osd_shallow_scrub_chunk_min"}
2555+
, osd_stats_update_period_scrubbing{
2556+
m_osds->cct->_conf, "osd_stats_update_period_scrubbing"}
2557+
, osd_stats_update_period_not_scrubbing{
2558+
m_osds->cct->_conf, "osd_stats_update_period_not_scrubbing"}
25492559
, preemption_data{pg}
25502560
{
25512561
m_fsm = std::make_unique<ScrubMachine>(m_pg, this);
@@ -2674,7 +2684,8 @@ const OSDMapRef& PgScrubber::get_osdmap() const
26742684

26752685
LoggerSinkSet& PgScrubber::get_logger() const { return *m_osds->clog.get(); }
26762686

2677-
ostream &operator<<(ostream &out, const PgScrubber &scrubber) {
2687+
ostream& operator<<(ostream& out, const PgScrubber& scrubber)
2688+
{
26782689
return out << scrubber.m_flags;
26792690
}
26802691

@@ -2788,16 +2799,14 @@ void PgScrubber::update_scrub_stats(ceph::coarse_real_clock::time_point now_is)
27882799
using clock = ceph::coarse_real_clock;
27892800
using namespace std::chrono;
27902801

2791-
const seconds period_active = seconds(m_pg->get_cct()->_conf.get_val<int64_t>(
2792-
"osd_stats_update_period_scrubbing"));
2802+
const seconds period_active = seconds(*osd_stats_update_period_scrubbing);
27932803
if (!period_active.count()) {
27942804
// a way for the operator to disable these stats updates
27952805
return;
27962806
}
2797-
const seconds period_inactive =
2798-
seconds(m_pg->get_cct()->_conf.get_val<int64_t>(
2799-
"osd_stats_update_period_not_scrubbing") +
2800-
m_pg_id.pgid.m_seed % 30);
2807+
const seconds period_inactive = seconds(
2808+
*osd_stats_update_period_not_scrubbing +
2809+
m_pg_id.pgid.m_seed % 30);
28012810

28022811
// determine the required update period, based on our current state
28032812
auto period{period_inactive};
@@ -2831,10 +2840,10 @@ void PgScrubber::update_scrub_stats(ceph::coarse_real_clock::time_point now_is)
28312840

28322841
// ///////////////////// preemption_data_t //////////////////////////////////
28332842

2834-
PgScrubber::preemption_data_t::preemption_data_t(PG* pg) : m_pg{pg}
2843+
PgScrubber::preemption_data_t::preemption_data_t(PG* pg) : m_pg{pg},
2844+
osd_scrub_max_preemptions{pg->cct->_conf, "osd_scrub_max_preemptions"}
28352845
{
2836-
m_left = static_cast<int>(
2837-
m_pg->get_cct()->_conf.get_val<uint64_t>("osd_scrub_max_preemptions"));
2846+
m_left = *osd_scrub_max_preemptions;
28382847
}
28392848

28402849
void PgScrubber::preemption_data_t::reset()
@@ -2843,8 +2852,7 @@ void PgScrubber::preemption_data_t::reset()
28432852

28442853
m_preemptable = false;
28452854
m_preempted = false;
2846-
m_left = static_cast<int>(
2847-
m_pg->cct->_conf.get_val<uint64_t>("osd_scrub_max_preemptions"));
2855+
m_left = *osd_scrub_max_preemptions;
28482856
m_size_divisor = 1;
28492857
}
28502858

src/osd/scrubber/pg_scrubber.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ Main Scrubber interfaces:
7575
#include <string_view>
7676
#include <vector>
7777

78+
#include "common/config_proxy.h"
79+
#include "common/config_cacher.h"
7880
#include "osd/PG.h"
7981
#include "osd/scrubber_common.h"
8082

@@ -895,6 +897,24 @@ class PgScrubber : public ScrubPgIF,
895897
// scrub state.
896898
ceph::coarse_real_clock::time_point m_last_stat_upd{};
897899

900+
// ------------------ cached (frequently used) configuration values
901+
902+
/// initial (& max) number of objects to scrub in one pass - deep scrub
903+
md_config_cacher_t<int64_t> osd_scrub_chunk_max;
904+
/// initial (& max) number of objects to scrub in one pass - shallow
905+
md_config_cacher_t<int64_t> osd_shallow_scrub_chunk_max;
906+
907+
/// chunk size won't be reduced (when preempted) below this
908+
/// value (deep scrub)
909+
md_config_cacher_t<int64_t> osd_scrub_chunk_min;
910+
/// chunk size won't be reduced below this value (shallow scrub)
911+
md_config_cacher_t<int64_t> osd_shallow_scrub_chunk_min;
912+
913+
/// stats update (publish_stats_to_osd()) interval while scrubbing
914+
md_config_cacher_t<int64_t> osd_stats_update_period_scrubbing;
915+
/// stats update interval while not scrubbing
916+
md_config_cacher_t<int64_t> osd_stats_update_period_not_scrubbing;
917+
898918
// ------------ members used if we are a replica
899919

900920
epoch_t m_replica_min_epoch; ///< the min epoch needed to handle this message
@@ -991,6 +1011,9 @@ class PgScrubber : public ScrubPgIF,
9911011
mutable ceph::mutex m_preemption_lock = ceph::make_mutex("preemption_lock");
9921012
bool m_preemptable{false};
9931013
bool m_preempted{false};
1014+
1015+
/// the number of preemptions allowed before we start blocking
1016+
md_config_cacher_t<uint64_t> osd_scrub_max_preemptions;
9941017
int m_left;
9951018
size_t m_size_divisor{1};
9961019
bool are_preemptions_left() const { return m_left > 0; }

0 commit comments

Comments
 (0)