Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix high memory usage when exec events are done.
authorAugustin Degomme <adegomme@users.noreply.github.com>
Wed, 29 Sep 2021 15:12:32 +0000 (17:12 +0200)
committerAugustin Degomme <adegomme@users.noreply.github.com>
Wed, 29 Sep 2021 15:12:32 +0000 (17:12 +0200)
Callbacks were connected but not removed until the end of simulation.
Thanks Julien Emmanuel for the report, agier for diagnosis and fsuter for patch.

src/kernel/activity/ExecImpl.cpp
src/kernel/activity/ExecImpl.hpp
src/s4u/s4u_Exec.cpp

index 3b55aff..7e16150 100644 (file)
@@ -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();
 }
index cdfd3e8..9fc5f88 100644 (file)
@@ -27,7 +27,7 @@ class XBT_PUBLIC ExecImpl : public ActivityImpl_T<ExecImpl> {
   std::vector<double> flops_amounts_;
   std::vector<double> 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_; }
index ab680d8..5ecdf6a 100644 (file)
@@ -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());
 }