Quote:
Originally Posted by
umen
...
how do i decrease virtual size of a process in c++/c ?
thanks
You basically need to explicitly control all memory allocation, using library calls like mmap() and munmap().
As you've found, malloc_trim() doesn't really work, because any one malloc()'d bit of memory in the wrong location in the heap will wind up pinning the entire heap anyway. That's because of the way the brk()/sbrk() calls underlying malloc()/free() work in managing the heap - the standard implementation heap of memory using brk()/sbrk() has to be a single contiguous chunk of memory that has a fixed starting point. If there is any memory in use that's deep into the allocated heap space, all the memory up to and including that in use memory can't be returned to the OS.
If this is for work, instead of spending time and money trying to solve this problem by writing what will probably be a lot of buggy code that doesn't really solve anything, just buy more RAM for you server.