Add --shm-no-cleanup option

When true, device will skip the segment cleanup even when it is the last
segment user
This commit is contained in:
Alexey Rybalchenko 2021-03-17 12:32:58 +01:00
parent a5ec83208d
commit c8ad684b18
2 changed files with 5 additions and 2 deletions

View File

@ -71,6 +71,7 @@ Plugin::ProgOptions ConfigPluginProgramOptions()
("shm-zero-segment", po::value<bool >()->default_value(false), "Shared memory: zero the shared memory segment memory after initialization.") ("shm-zero-segment", po::value<bool >()->default_value(false), "Shared memory: zero the shared memory segment memory after initialization.")
("shm-throw-bad-alloc", po::value<bool >()->default_value(true), "Throw a fair::mq::MessageBadAlloc if cannot allocate a message (retry if false).") ("shm-throw-bad-alloc", po::value<bool >()->default_value(true), "Throw a fair::mq::MessageBadAlloc if cannot allocate a message (retry if false).")
("shm-monitor", po::value<bool >()->default_value(true), "Shared memory: run monitor daemon.") ("shm-monitor", po::value<bool >()->default_value(true), "Shared memory: run monitor daemon.")
("shm-no-cleanup", po::value<bool >()->default_value(false), "Shared memory: do not cleanup the memory when last device leaves.")
("ofi-size-hint", po::value<size_t >()->default_value(0), "EXPERIMENTAL: OFI size hint for the allocator.") ("ofi-size-hint", po::value<size_t >()->default_value(0), "EXPERIMENTAL: OFI size hint for the allocator.")
("rate", po::value<float >()->default_value(0.), "Rate for conditional run loop (Hz).") ("rate", po::value<float >()->default_value(0.), "Rate for conditional run loop (Hz).")
("session", po::value<string >()->default_value("default"), "Session name.") ("session", po::value<string >()->default_value("default"), "Session name.")

View File

@ -78,6 +78,7 @@ class Manager
, fHeartbeatThread() , fHeartbeatThread()
, fSendHeartbeats(true) , fSendHeartbeats(true)
, fThrowOnBadAlloc(config ? config->GetProperty<bool>("shm-throw-bad-alloc", true) : true) , fThrowOnBadAlloc(config ? config->GetProperty<bool>("shm-throw-bad-alloc", true) : true)
, fNoCleanup(config ? config->GetProperty<bool>("shm-no-cleanup", false) : false)
{ {
using namespace boost::interprocess; using namespace boost::interprocess;
@ -608,7 +609,7 @@ class Manager
(fDeviceCounter->fCount)--; (fDeviceCounter->fCount)--;
if (fDeviceCounter->fCount == 0) { if (fDeviceCounter->fCount == 0) {
LOG(debug) << "Last segment user, removing segment."; LOG(debug) << "Last segment user, " << (fNoCleanup ? "skipping removal (--shm-no-cleanup is true)." : "removing segment.");
lastRemoved = true; lastRemoved = true;
} else { } else {
LOG(debug) << "Other segment users present (" << fDeviceCounter->fCount << "), skipping removal."; LOG(debug) << "Other segment users present (" << fDeviceCounter->fCount << "), skipping removal.";
@ -617,7 +618,7 @@ class Manager
LOG(error) << "Manager could not acquire lock: " << e.what(); LOG(error) << "Manager could not acquire lock: " << e.what();
} }
if (lastRemoved) { if (lastRemoved && !fNoCleanup) {
Monitor::Cleanup(ShmId{fShmId}); Monitor::Cleanup(ShmId{fShmId});
} }
} }
@ -657,6 +658,7 @@ class Manager
std::condition_variable fHeartbeatsCV; std::condition_variable fHeartbeatsCV;
bool fThrowOnBadAlloc; bool fThrowOnBadAlloc;
bool fNoCleanup;
}; };
} // namespace fair::mq::shmem } // namespace fair::mq::shmem