Title: [287007] branches/safari-613.1.11-branch/Source/WTF
Revision
287007
Author
[email protected]
Date
2021-12-13 19:28:02 -0800 (Mon, 13 Dec 2021)

Log Message

Cherry-pick r286849. rdar://problem/86445989

    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):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@286849 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-613.1.11-branch/Source/WTF/ChangeLog (287006 => 287007)


--- branches/safari-613.1.11-branch/Source/WTF/ChangeLog	2021-12-14 03:28:00 UTC (rev 287006)
+++ branches/safari-613.1.11-branch/Source/WTF/ChangeLog	2021-12-14 03:28:02 UTC (rev 287007)
@@ -1,3 +1,34 @@
+2021-12-13  Russell Epstein  <[email protected]>
+
+        Cherry-pick r286849. rdar://problem/86445989
+
+    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):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@286849 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-12-10  Keith Miller  <[email protected]>
+
+            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):
+
 2021-12-03  Chris Dumez  <[email protected]>
 
         [WK2] Turn on Web Locks API support

Modified: branches/safari-613.1.11-branch/Source/WTF/wtf/posix/OSAllocatorPOSIX.cpp (287006 => 287007)


--- branches/safari-613.1.11-branch/Source/WTF/wtf/posix/OSAllocatorPOSIX.cpp	2021-12-14 03:28:00 UTC (rev 287006)
+++ branches/safari-613.1.11-branch/Source/WTF/wtf/posix/OSAllocatorPOSIX.cpp	2021-12-14 03:28:02 UTC (rev 287007)
@@ -44,6 +44,10 @@
 #endif // OS(DARWIN)
 #endif // ENABLE(JIT_CAGE)
 
+#if OS(DARWIN)
+#include <wtf/spi/cocoa/MachVMSPI.h>
+#endif
+
 namespace WTF {
 
 void* OSAllocator::reserveUncommitted(size_t bytes, Usage usage, bool writable, bool executable, bool jitCageEnabled, bool includesGuardPages)
@@ -73,11 +77,36 @@
     return result;
 }
 
-
-// FIXME: Make a smarter version of this for Linux flavors that have aligned mmap.
 void* OSAllocator::reserveUncommittedAligned(size_t bytes, Usage usage, bool writable, bool executable, bool jitCageEnabled, bool includesGuardPages)
 {
     ASSERT(hasOneBitSet(bytes) && bytes >= pageSize());
+
+#if PLATFORM(MAC) || USE(APPLE_INTERNAL_SDK)
+    UNUSED_PARAM(usage); // Not supported for mach API.
+    ASSERT_UNUSED(includesGuardPages, !includesGuardPages);
+    ASSERT_UNUSED(jitCageEnabled, !jitCageEnabled); // Not supported for mach API.
+    vm_prot_t protections = VM_PROT_READ;
+    if (writable)
+        protections |= VM_PROT_WRITE;
+    if (executable)
+        protections |= VM_PROT_EXECUTE;
+
+    const vm_inherit_t childProcessInheritance = VM_INHERIT_DEFAULT;
+    const bool copy = false;
+    const int flags = VM_FLAGS_ANYWHERE;
+
+    void* aligned = nullptr;
+    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);
+    RELEASE_ASSERT(result == KERN_SUCCESS, result, bytes);
+#if HAVE(MADV_FREE_REUSE)
+    if (aligned) {
+        // To support the "reserve then commit" model, we have to initially decommit.
+        while (madvise(aligned, bytes, MADV_FREE_REUSABLE) == -1 && errno == EAGAIN) { }
+    }
+#endif
+
+    return aligned;
+#else
     // Double the size so we can ensure enough mapped memory to get an aligned start.
     size_t mappedSize = bytes * 2;
     char* mapped = reinterpret_cast<char*>(reserveUncommitted(mappedSize, usage, writable, executable, jitCageEnabled, includesGuardPages));
@@ -95,6 +124,7 @@
         releaseDecommitted(alignedEnd, rightExtra);
 
     return aligned;
+#endif
 }
 
 void* OSAllocator::reserveAndCommit(size_t bytes, Usage usage, bool writable, bool executable, bool jitCageEnabled, bool includesGuardPages)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to