Title: [271929] trunk/Source/WebCore
- Revision
- 271929
- Author
- [email protected]
- Date
- 2021-01-26 17:36:14 -0800 (Tue, 26 Jan 2021)
Log Message
[GPU Process] Compositing layout test crash in WebKit::GPUProcess::lowMemoryHandler
https://bugs.webkit.org/show_bug.cgi?id=221010
<rdar://problem/73631552>
Reviewed by Simon Fraser.
Make IOSurfacePool thread-safe now that it is used from multiple threads in the
GPUProcess.
* platform/graphics/cg/IOSurfacePool.cpp:
(WebCore::IOSurfacePool::IOSurfacePool):
(WebCore::IOSurfacePool::sharedPool):
(WebCore::IOSurfacePool::takeSurface):
(WebCore::IOSurfacePool::addSurface):
(WebCore::IOSurfacePool::setPoolSize):
(WebCore::IOSurfacePool::collectionTimerFired):
(WebCore::IOSurfacePool::discardAllSurfaces):
* platform/graphics/cg/IOSurfacePool.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (271928 => 271929)
--- trunk/Source/WebCore/ChangeLog 2021-01-27 01:13:33 UTC (rev 271928)
+++ trunk/Source/WebCore/ChangeLog 2021-01-27 01:36:14 UTC (rev 271929)
@@ -1,3 +1,24 @@
+2021-01-26 Chris Dumez <[email protected]>
+
+ [GPU Process] Compositing layout test crash in WebKit::GPUProcess::lowMemoryHandler
+ https://bugs.webkit.org/show_bug.cgi?id=221010
+ <rdar://problem/73631552>
+
+ Reviewed by Simon Fraser.
+
+ Make IOSurfacePool thread-safe now that it is used from multiple threads in the
+ GPUProcess.
+
+ * platform/graphics/cg/IOSurfacePool.cpp:
+ (WebCore::IOSurfacePool::IOSurfacePool):
+ (WebCore::IOSurfacePool::sharedPool):
+ (WebCore::IOSurfacePool::takeSurface):
+ (WebCore::IOSurfacePool::addSurface):
+ (WebCore::IOSurfacePool::setPoolSize):
+ (WebCore::IOSurfacePool::collectionTimerFired):
+ (WebCore::IOSurfacePool::discardAllSurfaces):
+ * platform/graphics/cg/IOSurfacePool.h:
+
2021-01-26 Saam Barati <[email protected]>
Revive the build when MALLOC_HEAP_BREAKDOWN is enabled
Modified: trunk/Source/WebCore/platform/graphics/cg/IOSurfacePool.cpp (271928 => 271929)
--- trunk/Source/WebCore/platform/graphics/cg/IOSurfacePool.cpp 2021-01-27 01:13:33 UTC (rev 271928)
+++ trunk/Source/WebCore/platform/graphics/cg/IOSurfacePool.cpp 2021-01-27 01:36:14 UTC (rev 271929)
@@ -34,12 +34,7 @@
static const Seconds collectionInterval { 500_ms };
static const Seconds surfaceAgeBeforeMarkingPurgeable { 2_s };
-const size_t defaultMaximumBytesCached = 1024 * 1024 * 64;
-// We'll never allow more than 1/2 of the cache to be filled with in-use surfaces, because
-// they can't be immediately returned when requested (but will be freed up in the future).
-const size_t maximumInUseBytes = defaultMaximumBytesCached / 2;
-
#define ENABLE_IOSURFACE_POOL_STATISTICS 0
#if ENABLE_IOSURFACE_POOL_STATISTICS
#define DUMP_POOL_STATISTICS(reason) do { showPoolStatistics(reason); } while (0);
@@ -50,16 +45,17 @@
namespace WebCore {
IOSurfacePool::IOSurfacePool()
- : m_collectionTimer(*this, &IOSurfacePool::collectionTimerFired)
- , m_bytesCached(0)
- , m_inUseBytesCached(0)
- , m_maximumBytesCached(defaultMaximumBytesCached)
+ : m_collectionTimer(RunLoop::main(), this, &IOSurfacePool::collectionTimerFired)
{
}
IOSurfacePool& IOSurfacePool::sharedPool()
{
- static NeverDestroyed<IOSurfacePool> pool;
+ static LazyNeverDestroyed<IOSurfacePool> pool;
+ static std::once_flag s_onceFlag;
+ std::call_once(s_onceFlag, [] {
+ pool.construct();
+ });
return pool;
}
@@ -108,6 +104,7 @@
std::unique_ptr<IOSurface> IOSurfacePool::takeSurface(IntSize size, CGColorSpaceRef colorSpace, IOSurface::Format format)
{
+ auto locker = holdLock(m_lock);
CachedSurfaceMap::iterator mapIter = m_cachedSurfaces.find(size);
if (mapIter == m_cachedSurfaces.end()) {
@@ -173,6 +170,7 @@
void IOSurfacePool::addSurface(std::unique_ptr<IOSurface> surface)
{
+ auto locker = holdLock(m_lock);
if (!shouldCacheSurface(*surface))
return;
@@ -205,6 +203,7 @@
void IOSurfacePool::setPoolSize(size_t poolSizeInBytes)
{
+ auto locker = holdLock(m_lock);
m_maximumBytesCached = poolSizeInBytes;
evict(0);
}
@@ -307,6 +306,7 @@
void IOSurfacePool::collectionTimerFired()
{
+ auto locker = holdLock(m_lock);
collectInUseSurfaces();
bool markedAllSurfaces = markOlderSurfacesPurgeable();
@@ -325,6 +325,7 @@
void IOSurfacePool::discardAllSurfaces()
{
+ auto locker = holdLock(m_lock);
m_bytesCached = 0;
m_inUseBytesCached = 0;
m_surfaceDetails.clear();
Modified: trunk/Source/WebCore/platform/graphics/cg/IOSurfacePool.h (271928 => 271929)
--- trunk/Source/WebCore/platform/graphics/cg/IOSurfacePool.h 2021-01-27 01:13:33 UTC (rev 271928)
+++ trunk/Source/WebCore/platform/graphics/cg/IOSurfacePool.h 2021-01-27 01:36:14 UTC (rev 271929)
@@ -33,7 +33,9 @@
#include "Timer.h"
#include <wtf/Deque.h>
#include <wtf/HashMap.h>
+#include <wtf/Lock.h>
#include <wtf/NeverDestroyed.h>
+#include <wtf/RunLoop.h>
namespace WebCore {
@@ -40,7 +42,7 @@
class IOSurfacePool {
WTF_MAKE_NONCOPYABLE(IOSurfacePool);
WTF_MAKE_FAST_ALLOCATED;
- friend class NeverDestroyed<IOSurfacePool>;
+ friend class LazyNeverDestroyed<IOSurfacePool>;
public:
WEBCORE_EXPORT static IOSurfacePool& sharedPool();
@@ -69,6 +71,12 @@
typedef Deque<std::unique_ptr<IOSurface>> CachedSurfaceQueue;
typedef HashMap<IntSize, CachedSurfaceQueue> CachedSurfaceMap;
typedef HashMap<IOSurface*, CachedSurfaceDetails> CachedSurfaceDetailsMap;
+
+ static constexpr size_t defaultMaximumBytesCached { 1024 * 1024 * 64 };
+
+ // We'll never allow more than 1/2 of the cache to be filled with in-use surfaces, because
+ // they can't be immediately returned when requested (but will be freed up in the future).
+ static constexpr size_t maximumInUseBytes = defaultMaximumBytesCached / 2;
bool shouldCacheSurface(const IOSurface&) const;
@@ -91,15 +99,16 @@
void showPoolStatistics(const char*);
- Timer m_collectionTimer;
+ RunLoop::Timer<IOSurfacePool> m_collectionTimer;
+ Lock m_lock;
CachedSurfaceMap m_cachedSurfaces;
CachedSurfaceQueue m_inUseSurfaces;
CachedSurfaceDetailsMap m_surfaceDetails;
Vector<IntSize> m_sizesInPruneOrder;
- size_t m_bytesCached;
- size_t m_inUseBytesCached;
- size_t m_maximumBytesCached;
+ size_t m_bytesCached { 0 };
+ size_t m_inUseBytesCached { 0 };
+ size_t m_maximumBytesCached { defaultMaximumBytesCached };
};
}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes