desktop/StaticLibrary_winloader.mk | 4 ++ desktop/win32/source/loader.cxx | 51 +++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+)
New commits: commit 6df7568e46b7f307ad6ae94730809fe63a6981a6 Author: Jan-Marek Glogowski <jan-marek.glogow...@extern.cib.de> AuthorDate: Wed Sep 11 14:35:19 2019 +0200 Commit: Jan-Marek Glogowski <glo...@fbihome.de> CommitDate: Fri Sep 13 20:11:38 2019 +0200 WIN allow setting a memory limit for soffice.bin This adds a Win32 section and two keys to the bootstrap.ini, which can be used to apply a memory limit to the soffice.bin process on Windows. Per default the limit won't affect any sub-processes, because the 2nd key adds JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK to the Jobs' flag list. To activte the limit, extend the bootstrap.ini like this: [Win32] LimitMaximumMemoryInMB=0 ExcludeChildProcessesFromLimit=true and adapt the values to your needs. Zero disables the limit. Change-Id: Ic474c6d6cdfe5ff3cfadbe6614030442171df1ae Reviewed-on: https://gerrit.libreoffice.org/78819 Tested-by: Jenkins Reviewed-by: Jan-Marek Glogowski <glo...@fbihome.de> diff --git a/desktop/StaticLibrary_winloader.mk b/desktop/StaticLibrary_winloader.mk index ca4fe691eed5..abee2aa3eef9 100644 --- a/desktop/StaticLibrary_winloader.mk +++ b/desktop/StaticLibrary_winloader.mk @@ -10,6 +10,10 @@ $(eval $(call gb_StaticLibrary_StaticLibrary,winloader)) +$(eval $(call gb_StaticLibrary_use_externals,winloader,\ + boost_headers \ +)) + $(eval $(call gb_StaticLibrary_add_exception_objects,winloader,\ desktop/win32/source/loader \ )) diff --git a/desktop/win32/source/loader.cxx b/desktop/win32/source/loader.cxx index d86a3b692ba4..8b750f45df6c 100644 --- a/desktop/win32/source/loader.cxx +++ b/desktop/win32/source/loader.cxx @@ -26,6 +26,9 @@ #include <desktop/exithelper.h> #include <tools/pathutils.hxx> +#include <boost/property_tree/ptree.hpp> +#include <boost/property_tree/ini_parser.hpp> + namespace { void fail() @@ -160,6 +163,47 @@ int officeloader_impl(bool bAllowConsole) } std::vector<std::wstring> aEscapedArgs; + // read limit values from bootstrap.ini + unsigned int nMaxMemoryInMB = 0; + bool bExcludeChildProcesses = true; + + const WCHAR* szIniFile = L"\\bootstrap.ini"; + const size_t nDirLen = wcslen(szIniDirectory); + if (wcslen(szIniFile) + nDirLen < MAX_PATH) + { + WCHAR szBootstrapIni[MAX_PATH]; + wcscpy(szBootstrapIni, szIniDirectory); + wcscpy(&szBootstrapIni[nDirLen], szIniFile); + + try + { + boost::property_tree::ptree pt; + std::fstream aFile(szBootstrapIni); + boost::property_tree::ini_parser::read_ini(aFile, pt); + nMaxMemoryInMB = pt.get("Win32.LimitMaximumMemoryInMB", nMaxMemoryInMB); + bExcludeChildProcesses = pt.get("Win32.ExcludeChildProcessesFromLimit", bExcludeChildProcesses); + } + catch (...) + { + nMaxMemoryInMB = 0; + } + } + + // create a Windows JobObject with a memory limit + HANDLE hJobObject = NULL; + if (nMaxMemoryInMB > 0) + { + JOBOBJECT_EXTENDED_LIMIT_INFORMATION aJobLimit; + aJobLimit.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_JOB_MEMORY; + if (bExcludeChildProcesses) + aJobLimit.BasicLimitInformation.LimitFlags |= JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK; + aJobLimit.JobMemoryLimit = nMaxMemoryInMB * 1024 * 1024; + hJobObject = CreateJobObjectW(NULL, NULL); + if (hJobObject != NULL) + SetInformationJobObject(hJobObject, JobObjectExtendedLimitInformation, &aJobLimit, + sizeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION)); + } + do { if (bFirst) @@ -247,6 +291,9 @@ int officeloader_impl(bool bAllowConsole) { DWORD dwWaitResult; + if (hJobObject) + AssignProcessToJobObject(hJobObject, aProcessInfo.hProcess); + do { // On Windows XP it seems as the desktop calls WaitForInputIdle after "OpenWith" so @@ -272,6 +319,10 @@ int officeloader_impl(bool bAllowConsole) } while (fSuccess && (EXITHELPER_CRASH_WITH_RESTART == dwExitCode || EXITHELPER_NORMAL_RESTART == dwExitCode)); + + if (hJobObject) + CloseHandle(hJobObject); + delete[] lpCommandLine; return fSuccess ? dwExitCode : -1; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits