I paste the code here which uses boost iostream for mmap and then writes to the associated file:
typedef unordered_map<int, string> work; int main() { work d; d[0] = "a"; boost::iostreams::mapped_file_params params; params.path = "map.dat"; params.new_file_size = 1000000000; params.mode = (std::ios_base::out | std::ios_base::in); boost::iostreams::mapped_file mf; mf.open(params); work* w = static_cast<work*>((void*)mf.data()); w[0] = d; for(int i=1; i <1000000000 ;++i) { w->insert(std::make_pair(i, "abcdef")); } mf.close(); }
When I ran this on my centos 6 field with 8 processors and 16 GB of RAM, I noticed the following:
When data was inserted into a memory-mapped file, RES (from the top command) was constantly increasing, and it reached up to 14 GB. I got the impression that when I mmap the VIRT file will grow, not RES. Similarly, when we write to the mmap file, first write it to memory, and then write to disk? Or is there an intermediate buffer / cache?
Using the "free" command, I also noticed that buffers are used after using up to 16 GB of memory. Here are a few snapshots of a free command at different times when the code ran:
total used free shared buffers cached Mem: 16334688 10530380 5804308 0 232576 9205532 -/+ buffers/cache: 1092272 15242416 Swap: 18579448 348020 18231428 total used free shared buffers cached Mem: 16334688 13594208 2740480 0 232608 9205800 -/+ buffers/cache: 4155800 12178888 Swap: 18579448 348020 18231428 total used free shared buffers cached Mem: 16334688 15385944 948744 0 232648 9205808 -/+ buffers/cache: 5947488 10387200 Swap: 18579448 348020 18231428 total used free shared buffers cached Mem: 16334688 16160368 174320 0 204940 4049224 -/+ buffers/cache: 11906204 4428484 Swap: 18579448 338092 18241356 total used free shared buffers cached Mem: 16334688 16155160 179528 0 141584 2397820 -/+ buffers/cache: 13615756 2718932 Swap: 18579448 338092 18241356 total used free shared buffers cached Mem: 16334688 16195960 138728 0 5440 17556 -/+ buffers/cache: 16172964 161724 Swap: 18579448 572052 18007396
What does this behavior mean?
It took a long time to write data to a memory-mapped file compared to writing to memory. What is the reason for this?
I wanted to use memory mapping to reduce the use of RES as I deal with huge data. But it seems that this is not so. I wanted to save all the data in the cartographic memory files and, if necessary, read them.
Am I using memory mapping incorrectly? Or that he is behaving?
c ++ boost linux memory-mapped-files boost-iostreams
Neha
source share