Author: Armin Rigo <ar...@tunes.org>
Branch: 
Changeset: r85691:06f4abd385c4
Date: 2016-07-14 14:02 +0200
http://bitbucket.org/pypy/pypy/changeset/06f4abd385c4/

Log:    Windows support for use-madv-free

diff --git a/rpython/rlib/rmmap.py b/rpython/rlib/rmmap.py
--- a/rpython/rlib/rmmap.py
+++ b/rpython/rlib/rmmap.py
@@ -82,7 +82,8 @@
     constant_names = ['PAGE_READONLY', 'PAGE_READWRITE', 'PAGE_WRITECOPY',
                       'FILE_MAP_READ', 'FILE_MAP_WRITE', 'FILE_MAP_COPY',
                       'DUPLICATE_SAME_ACCESS', 'MEM_COMMIT', 'MEM_RESERVE',
-                      'MEM_RELEASE', 'PAGE_EXECUTE_READWRITE', 'PAGE_NOACCESS']
+                      'MEM_RELEASE', 'PAGE_EXECUTE_READWRITE', 'PAGE_NOACCESS',
+                      'MEM_RESET']
     for name in constant_names:
         setattr(CConfig, name, rffi_platform.ConstantInteger(name))
 
@@ -232,6 +233,9 @@
     VirtualAlloc, VirtualAlloc_safe = winexternal('VirtualAlloc',
                                [rffi.VOIDP, rffi.SIZE_T, DWORD, DWORD],
                                rffi.VOIDP)
+    _, _VirtualAlloc_safe_no_wrapper = winexternal('VirtualAlloc',
+                               [rffi.VOIDP, rffi.SIZE_T, DWORD, DWORD],
+                               rffi.VOIDP, _nowrapper=True)
     _, _VirtualProtect_safe = winexternal('VirtualProtect',
                                   [rffi.VOIDP, rffi.SIZE_T, DWORD, LPDWORD],
                                   BOOL)
@@ -949,3 +953,12 @@
 
     def free(ptr, map_size):
         VirtualFree_safe(ptr, 0, MEM_RELEASE)
+
+    def madvise_free(addr, map_size):
+        r = _VirtualAlloc_safe_no_wrapper(
+            rffi.cast(rffi.VOIDP, addr),
+            rffi.cast(rffi.SIZE_T, map_size),
+            rffi.cast(DWORD, MEM_RESET),
+            rffi.cast(DWORD, PAGE_READWRITE))
+        from rpython.rlib import debug
+        debug.debug_print("madvise_free:", r)
diff --git a/rpython/rlib/test/test_rmmap.py b/rpython/rlib/test/test_rmmap.py
--- a/rpython/rlib/test/test_rmmap.py
+++ b/rpython/rlib/test/test_rmmap.py
@@ -5,11 +5,7 @@
 from rpython.rlib.rarithmetic import intmask
 from rpython.rlib import rmmap as mmap
 from rpython.rlib.rmmap import RTypeError, RValueError, alloc, free
-try:
-    from rpython.rlib.rmmap import madvise_free
-except ImportError:
-    def madvise_free(addr, size):
-        "Not available"
+from rpython.rlib.rmmap import madvise_free
 
 
 class TestMMap:
diff --git a/rpython/rtyper/lltypesystem/llarena.py 
b/rpython/rtyper/lltypesystem/llarena.py
--- a/rpython/rtyper/lltypesystem/llarena.py
+++ b/rpython/rtyper/lltypesystem/llarena.py
@@ -440,17 +440,6 @@
         if size > 0:    # clear the final misaligned part, if any
             llmemory.raw_memclear(baseaddr, size)
 
-    def madvise_arena_free(baseaddr, size):
-        from rpython.rlib import rmmap
-
-        pagesize = posixpagesize.get()
-        baseaddr = rffi.cast(lltype.Signed, baseaddr)
-        aligned_addr = (baseaddr + pagesize - 1) & ~(pagesize - 1)
-        size -= (aligned_addr - baseaddr)
-        if size >= pagesize:
-            rmmap.madvise_free(rffi.cast(rmmap.PTR, aligned_addr),
-                               size & ~(pagesize - 1))
-
 else:
     # XXX any better implementation on Windows?
     # Should use VirtualAlloc() to reserve the range of pages,
@@ -459,10 +448,22 @@
     # them immediately.
     clear_large_memory_chunk = llmemory.raw_memclear
 
-    def madvise_arena_free(baseaddr, size):
-        """XXX find a Windows equivalent?
-        'baseaddr' is in the middle of memory obtained with the C malloc()...
-        """
+    class PosixPageSize:
+        def get(self):
+            from rpython.rlib import rmmap
+            return rmmap.PAGESIZE
+    posixpagesize = PosixPageSize()
+
+def madvise_arena_free(baseaddr, size):
+    from rpython.rlib import rmmap
+
+    pagesize = posixpagesize.get()
+    baseaddr = rffi.cast(lltype.Signed, baseaddr)
+    aligned_addr = (baseaddr + pagesize - 1) & ~(pagesize - 1)
+    size -= (aligned_addr - baseaddr)
+    if size >= pagesize:
+        rmmap.madvise_free(rffi.cast(rmmap.PTR, aligned_addr),
+                           size & ~(pagesize - 1))
 
 
 if os.name == "posix":
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to