public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/63746] New: i/o fragmentation inside basic_filebuf::xsputn
@ 2014-11-05  9:05 pluto at agmk dot net
  2014-11-05 14:22 ` [Bug libstdc++/63746] " pluto at agmk dot net
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: pluto at agmk dot net @ 2014-11-05  9:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63746

            Bug ID: 63746
           Summary: i/o fragmentation inside basic_filebuf::xsputn
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pluto at agmk dot net

Hi,
i'm trying to minimize small i/o operations for better overal
application perfromance over networked filesystems.
setting quite large stream buffer doesn't work as axpected
in some cases.

#include <iostream>
#include <fstream>
#include <memory>
#include <sstream>
#include <string>

int main()
{
    std::size_t bufferSize = 1024*1024;
    std::unique_ptr< char > buffer( new char[ bufferSize ] );
    std::ofstream f;
    f.rdbuf()->pubsetbuf( buffer.get(), bufferSize );
    f.open( "s.txt", std::ios_base::out | std::ios_base::binary );

    std::stringstream ss;

    std::string s1( 10240, 'x' );

    ss.str( std::string() );
    ss << s1;
    f << ss.rdbuf();

    ss.str( std::string() );
    ss << s1;
    f << ss.rdbuf();

    f.close();
}



% g++ s.cpp -o s -Wall -g2 -std=c++11
% LANG=C strace ./s
(...)
open("s.txt", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
writev(3, [{NULL, 0}, {"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"..., 8136}], 2) = 8136
writev(3, [{"", 0}, {"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"..., 2104}], 2) = 2104
writev(3, [{"", 0}, {"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"..., 10240}], 2) = 10240
close(3)


i've expected that 20kB i/o from testcase will fit in the 1MB buffer
but the fstream.tcc contains magic const __chunk = 1k and logic that
not use the buffer in the optimal way.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug libstdc++/63746] i/o fragmentation inside basic_filebuf::xsputn
  2014-11-05  9:05 [Bug libstdc++/63746] New: i/o fragmentation inside basic_filebuf::xsputn pluto at agmk dot net
@ 2014-11-05 14:22 ` pluto at agmk dot net
  2022-11-07 13:54 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pluto at agmk dot net @ 2014-11-05 14:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63746

--- Comment #1 from Pawel Sikora <pluto at agmk dot net> ---
Created attachment 33893
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33893&action=edit
my hack.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug libstdc++/63746] i/o fragmentation inside basic_filebuf::xsputn
  2014-11-05  9:05 [Bug libstdc++/63746] New: i/o fragmentation inside basic_filebuf::xsputn pluto at agmk dot net
  2014-11-05 14:22 ` [Bug libstdc++/63746] " pluto at agmk dot net
@ 2022-11-07 13:54 ` redi at gcc dot gnu.org
  2022-11-07 14:12 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2022-11-07 13:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63746

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org
             Status|NEW                         |ASSIGNED
   Target Milestone|---                         |13.0

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
See https://gcc.gnu.org/pipermail/gcc-patches/2022-September/601082.html for a
new patch submission (making the same change) with a reproducer and benchmarks.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug libstdc++/63746] i/o fragmentation inside basic_filebuf::xsputn
  2014-11-05  9:05 [Bug libstdc++/63746] New: i/o fragmentation inside basic_filebuf::xsputn pluto at agmk dot net
  2014-11-05 14:22 ` [Bug libstdc++/63746] " pluto at agmk dot net
  2022-11-07 13:54 ` redi at gcc dot gnu.org
