0

When I call open on a boost::iostreams::mapped_file_source my program hangs for around two minutes. I tried attaching gdb to the process at this point and the backtrace shows

(gdb) backtrace
#0  0x00007f779226687a in mmap64 () at ../sysdeps/unix/syscall-template.S:81
#1  0x00007f7793c60f58 in boost::iostreams::detail::mapped_file_impl::try_map_file(boost::iostreams::basic_mapped_file_params<boost::iostreams::detail::path>) () from /usr/lib/x86_64-linux-gnu/libboost_iostreams.so.1.54.0
#2  0x00007f7793c61028 in boost::iostreams::detail::mapped_file_impl::map_file(boost::iostreams::basic_mapped_file_params<boost::iostreams::detail::path>&) () from /usr/lib/x86_64-linux-gnu/libboost_iostreams.so.1.54.0
#3  0x00007f7793c614d2 in boost::iostreams::detail::mapped_file_impl::open(boost::iostreams::basic_mapped_file_params<boost::iostreams::detail::path>) () from /usr/lib/x86_64-linux-gnu/libboost_iostreams.so.1.54.0
#4  0x00007f7793c6168e in boost::iostreams::mapped_file_source::open_impl(boost::iostreams::basic_mapped_file_params<boost::iostreams::detail::path> const&) () from /usr/lib/x86_64-linux-gnu/libboost_iostreams.so.1.54.0
#5  0x0000000000e07f86 in boost::iostreams::mapped_file_source::open<boost::iostreams::detail::path> (this=this@entry=0x1db63f8, p=...) at /usr/include/boost/iostreams/device/mapped_file.hpp:406
#6  0x0000000000e08011 in boost::iostreams::mapped_file_source::open<boost::filesystem::path> (this=this@entry=0x1db63f8, path=..., length=length@entry=18446744073709551615, offset=offset@entry=0)
at /usr/include/boost/iostreams/device/mapped_file.hpp:416

Why is the call to open so slow here? Shouldn't it return quickly here?

k-r
  • 11
  • 3
  • What is the size of your mapped file? May your file be swapped out of memory and getting loaded once you try to open it? – fernando.reyes Sep 08 '16 at 23:03
  • Thanks @fernando.reyes. The mapped file is 5.7G, but the machine I'm using has 30GiB memory. Do you know how to tell if the file is getting swapped out of memory? – k-r Sep 08 '16 at 23:36
  • I wouldn't bet on it. Even if it is swapped out, it should not matter a lot. – sehe Sep 09 '16 at 07:30
  • That definitely ought to be a very fast call. This isn't really an iostreams problem, you should really be asking "why is mmap so slow?". I'd suggest replicating what iostreams is doing in your own code and try asking stackoverflow with an example code fragment people can run. It could be something silly like a bug in ext4 in your particular kernel version or something :) – Niall Douglas Sep 09 '16 at 09:30

0 Answers0