Changeset 242726 in webkit
- Timestamp:
- Mar 11, 2019, 12:30:42 PM (7 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 6 edited
-
ChangeLog (modified) (1 diff)
-
UIProcess/API/Cocoa/WKProcessPool.mm (modified) (1 diff)
-
UIProcess/WebProcessCache.cpp (modified) (6 diffs)
-
UIProcess/WebProcessCache.h (modified) (2 diffs)
-
UIProcess/WebProcessPool.cpp (modified) (1 diff)
-
UIProcess/WebProcessProxy.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r242723 r242726 1 2019-03-11 Chris Dumez <cdumez@apple.com> 2 3 WebProcessCache should keep track of processes being added 4 https://bugs.webkit.org/show_bug.cgi?id=195538 5 6 Reviewed by Geoffrey Garen. 7 8 WebProcessCache should keep track of processes being added, while they are being 9 checked for responsiveness. This is useful so that: 10 - Requests to clear the cache also clear processes being added 11 - Requests to remove a given process from the cache (either because it crashed 12 or because it is being used for a history navigation) actually remove the 13 process if it is still being checked for responsiveness. 14 - The cached process eviction timer applies to such processes in case something 15 goes wrong with the code and the pending request does not get processed. 16 17 * UIProcess/WebProcessCache.cpp: 18 (WebKit::generateAddRequestIdentifier): 19 (WebKit::WebProcessCache::addProcessIfPossible): 20 (WebKit::WebProcessCache::addProcess): 21 (WebKit::WebProcessCache::clear): 22 (WebKit::WebProcessCache::clearAllProcessesForSession): 23 (WebKit::WebProcessCache::removeProcess): 24 (WebKit::WebProcessCache::CachedProcess::evictionTimerFired): 25 (WebKit::WebProcessCache::evictProcess): Deleted. 26 * UIProcess/WebProcessCache.h: 27 (WebKit::WebProcessCache::size const): 28 * UIProcess/WebProcessPool.cpp: 29 (WebKit::WebProcessPool::processForNavigationInternal): 30 * UIProcess/WebProcessProxy.cpp: 31 (WebKit::WebProcessProxy::processDidTerminateOrFailedToLaunch): 32 1 33 2019-03-11 Alex Christensen <achristensen@webkit.org> 2 34 -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm
r242371 r242726 477 477 - (size_t)_webProcessCountIgnoringPrewarmedAndCached 478 478 { 479 return [self _webProcessCount] - ([self _hasPrewarmedWebProcess] ? 1 : 0) - _processPool->webProcessCache().size(); 479 size_t count = 0; 480 for (auto& process : _processPool->processes()) { 481 if (!process->isInProcessCache() && !process->isPrewarmed()) 482 ++count; 483 } 484 return count; 480 485 } 481 486 -
trunk/Source/WebKit/UIProcess/WebProcessCache.cpp
r242652 r242726 38 38 Seconds WebProcessCache::clearingDelayAfterApplicationResignsActive { 5_min }; 39 39 40 static uint64_t generateAddRequestIdentifier() 41 { 42 static uint64_t identifier = 0; 43 return ++identifier; 44 } 45 40 46 WebProcessCache::WebProcessCache(WebProcessPool& processPool) 41 47 : m_evictionTimer(RunLoop::main(), this, &WebProcessCache::clear) … … 74 80 return false; 75 81 82 uint64_t requestIdentifier = generateAddRequestIdentifier(); 83 m_pendingAddRequests.add(requestIdentifier, std::make_unique<CachedProcess>(process.copyRef())); 84 76 85 RELEASE_LOG(ProcessSwapping, "%p - WebProcessCache::addProcessIfPossible(): Checking if process %i is responsive before caching it...", this, process->processIdentifier()); 77 process->setIsInProcessCache(true); 78 process->isResponsive([process = process.copyRef(), processPool = makeRef(process->processPool()), registrableDomain](bool isResponsive) { 79 process->setIsInProcessCache(false); 86 process->isResponsive([this, processPool = makeRef(process->processPool()), requestIdentifier](bool isResponsive) { 87 auto cachedProcess = m_pendingAddRequests.take(requestIdentifier); 88 if (!cachedProcess) 89 return; 90 80 91 if (!isResponsive) { 81 RELEASE_LOG_ERROR(ProcessSwapping, "%p - WebProcessCache::addProcessIfPossible(): Not caching process %i because it is not responsive", &process->processPool().webProcessCache(), process->processIdentifier()); 82 process->shutDown(); 92 RELEASE_LOG_ERROR(ProcessSwapping, "%p - WebProcessCache::addProcessIfPossible(): Not caching process %i because it is not responsive", &processPool->webProcessCache(), cachedProcess->process().processIdentifier()); 83 93 return; 84 94 } 85 if (!processPool->webProcessCache().addProcess(registrableDomain, process.copyRef())) 86 process->shutDown(); 95 processPool->webProcessCache().addProcess(WTFMove(cachedProcess)); 87 96 }); 88 97 return true; 89 98 } 90 99 91 bool WebProcessCache::addProcess(const String& registrableDomain, Ref<WebProcessProxy>&& process) 92 { 93 ASSERT(!process->pageCount()); 94 ASSERT(!process->provisionalPageCount()); 95 ASSERT(!process->suspendedPageCount()); 96 97 if (!canCacheProcess(process)) 98 return false; 100 bool WebProcessCache::addProcess(std::unique_ptr<CachedProcess>&& cachedProcess) 101 { 102 ASSERT(!cachedProcess->process().pageCount()); 103 ASSERT(!cachedProcess->process().provisionalPageCount()); 104 ASSERT(!cachedProcess->process().suspendedPageCount()); 105 106 if (!canCacheProcess(cachedProcess->process())) 107 return false; 108 109 auto registrableDomain = cachedProcess->process().registrableDomain(); 110 RELEASE_ASSERT(!registrableDomain.isEmpty()); 111 112 if (auto previousProcess = m_processesPerRegistrableDomain.take(registrableDomain)) 113 RELEASE_LOG(ProcessSwapping, "%p - WebProcessCache::addProcess(): Evicting process %i from WebProcess cache because a new process was added for the same domain", this, previousProcess->process().processIdentifier()); 99 114 100 115 while (m_processesPerRegistrableDomain.size() >= capacity()) { 101 116 auto it = m_processesPerRegistrableDomain.random(); 102 RELEASE_LOG(ProcessSwapping, "%p - WebProcessCache::addProcess(): Evicting process %i from WebProcess cache ", this, it->value->process().processIdentifier());117 RELEASE_LOG(ProcessSwapping, "%p - WebProcessCache::addProcess(): Evicting process %i from WebProcess cache because capacity was reached", this, it->value->process().processIdentifier()); 103 118 m_processesPerRegistrableDomain.remove(it); 104 119 } 105 120 106 m_processesPerRegistrableDomain.set(registrableDomain, std::make_unique<CachedProcess>(process.copyRef()));107 RELEASE_LOG(ProcessSwapping, "%p - WebProcessCache::addProcess: Adding process %i to WebProcess cache, cache size: [%u / %u]", this, process->processIdentifier(), size(), capacity());121 RELEASE_LOG(ProcessSwapping, "%p - WebProcessCache::addProcess: Added process %i to WebProcess cache, cache size: [%u / %u]", this, cachedProcess->process().processIdentifier(), size() + 1, capacity()); 122 m_processesPerRegistrableDomain.add(registrableDomain, WTFMove(cachedProcess)); 108 123 109 124 return true; … … 156 171 void WebProcessCache::clear() 157 172 { 158 if (m_p rocessesPerRegistrableDomain.isEmpty())173 if (m_pendingAddRequests.isEmpty() && m_processesPerRegistrableDomain.isEmpty()) 159 174 return; 160 175 161 RELEASE_LOG(ProcessSwapping, "%p - WebProcessCache::clear() evicting %u processes", this, m_processesPerRegistrableDomain.size()); 176 RELEASE_LOG(ProcessSwapping, "%p - WebProcessCache::clear() evicting %u processes", this, m_pendingAddRequests.size() + m_processesPerRegistrableDomain.size()); 177 m_pendingAddRequests.clear(); 162 178 m_processesPerRegistrableDomain.clear(); 163 179 } … … 174 190 for (auto& key : keysToRemove) 175 191 m_processesPerRegistrableDomain.remove(key); 192 193 Vector<uint64_t> pendingRequestsToRemove; 194 for (auto& pair : m_pendingAddRequests) { 195 if (pair.value->process().websiteDataStore().sessionID() == sessionID) { 196 RELEASE_LOG(ProcessSwapping, "%p - WebProcessCache::clearAllProcessesForSession() evicting process %i because its session was destroyed", this, pair.value->process().processIdentifier()); 197 pendingRequestsToRemove.append(pair.key); 198 } 199 } 200 for (auto& key : pendingRequestsToRemove) 201 m_pendingAddRequests.remove(key); 176 202 } 177 203 … … 185 211 } 186 212 187 void WebProcessCache:: evictProcess(WebProcessProxy& process)213 void WebProcessCache::removeProcess(WebProcessProxy& process, ShouldShutDownProcess shouldShutDownProcess) 188 214 { 189 215 RELEASE_ASSERT(!process.registrableDomain().isEmpty()); 216 RELEASE_LOG(ProcessSwapping, "%p - WebProcessCache::evictProcess(): Evicting process %i from WebProcess cache because it expired", this, process.processIdentifier()); 217 218 std::unique_ptr<CachedProcess> cachedProcess; 190 219 auto it = m_processesPerRegistrableDomain.find(process.registrableDomain()); 191 ASSERT(it != m_processesPerRegistrableDomain.end()); 192 ASSERT(&it->value->process() == &process); 193 194 RELEASE_LOG(ProcessSwapping, "%p - WebProcessCache::evictProcess(): Evicting process %i from WebProcess cache because it expired", this, process.processIdentifier()); 195 196 m_processesPerRegistrableDomain.remove(it); 220 if (it != m_processesPerRegistrableDomain.end() && &it->value->process() == &process) { 221 cachedProcess = WTFMove(it->value); 222 m_processesPerRegistrableDomain.remove(it); 223 } else { 224 for (auto& pair : m_pendingAddRequests) { 225 if (&pair.value->process() == &process) { 226 cachedProcess = WTFMove(pair.value); 227 m_pendingAddRequests.remove(pair.key); 228 break; 229 } 230 } 231 } 232 ASSERT(cachedProcess); 233 if (!cachedProcess) 234 return; 235 236 ASSERT(&cachedProcess->process() == &process); 237 if (shouldShutDownProcess == ShouldShutDownProcess::No) 238 cachedProcess->takeProcess(); 197 239 } 198 240 … … 229 271 { 230 272 ASSERT(m_process); 231 m_process->processPool().webProcessCache(). evictProcess(*m_process);273 m_process->processPool().webProcessCache().removeProcess(*m_process, ShouldShutDownProcess::Yes); 232 274 } 233 275 -
trunk/Source/WebKit/UIProcess/WebProcessCache.h
r242496 r242726 56 56 void clearAllProcessesForSession(PAL::SessionID); 57 57 58 enum class ShouldShutDownProcess { No, Yes }; 59 void removeProcess(WebProcessProxy&, ShouldShutDownProcess); 60 58 61 private: 59 62 static Seconds cachedProcessLifetime; 60 63 static Seconds clearingDelayAfterApplicationResignsActive; 61 62 bool canCacheProcess(WebProcessProxy&) const;63 void evictProcess(WebProcessProxy&);64 void platformInitialize();65 bool addProcess(const String& registrableDomain, Ref<WebProcessProxy>&&);66 67 unsigned m_capacity { 0 };68 64 69 65 class CachedProcess { … … 83 79 }; 84 80 81 bool canCacheProcess(WebProcessProxy&) const; 82 void platformInitialize(); 83 bool addProcess(std::unique_ptr<CachedProcess>&&); 84 85 unsigned m_capacity { 0 }; 86 87 HashMap<uint64_t, std::unique_ptr<CachedProcess>> m_pendingAddRequests; 85 88 HashMap<String, std::unique_ptr<CachedProcess>> m_processesPerRegistrableDomain; 86 89 RunLoop::Timer<WebProcessCache> m_evictionTimer; -
trunk/Source/WebKit/UIProcess/WebProcessPool.cpp
r242712 r242726 2261 2261 // Make sure we remove the process from the cache if it is in there since we're about to use it. 2262 2262 if (process->isInProcessCache()) { 2263 auto removedProcess = webProcessCache().takeProcess(process->registrableDomain(), process->websiteDataStore());2264 ASSERT _UNUSED(removedProcess, removedProcess.get() == process.get());2263 webProcessCache().removeProcess(*process, WebProcessCache::ShouldShutDownProcess::No); 2264 ASSERT(!process->isInProcessCache()); 2265 2265 } 2266 2266 -
trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp
r242652 r242726 650 650 651 651 if (m_isInProcessCache) { 652 auto removedProcess = processPool().webProcessCache().takeProcess(registrableDomain(), websiteDataStore());653 ASSERT _UNUSED(removedProcess, removedProcess.get() == this);652 processPool().webProcessCache().removeProcess(*this, WebProcessCache::ShouldShutDownProcess::No); 653 ASSERT(!m_isInProcessCache); 654 654 } 655 655
Note:
See TracChangeset
for help on using the changeset viewer.