<div dir="ltr"><div><div><div><div><div><div>Even,<br><br></div>that was really helpful. Finally, I solved it without any need to modify GDAL.<br><br></div>I do the mmap() myself in my application. Then I create VSILFILE out of the mmapped block by VSIFileFromMemBuffer().<br><br></div>I can then GDALOpen() the /vsimem/ file and fork freely.<br><br>The GTIFF_USE_MMAP is a cherry on the cake.<br><br></div>I still have to evaluate performance impact, but it seems promising so far.<br><br></div>Thanks for the advice.<br><br></div>Jiri<br><div><div><div><div><div><br><br><br></div></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-12-15 11:29 GMT+01:00 Even Rouault <span dir="ltr"><<a href="mailto:even.rouault@spatialys.com" target="_blank">even.rouault@spatialys.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>
<div style="font-family:'Sans Serif';font-size:9pt;font-weight:400;font-style:normal"><span class="">
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">On jeudi 14 décembre 2017 23:31:48 CET Jiri Drbalek wrote:</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> Dear Even,</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> Thank you for your helpful answer.</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> I forgot to mention that when I was testing the fork() situation with</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> libtiff alone, it was working fine when the tiff file was memory</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> mapped. Unfortunately, for some reason, GDAL doesn't support memory</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> mapping of compressed tiffs. Libtiff can read them, at least those</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> with deflate compression I've tested. What is the reason for that</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> restriction?</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> </p>
</span><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">mmap is platform specific, so there was a need for a more general mechanism. And at the time the GeoTIFF driver was created, 32 bit processes were still common but large files already existed, so even on Linux, mmap wasn't really always usable. Another potential issue is that the OS might not behave appropriately if you mmap() a file larger than the available RAM and read it entirely. At least that was my experience with some older kernels where the OS wouldn't unload cached pages aggressively enough, making it irresponsive due to heavy cache swapping.</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">Another option at the /vsi level I looked yesterday was the use of pread() that takes both a file offset and size to read, and makes it possible to use the same underlying file descriptor from multiple threads/processes. But the caveat is that this translates directly as a system call, bypassing file stream buffering.</p><span class="">
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> Should I try to enable mmaping of compressed tiffs?</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> </p>
</span><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">That could be a solution worth investigating. Perhaps restricted to 64bit posix platforms, and with a configuration option, such as the existing GTIFF_USE_MMAP that you'll see if you look at frmts/gtiff/tifvsi.cpp. The name is a bit misleading since that's currently only available for a pseudo-mmap emulation for /vsimem/ files, that was added per <a href="https://trac.osgeo.org/gdal/changeset/39555" target="_blank">https://trac.osgeo.org/gdal/<wbr>changeset/39555</a>. As you may wonder why this was done, the aim was to be able to test the code paths in libtiff that are mmap() specific, when GDAL is tortured by oss-fuzz.</p><span class="">
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">Even</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">-- </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">Spatialys - Geospatial professional services</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><a href="http://www.spatialys.com" target="_blank">http://www.spatialys.com</a></p></span></div></blockquote></div><br></div>