Skip to content

Commit 1f44f38

Browse files
committed
common/mclock_common: don't use config keys to pass profile info to client_registry
Rather than overriding config variables for qos params based on profile, use MclockConfig::current_profile. This avoids the need to update the mon for cases where users set both a non-custom profile and one or more of the qos params. Also updates config descriptions to clarify that they are ignored unless osd_mclock_profile is set to custom. Signed-off-by: Samuel Just <[email protected]>
1 parent d6a45f8 commit 1f44f38

File tree

4 files changed

+95
-206
lines changed

4 files changed

+95
-206
lines changed

src/common/mclock_common.cc

Lines changed: 60 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ std::ostream& operator<<(std::ostream& out,
8080
* for the osd_mclock_scheduler_client_* parameters prior to calling
8181
* update_from_config -- see set_config_defaults_from_profile().
8282
*/
83-
void ClientRegistry::update_from_config(const ConfigProxy &conf,
84-
const double capacity_per_shard)
83+
void ClientRegistry::update_from_profile(const profile_t &current_profile,
84+
const double capacity_per_shard)
8585
{
86+
8687
auto get_res = [&](double res) {
8788
if (res) {
8889
return res * capacity_per_shard;
@@ -99,43 +100,22 @@ void ClientRegistry::update_from_config(const ConfigProxy &conf,
99100
}
100101
};
101102

102-
// Set external client infos
103-
double res = conf.get_val<double>(
104-
"osd_mclock_scheduler_client_res");
105-
double lim = conf.get_val<double>(
106-
"osd_mclock_scheduler_client_lim");
107-
uint64_t wgt = conf.get_val<uint64_t>(
108-
"osd_mclock_scheduler_client_wgt");
109103
default_external_client_info.update(
110-
get_res(res),
111-
wgt,
112-
get_lim(lim));
113-
114-
// Set background recovery client infos
115-
res = conf.get_val<double>(
116-
"osd_mclock_scheduler_background_recovery_res");
117-
lim = conf.get_val<double>(
118-
"osd_mclock_scheduler_background_recovery_lim");
119-
wgt = conf.get_val<uint64_t>(
120-
"osd_mclock_scheduler_background_recovery_wgt");
104+
get_res(current_profile.client.reservation),
105+
current_profile.client.weight,
106+
get_lim(current_profile.client.limit));
107+
121108
internal_client_infos[
122109
static_cast<size_t>(SchedulerClass::background_recovery)].update(
123-
get_res(res),
124-
wgt,
125-
get_lim(lim));
126-
127-
// Set background best effort client infos
128-
res = conf.get_val<double>(
129-
"osd_mclock_scheduler_background_best_effort_res");
130-
lim = conf.get_val<double>(
131-
"osd_mclock_scheduler_background_best_effort_lim");
132-
wgt = conf.get_val<uint64_t>(
133-
"osd_mclock_scheduler_background_best_effort_wgt");
110+
get_res(current_profile.background_recovery.reservation),
111+
current_profile.background_recovery.weight,
112+
get_lim(current_profile.background_recovery.limit));
113+
134114
internal_client_infos[
135115
static_cast<size_t>(SchedulerClass::background_best_effort)].update(
136-
get_res(res),
137-
wgt,
138-
get_lim(lim));
116+
get_res(current_profile.background_best_effort.reservation),
117+
current_profile.background_best_effort.weight,
118+
get_lim(current_profile.background_best_effort.limit));
139119
}
140120

141121
const dmc::ClientInfo *ClientRegistry::get_external_client(
@@ -180,66 +160,7 @@ static std::ostream &operator<<(std::ostream &lhs, const profile_t &rhs)
180160
<< "]";
181161
}
182162

