<div dir="ltr"><div>What I mean is doing something like this.</div><div><br></div><div> int in = open(infile, O_RDONLY, 0);</div><div> int out = open(outfile, O_WRONLY | O_CREAT, 0644);</div><div> void *buf = mmap(NULL, filesize, PROT_READ, MAP_PRIVATE, in, 0);</div><div> write(out, buf, filesize);</div><div><br></div><div>By write, I mean write system call and not a general read or write.</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jun 6, 2016 at 12:20 PM, Matt Godbolt <span dir="ltr"><<a href="mailto:matt@godbolt.org" target="_blank">matt@godbolt.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Perhaps I misunderstand: the kernel can tell (upon a page fault) what memory address is being written to, and likewise upon a page fault which memory has been read from. But it can't put these things together to infer "process A is reading from X and writing to Y": it sees the reads and writes in isolation, and indeed only at page granularity and when a page fault happens.</div><div><div><br><div class="gmail_quote"><div dir="ltr">On Mon, Jun 6, 2016 at 2:18 PM Rui Ueyama <<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Jun 6, 2016 at 12:11 PM, Matt Godbolt <span dir="ltr"><<a href="mailto:matt@godbolt.org" target="_blank">matt@godbolt.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_quote"><span><div dir="ltr">On Mon, Jun 6, 2016 at 1:41 PM Rui Ueyama via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">As to leave an opportunity for the kernel, I think mmap+write would be enough. Because the kernel knows what address is mmap'ed, it can detect that write's source is actually a mmap'ed file and if that's the case it can optimize as it does for sendfile. It seems that Linux doesn't do that now, though.</div></blockquote><div><br></div></span><div>Pardon my ignorance here, but how might the kernel in general know what the "source" of a write is?</div></div></div></blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>The kernel knows where all mmap'ed files are mapped. So, it can decides whether a memory address is in a mmap'ed region or not, no?</div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div>Also, in terms of the async_io option, in my (non-llvm) experimentation with reading very large files the aio subsystem is not well-supported or optimized (hence the lack of Glibc support).</div></div></div>
</blockquote></div></div></div></blockquote></div>
</div></div></blockquote></div><br></div></div>