@ 2022-11-07 14:12 ` redi at gcc dot gnu.org
  2022-11-08 17:44 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2022-11-07 14:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63746

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=11378

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
For the record, the change to bypass the buffer for large writes (including
anything >= 1024) was done for PR 11378.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug libstdc++/63746] i/o fragmentation inside basic_filebuf::xsputn
  2014-11-05  9:05 [Bug libstdc++/63746] New: i/o fragmentation inside basic_filebuf::xsputn pluto at agmk dot net
                   ` (2 preceding siblings ...)
  2022-11-07 14:12 ` redi at gcc dot gnu.org
@ 2022-11-08 17:44 ` cvs-commit at gcc dot gnu.org
  2022-11-08 18:02 ` redi at gcc dot gnu.org
  2022-11-08 18:19 ` pawel_sikora at zoho dot com
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-11-08 17:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63746

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:3f1519eef5cbdcea2f18445852f5482798e3936a

commit r13-3815-g3f1519eef5cbdcea2f18445852f5482798e3936a
Author: Charles-François Natali <cf.natali@gmail.com>
Date:   Thu Oct 6 20:02:56 2022 +0100

    libstdc++: basic_filebuf: don't flush more often than necessary [PR63746]

    `basic_filebuf::xsputn` would bypass the buffer when passed a chunk of
    size 1024 and above, seemingly as an optimisation.

    This can have a significant performance impact if the overhead of a
    `write` syscall is non-negligible, e.g. on a slow disk, on network
    filesystems, or simply during IO contention because instead of flushing
    every `BUFSIZ` (by default), we can flush every 1024 char.
    The impact is even greater with custom larger buffers, e.g. for network
    filesystems, because the code could issue `write` for example 1000X more
    often than necessary with respect to the buffer size.
    It also introduces a significant discontinuity in performance when
    writing chunks of size 1024 and above.

    Instead, it makes sense to only bypass the buffer if the amount of data
    to be written is larger than the buffer capacity.

    Signed-off-by: Charles-Francois Natali <cf.natali@gmail.com>

    libstdc++-v3/ChangeLog:

            PR libstdc++/63746
            * include/bits/fstream.tcc (basic_filbuf::xsputn): Remove
            1024-byte chunking that bypasses the buffer for large writes.
            * testsuite/27_io/basic_filebuf/sputn/char/63746.cc: New test.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug libstdc++/63746] i/o fragmentation inside basic_filebuf::xsputn
  2014-11-05  9:05 [Bug libstdc++/63746] New: i/o fragmentation inside basic_filebuf::xsputn pluto at agmk dot net
                   ` (3 preceding siblings ...)
  2022-11-08 17:44 ` cvs-commit at gcc dot gnu.org
@ 2022-11-08 18:02 ` redi at gcc dot gnu.org
  2022-11-08 18:19 ` pawel_sikora at zoho dot com
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2022-11-08 18:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63746

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Done for GCC 13

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug libstdc++/63746] i/o fragmentation inside basic_filebuf::xsputn
  2014-11-05  9:05 [Bug libstdc++/63746] New: i/o fragmentation inside basic_filebuf::xsputn pluto at agmk dot net
                   ` (4 preceding siblings ...)
  2022-11-08 18:02 ` redi at gcc dot gnu.org
@ 2022-11-08 18:19 ` pawel_sikora at zoho dot com
  5 siblings, 0 replies; 7+ messages in thread
From: pawel_sikora at zoho dot com @ 2022-11-08 18:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63746

--- Comment #8 from Pawel Sikora <pawel_sikora at zoho dot com> ---
hi,

nice to see a final gcc fix.

gl&br, pawel.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-11-08 18:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-05  9:05 [Bug libstdc++/63746] New: i/o fragmentation inside basic_filebuf::xsputn pluto at agmk dot net
2014-11-05 14:22 ` [Bug libstdc++/63746] " pluto at agmk dot net
2022-11-07 13:54 ` redi at gcc dot gnu.org
2022-11-07 14:12 ` redi at gcc dot gnu.org
2022-11-08 17:44 ` cvs-commit at gcc dot gnu.org
2022-11-08 18:02 ` redi at gcc dot gnu.org
2022-11-08 18:19 ` pawel_sikora at zoho dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).