183-
void MclockConfig::set_config_defaults_from_profile()
184-
{
185-
// Let only a single osd shard (id:0) set the profile configs
186-
if (shard_id > 0) {
187-
return;
188-
}
189-
190-
const profile_t *profile = nullptr;
191-
auto mclock_profile = cct->_conf.get_val<std::string>("osd_mclock_profile");
192-
if (mclock_profile == "high_client_ops") {
193-
profile = &HIGH_CLIENT_OPS;
194-
dout(10) << "Setting high_client_ops profile " << *profile << dendl;
195-
} else if (mclock_profile == "high_recovery_ops") {
196-
profile = &HIGH_RECOVERY_OPS;
197-
dout(10) << "Setting high_recovery_ops profile " << *profile << dendl;
198-
} else if (mclock_profile == "balanced") {
199-
profile = &BALANCED;
200-
dout(10) << "Setting balanced profile " << *profile << dendl;
201-
} else if (mclock_profile == "custom") {
202-
dout(10) << "Profile set to custom, not setting defaults" << dendl;
203-
return;
204-
} else {
205-
derr << "Invalid mclock profile: " << mclock_profile << dendl;
206-
ceph_assert("Invalid choice of mclock profile" == 0);
207-
return;
208-
}
209-
ceph_assert(nullptr != profile);
210-
211-
auto set_config = [&conf = cct->_conf](const char *key, auto val) {
212-
conf.set_val_default(key, std::to_string(val));
213-
};
214-
215-
set_config("osd_mclock_scheduler_client_res", profile->client.reservation);
216-
set_config("osd_mclock_scheduler_client_wgt", profile->client.weight);
217-
set_config("osd_mclock_scheduler_client_lim", profile->client.limit);
218-
219-
set_config(
220-
"osd_mclock_scheduler_background_recovery_res",
221-
profile->background_recovery.reservation);
222-
set_config(
223-
"osd_mclock_scheduler_background_recovery_wgt",
224-
profile->background_recovery.weight);
225-
set_config(
226-
"osd_mclock_scheduler_background_recovery_lim",
227-
profile->background_recovery.limit);
228-
229-
set_config(
230-
"osd_mclock_scheduler_background_best_effort_res",
231-
profile->background_best_effort.reservation);
232-
set_config(
233-
"osd_mclock_scheduler_background_best_effort_wgt",
234-
profile->background_best_effort.weight);
235-
set_config(
236-
"osd_mclock_scheduler_background_best_effort_lim",
237-
profile->background_best_effort.limit);
238-
239-
cct->_conf.apply_changes(nullptr);
240-
}
241-
242-
void MclockConfig::set_osd_capacity_params_from_config()
163+
void MclockConfig::set_from_config()
243164
{
244165
uint64_t osd_bandwidth_capacity;
245166
double osd_iop_capacity;
@@ -272,6 +193,47 @@ void MclockConfig::set_osd_capacity_params_from_config()
272193
<< ", osd_bandwidth_capacity_per_shard "
273194
<< osd_bandwidth_capacity_per_shard << " bytes/second"
274195
<< dendl;
196+
197+
auto mclock_profile = cct->_conf.get_val<std::string>("osd_mclock_profile");
198+
if (mclock_profile == "high_client_ops") {
199+
current_profile = HIGH_CLIENT_OPS;
200+
dout(10) << "Setting high_client_ops profile " << current_profile << dendl;
201+
} else if (mclock_profile == "high_recovery_ops") {
202+
current_profile = HIGH_RECOVERY_OPS;
203+
dout(10) << "Setting high_recovery_ops profile " << current_profile << dendl;
204+
} else if (mclock_profile == "balanced") {
205+
current_profile = BALANCED;
206+
dout(10) << "Setting balanced profile " << current_profile << dendl;
207+
} else if (mclock_profile == "custom") {
208+
current_profile = {
209+
{
210+
cct->_conf.get_val<double>("osd_mclock_scheduler_client_res"),
211+
cct->_conf.get_val<uint64_t>("osd_mclock_scheduler_client_wgt"),
212+
cct->_conf.get_val<double>("osd_mclock_scheduler_client_lim")
213+
}, {
214+
cct->_conf.get_val<double>(
215+
"osd_mclock_scheduler_background_recovery_res"),
216+
cct->_conf.get_val<uint64_t>(
217+
"osd_mclock_scheduler_background_recovery_wgt"),
218+
cct->_conf.get_val<double>(
219+
"osd_mclock_scheduler_background_recovery_lim")
220+
}, {
221+
cct->_conf.get_val<double>(
222+
"osd_mclock_scheduler_background_best_effort_res"),
223+
cct->_conf.get_val<uint64_t>(
224+
"osd_mclock_scheduler_background_best_effort_wgt"),
225+
cct->_conf.get_val<double>(
226+
"osd_mclock_scheduler_background_best_effort_lim")
227+
}
228+
};
229+
dout(10) << "Setting custom profile " << current_profile << dendl;
230+
} else {
231+
derr << "Invalid mclock profile: " << mclock_profile << dendl;
232+
ceph_assert("Invalid choice of mclock profile" == 0);
233+
return;
234+
}
235+
client_registry.update_from_profile(
236+
current_profile, osd_bandwidth_capacity_per_shard);
275237
}
276238

