Changeset 220401 in webkit


Ignore:
Timestamp:
Aug 8, 2017 6:11:00 AM (7 years ago)
Author:
Yusuke Suzuki
Message:

[Linux] Clear WasmMemory with madvice instead of memset
https://bugs.webkit.org/show_bug.cgi?id=175150

Reviewed by Filip Pizlo.

In Linux, zeroing pages with memset populates backing store.
Instead, we should use madvise with MADV_DONTNEED. It discards
pages. And if you access these pages, on-demand-zero-pages will
be shown.

We also commit grown pages in all OSes.

  • wasm/WasmMemory.cpp:

(JSC::Wasm::commitZeroPages):
(JSC::Wasm::Memory::create):
(JSC::Wasm::Memory::grow):

Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r220377 r220401  
     12017-08-06  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        [Linux] Clear WasmMemory with madvice instead of memset
     4        https://bugs.webkit.org/show_bug.cgi?id=175150
     5
     6        Reviewed by Filip Pizlo.
     7
     8        In Linux, zeroing pages with memset populates backing store.
     9        Instead, we should use madvise with MADV_DONTNEED. It discards
     10        pages. And if you access these pages, on-demand-zero-pages will
     11        be shown.
     12
     13        We also commit grown pages in all OSes.
     14
     15        * wasm/WasmMemory.cpp:
     16        (JSC::Wasm::commitZeroPages):
     17        (JSC::Wasm::Memory::create):
     18        (JSC::Wasm::Memory::grow):
     19
    1202017-08-07  Robin Morisset  <rmorisset@apple.com>
    221
  • trunk/Source/JavaScriptCore/wasm/WasmMemory.cpp

    r220352 r220401  
    256256}
    257257
     258static void commitZeroPages(void* startAddress, size_t sizeInBytes)
     259{
     260    bool writable = true;
     261    bool executable = false;
     262#if OS(LINUX)
     263    // In Linux, MADV_DONTNEED clears backing pages with zero. Be Careful that MADV_DONTNEED shows different semantics in different OSes.
     264    // For example, FreeBSD does not clear backing pages immediately.
     265    while (madvise(startAddress, sizeInBytes, MADV_DONTNEED) == -1 && errno == EAGAIN) { }
     266    OSAllocator::commit(startAddress, sizeInBytes, writable, executable);
     267#else
     268    OSAllocator::commit(startAddress, sizeInBytes, writable, executable);
     269    memset(startAddress, 0, sizeInBytes);
     270#endif
     271}
     272
    258273RefPtr<Memory> Memory::create(VM& vm, PageCount initial, PageCount maximum)
    259274{
     
    294309   
    295310    if (fastMemory) {
    296         bool writable = true;
    297         bool executable = false;
    298         OSAllocator::commit(fastMemory, initialBytes, writable, executable);
    299311       
    300312        if (mprotect(fastMemory + initialBytes, Memory::fastMappedBytes() - initialBytes, PROT_NONE)) {
     
    302314            RELEASE_ASSERT_NOT_REACHED();
    303315        }
    304        
    305         memset(fastMemory, 0, initialBytes);
     316
     317        commitZeroPages(fastMemory, initialBytes);
     318       
    306319        return adoptRef(new Memory(fastMemory, initial, maximum, Memory::fastMappedBytes(), MemoryMode::Signaling));
    307320    }
     
    401414            return false;
    402415        }
    403         memset(startAddress, 0, extraBytes);
     416        commitZeroPages(startAddress, extraBytes);
    404417        m_size = desiredSize;
    405418        return true;
Note: See TracChangeset for help on using the changeset viewer.