Diff
Modified: trunk/Source/WTF/ChangeLog (261427 => 261428)
--- trunk/Source/WTF/ChangeLog 2020-05-09 00:02:45 UTC (rev 261427)
+++ trunk/Source/WTF/ChangeLog 2020-05-09 01:13:46 UTC (rev 261428)
@@ -1,3 +1,25 @@
+2020-05-08 Basuke Suzuki <[email protected]>
+
+ [WTF] Share Linux's MemoryPressureHandler among other Unix ports
+ https://bugs.webkit.org/show_bug.cgi?id=208955
+
+ Reviewed by Yusuke Suzuki.
+
+ Renamed MemoryPressureHandlerLinux to MemoryPressureHandlerUnix and added FreeBSD implementation
+ of memory status functions. Change PlayStation port to use it from generic implementation.
+
+ * wtf/MemoryPressureHandler.cpp:
+ (WTF::MemoryPressureHandler::MemoryPressureHandler):
+ * wtf/MemoryPressureHandler.h:
+ * wtf/PlatformGTK.cmake:
+ * wtf/PlatformJSCOnly.cmake:
+ * wtf/PlatformPlayStation.cmake:
+ * wtf/PlatformWPE.cmake:
+ * wtf/generic/MemoryFootprintGeneric.cpp:
+ (WTF::memoryFootprint):
+ * wtf/unix/MemoryPressureHandlerUnix.cpp: Renamed from Source\WTF\wtf\linux\MemoryPressureHandlerLinux.cpp.
+ (WTF::processMemoryUsage):
+
2020-05-08 Darin Adler <[email protected]>
Remove now-unneeded HAVE(AVFOUNDATION_LOADER_DELEGATE)
Modified: trunk/Source/WTF/wtf/MemoryPressureHandler.cpp (261427 => 261428)
--- trunk/Source/WTF/wtf/MemoryPressureHandler.cpp 2020-05-09 00:02:45 UTC (rev 261427)
+++ trunk/Source/WTF/wtf/MemoryPressureHandler.cpp 2020-05-09 01:13:46 UTC (rev 261428)
@@ -53,7 +53,7 @@
}
MemoryPressureHandler::MemoryPressureHandler()
-#if OS(LINUX)
+#if OS(LINUX) || OS(FREEBSD)
: m_holdOffTimer(RunLoop::main(), this, &MemoryPressureHandler::holdOffTimerFired)
#elif OS(WINDOWS)
: m_windowsMeasurementTimer(RunLoop::main(), this, &MemoryPressureHandler::windowsMeasurementTimerFired)
Modified: trunk/Source/WTF/wtf/MemoryPressureHandler.h (261427 => 261428)
--- trunk/Source/WTF/wtf/MemoryPressureHandler.h 2020-05-09 00:02:45 UTC (rev 261427)
+++ trunk/Source/WTF/wtf/MemoryPressureHandler.h 2020-05-09 01:13:46 UTC (rev 261428)
@@ -66,7 +66,7 @@
WTF_EXPORT_PRIVATE void setShouldUsePeriodicMemoryMonitor(bool);
-#if OS(LINUX)
+#if OS(LINUX) || OS(FREEBSD)
WTF_EXPORT_PRIVATE void triggerMemoryPressureEvent(bool isCritical);
#endif
@@ -200,7 +200,7 @@
Win32Handle m_lowMemoryHandle;
#endif
-#if OS(LINUX)
+#if OS(LINUX) || OS(FREEBSD)
RunLoop::Timer<MemoryPressureHandler> m_holdOffTimer;
void holdOffTimerFired();
#endif
Modified: trunk/Source/WTF/wtf/PlatformGTK.cmake (261427 => 261428)
--- trunk/Source/WTF/wtf/PlatformGTK.cmake 2020-05-09 00:02:45 UTC (rev 261427)
+++ trunk/Source/WTF/wtf/PlatformGTK.cmake 2020-05-09 01:13:46 UTC (rev 261428)
@@ -45,8 +45,15 @@
list(APPEND WTF_SOURCES
linux/CurrentProcessMemoryStatus.cpp
linux/MemoryFootprintLinux.cpp
- linux/MemoryPressureHandlerLinux.cpp
+
+ unix/MemoryPressureHandlerUnix.cpp
)
+elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
+ list(APPEND WTF_SOURCES
+ generic/MemoryFootprintGeneric.cpp
+
+ unix/MemoryPressureHandlerUnix.cpp
+ )
else ()
list(APPEND WTF_SOURCES
generic/MemoryFootprintGeneric.cpp
Modified: trunk/Source/WTF/wtf/PlatformJSCOnly.cmake (261427 => 261428)
--- trunk/Source/WTF/wtf/PlatformJSCOnly.cmake 2020-05-09 00:02:45 UTC (rev 261427)
+++ trunk/Source/WTF/wtf/PlatformJSCOnly.cmake 2020-05-09 01:13:46 UTC (rev 261428)
@@ -82,12 +82,19 @@
list(APPEND WTF_SOURCES
linux/CurrentProcessMemoryStatus.cpp
linux/MemoryFootprintLinux.cpp
- linux/MemoryPressureHandlerLinux.cpp
+
+ unix/MemoryPressureHandlerUnix.cpp
)
list(APPEND WTF_PUBLIC_HEADERS
linux/ProcessMemoryFootprint.h
linux/CurrentProcessMemoryStatus.h
)
+elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
+ list(APPEND WTF_SOURCES
+ generic/MemoryFootprintGeneric.cpp
+
+ unix/MemoryPressureHandlerUnix.cpp
+ )
else ()
list(APPEND WTF_SOURCES
generic/MemoryFootprintGeneric.cpp
Modified: trunk/Source/WTF/wtf/PlatformPlayStation.cmake (261427 => 261428)
--- trunk/Source/WTF/wtf/PlatformPlayStation.cmake 2020-05-09 00:02:45 UTC (rev 261427)
+++ trunk/Source/WTF/wtf/PlatformPlayStation.cmake 2020-05-09 01:13:46 UTC (rev 261428)
@@ -1,7 +1,6 @@
list(APPEND WTF_SOURCES
generic/MainThreadGeneric.cpp
generic/MemoryFootprintGeneric.cpp
- generic/MemoryPressureHandlerGeneric.cpp
generic/RunLoopGeneric.cpp
generic/WorkQueueGeneric.cpp
@@ -15,6 +14,7 @@
text/unix/TextBreakIteratorInternalICUUnix.cpp
unix/CPUTimeUnix.cpp
+ unix/MemoryPressureHandlerUnix.cpp
)
list(APPEND WTF_LIBRARIES
Modified: trunk/Source/WTF/wtf/PlatformWPE.cmake (261427 => 261428)
--- trunk/Source/WTF/wtf/PlatformWPE.cmake 2020-05-09 00:02:45 UTC (rev 261427)
+++ trunk/Source/WTF/wtf/PlatformWPE.cmake 2020-05-09 01:13:46 UTC (rev 261428)
@@ -27,7 +27,6 @@
glib/URLGLib.cpp
linux/CurrentProcessMemoryStatus.cpp
- linux/MemoryPressureHandlerLinux.cpp
posix/OSAllocatorPOSIX.cpp
posix/ThreadingPOSIX.cpp
@@ -36,6 +35,7 @@
unix/CPUTimeUnix.cpp
unix/LanguageUnix.cpp
+ unix/MemoryPressureHandlerUnix.cpp
unix/UniStdExtrasUnix.cpp
)
Modified: trunk/Source/WTF/wtf/generic/MemoryFootprintGeneric.cpp (261427 => 261428)
--- trunk/Source/WTF/wtf/generic/MemoryFootprintGeneric.cpp 2020-05-09 00:02:45 UTC (rev 261427)
+++ trunk/Source/WTF/wtf/generic/MemoryFootprintGeneric.cpp 2020-05-09 01:13:46 UTC (rev 261428)
@@ -25,8 +25,9 @@
#include "config.h"
#include <wtf/MemoryFootprint.h>
+#include <wtf/Platform.h>
-#if !(defined(USE_SYSTEM_MALLOC) && USE_SYSTEM_MALLOC) && OS(LINUX)
+#if !USE(SYSTEM_MALLOC) && (OS(LINUX) || OS(FREEBSD))
#include <bmalloc/bmalloc.h>
#endif
@@ -34,7 +35,7 @@
size_t memoryFootprint()
{
-#if !(defined(USE_SYSTEM_MALLOC) && USE_SYSTEM_MALLOC) && OS(LINUX)
+#if !USE(SYSTEM_MALLOC) && (OS(LINUX) || OS(FREEBSD))
return bmalloc::api::memoryFootprint();
#else
return 0;
Deleted: trunk/Source/WTF/wtf/linux/MemoryPressureHandlerLinux.cpp (261427 => 261428)
--- trunk/Source/WTF/wtf/linux/MemoryPressureHandlerLinux.cpp 2020-05-09 00:02:45 UTC (rev 261427)
+++ trunk/Source/WTF/wtf/linux/MemoryPressureHandlerLinux.cpp 2020-05-09 01:13:46 UTC (rev 261428)
@@ -1,139 +0,0 @@
-/*
- * Copyright (C) 2011, 2012 Apple Inc. All Rights Reserved.
- * Copyright (C) 2014 Raspberry Pi Foundation. All Rights Reserved.
- * Copyright (C) 2018 Igalia S.L.
- *
- * 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 <wtf/MemoryPressureHandler.h>
-
-#include <malloc.h>
-#include <unistd.h>
-#include <wtf/MainThread.h>
-#include <wtf/MemoryFootprint.h>
-#include <wtf/linux/CurrentProcessMemoryStatus.h>
-#include <wtf/text/WTFString.h>
-
-#define LOG_CHANNEL_PREFIX Log
-
-namespace WTF {
-
-// Disable memory event reception for a minimum of s_minimumHoldOffTime
-// seconds after receiving an event. Don't let events fire any sooner than
-// s_holdOffMultiplier times the last cleanup processing time. Effectively
-// this is 1 / s_holdOffMultiplier percent of the time.
-// If after releasing the memory we don't free at least s_minimumBytesFreedToUseMinimumHoldOffTime,
-// we wait longer to try again (s_maximumHoldOffTime).
-// These value seems reasonable and testing verifies that it throttles frequent
-// low memory events, greatly reducing CPU usage.
-static const Seconds s_minimumHoldOffTime { 5_s };
-static const Seconds s_maximumHoldOffTime { 30_s };
-static const size_t s_minimumBytesFreedToUseMinimumHoldOffTime = 1 * MB;
-static const unsigned s_holdOffMultiplier = 20;
-
-void MemoryPressureHandler::triggerMemoryPressureEvent(bool isCritical)
-{
- if (!m_installed)
- return;
-
- if (ReliefLogger::loggingEnabled())
- LOG(MemoryPressure, "Got memory pressure notification (%s)", isCritical ? "critical" : "non-critical");
-
- setUnderMemoryPressure(true);
-
- if (isMainThread())
- respondToMemoryPressure(isCritical ? Critical::Yes : Critical::No);
- else
- RunLoop::main().dispatch([this, isCritical] {
- respondToMemoryPressure(isCritical ? Critical::Yes : Critical::No);
- });
-
- if (ReliefLogger::loggingEnabled() && isUnderMemoryPressure())
- LOG(MemoryPressure, "System is no longer under memory pressure.");
-
- setUnderMemoryPressure(false);
-}
-
-void MemoryPressureHandler::install()
-{
- if (m_installed || m_holdOffTimer.isActive())
- return;
-
- m_installed = true;
-}
-
-void MemoryPressureHandler::uninstall()
-{
- if (!m_installed)
- return;
-
- m_holdOffTimer.stop();
-
- m_installed = false;
-}
-
-void MemoryPressureHandler::holdOffTimerFired()
-{
- install();
-}
-
-void MemoryPressureHandler::holdOff(Seconds seconds)
-{
- m_holdOffTimer.startOneShot(seconds);
-}
-
-static size_t processMemoryUsage()
-{
- ProcessMemoryStatus memoryStatus;
- currentProcessMemoryStatus(memoryStatus);
- return (memoryStatus.resident - memoryStatus.shared);
-}
-
-void MemoryPressureHandler::respondToMemoryPressure(Critical critical, Synchronous synchronous)
-{
- uninstall();
-
- MonotonicTime startTime = MonotonicTime::now();
- int64_t processMemory = processMemoryUsage();
- releaseMemory(critical, synchronous);
- int64_t bytesFreed = processMemory - processMemoryUsage();
- Seconds holdOffTime = s_maximumHoldOffTime;
- if (bytesFreed > 0 && static_cast<size_t>(bytesFreed) >= s_minimumBytesFreedToUseMinimumHoldOffTime)
- holdOffTime = (MonotonicTime::now() - startTime) * s_holdOffMultiplier;
- holdOff(std::max(holdOffTime, s_minimumHoldOffTime));
-}
-
-void MemoryPressureHandler::platformReleaseMemory(Critical)
-{
-#if HAVE(MALLOC_TRIM)
- malloc_trim(0);
-#endif
-}
-
-Optional<MemoryPressureHandler::ReliefLogger::MemoryUsage> MemoryPressureHandler::ReliefLogger::platformMemoryUsage()
-{
- return MemoryUsage {processMemoryUsage(), memoryFootprint()};
-}
-
-} // namespace WTF
Copied: trunk/Source/WTF/wtf/unix/MemoryPressureHandlerUnix.cpp (from rev 261427, trunk/Source/WTF/wtf/linux/MemoryPressureHandlerLinux.cpp) (0 => 261428)
--- trunk/Source/WTF/wtf/unix/MemoryPressureHandlerUnix.cpp (rev 0)
+++ trunk/Source/WTF/wtf/unix/MemoryPressureHandlerUnix.cpp 2020-05-09 01:13:46 UTC (rev 261428)
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2011, 2012 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2014 Raspberry Pi Foundation. All Rights Reserved.
+ * Copyright (C) 2018 Igalia S.L.
+ *
+ * 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 <wtf/MemoryPressureHandler.h>
+
+#include <malloc.h>
+#include <unistd.h>
+#include <wtf/MainThread.h>
+#include <wtf/MemoryFootprint.h>
+#include <wtf/text/WTFString.h>
+
+#if OS(LINUX)
+#include <wtf/linux/CurrentProcessMemoryStatus.h>
+#elif OS(FREEBSD)
+#include <sys/sysctl.h>
+#include <sys/types.h>
+#include <sys/user.h>
+#endif
+
+#define LOG_CHANNEL_PREFIX Log
+
+namespace WTF {
+
+// Disable memory event reception for a minimum of s_minimumHoldOffTime
+// seconds after receiving an event. Don't let events fire any sooner than
+// s_holdOffMultiplier times the last cleanup processing time. Effectively
+// this is 1 / s_holdOffMultiplier percent of the time.
+// If after releasing the memory we don't free at least s_minimumBytesFreedToUseMinimumHoldOffTime,
+// we wait longer to try again (s_maximumHoldOffTime).
+// These value seems reasonable and testing verifies that it throttles frequent
+// low memory events, greatly reducing CPU usage.
+static const Seconds s_minimumHoldOffTime { 5_s };
+static const Seconds s_maximumHoldOffTime { 30_s };
+static const size_t s_minimumBytesFreedToUseMinimumHoldOffTime = 1 * MB;
+static const unsigned s_holdOffMultiplier = 20;
+
+void MemoryPressureHandler::triggerMemoryPressureEvent(bool isCritical)
+{
+ if (!m_installed)
+ return;
+
+ if (ReliefLogger::loggingEnabled())
+ LOG(MemoryPressure, "Got memory pressure notification (%s)", isCritical ? "critical" : "non-critical");
+
+ setUnderMemoryPressure(true);
+
+ if (isMainThread())
+ respondToMemoryPressure(isCritical ? Critical::Yes : Critical::No);
+ else
+ RunLoop::main().dispatch([this, isCritical] {
+ respondToMemoryPressure(isCritical ? Critical::Yes : Critical::No);
+ });
+
+ if (ReliefLogger::loggingEnabled() && isUnderMemoryPressure())
+ LOG(MemoryPressure, "System is no longer under memory pressure.");
+
+ setUnderMemoryPressure(false);
+}
+
+void MemoryPressureHandler::install()
+{
+ if (m_installed || m_holdOffTimer.isActive())
+ return;
+
+ m_installed = true;
+}
+
+void MemoryPressureHandler::uninstall()
+{
+ if (!m_installed)
+ return;
+
+ m_holdOffTimer.stop();
+
+ m_installed = false;
+}
+
+void MemoryPressureHandler::holdOffTimerFired()
+{
+ install();
+}
+
+void MemoryPressureHandler::holdOff(Seconds seconds)
+{
+ m_holdOffTimer.startOneShot(seconds);
+}
+
+static size_t processMemoryUsage()
+{
+#if OS(LINUX)
+ ProcessMemoryStatus memoryStatus;
+ currentProcessMemoryStatus(memoryStatus);
+ return (memoryStatus.resident - memoryStatus.shared);
+#elif OS(FREEBSD)
+ static size_t pageSize = sysconf(_SC_PAGE_SIZE);
+ struct kinfo_proc info;
+ size_t infolen = sizeof(info);
+
+ int mib[4];
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_PROC;
+ mib[2] = KERN_PROC_PID;
+ mib[3] = getpid();
+
+ if (sysctl(mib, 4, &info, &infolen, nullptr, 0))
+ return 0;
+
+ return static_cast<size_t>(info.ki_rssize - info.ki_tsize) * pageSize;
+#else
+#error "Missing a platform specific way of determining the memory usage"
+#endif
+}
+
+void MemoryPressureHandler::respondToMemoryPressure(Critical critical, Synchronous synchronous)
+{
+ uninstall();
+
+ MonotonicTime startTime = MonotonicTime::now();
+ int64_t processMemory = processMemoryUsage();
+ releaseMemory(critical, synchronous);
+ int64_t bytesFreed = processMemory - processMemoryUsage();
+ Seconds holdOffTime = s_maximumHoldOffTime;
+ if (bytesFreed > 0 && static_cast<size_t>(bytesFreed) >= s_minimumBytesFreedToUseMinimumHoldOffTime)
+ holdOffTime = (MonotonicTime::now() - startTime) * s_holdOffMultiplier;
+ holdOff(std::max(holdOffTime, s_minimumHoldOffTime));
+}
+
+void MemoryPressureHandler::platformReleaseMemory(Critical)
+{
+#if HAVE(MALLOC_TRIM)
+ malloc_trim(0);
+#endif
+}
+
+Optional<MemoryPressureHandler::ReliefLogger::MemoryUsage> MemoryPressureHandler::ReliefLogger::platformMemoryUsage()
+{
+ return MemoryUsage {processMemoryUsage(), memoryFootprint()};
+}
+
+} // namespace WTF
Modified: trunk/Source/bmalloc/ChangeLog (261427 => 261428)
--- trunk/Source/bmalloc/ChangeLog 2020-05-09 00:02:45 UTC (rev 261427)
+++ trunk/Source/bmalloc/ChangeLog 2020-05-09 01:13:46 UTC (rev 261428)
@@ -1,3 +1,18 @@
+2020-05-08 Basuke Suzuki <[email protected]>
+
+ [WTF] Share Linux's MemoryPressureHandler among other Unix ports
+ https://bugs.webkit.org/show_bug.cgi?id=208955
+
+ Reviewed by Yusuke Suzuki.
+
+ Added FreeBSD implementation of memoryFootprint().
+
+ * bmalloc/AvailableMemory.cpp:
+ (bmalloc::memoryStatus):
+ * bmalloc/AvailableMemory.h:
+ (bmalloc::isUnderMemoryPressure):
+ * bmalloc/bmalloc.h:
+
2020-05-05 Saam Barati <[email protected]>
Don't use the DebugHeap for catalyst
Modified: trunk/Source/bmalloc/bmalloc/AvailableMemory.cpp (261427 => 261428)
--- trunk/Source/bmalloc/bmalloc/AvailableMemory.cpp 2020-05-09 00:02:45 UTC (rev 261427)
+++ trunk/Source/bmalloc/bmalloc/AvailableMemory.cpp 2020-05-09 01:13:46 UTC (rev 261428)
@@ -47,6 +47,11 @@
#if BOS(LINUX)
#include <algorithm>
#include <fcntl.h>
+#elif BOS(FREEBSD)
+#include "VMAllocate.h"
+#include <sys/sysctl.h>
+#include <sys/types.h>
+#include <sys/user.h>
#endif
#include <unistd.h>
#endif
@@ -184,7 +189,7 @@
return availableMemory;
}
-#if BPLATFORM(IOS_FAMILY) || BOS(LINUX)
+#if BPLATFORM(IOS_FAMILY) || BOS(LINUX) || BOS(FREEBSD)
MemoryStatus memoryStatus()
{
#if BPLATFORM(IOS_FAMILY)
@@ -200,6 +205,21 @@
auto& memory = LinuxMemory::singleton();
size_t memoryFootprint = memory.footprint();
double percentInUse = static_cast<double>(memoryFootprint) / static_cast<double>(memory.availableMemory);
+#elif BOS(FREEBSD)
+ struct kinfo_proc info;
+ size_t infolen = sizeof(info);
+
+ int mib[4];
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_PROC;
+ mib[2] = KERN_PROC_PID;
+ mib[3] = getpid();
+
+ size_t memoryFootprint = 0;
+ if (!sysctl(mib, 4, &info, &infolen, nullptr, 0))
+ memoryFootprint = static_cast<size_t>(info.ki_rssize) * vmPageSize();
+
+ double percentInUse = static_cast<double>(memoryFootprint) / static_cast<double>(availableMemory());
#endif
double percentAvailableMemoryInUse = std::min(percentInUse, 1.0);
Modified: trunk/Source/bmalloc/bmalloc/AvailableMemory.h (261427 => 261428)
--- trunk/Source/bmalloc/bmalloc/AvailableMemory.h 2020-05-09 00:02:45 UTC (rev 261427)
+++ trunk/Source/bmalloc/bmalloc/AvailableMemory.h 2020-05-09 01:13:46 UTC (rev 261428)
@@ -32,7 +32,7 @@
BEXPORT size_t availableMemory();
-#if BPLATFORM(IOS_FAMILY) || BOS(LINUX)
+#if BPLATFORM(IOS_FAMILY) || BOS(LINUX) || BOS(FREEBSD)
struct MemoryStatus {
MemoryStatus(size_t memoryFootprint, double percentAvailableMemoryInUse)
: memoryFootprint(memoryFootprint)
@@ -61,7 +61,7 @@
inline bool isUnderMemoryPressure()
{
-#if BPLATFORM(IOS_FAMILY) || BOS(LINUX)
+#if BPLATFORM(IOS_FAMILY) || BOS(LINUX) || BOS(FREEBSD)
return percentAvailableMemoryInUse() > memoryPressureThreshold;
#else
return false;
Modified: trunk/Source/bmalloc/bmalloc/bmalloc.h (261427 => 261428)
--- trunk/Source/bmalloc/bmalloc/bmalloc.h 2020-05-09 00:02:45 UTC (rev 261427)
+++ trunk/Source/bmalloc/bmalloc/bmalloc.h 2020-05-09 01:13:46 UTC (rev 261428)
@@ -111,7 +111,7 @@
return bmalloc::availableMemory();
}
-#if BPLATFORM(IOS_FAMILY) || BOS(LINUX)
+#if BPLATFORM(IOS_FAMILY) || BOS(LINUX) || BOS(FREEBSD)
inline size_t memoryFootprint()
{
return bmalloc::memoryFootprint();
Modified: trunk/Tools/ChangeLog (261427 => 261428)
--- trunk/Tools/ChangeLog 2020-05-09 00:02:45 UTC (rev 261427)
+++ trunk/Tools/ChangeLog 2020-05-09 01:13:46 UTC (rev 261428)
@@ -1,3 +1,14 @@
+2020-05-08 Basuke Suzuki <[email protected]>
+
+ [WTF] Share Linux's MemoryPressureHandler among other Unix ports
+ https://bugs.webkit.org/show_bug.cgi?id=208955
+
+ Reviewed by Yusuke Suzuki.
+
+ Fix unneeded library dependency.
+
+ * TestWebKitAPI/CMakeLists.txt:
+
2020-05-08 Jonathan Bedard <[email protected]>
webkitpy: 'iPhone SE' should match 'iPhone SE 1st generation'
Modified: trunk/Tools/TestWebKitAPI/CMakeLists.txt (261427 => 261428)
--- trunk/Tools/TestWebKitAPI/CMakeLists.txt 2020-05-09 00:02:45 UTC (rev 261427)
+++ trunk/Tools/TestWebKitAPI/CMakeLists.txt 2020-05-09 01:13:46 UTC (rev 261428)
@@ -333,7 +333,7 @@
target_compile_definitions(TestWebKitAPIInjectedBundle PRIVATE BUILDING_TestWebKit)
target_include_directories(TestWebKitAPIInjectedBundle PRIVATE ${TestWebKit_PRIVATE_INCLUDE_DIRECTORIES})
- target_link_libraries(TestWebKitAPIInjectedBundle PRIVATE WebKit::WebKit WTF)
+ target_link_libraries(TestWebKitAPIInjectedBundle PRIVATE WebKit::WebKit)
if (COMPILER_IS_GCC_OR_CLANG)
WEBKIT_ADD_TARGET_CXX_FLAGS(TestWebKitAPIInjectedBundle -Wno-dangling-else