[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-2-1' - wsd/Admin.cpp wsd/Admin.hpp wsd/LOOLWSD.cpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Mon Jul 31 21:11:36 UTC 2017
wsd/Admin.cpp | 11 +++++++++++
wsd/Admin.hpp | 12 +++++++++++-
wsd/LOOLWSD.cpp | 32 ++++++++++++++++++++------------
3 files changed, 42 insertions(+), 13 deletions(-)
New commits:
commit 34d588a78873eb1d61ae4950cd6335a992a872c9
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Sun Jun 11 23:47:48 2017 -0400
wsd: apply rlimits set from Admin Console to ForKit
Change-Id: I425c28ce08c5ecd659c4fe8eaa1a7ed3634e7f18
Reviewed-on: https://gerrit.libreoffice.org/38678
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
(cherry picked from commit 459249b17759d5f15fe17b96bdd7897b0c8b47ba)
Reviewed-on: https://gerrit.libreoffice.org/38763
Reviewed-by: Jan Holesovsky <kendy at collabora.com>
Tested-by: Jan Holesovsky <kendy at collabora.com>
diff --git a/wsd/Admin.cpp b/wsd/Admin.cpp
index 29d77c16..24c9716f 100644
--- a/wsd/Admin.cpp
+++ b/wsd/Admin.cpp
@@ -318,6 +318,7 @@ Admin::Admin() :
SocketPoll("admin"),
_model(AdminModel()),
_forKitPid(-1),
+ _forKitWritePipe(-1),
_lastTotalMemory(0),
_memStatsTaskIntervalMs(5000),
_cpuStatsTaskIntervalMs(5000)
@@ -506,6 +507,16 @@ void Admin::triggerMemoryCleanup(size_t totalMem)
LOG_TRC("OOM: Memory to free percentage : " << memToFreePercentage);
}
+void Admin::notifyForkit()
+{
+ std::ostringstream oss;
+ oss << "setconfig limit_virt_mem_mb " << _defDocProcSettings.LimitVirtMemMb << '\n'
+ << "setconfig limit_data_mem_kb " << _defDocProcSettings.LimitDataMemKb << '\n'
+ << "setconfig limit_stack_mem_kb " << _defDocProcSettings.LimitStackMemKb << '\n'
+ << "setconfig limit_file_size_mb " << _defDocProcSettings.LimitFileSizeMb << '\n';
+ IoUtil::writeToPipe(_forKitWritePipe, oss.str());
+}
+
void Admin::dumpState(std::ostream& os)
{
// FIXME: be more helpful ...
diff --git a/wsd/Admin.hpp b/wsd/Admin.hpp
index 2edaba85..8c597008 100644
--- a/wsd/Admin.hpp
+++ b/wsd/Admin.hpp
@@ -85,6 +85,7 @@ public:
void rmDoc(const std::string& docKey);
void setForKitPid(const int forKitPid) { _forKitPid = forKitPid; }
+ void setForKitWritePipe(const int forKitWritePipe) { _forKitWritePipe = forKitWritePipe; }
/// Callers must ensure that modelMutex is acquired
AdminModel& getModel();
@@ -103,7 +104,15 @@ public:
void dumpState(std::ostream& os) override;
const DocProcSettings& getDefDocProcSettings() const { return _defDocProcSettings; }
- void setDefDocProcSettings(const DocProcSettings& docProcSettings) { _defDocProcSettings = docProcSettings; }
+ void setDefDocProcSettings(const DocProcSettings& docProcSettings)
+ {
+ _defDocProcSettings = docProcSettings;
+ notifyForkit();
+ }
+
+private:
+ /// Notify Forkit of changed settings.
+ void notifyForkit();
private:
/// Memory consumption has increased, start killing kits etc. till memory consumption gets back
@@ -115,6 +124,7 @@ private:
/// the Admin Poll thread.
AdminModel _model;
int _forKitPid;
+ int _forKitWritePipe;
size_t _lastTotalMemory;
size_t _totalSysMem;
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 7a1333ab..3be5db41 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -801,6 +801,13 @@ void LOOLWSD::initialize(Application& self)
ServerApplication::initialize(self);
+ DocProcSettings docProcSettings;
+ docProcSettings.LimitVirtMemMb = getConfigValue<int>("per_document.limit_virt_mem_mb", 0);
+ docProcSettings.LimitDataMemKb = getConfigValue<int>("per_document.limit_data_mem_kb", 0);
+ docProcSettings.LimitStackMemKb = getConfigValue<int>("per_document.limit_stack_mem_kb", 0);
+ docProcSettings.LimitFileSizeMb = getConfigValue<int>("per_document.limit_file_size_mb", 0);
+ Admin::instance().setDefDocProcSettings(docProcSettings);
+
#if ENABLE_DEBUG
std::cerr << "\nLaunch this in your browser:\n\n"
<< getLaunchURI() << '\n' << std::endl;
@@ -1168,13 +1175,7 @@ bool LOOLWSD::createForKit()
args.push_back("--clientport=" + std::to_string(ClientPortNumber));
args.push_back("--masterport=" + std::to_string(MasterPortNumber));
- DocProcSettings docProcSettings;
- docProcSettings.LimitVirtMemMb = getConfigValue<int>("per_document.limit_virt_mem_mb", 0);
- docProcSettings.LimitDataMemKb = getConfigValue<int>("per_document.limit_data_mem_kb", 0);
- docProcSettings.LimitStackMemKb = getConfigValue<int>("per_document.limit_stack_mem_kb", 0);
- docProcSettings.LimitFileSizeMb = getConfigValue<int>("per_document.limit_file_size_mb", 0);
- Admin::instance().setDefDocProcSettings(docProcSettings);
-
+ const DocProcSettings& docProcSettings = Admin::instance().getDefDocProcSettings();
std::ostringstream ossRLimits;
ossRLimits << "limit_virt_mem_mb:" << docProcSettings.LimitVirtMemMb;
ossRLimits << ";limit_data_mem_kb:" << docProcSettings.LimitDataMemKb;
@@ -1200,14 +1201,20 @@ bool LOOLWSD::createForKit()
}
// Always reap first, in case we haven't done so yet.
- int status;
- waitpid(ForKitProcId, &status, WUNTRACED | WNOHANG);
- ForKitProcId = -1;
- Admin::instance().setForKitPid(ForKitProcId);
+ if (ForKitProcId != -1)
+ {
+ int status;
+ waitpid(ForKitProcId, &status, WUNTRACED | WNOHANG);
+ ForKitProcId = -1;
+ Admin::instance().setForKitPid(ForKitProcId);
+ }
if (ForKitWritePipe != -1)
+ {
close(ForKitWritePipe);
- ForKitWritePipe = -1;
+ ForKitWritePipe = -1;
+ Admin::instance().setForKitWritePipe(ForKitWritePipe);
+ }
// ForKit always spawns one.
++OutstandingForks;
@@ -1228,6 +1235,7 @@ bool LOOLWSD::createForKit()
// Init the Admin manager
Admin::instance().setForKitPid(ForKitProcId);
+ Admin::instance().setForKitWritePipe(ForKitWritePipe);
rebalanceChildren(LOOLWSD::NumPreSpawnedChildren - 1);
return ForKitProcId != -1;
More information about the Libreoffice-commits
mailing list