277239
void MclockConfig::init_logger()
@@ -380,80 +342,10 @@ uint32_t MclockConfig::calc_scaled_cost(int item_cost)
380342
void MclockConfig::handle_conf_change(const ConfigProxy& conf,
381343
const std::set<std::string> &changed)
382344
{
383-
if (changed.count("osd_mclock_max_capacity_iops_hdd") ||
384-
changed.count("osd_mclock_max_capacity_iops_ssd")) {
385-
set_osd_capacity_params_from_config();
386-
client_registry.update_from_config(
387-
conf, osd_bandwidth_capacity_per_shard);
388-
}
389-
if (changed.count("osd_mclock_max_sequential_bandwidth_hdd") ||
390-
changed.count("osd_mclock_max_sequential_bandwidth_ssd")) {
391-
set_osd_capacity_params_from_config();
392-
client_registry.update_from_config(
393-
conf, osd_bandwidth_capacity_per_shard);
394-
}
395-
if (changed.count("osd_mclock_profile")) {
396-
set_config_defaults_from_profile();
397-
client_registry.update_from_config(
398-
conf, osd_bandwidth_capacity_per_shard);
399-
}
400-
401-
auto get_changed_key = [&changed]() -> std::optional<std::string> {
402-
static const std::vector<std::string> qos_params = {
403-
"osd_mclock_scheduler_client_res",
404-
"osd_mclock_scheduler_client_wgt",
405-
"osd_mclock_scheduler_client_lim",
406-
"osd_mclock_scheduler_background_recovery_res",
407-
"osd_mclock_scheduler_background_recovery_wgt",
408-
"osd_mclock_scheduler_background_recovery_lim",
409-
"osd_mclock_scheduler_background_best_effort_res",
410-
"osd_mclock_scheduler_background_best_effort_wgt",
411-
"osd_mclock_scheduler_background_best_effort_lim"
412-
};
413-
414-
for (auto &qp : qos_params) {
415-
if (changed.count(qp)) {
416-
return qp;
417-
}
418-
}
419-
return std::nullopt;
420-
};
421-
if (auto key = get_changed_key(); key.has_value()) {
422-
auto mclock_profile = cct->_conf.get_val<std::string>("osd_mclock_profile");
423-
if (mclock_profile == "custom") {
424-
client_registry.update_from_config(
425-
conf, osd_bandwidth_capacity_per_shard);
426-
} else {
427-
// Attempt to change QoS parameter for a built-in profile. Restore the
428-
// profile defaults by making one of the OSD shards remove the key from
429-
// config monitor store. Note: monc is included in the check since the
430-
// mock unit test currently doesn't initialize it.
431-
if (shard_id == 0 && monc) {
432-
static const std::vector<std::string> osds = {
433-
"osd",
434-
"osd." + std::to_string(whoami)
435-
};
436-
437-
for (auto osd : osds) {
438-
std::string cmd =
439-
"{"
440-
"\"prefix\": \"config rm\", "
441-
"\"who\": \"" + osd + "\", "
442-
"\"name\": \"" + *key + "\""
443-
"}";
444-
std::vector<std::string> vcmd{cmd};
445-
446-
dout(10) << __func__ << " Removing Key: " << *key
447-
<< " for " << osd << " from Mon db" << dendl;
448-
monc->start_mon_command(vcmd, {}, nullptr, nullptr, nullptr);
449-
}
450-
}
451-
}
452-
// Alternatively, the QoS parameter, if set ephemerally for this OSD via
453-
// the 'daemon' or 'tell' interfaces must be removed.
454-
if (!cct->_conf.rm_val(*key)) {
455-
dout(10) << __func__ << " Restored " << *key << " to default" << dendl;
456-
cct->_conf.apply_changes(nullptr);
345+
for (auto &key : get_tracked_keys()) {
346+
if (changed.count(key)) {
347+
set_from_config();
348+
return;
457349
}
458350
}
459351
}

src/common/mclock_common.h

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,10 @@ class ClientRegistry {
180180
internal_client_infos.emplace_back(1, 1, 1);
181181
}
182182
}
183-
void update_from_config(const ConfigProxy &conf,
184-
double capacity_per_shard);
183+
void update_from_profile(
184+
const profile_t &current_profile,
185+
const double capacity_per_shard);
186+
185187
const crimson::dmclock::ClientInfo *get_info(
186188
const scheduler_id_t &id) const;
187189
};
@@ -191,55 +193,32 @@ class MclockConfig final : public md_config_obs_t {
191193
CephContext *cct;
192194
uint32_t num_shards;
193195
bool is_rotational;
194-
PerfCounters *logger;
196+
PerfCounters *logger = nullptr;
195197
int shard_id;
196198
int whoami;
197-
double osd_bandwidth_cost_per_io;
198-
double osd_bandwidth_capacity_per_shard;
199+
double osd_bandwidth_cost_per_io = 0.0;
200+
double osd_bandwidth_capacity_per_shard = 0.0;
199201
ClientRegistry& client_registry;
200-
#ifndef WITH_CRIMSON
201-
MonClient *monc;
202-
#endif
202+
203+
// currently active profile, will be overridden from config on startup
204+
// and upon config change
205+
profile_t current_profile = BALANCED;
203206
public:
204-
#ifdef WITH_CRIMSON
205207
MclockConfig(CephContext *cct, ClientRegistry& creg,
206208
uint32_t num_shards, bool is_rotational, int shard_id,
207209
int whoami):cct(cct),
208210
num_shards(num_shards),
209211
is_rotational(is_rotational),
210-
logger(nullptr),shard_id(shard_id),
211-
whoami(whoami), osd_bandwidth_cost_per_io(0.0),
212-
osd_bandwidth_capacity_per_shard(0.0),
212+
shard_id(shard_id),
213+
whoami(whoami),
213214
client_registry(creg)
214215
{
215216
cct->_conf.add_observer(this);
216-
set_osd_capacity_params_from_config();
217-
set_config_defaults_from_profile();
218-
client_registry.update_from_config(
219-
cct->_conf, get_capacity_per_shard());
220-
}
221-
#else
222-
MclockConfig(CephContext *cct, ClientRegistry& creg,
223-
MonClient *monc, uint32_t num_shards, bool is_rotational,
224-
int shard_id, int whoami):cct(cct),
225-
num_shards(num_shards),
226-
is_rotational(is_rotational),
227-
logger(nullptr),shard_id(shard_id),
228-
whoami(whoami),
229-
osd_bandwidth_cost_per_io(0.0),
230-
osd_bandwidth_capacity_per_shard(0.0),
231-
client_registry(creg), monc(monc)
232-
{
233-
cct->_conf.add_observer(this);
234-
set_osd_capacity_params_from_config();
235-
set_config_defaults_from_profile();
236-
client_registry.update_from_config(
237-
cct->_conf, get_capacity_per_shard());
217+
set_from_config();
238218
}
239-
#endif
240219
~MclockConfig() final;
241-
void set_config_defaults_from_profile();
242-
void set_osd_capacity_params_from_config();
220+
221+
void set_from_config();
243222
void init_logger();
244223
void get_mclock_counter(scheduler_id_t id);
245224
void put_mclock_counter(scheduler_id_t id);

0 commit comments

Comments
 (0)