Changeset 139218 in webkit
- Timestamp:
- Jan 9, 2013, 12:08:32 PM (12 years ago)
- Location:
- trunk/Source
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def
r138636 r139218 209 209 ?fastMallocSize@WTF@@YAIPBX@Z 210 210 ?fastMallocStatistics@WTF@@YA?AUFastMallocStatistics@1@XZ 211 ?releaseFastMallocFreeMemory@WTF@@YAXXZ 211 212 ?fastRealloc@WTF@@YAPAXPAXI@Z 212 213 ?fastStrDup@WTF@@YAPADPBD@Z -
trunk/Source/WTF/ChangeLog
r139184 r139218 1 2013-01-09 Antti Koivisto <antti@apple.com> 2 3 Release FastMalloc thread caches on memory warning 4 https://bugs.webkit.org/show_bug.cgi?id=106471 5 6 Reviewed by Geoff Garen. 7 8 Use TCMalloc_ThreadCache::Cleanup() instead of calling Scavenge() twice. This releases all the memory 9 and looks nicer too. 10 11 * wtf/FastMalloc.cpp: 12 (WTF::releaseFastMallocFreeMemory): 13 1 14 2013-01-09 Carlos Garcia Campos <cgarcia@igalia.com> 2 15 -
trunk/Source/WTF/wtf/FastMalloc.cpp
r139004 r139218 4383 4383 { 4384 4384 // Flush free pages in the current thread cache back to the page heap. 4385 // Low watermark mechanism in Scavenge() prevents full return on the first pass. 4386 // The second pass flushes everything. 4387 if (TCMalloc_ThreadCache* threadCache = TCMalloc_ThreadCache::GetCacheIfPresent()) { 4388 threadCache->Scavenge(); 4389 threadCache->Scavenge(); 4390 } 4385 if (TCMalloc_ThreadCache* threadCache = TCMalloc_ThreadCache::GetCacheIfPresent()) 4386 threadCache->Cleanup(); 4391 4387 4392 4388 SpinLockHolder h(&pageheap_lock); 4393 4389 pageheap->ReleaseFreePages(); 4394 4390 } 4395 4391 4396 4392 FastMallocStatistics fastMallocStatistics() 4397 4393 { -
trunk/Source/WebCore/ChangeLog
r139217 r139218 1 2013-01-09 Antti Koivisto <antti@apple.com> 2 3 Release FastMalloc thread caches on memory warning 4 https://bugs.webkit.org/show_bug.cgi?id=106471 5 6 Reviewed by Geoff Garen. 7 8 FastMalloc keeps some memory in per-thread caches (currently 2MB each). We currently flush these caches on memory warning 9 for the main thread only. We should do it for other WebKit threads that use FastMalloc too. 10 11 Call WTF::releaseFastMallocFreeMemory in a bunch of WebCore support threads on memory warning. Unfortunately we don't have 12 an uniform way of doing threads so this requires bunch of thread type specific code. 13 14 Looks to be ~1% progression in membuster3 final and maximum numbers. 15 16 * platform/mac/MemoryPressureHandlerMac.mm: 17 (WebCore::MemoryPressureHandler::releaseMemory): 18 * storage/StorageTask.cpp: 19 (WebCore::StorageTask::performTask): 20 * storage/StorageTask.h: 21 (WebCore::StorageTask::createReleaseFastMallocFreeMemory): 22 * storage/StorageThread.cpp: 23 (WebCore::storageThreads): 24 (WebCore): 25 (WebCore::StorageThread::StorageThread): 26 (WebCore::StorageThread::~StorageThread): 27 (WebCore::StorageThread::releaseFastMallocFreeMemoryInAllThread): 28 * storage/StorageThread.h: 29 (StorageThread): 30 * workers/WorkerThread.cpp: 31 (WebCore::threadSetMutex): 32 (WebCore::workerThreads): 33 (WebCore::WorkerThread::workerThreadCount): 34 (WebCore::WorkerThread::WorkerThread): 35 (WebCore::WorkerThread::~WorkerThread): 36 (WebCore::WorkerThread::releaseFastMallocFreeMemoryInAllThread): 37 (WebCore): 38 * workers/WorkerThread.h: 39 (WorkerThread): 40 1 41 2013-01-09 Tony Gentilcore <tonyg@chromium.org> 2 42 -
trunk/Source/WebCore/platform/mac/MemoryPressureHandlerMac.mm
r138482 r139218 33 33 #import <WebCore/PageCache.h> 34 34 #import <WebCore/LayerPool.h> 35 #import <WebCore/ScrollingThread.h> 36 #import <WebCore/StorageThread.h> 37 #import <WebCore/WorkerThread.h> 35 38 #import <wtf/CurrentTime.h> 36 39 #import <wtf/FastMalloc.h> 40 #import <wtf/Functional.h> 37 41 38 42 #if !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 … … 161 165 gcController().discardAllCompiledCode(); 162 166 167 // FastMalloc has lock-free thread specific caches that can only be cleared from the thread itself. 168 StorageThread::releaseFastMallocFreeMemoryInAllThreads(); 169 #if ENABLE(WORKERS) 170 WorkerThread::releaseFastMallocFreeMemoryInAllThreads(); 171 #endif 172 #if ENABLE(THREADED_SCROLLING) 173 ScrollingThread::dispatch(bind(WTF::releaseFastMallocFreeMemory)); 174 #endif 163 175 WTF::releaseFastMallocFreeMemory(); 164 176 } -
trunk/Source/WebCore/storage/StorageTask.cpp
r112343 r139218 106 106 m_area->deleteEmptyDatabase(); 107 107 break; 108 case ReleaseFastMallocFreeMemory: 109 WTF::releaseFastMallocFreeMemory(); 110 break; 108 111 case TerminateThread: 109 112 m_thread->performTerminate(); -
trunk/Source/WebCore/storage/StorageTask.h
r127757 r139218 39 39 WTF_MAKE_NONCOPYABLE(StorageTask); WTF_MAKE_FAST_ALLOCATED; 40 40 public: 41 enum Type { AreaImport, AreaSync, DeleteEmptyDatabase, SetOriginDetails, ImportOrigins, DeleteAllOrigins, DeleteOrigin, TerminateThread };41 enum Type { AreaImport, AreaSync, DeleteEmptyDatabase, SetOriginDetails, ImportOrigins, DeleteAllOrigins, DeleteOrigin, ReleaseFastMallocFreeMemory, TerminateThread }; 42 42 43 43 ~StorageTask(); … … 50 50 static PassOwnPtr<StorageTask> createDeleteOrigin(const String& originIdentifier) { return adoptPtr(new StorageTask(DeleteOrigin, originIdentifier)); } 51 51 static PassOwnPtr<StorageTask> createDeleteAllOrigins() { return adoptPtr(new StorageTask(DeleteAllOrigins)); } 52 static PassOwnPtr<StorageTask> createReleaseFastMallocFreeMemory() { return adoptPtr(new StorageTask(ReleaseFastMallocFreeMemory)); } 52 53 static PassOwnPtr<StorageTask> createTerminate(StorageThread* thread) { return adoptPtr(new StorageTask(TerminateThread, thread)); } 53 54 -
trunk/Source/WebCore/storage/StorageThread.cpp
r114656 r139218 30 30 #include "StorageTask.h" 31 31 #include "StorageAreaSync.h" 32 #include <wtf/HashSet.h> 32 33 #include <wtf/MainThread.h> 33 34 34 35 namespace WebCore { 36 37 static HashSet<StorageThread*>& storageThreads() 38 { 39 ASSERT(isMainThread()); 40 DEFINE_STATIC_LOCAL(HashSet<StorageThread*>, threads, ()); 41 return threads; 42 } 35 43 36 44 PassOwnPtr<StorageThread> StorageThread::create() … … 42 50 : m_threadID(0) 43 51 { 52 ASSERT(isMainThread()); 53 storageThreads().add(this); 44 54 } 45 55 … … 48 58 ASSERT(isMainThread()); 49 59 ASSERT(!m_threadID); 60 storageThreads().remove(this); 50 61 } 51 62 … … 101 112 } 102 113 114 void StorageThread::releaseFastMallocFreeMemoryInAllThreads() 115 { 116 HashSet<StorageThread*>& threads = storageThreads(); 117 HashSet<StorageThread*>::iterator end = threads.end(); 118 for (HashSet<StorageThread*>::iterator it = threads.begin(); it != end; ++it) 119 (*it)->scheduleTask(StorageTask::createReleaseFastMallocFreeMemory()); 103 120 } 121 122 } -
trunk/Source/WebCore/storage/StorageThread.h
r108746 r139218 51 51 void performTerminate(); 52 52 53 static void releaseFastMallocFreeMemoryInAllThreads(); 54 53 55 private: 54 56 StorageThread(); -
trunk/Source/WebCore/workers/WorkerThread.cpp
r137520 r139218 54 54 namespace WebCore { 55 55 56 static Mutex& thread CountMutex()56 static Mutex& threadSetMutex() 57 57 { 58 58 AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex); … … 60 60 } 61 61 62 unsigned WorkerThread::m_threadCount = 0; 62 static HashSet<WorkerThread*>& workerThreads() 63 { 64 DEFINE_STATIC_LOCAL(HashSet<WorkerThread*>, threads, ()); 65 return threads; 66 } 63 67 64 68 unsigned WorkerThread::workerThreadCount() 65 69 { 66 MutexLocker lock(thread CountMutex());67 return m_threadCount;70 MutexLocker lock(threadSetMutex()); 71 return workerThreads().size(); 68 72 } 69 73 … … 115 119 #endif 116 120 { 117 MutexLocker lock(thread CountMutex());118 m_threadCount++;121 MutexLocker lock(threadSetMutex()); 122 workerThreads().add(this); 119 123 } 120 124 121 125 WorkerThread::~WorkerThread() 122 126 { 123 MutexLocker lock(thread CountMutex());124 ASSERT( m_threadCount > 0);125 m_threadCount--;127 MutexLocker lock(threadSetMutex()); 128 ASSERT(workerThreads().contains(this)); 129 workerThreads().remove(this); 126 130 } 127 131 … … 273 277 } 274 278 279 class ReleaseFastMallocFreeMemoryTask : public ScriptExecutionContext::Task { 280 virtual void performTask(ScriptExecutionContext*) OVERRIDE { WTF::releaseFastMallocFreeMemory(); } 281 }; 282 283 void WorkerThread::releaseFastMallocFreeMemoryInAllThreads() 284 { 285 MutexLocker lock(threadSetMutex()); 286 HashSet<WorkerThread*>& threads = workerThreads(); 287 HashSet<WorkerThread*>::iterator end = threads.end(); 288 for (HashSet<WorkerThread*>::iterator it = threads.begin(); it != end; ++it) 289 (*it)->runLoop().postTask(adoptPtr(new ReleaseFastMallocFreeMemoryTask)); 290 } 291 275 292 } // namespace WebCore 276 293 -
trunk/Source/WebCore/workers/WorkerThread.h
r126365 r139218 64 64 // Number of active worker threads. 65 65 static unsigned workerThreadCount(); 66 static void releaseFastMallocFreeMemoryInAllThreads(); 66 67 67 68 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) … … 99 100 NotificationClient* m_notificationClient; 100 101 #endif 101 102 // Track the number of WorkerThread instances for use in layout tests.103 static unsigned m_threadCount;104 102 }; 105 103
Note:
See TracChangeset
for help on using the changeset viewer.