Handle memory correctly with a pool of structures

I have a program with three structure pools. For each of them I use a list of a used structures and one more for unused structures. At run time, the program consumes the structures and returns them back to the pool on demand. In addition, there is a garbage collector that cleans up zombie structures and returns them to the pool.

At the beginning of execution, virtual memory, as expected, displays about 10 GB * of allocated memory, and as the pool is used in memory, RSS memory increases.

Although used sites are returned to the pool marked as unused sites, RSS memory is not reduced. I expect this because the OS does not know what I am doing with memory, it cannot notice whether I really use them or manage the pool.

What I would like to do is make unused memory return to virtual memory whenever I want, for example, when RSS memory grows above X GB.

Is there a way to mark, given the memory pointer, a memory area to put it in virtual memory? I know this is an operating system, but maybe there is a way to force it.

Maybe I don't care what you think?

Thanks in advance.

  • Note 1: This program is used in high-performance computing, so it uses this amount of memory.

I provide an image of pool usage and memory usage for multiple files. As you can see, the sudden drop in pool usage is due to the garbage collector, so what I would like to see is the drop in memory usage.

Struct Pools Usage & Memory Usage

+4
1

, mmap, malloc. madvise POSIX_MADV_DONTNEED.

madvise POSIX_MADV_WILLNEED, , , .

, , , .

+1

All Articles