Changeset 130212 in webkit


Ignore:
Timestamp:
Oct 2, 2012, 2:24:19 PM (13 years ago)
Author:
mhahnenberg@apple.com
Message:

Block freeing thread should sleep indefinitely when there's no work to do
https://bugs.webkit.org/show_bug.cgi?id=98084

Reviewed by Geoffrey Garen.

Currently the block freeing thread wakes up once a second to check if there are any blocks
for it to release back to the OS. This is wasteful. We should change it to sleep when it
realizes there are no more blocks to free. Any thread that returns a block to the BlockAllocator
should then notify the block freeing thread that there is more work to do now.

  • heap/BlockAllocator.cpp:

(JSC::BlockAllocator::BlockAllocator):
(JSC::BlockAllocator::blockFreeingThreadMain):

  • heap/BlockAllocator.h:

(BlockAllocator):
(JSC::BlockAllocator::deallocate):

Location:
trunk/Source/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r130109 r130212  
     12012-10-01  Mark Hahnenberg  <mhahnenberg@apple.com>
     2
     3        Block freeing thread should sleep indefinitely when there's no work to do
     4        https://bugs.webkit.org/show_bug.cgi?id=98084
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Currently the block freeing thread wakes up once a second to check if there are any blocks
     9        for it to release back to the OS. This is wasteful. We should change it to sleep when it
     10        realizes there are no more blocks to free. Any thread that returns a block to the BlockAllocator
     11        should then notify the block freeing thread that there is more work to do now.
     12
     13        * heap/BlockAllocator.cpp:
     14        (JSC::BlockAllocator::BlockAllocator):
     15        (JSC::BlockAllocator::blockFreeingThreadMain):
     16        * heap/BlockAllocator.h:
     17        (BlockAllocator):
     18        (JSC::BlockAllocator::deallocate):
     19
    1202012-10-01  Michael Saboff  <msaboff@apple.com>
    221
  • trunk/Source/JavaScriptCore/heap/BlockAllocator.cpp

    r124250 r130212  
    139139            DeadBlock::destroy(block).deallocate();
    140140        }
     141
     142        // Sleep until there is actually work to do rather than waking up every second to check.
     143        MutexLocker locker(m_freeBlockConditionLock);
     144        m_freeBlockLock.Lock();
     145        while (!m_numberOfFreeBlocks && !m_blockFreeingThreadShouldQuit) {
     146            m_freeBlockLock.Unlock();
     147            m_freeBlockCondition.wait(m_freeBlockConditionLock);
     148            m_freeBlockLock.Lock();
     149        }
     150        m_freeBlockLock.Unlock();
    141151    }
    142152}
  • trunk/Source/JavaScriptCore/heap/BlockAllocator.h

    r124250 r130212  
    105105inline void BlockAllocator::deallocate(PageAllocationAligned allocation)
    106106{
    107     SpinLockHolder locker(&m_freeBlockLock);
    108     m_freeBlocks.push(DeadBlock::create(allocation));
    109     m_numberOfFreeBlocks++;
     107    size_t numberOfFreeBlocks;
     108    {
     109        SpinLockHolder locker(&m_freeBlockLock);
     110        m_freeBlocks.push(DeadBlock::create(allocation));
     111        numberOfFreeBlocks = m_numberOfFreeBlocks++;
     112    }
     113
     114    if (!numberOfFreeBlocks) {
     115        MutexLocker mutexLocker(m_freeBlockConditionLock);
     116        m_freeBlockCondition.signal();
     117    }
    110118}
    111119
Note: See TracChangeset for help on using the changeset viewer.