Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
is there any way to know the amount of actuall amount free memory available at runtime. I mean how to find the amount of available free memory + current buffer cache size.
Amount of available free memory can be found using - linux API sysconf(_SC_AVPHYS_PAGES). Similarly is there any way to find the current buffer cache size
Get it from the same place free does - /proc/meminfo
Yes thats right. But in my case, I need to check actual amount of free memory each time before I start the operation. This operation is started from the user, which we dont have control. So reading and parsing for free memory from file (i.e /etc/meminfo) each time before starting operation would be time consuming.
I need to check actual amount of free memory each time before I start the operation. This operation is started from the user, which we dont have control. So reading and parsing for free memory from file (i.e /etc/meminfo) each time before starting operation would be time consuming.
Maybe reading and parsing /proc/meminfo will be much faster than you expect.
If you are starting an operation so memory intensive that you need to check the system wide memory resources, the cost of that check will be relatively tiny.
Notice also, syg00 to did not say "file (i.e /etc/meminfo)". He said "/proc/meminfo". That is not an ordinary file. You read it like a file, but the kernel code servicing it is doing something very different from code reading an actual file.
Parsing of the file is, indeed, the way to find this info... but you may be barking up the wrong tree.
The file-buffer space is a variable-sized, low-priority memory pool. Basically, the kernel always wants 100% of memory to be in-use doing "something," and file-buffering is a low-priority use for it. If other forms of memory-pressure arise, the file-buffer pool shrinks.