Changeset 211799 in webkit


Ignore:
Timestamp:
Feb 7, 2017 1:38:43 AM (7 years ago)
Author:
Carlos Garcia Campos
Message:

Merge r211206 - ImageBufferCairo: cairo_image_surface should use bmalloc-allocated memory
https://bugs.webkit.org/show_bug.cgi?id=165751

Reviewed by Carlos Garcia Campos.

Allocate the underlying memory for cairo_image_surface objects through FastMalloc.
This way we can steer such large allocations away from the default libc allocator.

Objects of this class can create Cairo surfaces that need as much as 4MB of memory
for the underlying pixel buffer. Allocating such objects through the default
libc allocator can lead to increased memory usage because of non-optimal allocation
strategy in libc. In contrast, bmalloc performs large allocations by directly using
mmap() to reserve the necessary memory.

The improvements can be significant. On nytimes.com, with the threaded version of
the CoordinatedGraphics system, the memory consumption can drop by roughly 20%.

  • platform/graphics/cairo/ImageBufferCairo.cpp:

(WebCore::ImageBuffer::ImageBuffer): Zero-allocate the necessary memory via FastMalloc.
Tie that memory lifetime to the lifetime of the surface by using
cairo_surface_set_user_data() with the specific user data key.

Location:
releases/WebKitGTK/webkit-2.14/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • releases/WebKitGTK/webkit-2.14/Source/WebCore/ChangeLog

    r211795 r211799  
     12017-01-26  Zan Dobersek  <zdobersek@igalia.com>
     2
     3        ImageBufferCairo: cairo_image_surface should use bmalloc-allocated memory
     4        https://bugs.webkit.org/show_bug.cgi?id=165751
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        Allocate the underlying memory for cairo_image_surface objects through FastMalloc.
     9        This way we can steer such large allocations away from the default libc allocator.
     10
     11        Objects of this class can create Cairo surfaces that need as much as 4MB of memory
     12        for the underlying pixel buffer. Allocating such objects through the default
     13        libc allocator can lead to increased memory usage because of non-optimal allocation
     14        strategy in libc. In contrast, bmalloc performs large allocations by directly using
     15        mmap() to reserve the necessary memory.
     16
     17        The improvements can be significant. On nytimes.com, with the threaded version of
     18        the CoordinatedGraphics system, the memory consumption can drop by roughly 20%.
     19
     20        * platform/graphics/cairo/ImageBufferCairo.cpp:
     21        (WebCore::ImageBuffer::ImageBuffer): Zero-allocate the necessary memory via FastMalloc.
     22        Tie that memory lifetime to the lifetime of the surface by using
     23        cairo_surface_set_user_data() with the specific user data key.
     24
    1252017-01-30  Carlos Garcia Campos  <cgarcia@igalia.com>
    226
  • releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp

    r207944 r211799  
    219219    ASSERT(m_data.m_renderingMode != Accelerated);
    220220#endif
    221         m_data.m_surface = adoptRef(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, m_size.width(), m_size.height()));
     221    {
     222        static cairo_user_data_key_t s_surfaceDataKey;
     223
     224        int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, m_size.width());
     225        auto* surfaceData = fastZeroedMalloc(m_size.height() * stride);
     226
     227        m_data.m_surface = adoptRef(cairo_image_surface_create_for_data(static_cast<unsigned char*>(surfaceData), CAIRO_FORMAT_ARGB32, m_size.width(), m_size.height(), stride));
     228        cairo_surface_set_user_data(m_data.m_surface.get(), &s_surfaceDataKey, surfaceData, [](void* data) { fastFree(data); });
     229    }
    222230
    223231    if (cairo_surface_status(m_data.m_surface.get()) != CAIRO_STATUS_SUCCESS)
Note: See TracChangeset for help on using the changeset viewer.