Add --shm-mlock-segment-on-creation option

This commit is contained in:
David Rohr 2021-07-15 21:41:42 +02:00 committed by Alexey Rybalchenko
parent 38f9870893
commit a6193a380d
3 changed files with 32 additions and 21 deletions

View File

@ -68,6 +68,7 @@ Plugin::ProgOptions ConfigPluginProgramOptions()
("shm-allocation", po::value<string >()->default_value("rbtree_best_fit"), "Shared memory allocation algorithm: rbtree_best_fit/simple_seq_fit.") ("shm-allocation", po::value<string >()->default_value("rbtree_best_fit"), "Shared memory allocation algorithm: rbtree_best_fit/simple_seq_fit.")
("shm-segment-id", po::value<uint16_t >()->default_value(0), "EXPERIMENTAL: Shared memory segment id for message creation.") ("shm-segment-id", po::value<uint16_t >()->default_value(0), "EXPERIMENTAL: Shared memory segment id for message creation.")
("shm-mlock-segment", po::value<bool >()->default_value(false), "Shared memory: mlock the shared memory segment after initialization.") ("shm-mlock-segment", po::value<bool >()->default_value(false), "Shared memory: mlock the shared memory segment after initialization.")
("shm-mlock-segment-on-creation", po::value<bool >()->default_value(false), "Shared memory: mlock the shared memory segment only once when created.")
("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.")

View File

@ -90,11 +90,13 @@ class Manager
LOG(debug) << "Generated shmid '" << fShmId << "' out of session id '" << sessionName << "'."; LOG(debug) << "Generated shmid '" << fShmId << "' out of session id '" << sessionName << "'.";
bool mlockSegment = false; bool mlockSegment = false;
bool mlockSegmentOnCreation = false;
bool zeroSegment = false; bool zeroSegment = false;
bool autolaunchMonitor = false; bool autolaunchMonitor = false;
std::string allocationAlgorithm("rbtree_best_fit"); std::string allocationAlgorithm("rbtree_best_fit");
if (config) { if (config) {
mlockSegment = config->GetProperty<bool>("shm-mlock-segment", mlockSegment); mlockSegment = config->GetProperty<bool>("shm-mlock-segment", mlockSegment);
mlockSegmentOnCreation = config->GetProperty<bool>("shm-mlock-segment-on-creation", mlockSegmentOnCreation);
zeroSegment = config->GetProperty<bool>("shm-zero-segment", zeroSegment); zeroSegment = config->GetProperty<bool>("shm-zero-segment", zeroSegment);
autolaunchMonitor = config->GetProperty<bool>("shm-monitor", autolaunchMonitor); autolaunchMonitor = config->GetProperty<bool>("shm-monitor", autolaunchMonitor);
allocationAlgorithm = config->GetProperty<std::string>("shm-allocation", allocationAlgorithm); allocationAlgorithm = config->GetProperty<std::string>("shm-allocation", allocationAlgorithm);
@ -162,6 +164,13 @@ class Manager
} }
ss << "Created "; ss << "Created ";
(fEventCounter->fCount)++; (fEventCounter->fCount)++;
if (mlockSegmentOnCreation) {
LOG(error) << "Locking the managed segment memory pages...";
if (mlock(boost::apply_visitor(SegmentAddress(), fSegments.at(fSegmentId)), boost::apply_visitor(SegmentSize(), fSegments.at(fSegmentId))) == -1) {
LOG(error) << "Could not lock the managed segment memory. Code: " << errno << ", reason: " << strerror(errno);
}
LOG(error) << "Successfully locked the managed segment memory pages.";
}
} else { } else {
op = "open"; op = "open";
// found segment with the given id, opening // found segment with the given id, opening

View File

@ -75,6 +75,7 @@ void ZeroingAndMlock(const string& transport)
config.SetProperty<size_t>("shm-segment-size", 16384); config.SetProperty<size_t>("shm-segment-size", 16384);
config.SetProperty<bool>("shm-zero-segment", true); config.SetProperty<bool>("shm-zero-segment", true);
config.SetProperty<bool>("shm-mlock-segment", true); config.SetProperty<bool>("shm-mlock-segment", true);
config.SetProperty<bool>("shm-mlock-segment-on-creation", true);
auto factory = FairMQTransportFactory::CreateTransportFactory(transport, fair::mq::tools::Uuid(), &config); auto factory = FairMQTransportFactory::CreateTransportFactory(transport, fair::mq::tools::Uuid(), &config);