From: Sebastian Lackner Subject: ntdll: Reuse old async fileio structures if possible. Message-Id: <54F51ED0.5020106@fds-team.de> Date: Tue, 03 Mar 2015 03:39:12 +0100 This should speed up apps which heavily rely on async io stuff. Some tests (using the kernel and ntdll wine tests) show that it is very often possible to reuse old fileio structures. --- dlls/ntdll/file.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) From 7105512499825c7976c045f2bc8dfeb98f2f4c1a Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Tue, 3 Mar 2015 03:29:15 +0100 Subject: ntdll: Reuse old async fileio structures if possible. --- dlls/ntdll/file.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/dlls/ntdll/file.c b/dlls/ntdll/file.c index 43b6097..5ac86bc 100644 --- a/dlls/ntdll/file.c +++ b/dlls/ntdll/file.c @@ -332,6 +332,7 @@ NTSTATUS WINAPI NtCreateFile( PHANDLE handle, ACCESS_MASK access, POBJECT_ATTRIB struct async_fileio { struct async_fileio *next; + DWORD size; HANDLE handle; PIO_APC_ROUTINE apc; void *apc_arg; @@ -370,17 +371,28 @@ static struct async_fileio *alloc_fileio( DWORD size, HANDLE handle, PIO_APC_ROU { /* first free remaining previous fileinfos */ - struct async_fileio *io = interlocked_xchg_ptr( (void **)&fileio_freelist, NULL ); + struct async_fileio *old_io = interlocked_xchg_ptr( (void **)&fileio_freelist, NULL ); + struct async_fileio *io = NULL; - while (io) + while (old_io) { - struct async_fileio *next = io->next; - RtlFreeHeap( GetProcessHeap(), 0, io ); - io = next; + if (!io && old_io->size >= size) + { + io = old_io; + size = old_io->size; + old_io = old_io->next; + } + else + { + struct async_fileio *next = old_io->next; + RtlFreeHeap( GetProcessHeap(), 0, old_io ); + old_io = next; + } } - if ((io = RtlAllocateHeap( GetProcessHeap(), 0, size ))) + if (io || (io = RtlAllocateHeap( GetProcessHeap(), 0, size ))) { + io->size = size; io->handle = handle; io->apc = apc; io->apc_arg = arg; -- 2.3.0