<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Dec 13, 2014 at 2:03 PM, Reid Kleckner <span dir="ltr"><<a href="mailto:rnk@google.com" target="_blank">rnk@google.com</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">My best theory is that mmap has to map zero pages first. Typically everything is mapped to one zero page, and then every new page write causes a COW page fault. That might explain Sean's observations of lots of functions that execute #bytes/4096 times.<div><br></div><div>I wonder if there are some tweaks to the mmap path that would help, like only mapping 10MB of output buffer per file and then remapping it to a +10MB offset. There are probably also things like MAP_POPULATE or explicitly asking for a few huge pages that might help.<br><div><br></div><div><br></div></div></div></blockquote><div><br></div><div>One more thing: on my particular machine (new Mac Pro), Rafael's test program is actually CPU-bottlenecked; the new Mac Pro's have insanely fast SSD's connected over PCI-e. Just doing the CPU work of generating the random numbers (1GiB version) takes 1.6s, which is basically the same time that the write version takes; even just generating all 1GiB of random numbers in place (no large memory allocation involved, no file creation involved) takes 1.1s. Just writing 1GiB to disk sequentially takes 1.0s.</div><div><br></div><div>Also, it takes about .45 seconds to just memset a 1GiB malloc'd region with 0's; most of this is virtual memory overhead, since if you reuse the same 1GiB region, then after the first run it takes <0.1s.</div><div><br></div><div>-- Sean Silva</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Fri, Dec 12, 2014 at 3:30 PM, Rafael Ávila de Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:</span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">It seems that the common wisdom on the fastest way to create a file is<br>
<br>
* create the file<br>
* resize it to the final size<br>
* mmap it rw<br>
* write the data to the mapping<br>
<br>
I benchmarked that against doing 1 MB writes to create a 1GB file with pseudo random data.<br>
<br>
The test program is attached. The results I got were (in seconds, mmap is the first):<br>
<br>
btrfs<br>
1.752698e+00<br>
1.112864e+00<br>
<br>
tmpsfs<br>
1.484731e+00<br>
1.113772e+00<br>
<br>
hfs+ (laptop)<br>
4.015817e+00<br>
2.240137e+00<br>
<br>
windows 7 (vm)<br>
1.609375e+00<br>
3.875000e+00<br>
<br>
ext2 on arm (old google chrome book):<br>
5.910171e+01<br>
6.566929e+01<br>
<br>
So on Windows it is true, mmap seems to be faster than writes. On Linux and OS X x86_64 the situation is inverted. On arm mmap is a bit faster.<br>
<br>
It would be interesting to see if someone else can reproduce these numbers. It would be particularly nice to try a newer arm system and windows outside a vm.<br>
<br>
Also, does anyone have a theory of where the difference comes from?<br>
<br>
Cheers,<br>
Rafael<br>
<br><br>
<br>
<br></div></div><span class="">
Sent from my iPhone<br>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br></span></blockquote></div></div>
<br>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br></blockquote></div></div></div>