Changeset 204091 in webkit


Ignore:
Timestamp:
Aug 3, 2016 11:43:15 AM (8 years ago)
Author:
ggaren@apple.com
Message:

[bmalloc] Merging of XLargeRanges can leak the upper range
https://bugs.webkit.org/show_bug.cgi?id=160403

Reviewed by Michael Saboff.

  • bmalloc/Heap.cpp:

(bmalloc::Heap::scavengeLargeObjects): Don't use removePhysical().
Recorded physical size is a performance optimization. It is not the
truth. So it might be zero even if a range contains physical pages.

Instead, iterate each range in the map unconditionally.

The map can shrink when we release the lock, so we must clamp our
iterator each time through the loop.

The map can grow when we release the lock, but we don't care because
growth restarts the scavenger from the beginning.

  • bmalloc/XLargeMap.cpp:

(bmalloc::XLargeMap::removePhysical): Deleted. Not used anymore.

  • bmalloc/XLargeMap.h:

(bmalloc::XLargeMap::ranges): Added direct access for the sake of
scavengeLargeObjects. (This violates our naming conventions -- I'll do
a rename in a follow-up patch.)

Location:
trunk/Source/bmalloc
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/bmalloc/ChangeLog

    r203169 r204091  
     12016-08-03  Geoffrey Garen  <ggaren@apple.com>
     2
     3        [bmalloc] Merging of XLargeRanges can leak the upper range
     4        https://bugs.webkit.org/show_bug.cgi?id=160403
     5
     6        Reviewed by Michael Saboff.
     7
     8        * bmalloc/Heap.cpp:
     9        (bmalloc::Heap::scavengeLargeObjects): Don't use removePhysical().
     10        Recorded physical size is a performance optimization. It is not the
     11        truth. So it might be zero even if a range contains physical pages.
     12
     13        Instead, iterate each range in the map unconditionally.
     14
     15        The map can shrink when we release the lock, so we must clamp our
     16        iterator each time through the loop.
     17
     18        The map can grow when we release the lock, but we don't care because
     19        growth restarts the scavenger from the beginning.
     20
     21        * bmalloc/XLargeMap.cpp:
     22        (bmalloc::XLargeMap::removePhysical): Deleted. Not used anymore.
     23
     24        * bmalloc/XLargeMap.h:
     25        (bmalloc::XLargeMap::ranges): Added direct access for the sake of
     26        scavengeLargeObjects. (This violates our naming conventions -- I'll do
     27        a rename in a follow-up patch.)
     28
    1292016-07-13  Enrica Casucci  <enrica@apple.com>
    230
  • trunk/Source/bmalloc/bmalloc/Heap.cpp

    r200167 r204091  
    132132void Heap::scavengeLargeObjects(std::unique_lock<StaticMutex>& lock, std::chrono::milliseconds sleepDuration)
    133133{
    134     while (XLargeRange range = m_largeFree.removePhysical()) {
     134    auto& ranges = m_largeFree.ranges();
     135    for (size_t i = ranges.size(); i-- > 0; i = std::min(i, ranges.size())) {
     136        auto range = ranges.pop(i);
     137
    135138        lock.unlock();
    136139        vmDeallocatePhysicalPagesSloppy(range.begin(), range.size());
    137140        lock.lock();
    138        
     141
    139142        range.setPhysicalSize(0);
    140         m_largeFree.add(range);
     143        ranges.push(range);
    141144
    142145        waitUntilFalse(lock, sleepDuration, m_isAllocatingPages);
  • trunk/Source/bmalloc/bmalloc/XLargeMap.cpp

    r199746 r204091  
    7777}
    7878
    79 XLargeRange XLargeMap::removePhysical()
    80 {
    81     auto it = std::find_if(m_free.begin(), m_free.end(), [](const XLargeRange& range) {
    82         return range.physicalSize();
    83     });
    84 
    85     if (it == m_free.end())
    86         return XLargeRange();
    87 
    88     return m_free.pop(it);
    89 }
    90 
    9179} // namespace bmalloc
  • trunk/Source/bmalloc/bmalloc/XLargeMap.h

    r199746 r204091  
    3737    void add(const XLargeRange&);
    3838    XLargeRange remove(size_t alignment, size_t);
    39     XLargeRange removePhysical();
     39    Vector<XLargeRange>& ranges() { return m_free; }
    4040
    4141private:
Note: See TracChangeset for help on using the changeset viewer.