0

I'm sharing many memory blocks between two processes in Linux, one process receives data from network, and the other uses the data in those blocks (buffers).

Some buffers are small (hundreds bytes), and some buffers are very large(2G~4G bytes), while they all have same struct (array of a struct) and will be treated with a same algorithm.

I can NOT allocate all buffers as maximal size at beginning, because that will exceed the total memory of system too far. I have to periodically check and re-allocate them respectively.

The problem is that I have to make the client process re-mmap the block, after the server process enlarge (re-allocate) the buffer on the same name.

Regarding performance, is there a way, I can allocate a buffer with some manner likes "lazy allocating"? i.e. it will occupy very small real memory at the beginning but always seat a same virtual address even through I continuously write data resulting that it occupys more and more real memory, and the client does NOT need to re-mmap the buffer, and always can access the data with a fixed virtual address in its own virtual space.

If any, I don't need to do a lot of IPC/locking/sync things. If any, should I set a very huge swap space?

halfer
  • 19,824
  • 17
  • 99
  • 186
Leon
  • 1,489
  • 1
  • 12
  • 31
  • Even if anybody else is doing the reallocation, it will still happen the same. – ceving Jan 27 '22 at 09:13
  • @ceving Thanks! I don't know what are you meaning. Should I re-call the shm_open again for another buffer? – Leon Jan 27 '22 at 10:13
  • 2
    You have the requirement to enlarge a memory block. You know how to do it, but you are concerned that the memory has to be copied from the old location to the new location. Now you ask, if there is any kind of library, which provides resizable memory chunks. But how would the library implement it? The library would copy the memory from the old location to the new location. How does this help? The data gets sill copied. – ceving Jan 27 '22 at 10:25
  • At least, I don't need to re-map the shared memory in client app. – Leon Jan 27 '22 at 11:00

0 Answers0