summaryrefslogtreecommitdiffstats
path: root/src/crimson/osd/pg_shard_manager.h
diff options
context:
space:
mode:
authorSamuel Just <sjust@redhat.com>2022-09-14 04:09:58 +0200
committerSamuel Just <sjust@redhat.com>2022-09-27 04:35:41 +0200
commitce65d7e6fa13bb8ee88ac94431b7b57627b99470 (patch)
treee3c6f007dcaf009358e5fb3b43acb1a4b33346bf /src/crimson/osd/pg_shard_manager.h
parentcrimson/osd: move hb_stamps to PerShardState (diff)
downloadceph-ce65d7e6fa13bb8ee88ac94431b7b57627b99470.tar.xz
ceph-ce65d7e6fa13bb8ee88ac94431b7b57627b99470.zip
crimson/osd: shard PerShardState across cores
Signed-off-by: Samuel Just <sjust@redhat.com>
Diffstat (limited to 'src/crimson/osd/pg_shard_manager.h')
-rw-r--r--src/crimson/osd/pg_shard_manager.h82
1 files changed, 57 insertions, 25 deletions
diff --git a/src/crimson/osd/pg_shard_manager.h b/src/crimson/osd/pg_shard_manager.h
index 2135719fa06..66b289a073e 100644
--- a/src/crimson/osd/pg_shard_manager.h
+++ b/src/crimson/osd/pg_shard_manager.h
@@ -21,8 +21,8 @@ namespace crimson::osd {
* etc)
*/
class PGShardManager {
- std::unique_ptr<OSDSingletonState> osd_singleton_state;
- std::unique_ptr<ShardServices> shard_services;
+ seastar::sharded<OSDSingletonState> osd_singleton_state;
+ seastar::sharded<ShardServices> shard_services;
#define FORWARD_CONST(FROM_METHOD, TO_METHOD, TARGET) \
template <typename... Args> \
@@ -54,22 +54,53 @@ public:
crimson::os::FuturizedStore &store);
seastar::future<> stop();
- auto &get_osd_singleton_state() { return *osd_singleton_state; }
- auto &get_osd_singleton_state() const { return *osd_singleton_state; }
- auto &get_shard_services() { return *shard_services; }
- auto &get_shard_services() const { return *shard_services; }
- auto &get_local_state() { return shard_services->local_state; }
- auto &get_local_state() const { return shard_services->local_state; }
+ auto &get_osd_singleton_state() {
+ ceph_assert(seastar::this_shard_id() == PRIMARY_CORE);
+ return osd_singleton_state.local();
+ }
+ auto &get_osd_singleton_state() const {
+ ceph_assert(seastar::this_shard_id() == PRIMARY_CORE);
+ return osd_singleton_state.local();
+ }
+ auto &get_shard_services() {
+ ceph_assert(seastar::this_shard_id() == PRIMARY_CORE);
+ return shard_services.local();
+ }
+ auto &get_shard_services() const {
+ ceph_assert(seastar::this_shard_id() == PRIMARY_CORE);
+ return shard_services.local();
+ }
+ auto &get_local_state() { return get_shard_services().local_state; }
+ auto &get_local_state() const { return get_shard_services().local_state; }
seastar::future<> update_map(local_cached_map_t &&map) {
- auto fmap = make_local_shared_foreign(std::move(map));
- get_osd_singleton_state().update_map(fmap);
- get_local_state().update_map(std::move(fmap));
- return seastar::now();
+ get_osd_singleton_state().update_map(
+ make_local_shared_foreign(local_cached_map_t(map))
+ );
+ /* We need each core to get its own foreign_ptr<local_cached_map_t>.
+ * foreign_ptr can't be cheaply copied, so we make one for each core
+ * up front. */
+ return seastar::do_with(
+ std::vector<seastar::foreign_ptr<local_cached_map_t>>(),
+ [this, map](auto &fmaps) {
+ fmaps.resize(seastar::smp::count);
+ for (auto &i: fmaps) {
+ i = seastar::foreign_ptr(map);
+ }
+ return shard_services.invoke_on_all(
+ [&fmaps](auto &local) mutable {
+ local.local_state.update_map(
+ make_local_shared_foreign(
+ std::move(fmaps[seastar::this_shard_id()])
+ ));
+ });
+ });
}
- auto stop_registries() {
- return get_local_state().stop_registry();
+ seastar::future<> stop_registries() {
+ return shard_services.invoke_on_all([](auto &local) {
+ return local.local_state.stop_registry();
+ });
}
FORWARD_TO_OSD_SINGLETON(send_pg_created)
@@ -106,14 +137,11 @@ public:
template <typename F>
auto with_remote_shard_state(core_id_t core, F &&f) {
- ceph_assert(core == 0);
- auto &local_state_ref = get_local_state();
- auto &shard_services_ref = get_shard_services();
- return seastar::smp::submit_to(
- core,
- [f=std::forward<F>(f), &local_state_ref, &shard_services_ref]() mutable {
+ return shard_services.invoke_on(
+ core, [f=std::move(f)](auto &target_shard_services) mutable {
return std::invoke(
- std::move(f), local_state_ref, shard_services_ref);
+ std::move(f), target_shard_services.local_state,
+ target_shard_services);
});
}
@@ -202,10 +230,14 @@ public:
*/
template <typename F>
seastar::future<> for_each_pg(F &&f) const {
- for (auto &&pg: get_local_state().pg_map.get_pgs()) {
- std::apply(f, pg);
- }
- return seastar::now();
+ return sharded_map_seq(
+ shard_services,
+ [f=std::move(f)](const auto &local_service) mutable {
+ for (auto &pg: local_service.local_state.pg_map.get_pgs()) {
+ std::apply(f, pg);
+ }
+ return seastar::now();
+ });
}
auto get_num_pgs() const {