Skip to content

Commit

Permalink
Merge r229894 - WebProcess memory monitor thresholds should be better…
Browse files Browse the repository at this point in the history
… tuned for embedded systems.

https://bugs.webkit.org/show_bug.cgi?id=183773

Reviewed by Yusuke Suzuki.

Take into account the total system RAM for the thresholds calculation.

For systems with more than 3GB the conservative and strict thresholds remain as they are,
but for systems with less RAM the thresholds are dynamically configured as follows:

- Conservative threshold (release non critical memory) if WebProcess using more than 33% of the total RAM.
- Strict threshold (release all possible memory) if WebProcess using more than 50% of the total RAM.

The Kill threshold is also modified. Now it is capped at 90% of the total RAM.

* wtf/MemoryPressureHandler.cpp:
(WTF::thresholdForMemoryKillWithProcessState):
(WTF::thresholdForPolicy):
(WTF::MemoryPressureHandler::shrinkOrDie):
  • Loading branch information
clopez authored and carlosgcampos committed Apr 9, 2018
1 parent 29ce157 commit 9d1bfb1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
22 changes: 22 additions & 0 deletions Source/WTF/ChangeLog
@@ -1,3 +1,25 @@
2018-03-23 Carlos Alberto Lopez Perez <clopez@igalia.com>

WebProcess memory monitor thresholds should be better tuned for embedded systems.
https://bugs.webkit.org/show_bug.cgi?id=183773

Reviewed by Yusuke Suzuki.

Take into account the total system RAM for the thresholds calculation.

For systems with more than 3GB the conservative and strict thresholds remain as they are,
but for systems with less RAM the thresholds are dynamically configured as follows:

- Conservative threshold (release non critical memory) if WebProcess using more than 33% of the total RAM.
- Strict threshold (release all possible memory) if WebProcess using more than 50% of the total RAM.

The Kill threshold is also modified. Now it is capped at 90% of the total RAM.

* wtf/MemoryPressureHandler.cpp:
(WTF::thresholdForMemoryKillWithProcessState):
(WTF::thresholdForPolicy):
(WTF::MemoryPressureHandler::shrinkOrDie):

2018-03-08 Zan Dobersek <zdobersek@igalia.com>

[GLib] RunLoop::wakeUp(): use a zero value instead of the monotonic time
Expand Down
22 changes: 11 additions & 11 deletions Source/WTF/wtf/MemoryPressureHandler.cpp
Expand Up @@ -28,6 +28,7 @@

#include <wtf/MemoryFootprint.h>
#include <wtf/NeverDestroyed.h>
#include <wtf/RAMSize.h>

#define LOG_CHANNEL_PREFIX Log

Expand Down Expand Up @@ -84,20 +85,17 @@ static const char* toString(MemoryUsagePolicy policy)

static size_t thresholdForMemoryKillWithProcessState(WebsamProcessState processState, unsigned tabCount)
{
size_t baseThreshold = 2 * GB;
#if CPU(X86_64) || CPU(ARM64)
size_t baseThreshold;
if (processState == WebsamProcessState::Active)
baseThreshold = 4 * GB;
else
baseThreshold = 2 * GB;
if (tabCount <= 1)
return baseThreshold;
return baseThreshold + (std::min(tabCount - 1, 4u) * 1 * GB);
if (tabCount > 1)
baseThreshold += std::min(tabCount - 1, 4u) * 1 * GB;
#else
UNUSED_PARAM(processState);
UNUSED_PARAM(tabCount);
return 3 * GB;
if ((tabCount > 1) || (processState == WebsamProcessState::Active))
baseThreshold = 3 * GB;
#endif
return std::min(baseThreshold, static_cast<size_t>(ramSize() * 0.9));
}

void MemoryPressureHandler::setPageCount(unsigned pageCount)
Expand All @@ -114,11 +112,12 @@ size_t MemoryPressureHandler::thresholdForMemoryKill()

static size_t thresholdForPolicy(MemoryUsagePolicy policy)
{
const size_t baseThresholdForPolicy = std::min(3 * GB, ramSize());
switch (policy) {
case MemoryUsagePolicy::Conservative:
return 1 * GB;
return baseThresholdForPolicy / 3;
case MemoryUsagePolicy::Strict:
return 1.5 * GB;
return baseThresholdForPolicy / 2;
case MemoryUsagePolicy::Unrestricted:
default:
ASSERT_NOT_REACHED();
Expand Down Expand Up @@ -150,6 +149,7 @@ void MemoryPressureHandler::shrinkOrDie()
return;
}

WTFLogAlways("Unable to shrink memory footprint of process (%lu MB) below the kill thresold (%lu MB). Killed\n", footprint.value() / MB, thresholdForMemoryKill() / MB);
RELEASE_ASSERT(m_memoryKillCallback);
m_memoryKillCallback();
}
Expand Down

0 comments on commit 9d1bfb1

Please sign in to comment.