⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 286849 in webkit


Ignore:
Timestamp:
Dec 10, 2021, 6:28:35 AM (5 years ago)
Author:
keith_miller@apple.com
Message:

Reduce maximum mmap size for Structure regions to help placate ios
https://bugs.webkit.org/show_bug.cgi?id=234091

Reviewed by Saam Barati.

Use mach_vm_map since that supports memory alignement so we don't have to map 2x desired address space then free then trim.

  • wtf/PlatformHave.h:
  • wtf/posix/OSAllocatorPOSIX.cpp:

(WTF::OSAllocator::reserveUncommittedAligned):

Location:
trunk/Source/WTF
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r286845 r286849  
     12021-12-10  Keith Miller  <keith_miller@apple.com>
     2
     3        Reduce maximum mmap size for Structure regions to help placate ios
     4        https://bugs.webkit.org/show_bug.cgi?id=234091
     5
     6        Reviewed by Saam Barati.
     7
     8        Use mach_vm_map since that supports memory alignement so we don't have to map 2x desired address space then free then trim.
     9
     10        * wtf/PlatformHave.h:
     11        * wtf/posix/OSAllocatorPOSIX.cpp:
     12        (WTF::OSAllocator::reserveUncommittedAligned):
     13
    1142021-12-10  Antti Koivisto  <antti@apple.com>
    215
  • trunk/Source/WTF/wtf/posix/OSAllocatorPOSIX.cpp

    r286818 r286849  
    4545#endif // ENABLE(JIT_CAGE)
    4646
     47#if OS(DARWIN)
     48#include <wtf/spi/cocoa/MachVMSPI.h>
     49#endif
     50
    4751namespace WTF {
    4852
     
    7478}
    7579
    76 
    77 // FIXME: Make a smarter version of this for Linux flavors that have aligned mmap.
    7880void* OSAllocator::reserveUncommittedAligned(size_t bytes, Usage usage, bool writable, bool executable, bool jitCageEnabled, bool includesGuardPages)
    7981{
    8082    ASSERT(hasOneBitSet(bytes) && bytes >= pageSize());
     83
     84#if PLATFORM(MAC) || USE(APPLE_INTERNAL_SDK)
     85    UNUSED_PARAM(usage); // Not supported for mach API.
     86    ASSERT_UNUSED(includesGuardPages, !includesGuardPages);
     87    ASSERT_UNUSED(jitCageEnabled, !jitCageEnabled); // Not supported for mach API.
     88    vm_prot_t protections = VM_PROT_READ;
     89    if (writable)
     90        protections |= VM_PROT_WRITE;
     91    if (executable)
     92        protections |= VM_PROT_EXECUTE;
     93
     94    const vm_inherit_t childProcessInheritance = VM_INHERIT_DEFAULT;
     95    const bool copy = false;
     96    const int flags = VM_FLAGS_ANYWHERE;
     97
     98    void* aligned = nullptr;
     99    kern_return_t result = mach_vm_map(mach_task_self(), reinterpret_cast<mach_vm_address_t*>(&aligned), bytes, bytes - 1, flags, MEMORY_OBJECT_NULL, 0, copy, protections, protections, childProcessInheritance);
     100    RELEASE_ASSERT(result == KERN_SUCCESS, result, bytes);
     101#if HAVE(MADV_FREE_REUSE)
     102    if (aligned) {
     103        // To support the "reserve then commit" model, we have to initially decommit.
     104        while (madvise(aligned, bytes, MADV_FREE_REUSABLE) == -1 && errno == EAGAIN) { }
     105    }
     106#endif
     107
     108    return aligned;
     109#else
    81110    // Double the size so we can ensure enough mapped memory to get an aligned start.
    82111    size_t mappedSize = bytes * 2;
     
    96125
    97126    return aligned;
     127#endif
    98128}
    99129
Note: See TracChangeset for help on using the changeset viewer.