From: Augustin Degomme Date: Wed, 29 Sep 2021 15:12:32 +0000 (+0200) Subject: Fix high memory usage when exec events are done. X-Git-Tag: v3.29~34 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/9b9ece86830602596f90e783515536536ace11d1 Fix high memory usage when exec events are done. Callbacks were connected but not removed until the end of simulation. Thanks Julien Emmanuel for the report, agier for diagnosis and fsuter for patch. --- diff --git a/src/kernel/activity/ExecImpl.cpp b/src/kernel/activity/ExecImpl.cpp index 3b55aff1ca..7e1615038f 100644 --- a/src/kernel/activity/ExecImpl.cpp +++ b/src/kernel/activity/ExecImpl.cpp @@ -146,6 +146,8 @@ void ExecImpl::post() actor_->activities_.remove(this); actor_ = nullptr; } + if (state_ != State::FAILED && cb_id_ >= 0) + s4u::Host::on_state_change.disconnect(cb_id_); /* Answer all simcalls associated with the synchro */ finish(); } diff --git a/src/kernel/activity/ExecImpl.hpp b/src/kernel/activity/ExecImpl.hpp index cdfd3e8d68..9fc5f882b5 100644 --- a/src/kernel/activity/ExecImpl.hpp +++ b/src/kernel/activity/ExecImpl.hpp @@ -27,7 +27,7 @@ class XBT_PUBLIC ExecImpl : public ActivityImpl_T { std::vector flops_amounts_; std::vector bytes_amounts_; s4u::Exec* piface_; - + int cb_id_ = -1; // callback id from Host::on_state_change.connect() public: ExecImpl(); s4u::Exec* get_iface() { return piface_; } @@ -35,6 +35,7 @@ public: ExecImpl& set_timeout(double timeout) override; ExecImpl& set_bound(double bound); ExecImpl& set_sharing_penalty(double sharing_penalty); + void set_cb_id(unsigned int cb_id) { cb_id_ = cb_id; } double get_start_time() const { return start_time_; } double get_finish_time() const { return finish_time_; } diff --git a/src/s4u/s4u_Exec.cpp b/src/s4u/s4u_Exec.cpp index ab680d81ae..5ecdf6a341 100644 --- a/src/s4u/s4u_Exec.cpp +++ b/src/s4u/s4u_Exec.cpp @@ -34,13 +34,14 @@ void Exec::complete(Activity::State state) ExecPtr Exec::init() { auto pimpl = kernel::activity::ExecImplPtr(new kernel::activity::ExecImpl()); - Host::on_state_change.connect([pimpl](s4u::Host const& h) { + unsigned int cb_id = Host::on_state_change.connect([pimpl](s4u::Host const& h) { if (not h.is_on() && pimpl->state_ == kernel::activity::State::RUNNING && std::find(pimpl->get_hosts().begin(), pimpl->get_hosts().end(), &h) != pimpl->get_hosts().end()) { pimpl->state_ = kernel::activity::State::FAILED; pimpl->post(); } }); + pimpl->set_cb_id(cb_id); return ExecPtr(pimpl->get_iface()); }