<div dir="ltr"><div>I would suggest that when O_DIRECT gives you less than optimal throughput, then your application is not getting the block size or concurrency that it's getting from buffered I/O. My limited experiments show that with larger block size with direct I/O an application can get the same throughput as with at lower CPU cost. Since you seem to be mainly writing, I'd imaging 64K is pretty small. Obviously you don't want every application to invent this on his own, which is why we have buffered I/O. <br>
<br></div><div>Rob<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 4 July 2013 02:31, Mathieu Desnoyers <span dir="ltr"><<a href="mailto:mathieu.desnoyers@efficios.com" target="_blank">mathieu.desnoyers@efficios.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">* Dave Chinner (<a href="mailto:david@fromorbit.com">david@fromorbit.com</a>) wrote:<br>
</div><div><div class="h5">> On Wed, Jul 03, 2013 at 10:53:08AM -0400, Jeff Moyer wrote:<br>
> > Mel Gorman <<a href="mailto:mgorman@suse.de">mgorman@suse.de</a>> writes:<br>
> ><br>
> > >> > I just tried replacing my sync_file_range()+fadvise() calls and instead<br>
> > >> > pass the O_DIRECT flag to open(). Unfortunately, I must be doing<br>
> > >> > something very wrong, because I get only 1/3rd of the throughput, and<br>
> > >> > the page cache fills up. Any idea why ?<br>
> > >><br>
> > >> Since O_DIRECT does not seem to provide acceptable throughput, it may be<br>
> > >> interesting to investigate other ways to lessen the latency impact of<br>
> > >> the fadvise DONTNEED hint.<br>
> > >><br>
> > ><br>
> > > There are cases where O_DIRECT falls back to buffered IO which is why you<br>
> > > might have found that page cache was still filling up. There are a few<br>
> > > reasons why this can happen but I would guess the common cause is that<br>
> > > the range of pages being written was in the page cache already and could<br>
> > > not be invalidated for some reason. I'm guessing this is the common case<br>
> > > for page cache filling even with O_DIRECT but would not bet money on it<br>
> > > as it's not a problem I investigated before.<br>
> ><br>
> > Even when O_DIRECT falls back to buffered I/O for writes, it will<br>
> > invalidate the page cache range described by the buffered I/O once it<br>
> > completes.  For reads, the range is written out synchronously before the<br>
> > direct I/O is issued.  Either way, you shouldn't see the page cache<br>
> > filling up.<br>
><br>
> <sigh><br>
><br>
> I keep forgetting that filesystems other than XFS have sub-optimal<br>
> direct IO implementations. I wish that "silent fallback to buffered<br>
> IO" idea had never seen the light of day, and that filesystems<br>
> implemented direct IO properly.<br>
><br>
> > Switching to O_DIRECT often incurs a performance hit, especially if the<br>
> > application does not submit more than one I/O at a time.  Remember,<br>
> > you're not getting readahead, and you're not getting the benefit of the<br>
> > writeback code submitting batches of I/O.<br>
><br>
> With the way IO is being done, there won't be any readahead (write<br>
> only workload) and they are directly controlling writeback one chunk<br>
> at a time, so there's not writeback caching to do batching, either.<br>
> There's no obvious reason that direct IO should be any slower<br>
> assuming that the application is actually doing 1MB sized and<br>
> aligned IOs like was mentioned, because both methods are directly<br>
> dispatching and then waiting for IO completion.<br>
<br>
</div></div>As a clarification, I use 256kB "chunks" (sub-buffers) in my tests, not<br>
1MB. Also, please note that since I'm using splice(), each individual<br>
splice call is internally limited to 16 pages worth of data transfer<br>
(64kB).<br>
<div class="im"><br>
> What filesystem is in use here?<br>
<br>
</div>My test was performed on ext3 filesystem, that was itself sitting on<br>
raid-1 software raid.<br>
<br>
Thanks,<br>
<br>
Mathieu<br>
<div class="im HOEnZb"><br>
><br>
> Cheers,<br>
><br>
> Dave.<br>
> --<br>
> Dave Chinner<br>
> <a href="mailto:david@fromorbit.com">david@fromorbit.com</a><br>
<br>
</div><div class="HOEnZb"><div class="h5">--<br>
Mathieu Desnoyers<br>
EfficiOS Inc.<br>
<a href="http://www.efficios.com" target="_blank">http://www.efficios.com</a><br>
</div></div></blockquote></div><br></div>