Hacker News new | ask | show | jobs
by _urga 2033 days ago
Is there any syscall to do the equivalent but from C?

e.g. If you were pre-allocating hash tables for a caching service, it would be convenient if the config could stipulate 80% of the system memory instead of the user having to specify the exact amount.

3 comments

Use /proc/meminfo. What could a caching service possibly care about the bit of memory that is reserved for system use? It's not getting its hands on those pages under any circumstances.

There is no interface for that information because at the level of abstraction at which userspace applications operate, that information has no meaning.

As a comment above already mentioned - you should not try to work around and find the size of the physical memory installed because it often has no correlation to the amount of memory available to the kernel (and, to the user).