Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Source/JavaScriptCore:
[Mac] In-process memory pressure monitor for WebContent processes. <https://webkit.org/b/167491> <rdar://problem/30116072> Reviewed by Antti Koivisto. Remove the sloppy "max live heap size" mechanism from JSC in favor of the new WebCore-side memory footprint monitor. * heap/Heap.cpp: (JSC::Heap::updateAllocationLimits): (JSC::Heap::didExceedMaxLiveSize): Deleted. * heap/Heap.h: (JSC::Heap::setMaxLiveSize): Deleted. Source/WebCore: [Mac] In-process memory pressure monitor for WebContent processes AKA websam <https://webkit.org/b/167491> <rdar://problem/30116072> Reviewed by Antti Koivisto. Add a new timer-based memory pressure monitor that checks the process memory footprint every 30 seconds and reacts to changes by setting a MemoryUsagePolicy. There are four MemoryUsagePolicy values: - Unrestricted (below 1GB) - Conservative (above 1GB) - Strict (above 2GB) - Panic (above 4GB, or 3GB if 32-bit) For Strict and above, the old-style "isUnderMemoryPressure()" API will return true. Transitioning to a higher policy will cause memory pressure handlers to run: At Strict, we run the "non-critical" memory pressure handler, then carry on. At Panic, we run the "critical" memory pressure handler. If that fails to recover enough memory to bring us back below 4GB, we may kill the process: A process is eligible to get killed for using too much memory if: - It's not visible on screen (i.e it's a background tab.) - It's not playing audio. - It has not performed a main frame navigation in the last hour. Before killing the process, an exit-time callback will run. This patch installs such a callback that prints out some time-of-death statistics about C++ and JavaScript memory usage to hopefully help understand what was soaking up all the memory. * bindings/js/CommonVM.cpp: (WebCore::commonVMSlow): * loader/FrameLoader.cpp: (WebCore::FrameLoader::setState): * page/MainFrame.cpp: (WebCore::MainFrame::didCompleteLoad): * page/MainFrame.h: * page/MemoryRelease.cpp: (WebCore::pageCount): (WebCore::logMemoryStatisticsAtTimeOfDeath): (WebCore::didExceedMemoryLimitAndFailedToRecover): (WebCore::processIsEligibleForMemoryKill): * page/MemoryRelease.h: * page/ResourceUsageThread.h: * page/cocoa/ResourceUsageThreadCocoa.mm: (WebCore::vmPageSize): * platform/MemoryPressureHandler.cpp: (WebCore::MemoryPressureHandler::MemoryPressureHandler): (WebCore::MemoryPressureHandler::setShouldUsePeriodicMemoryMonitor): (WebCore::toString): (WebCore::thresholdForPolicy): (WebCore::policyForFootprint): (WebCore::MemoryPressureHandler::measurementTimerFired): * platform/MemoryPressureHandler.h: (WebCore::MemoryPressureHandler::setMemoryKillCallback): (WebCore::MemoryPressureHandler::setProcessIsEligibleForMemoryKillCallback): (WebCore::MemoryPressureHandler::isUnderMemoryPressure): Source/WebKit2: [Mac] In-process memory pressure monitor for WebContent processes. <https://webkit.org/b/167491> <rdar://problem/30116072> Reviewed by Antti Koivisto. Enable the in-process memory monitor for WebContent processes on macOS 10.12+ * WebProcess/WebProcess.cpp: (WebKit::WebProcess::initializeWebProcess): Source/WTF: [Mac] In-process memory pressure monitor for WebContent processes. <https://webkit.org/b/167491> <rdar://problem/30116072> Reviewed by Antti Koivisto. Add a WTF helper function for getting the current process's memory footprint. * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/MemoryFootprint.cpp: (WTF::memoryFootprint): * wtf/MemoryFootprint.h: Canonical link: https://commits.webkit.org/184785@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@211571 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Andreas Kling
committed
Feb 2, 2017
1 parent
58e85ee
commit 7532df3
Showing
21 changed files
with
468 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (C) 2017 Apple Inc. All Rights Reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | ||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "config.h" | ||
#include "MemoryFootprint.h" | ||
|
||
#if PLATFORM(COCOA) | ||
#include <mach/mach.h> | ||
#include <mach/task_info.h> | ||
#endif | ||
|
||
namespace WTF { | ||
|
||
std::optional<size_t> memoryFootprint() | ||
{ | ||
#if PLATFORM(COCOA) | ||
task_vm_info_data_t vmInfo; | ||
mach_msg_type_number_t count = TASK_VM_INFO_COUNT; | ||
kern_return_t result = task_info(mach_task_self(), TASK_VM_INFO, (task_info_t) &vmInfo, &count); | ||
if (result != KERN_SUCCESS) | ||
return std::nullopt; | ||
return static_cast<size_t>(vmInfo.phys_footprint); | ||
#else | ||
return std::nullopt; | ||
#endif | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (C) 2017 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <wtf/Optional.h> | ||
|
||
namespace WTF { | ||
|
||
WTF_EXPORT_PRIVATE std::optional<size_t> memoryFootprint(); | ||
|
||
} | ||
|
||
using WTF::memoryFootprint; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.