Title: [137994] trunk/Source/WTF
Revision
137994
Author
[email protected]
Date
2012-12-18 00:37:24 -0800 (Tue, 18 Dec 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-12-18
Reviewed by Simon Hausmann.

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 (137993 => 137994)


--- trunk/Source/WTF/ChangeLog	2012-12-18 08:25:58 UTC (rev 137993)
+++ trunk/Source/WTF/ChangeLog	2012-12-18 08:37:24 UTC (rev 137994)
@@ -1,3 +1,22 @@
+2012-12-18  Uli Schlachter  <[email protected]>
+
+        Implement uncommitted memory for Linux.
+        https://bugs.webkit.org/show_bug.cgi?id=65766
+
+        Reviewed by Simon Hausmann.
+
+        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-12-17  Ilya Tikhonovsky  <[email protected]>
 
         Web Inspector: Native Memory Instrumentation: MemoryInstrumentation doesn't detect reportMemoryUsage method defined in a base class.

Modified: trunk/Source/WTF/wtf/OSAllocatorPosix.cpp (137993 => 137994)


--- trunk/Source/WTF/wtf/OSAllocatorPosix.cpp	2012-12-18 08:25:58 UTC (rev 137993)
+++ trunk/Source/WTF/wtf/OSAllocatorPosix.cpp	2012-12-18 08:37:24 UTC (rev 137994)
@@ -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
@@ -142,8 +132,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);
@@ -165,6 +160,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