Re: [Boost-bugs] [Boost C++ Libraries] #7420: If I call managed_shared_memory() function when I create a lot of objects, it ocurrs error.

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #7420: If I call managed_shared_memory() function when I create a lot of objects, it ocurrs error.
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-10-05 09:38:32


#7420: If I call managed_shared_memory() function when I create a lot of objects,
it ocurrs error.
-------------------------------+--------------------------------------------
  Reporter: anonymous | Owner: igaztanaga
      Type: Bugs | Status: new
 Milestone: To Be Determined | Component: interprocess
   Version: Boost 1.47.0 | Severity: Problem
Resolution: | Keywords: interprocess, shared_memeory
-------------------------------+--------------------------------------------

Comment (by Robert Luberda <robert@…>):

 Hi,

 We have observed a similar issue under Linux. We have recently switched
 from boost 1.42 to boost 1.48 and noticed that out application, which
 creates about 10,000 /dev/shm files, started to fail with "Too many open
 files" error.

 It turned out the for some reason the interprocess library no longer
 closes file descriptors after shm_open() and mmap() calls. This is most
 probably caused by the following `if' that was added into
 managed_open_or_create_impl.hpp (the value of StoreDevice seems to be
 always true)

 {{{
  if(StoreDevice){
          this->DevHolder::get_device() = boost::interprocess::move(dev);
       }
 }}}

 The same issue exists on boost 1.50 and boost 1.51.


 '''Sample program''':
 {{{
 /* First set open files limit to 10
  * Then try to create 20 shm files and display number of files
  * in /proc/self/fd after each created file */
 #include <boost/interprocess/managed_shared_memory.hpp>
 #include <boost/lexical_cast.hpp>
 #include <unistd.h>
 #include <vector>
 #include <stdio.h>
 #include <sys/resource.h>

 int main(int /*argc*/, char ** /*argv*/)
 {
    // decrease limit of open files
   struct rlimit rlp = { 10, 10 };
   setrlimit(RLIMIT_NOFILE, &rlp);


   std::system("rm -f /dev/shm/ShmTest*");
   using namespace boost::interprocess;
   const std::string fdCountStr = "ls -1 /proc/" +
 boost::lexical_cast<std::string>(getpid()) + "/fd | wc -l";
   std::vector<managed_shared_memory*> v;

   for (int i = 0 ; i < 20; ++i)
   {
    const std::string name = "ShmTest" +
 boost::lexical_cast<std::string>(i);
    v.push_back(new managed_shared_memory(create_only, name.c_str(),
 1024));
    std::system (fdCountStr.c_str());
   }

   return 0;
 }
 }}}

 '''Output when compiled with boost 1.48:'''

 {{{
> ./a.out
 4
 5
 6
 7
 8
 9
 terminate called after throwing an instance of
 'boost::interprocess::interprocess_exception'
   what(): Too many open files
 Aborted (core dumped)
 }}}

 '''Output when compiled with boost 1.42:'''
 {{{
> ./a.out
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/7420#comment:1>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:10 UTC