I was monitoring Subversion server I/O on Windows and noticed that
apr_file_info_get(APR_FINFO_SIZE) involves two syscalls
(QueryInformationVolume and QueryAllInformationFile). The
apr_file_info_get(APR_FINFO_SIZE) is actively used by Subversion
filesystem and optimizing it gives around 5-10% IO reduction.

Attached patch adds optimized codepath to apr_file_info_get() when
only APR_FINFO_SIZE is requested.

-- 
Ivan Zhakov
Index: file_io/win32/filestat.c
===================================================================
--- file_io/win32/filestat.c    (revision 1755968)
+++ file_io/win32/filestat.c    (working copy)
@@ -427,6 +427,24 @@
             return rv;
     }
 
+    /* GetFileInformationByHandle() is implemented via two syscalls:
+     * QueryInformationVolume and QueryAllInformationFile. Use cheaper
+     * GetFileSizeEx() API if we only need to get the file size. */
+    if (wanted == APR_FINFO_SIZE) {
+       LARGE_INTEGER size;
+
+       if (!GetFileSizeEx(thefile->filehand, &size)) {
+          return apr_get_os_error();
+       }
+
+       finfo->pool = thefile->pool;
+       finfo->fname = thefile->fname;
+       finfo->size = size.QuadPart;
+       finfo->valid = APR_FINFO_SIZE;
+
+       return APR_SUCCESS;
+    }
+
     if (!GetFileInformationByHandle(thefile->filehand, &FileInfo)) {
         return apr_get_os_error();
     }

Reply via email to