[Libreoffice-commits] online.git: 2 commits - wsd/Admin.cpp wsd/LOOLWSD.cpp wsd/LOOLWSD.hpp
Pranav Kant
pranavk at collabora.co.uk
Tue Jul 11 12:45:37 UTC 2017
wsd/Admin.cpp | 11 ++++++++++-
wsd/LOOLWSD.cpp | 13 +++++++++++++
wsd/LOOLWSD.hpp | 3 +++
3 files changed, 26 insertions(+), 1 deletion(-)
New commits:
commit 160c1f555a12f53c0cd6e3f7994bf2d62ed49230
Author: Pranav Kant <pranavk at collabora.co.uk>
Date: Mon Jul 10 22:45:04 2017 +0530
Save unsaved documents when memory consumption is high
These saved documents are then removed to free some memory when next
memory cleanup is triggered in the admin loop.
Change-Id: Ia789a65dc204b546f1d3627a8006c4590bdca371
diff --git a/wsd/Admin.cpp b/wsd/Admin.cpp
index 5e00d455..5102ff33 100644
--- a/wsd/Admin.cpp
+++ b/wsd/Admin.cpp
@@ -570,6 +570,15 @@ void Admin::triggerMemoryCleanup(size_t totalMem)
else
++docIt;
}
+
+ // Save unsaved documents
+ docIt = docList.begin();
+ while (docIt != docList.end() && memToFree > 0)
+ {
+ LOG_TRC("Saving document: DocKey[" << docIt->_docKey << "].");
+ LOOLWSD::autoSave(docIt->_docKey);
+ ++docIt;
+ }
}
LOG_TRC("OOM: Memory to free percentage : " << memToFreePercentage);
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 3d286f3a..83f34ac5 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1131,6 +1131,19 @@ void LOOLWSD::closeDocument(const std::string& docKey, const std::string& messag
}
}
+void LOOLWSD::autoSave(const std::string& docKey)
+{
+ std::unique_lock<std::mutex> docBrokersLock(DocBrokersMutex);
+ auto docBrokerIt = DocBrokers.find(docKey);
+ if (docBrokerIt != DocBrokers.end())
+ {
+ std::shared_ptr<DocumentBroker> docBroker = docBrokerIt->second;
+ docBroker->addCallback([docBroker]() {
+ docBroker->autoSave(true);
+ });
+ }
+}
+
/// Really do the house-keeping
void PrisonerPoll::wakeupHook()
{
diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp
index c26d6858..7ed29e15 100644
--- a/wsd/LOOLWSD.hpp
+++ b/wsd/LOOLWSD.hpp
@@ -124,6 +124,9 @@ public:
/// Close document with @docKey and a @message
static void closeDocument(const std::string& docKey, const std::string& message);
+ /// Autosave a given document
+ static void autoSave(const std::string& docKey);
+
protected:
void initialize(Poco::Util::Application& self) override;
void defineOptions(Poco::Util::OptionSet& options) override;
commit ccce64eeeffce4ebef4f3cf7bde6ab288c6a1989
Author: Pranav Kant <pranavk at collabora.co.uk>
Date: Tue Jul 11 17:48:21 2017 +0530
This is percentage of total sys memory, not total consumed memory
Change-Id: I16b8b3d217cd0fabed83a9c63a5966cc6fe4d8fb
diff --git a/wsd/Admin.cpp b/wsd/Admin.cpp
index b4fdfa4b..5e00d455 100644
--- a/wsd/Admin.cpp
+++ b/wsd/Admin.cpp
@@ -547,7 +547,7 @@ void Admin::triggerMemoryCleanup(size_t totalMem)
float memToFreePercentage = 0;
if ( (memToFreePercentage = (totalMem/static_cast<double>(_totalSysMem)) - memLimit/100.) > 0.0 )
{
- int memToFree = memToFreePercentage * totalMem;
+ int memToFree = memToFreePercentage * _totalSysMem;
LOG_TRC("Memory to be freed (in kB) : " << memToFree);
// prepare document list sorted by most idle times
std::list<DocBasicInfo> docList = _model.getDocumentsSortedByIdle();
More information about the Libreoffice-commits
mailing list