Hello,
I'm writing a software in C. As you know, in C we don't have standard library provided hash tables, so I'm relying on a header-only library that I found on github.
While designing this software I was very careful with memory: I pre-allocated the maximum amount of session objects, and I made sure that the hash table which is bookmarking sessions is large enough to minimize the number of reallocations. The program will evict sessions in LRU fashion if we have too many, hence freeing the handler in the hash table. A little testing highlighted that, despite my efforts, the hash table implementation needs to do some re-shuffling from time to time. This happens fairly infrequently, so I think it is acceptable.
Once my software seemed baked and ready to be tested, I made it run on my FreeBSD 15 box. It is a daemon, it needs to work for long time, so memory footprint is a thing to check. I found that the process keeps piling memory, despite address sanitizers and valgrind not detecting any defect.
I could eventually isolate the issue, and the culprit seems to be to the hash table I mentioned above. The implementation will sporadically issue `free(3)` for a certain buffer, followed by a new `malloc(3)`. ...which is perfectly OK, on my book, since allocated blocks are freed on the next re-shuffle, and everything is cleaned when the process is terminated. I concluded that the memory handling is reasonable. Using a memory profiler seems to confirm it. Moreover, under Linux the very same daemon does not show any memory leaking behavior.
I start wondering if this problem could be a non-problem, and maybe just being related to how FreeBSD handles memory. E.g. I'd like to test what would happen if I capped memory to a certain maximum: will I end up out of memory?
Do you have any recommendation?
I'm writing a software in C. As you know, in C we don't have standard library provided hash tables, so I'm relying on a header-only library that I found on github.
While designing this software I was very careful with memory: I pre-allocated the maximum amount of session objects, and I made sure that the hash table which is bookmarking sessions is large enough to minimize the number of reallocations. The program will evict sessions in LRU fashion if we have too many, hence freeing the handler in the hash table. A little testing highlighted that, despite my efforts, the hash table implementation needs to do some re-shuffling from time to time. This happens fairly infrequently, so I think it is acceptable.
Once my software seemed baked and ready to be tested, I made it run on my FreeBSD 15 box. It is a daemon, it needs to work for long time, so memory footprint is a thing to check. I found that the process keeps piling memory, despite address sanitizers and valgrind not detecting any defect.
I could eventually isolate the issue, and the culprit seems to be to the hash table I mentioned above. The implementation will sporadically issue `free(3)` for a certain buffer, followed by a new `malloc(3)`. ...which is perfectly OK, on my book, since allocated blocks are freed on the next re-shuffle, and everything is cleaned when the process is terminated. I concluded that the memory handling is reasonable. Using a memory profiler seems to confirm it. Moreover, under Linux the very same daemon does not show any memory leaking behavior.
I start wondering if this problem could be a non-problem, and maybe just being related to how FreeBSD handles memory. E.g. I'd like to test what would happen if I capped memory to a certain maximum: will I end up out of memory?
Do you have any recommendation?