[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] Reduce the amount of WriteFile() syscalls when writing to buffered files

From: Evgeny Kotkov <evgeny.kotkov_at_visualsvn.com>
Date: Tue, 22 Aug 2017 17:19:56 +0300

Markus Schaber <m.schaber_at_codesys.com> writes:

> Hi, Evgeny,
>
> Great work, IMHO.

Thank you :-)

>> This patch series reduces the amount of syscalls in such situations by
>> performing a single WriteFile() call without any buffering, if possible.
>> If some data is already buffered, then the buffer is first filled, flushed
>> and the remaining part of the data is written with a single WriteFile().
>
> Why first refilling the buffer, instead of flushing the partial buffer
> content, and then the original data to write?
>
> From my first glance, it looks like the number of syscalls should be
> the same, and we could skip the mem copy?

My original intention here was to avoid issuing small and non-4K-sized
writes, which could happen if we don't refill the buffer.

For instance, in the example above doing so would result in

    WriteFile(13)
    WriteFile(86267)
    WriteFile(13)
    WriteFile(86400)
    ...

instead of

    WriteFile(4096)
    WriteFile(82185)
    WriteFile(4096)
    WriteFile(82317)
    ...

But I should also say that I ran a couple of tests and I can't see any
measurable performance difference between these two approaches, so it
might indeed make sense to switch to the first of them and avoid a memcpy().

In the meanwhile, apparently, there is an oversight in the core V1 patch
(3-reduce-syscalls-for-buffered-writes-v1.patch.txt):

If the buffer is not empty, and the caller issues a write with a chunk
that slightly exceeds the buffer size, for example, 4100 bytes, it would
result in flushing the buffer _and_ writing the remaining couple of bytes
with WriteFile(). An appropriate thing to do here would be to flush the
buffer, but put the few remaining bytes into the buffer, instead of writing
them to disk and thus making an unnecessary syscall.

With all this in mind, I will prepare the V2 version of the core patch.

Thanks,
Evgeny Kotkov
Received on 2017-08-22 16:20:26 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.