From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23983 invoked by alias); 5 Nov 2014 09:05:36 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 23957 invoked by uid 48); 5 Nov 2014 09:05:32 -0000 From: "pluto at agmk dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/63746] New: i/o fragmentation inside basic_filebuf::xsputn Date: Wed, 05 Nov 2014 09:05:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 4.9.2 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: pluto at agmk dot net X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-11/txt/msg00239.txt.bz2 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 #include #include #include #include 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.