I would like to implement an in memory cache (of some type) in my user space linux application.
what i'm after is essentially the same behavior as linux's filesystem buffer cache : whatever memory isn't used by anything else, is used by my processes that are caching.
if i were to write this with a hard coded limit on how large my cache should be, I must essentially limit my cache to some predefined value, instead of it growing if the rest of the processes aren't using as much memory, or it shrinking, if memory usage balloons.
what i would like, is linux to call some kind of callback that notifies me to drop some entries from my cache, when it actually needs memory.
that way, whatever memory is needed by the processes can be taken away from my cache, and whatever is left of memory is dedicated to my cache.
is there a way to do this in linux?
is the best method of doing this just monitoring /proc/meminfo and increasing my cache size such that the used physical memory is barely less than total physical memory?