Hi, thanks to everyone for the suggestions,
It seems that there is in fact not a memory leak (still not totally sure), but for some reason, the go runtime keeps allocating memory event when is not needed, I think the problem is in the interaction from the memory model of the go runtime with a Linux system with low ram (128MB).
If I force a low memory situation (by allocating memory in another program), the go runtime give back most of his memory (goes from 23 MB to 6MB), but before that happen the system become very unstable at the point that I'm unable to spawn new process (related to issue
#31936), and other services start to crash(not yet sure why) or the OOMkiller start killing process. go 1.16, should "fix" this, with how it releases memory back to the system (not yet tested).
I'm still a bit perplexed by the numbers from runtime. memstat, I don't help that my code does a lot of small, short-lived allocations, which makes analysis a lot harder, I will now enable memstat metric even in production hoping that will help, and working on reducing allocation in some hot path, to make the output less busy.
@Tom Mitchell: yes objects plural, sorry. i will try your suggestions.
a couple of notes:
- I don't use CGO
- I, unfortunately, can't change the environment variable, so I can use
"GODEBUG=gctrace=1" only on my machine which runs/behave differently in virtue of not having the same hardware, and does not present the same memory problems/behavior, I also can't launch myself with the new variable(for a bunch of reasons that are a bit hard to explain, without going in many details), I have a couple of idea on how to fix it but I wasn't able to,
- On this device run other services, that for me are black boxes, some of which seem to crash in low memory situation but I don't know yet why (i emailed the respective developers and awaiting a response)
I will update, if I find something.
Again thanks to everyone.