ntdll: Make msync() asynchronous in NtFlushVirtualMemory

FeepingCreature default_357-line at yahoo.de
Fri Mar 8 10:04:12 CST 2013


Fixes bug 33146. Path of Exile's updater runs extremely slow (factor of 1000 compared to Windows) due to frequent FlushViewOfFile calls. FlushViewOfFile calls NtFlushVirtualMemory, which calls msync with MS_SYNC. FlushViewOfFile is the only function that calls NtFlushVirtualMemory in Wine, and is specified in the MSDN as asynchronous (http://msdn.microsoft.com/en-us/library/windows/desktop/aa366563%28v=vs.85%29.aspx ).

> The FlushViewOfFile function does not flush the file metadata, and it does not wait to return until the changes are flushed from the underlying hardware disk cache and physically written to disk.

As such, NtFlushVirtualMemory is almost certainly supposed to be asynchronous here. Changing msync to be MS_ASYNC fixes the slowdown in bug 33146.

---
 dlls/ntdll/virtual.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index a99bca4..e4f2bb6 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -62,6 +62,10 @@ WINE_DECLARE_DEBUG_CHANNEL(module);
 #define MS_SYNC 0
 #endif
 
+#ifndef MS_ASYNC
+#define MS_ASYNC 1
+#endif
+
 #ifndef MAP_NORESERVE
 #define MAP_NORESERVE 0
 #endif
@@ -2780,7 +2784,7 @@ NTSTATUS WINAPI NtFlushVirtualMemory( HANDLE process, LPCVOID *addr_ptr,
     {
         if (!*size_ptr) *size_ptr = view->size;
         *addr_ptr = addr;
-        if (msync( addr, *size_ptr, MS_SYNC )) status = STATUS_NOT_MAPPED_DATA;
+        if (msync( addr, *size_ptr, MS_ASYNC )) status = STATUS_NOT_MAPPED_DATA;
     }
     server_leave_uninterrupted_section( &csVirtual, &sigset );
     return status;
-- 
1.7.12

-------------- next part --------------
A non-text attachment was scrubbed...
Name: make msync in NtFlushVirtualMemory asynchronous.patch
Type: text/x-patch
Size: 1264 bytes
Desc: not available
URL: <http://www.winehq.org/pipermail/wine-patches/attachments/20130308/b7366678/attachment-0001.bin>


More information about the wine-patches mailing list