Title: [128796] trunk/Source/WTF
Revision
128796
Author
[email protected]
Date
2012-09-17 13:07:11 -0700 (Mon, 17 Sep 2012)

Log Message

Implement uncommitted memory for Linux.
https://bugs.webkit.org/show_bug.cgi?id=65766

Patch by Uli Schlachter <[email protected]> on 2012-09-17
Reviewed by Gavin Barraclough.

The old approach used MAP_NORESERVE to allocate address space without
committing it. However, that flag gets ignored if
/proc/sys/vm/overcommit_memory is set to 2. The new approach uses a
mapping with PROT_NONE. This works because mappings which aren't even
readable don't get accounted as committed on Linux.

* wtf/OSAllocatorPosix.cpp:
(WTF::OSAllocator::reserveUncommitted):
(WTF::OSAllocator::reserveAndCommit):
(WTF::OSAllocator::commit):
(WTF::OSAllocator::decommit):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (128795 => 128796)


--- trunk/Source/WTF/ChangeLog	2012-09-17 20:00:11 UTC (rev 128795)
+++ trunk/Source/WTF/ChangeLog	2012-09-17 20:07:11 UTC (rev 128796)
@@ -1,3 +1,22 @@
+2012-09-17  Uli Schlachter  <[email protected]>
+
+        Implement uncommitted memory for Linux.
+        https://bugs.webkit.org/show_bug.cgi?id=65766
+
+        Reviewed by Gavin Barraclough.
+
+        The old approach used MAP_NORESERVE to allocate address space without
+        committing it. However, that flag gets ignored if
+        /proc/sys/vm/overcommit_memory is set to 2. The new approach uses a
+        mapping with PROT_NONE. This works because mappings which aren't even
+        readable don't get accounted as committed on Linux.
+
+        * wtf/OSAllocatorPosix.cpp:
+        (WTF::OSAllocator::reserveUncommitted):
+        (WTF::OSAllocator::reserveAndCommit):
+        (WTF::OSAllocator::commit):
+        (WTF::OSAllocator::decommit):
+
 2012-09-17  Filip Pizlo  <[email protected]>
 
         Array profiling has convergence issues

Modified: trunk/Source/WTF/wtf/OSAllocatorPosix.cpp (128795 => 128796)


--- trunk/Source/WTF/wtf/OSAllocatorPosix.cpp	2012-09-17 20:00:11 UTC (rev 128795)
+++ trunk/Source/WTF/wtf/OSAllocatorPosix.cpp	2012-09-17 20:07:11 UTC (rev 128796)
@@ -41,12 +41,14 @@
     void* result = mmap(0, bytes, PROT_NONE, MAP_LAZY | MAP_PRIVATE | MAP_ANON, -1, 0);
     if (result == MAP_FAILED)
         CRASH();
-#else // OS(QNX)
-
-    void* result = reserveAndCommit(bytes, usage, writable, executable, includesGuardPages);
-#if OS(LINUX)
+#elif OS(LINUX)
+    void* result = mmap(0, bytes, PROT_NONE, MAP_NORESERVE | MAP_PRIVATE | MAP_ANON, -1, 0);
+    if (result == MAP_FAILED)
+        CRASH();
     madvise(result, bytes, MADV_DONTNEED);
-#elif HAVE(MADV_FREE_REUSE)
+#else
+    void* result = reserveAndCommit(bytes, usage, writable, executable, includesGuardPages);
+#if HAVE(MADV_FREE_REUSE)
     // To support the "reserve then commit" model, we have to initially decommit.
     while (madvise(result, bytes, MADV_FREE_REUSABLE) == -1 && errno == EAGAIN) { }
 #endif
@@ -71,18 +73,6 @@
         flags |= MAP_JIT;
 #endif
 
-#if (OS(LINUX) && CPU(X86_64))
-    // Linux distros usually do not allow overcommit by default, so
-    // JSC's strategy of mmaping a large amount of memory upfront
-    // won't work very well on some systems. Fortunately there's a
-    // flag we can pass to mmap to disable the overcommit check for
-    // this particular call, so we can get away with it as long as the
-    // overcommit flag value in /proc/sys/vm/overcommit_memory is 0
-    // ('heuristic') and not 2 (always check). 0 is the usual default
-    // value, so this should work well in general.
-    flags |= MAP_NORESERVE;
-#endif
-
 #if OS(DARWIN)
     int fd = usage;
 #else
@@ -141,8 +131,13 @@
     if (MAP_FAILED == mmap(address, bytes, protection, MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0))
         CRASH();
 #elif OS(LINUX)
-    UNUSED_PARAM(writable);
-    UNUSED_PARAM(executable);
+    int protection = PROT_READ;
+    if (writable)
+        protection |= PROT_WRITE;
+    if (executable)
+        protection |= PROT_EXEC;
+    if (!mprotect(address, bytes, protection))
+        CRASH();
     madvise(address, bytes, MADV_WILLNEED);
 #elif HAVE(MADV_FREE_REUSE)
     UNUSED_PARAM(writable);
@@ -164,6 +159,8 @@
     mmap(address, bytes, PROT_NONE, MAP_FIXED | MAP_LAZY | MAP_PRIVATE | MAP_ANON, -1, 0);
 #elif OS(LINUX)
     madvise(address, bytes, MADV_DONTNEED);
+    if (!mprotect(address, bytes, PROT_NONE))
+        CRASH();
 #elif HAVE(MADV_FREE_REUSE)
     while (madvise(address, bytes, MADV_FREE_REUSABLE) == -1 && errno == EAGAIN) { }
 #elif HAVE(MADV_FREE)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to