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

Changeset 286804 in webkit


Ignore:
Timestamp:
Dec 9, 2021, 2:56:06 PM (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

    r286783 r286804  
     12021-12-09  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-09  Antti Koivisto  <antti@apple.com>
    215
  • trunk/Source/WTF/wtf/posix/OSAllocatorPOSIX.cpp

    r286345 r286804  
    3939#define MAP_EXECUTABLE_FOR_JIT MAP_JIT
    4040#define MAP_EXECUTABLE_FOR_JIT_WITH_JIT_CAGE MAP_JIT
     41#include <wtf/spi/cocoa/MachVMSPI.h>
    4142#else // OS(DARWIN)
    4243#define MAP_EXECUTABLE_FOR_JIT 0
     
    7475}
    7576
    76 
    77 // FIXME: Make a smarter version of this for Linux flavors that have aligned mmap.
    7877void* OSAllocator::reserveUncommittedAligned(size_t bytes, Usage usage, bool writable, bool executable, bool jitCageEnabled, bool includesGuardPages)
    7978{
    8079    ASSERT(hasOneBitSet(bytes) && bytes >= pageSize());
     80
     81#if PLATFORM(MAC) || USE(APPLE_INTERNAL_SDK)
     82    UNUSED_PARAM(usage); // Not supported for mach API.
     83    ASSERT_UNUSED(includesGuardPages, !includesGuardPages);
     84    ASSERT_UNUSED(jitCageEnabled, !jitCageEnabled); // Not supported for mach API.
     85    vm_prot_t protections = VM_PROT_READ;
     86    if (writable)
     87        protections |= VM_PROT_WRITE;
     88    if (executable)
     89        protections |= VM_PROT_EXECUTE;
     90
     91    const vm_inherit_t childProcessInheritance = VM_INHERIT_DEFAULT;
     92
     93    void* aligned = nullptr;
     94    const bool copy = false;
     95    const int flags = VM_FLAGS_ANYWHERE;
     96
     97    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);
     98    RELEASE_ASSERT(result == KERN_SUCCESS, result, bytes);
     99#if HAVE(MADV_FREE_REUSE)
     100    if (aligned) {
     101        // To support the "reserve then commit" model, we have to initially decommit.
     102        while (madvise(aligned, bytes, MADV_FREE_REUSABLE) == -1 && errno == EAGAIN) { }
     103    }
     104#endif
     105
     106    return aligned;
     107#else
    81108    // Double the size so we can ensure enough mapped memory to get an aligned start.
    82109    size_t mappedSize = bytes * 2;
     
    96123
    97124    return aligned;
     125#endif
    98126}
    99127
Note: See TracChangeset for help on using the changeset viewer.