What is the difference between buffer and cache memory in Linux?
"Buffers" represent how much portion of RAM is dedicated to cache disk blocks. "Cached" is similar like "Buffers", only this time it caches pages from file reading.
quote from:
- https://web.archive.org/web/20110207101856/http://www.linuxforums.org/articles/using-top-more-efficiently_89.html
Linux free -m : Total, used and free memory values don't add up
For the main memory, the actual size of memory can be calculated as used+free+buffers+cache
OR used+free+buffers/cache
because buffers/cache = buffer+cache
.
The man page of free
highlights used
as Used memory (calculated as total - free - buffers - cache)
As the man page of free says :-
total Total installed memory (MemTotal and SwapTotal in /proc/meminfo)
used Used memory (calculated as total - free - buffers - cache)
free Unused memory (MemFree and SwapFree in /proc/meminfo)
shared Memory used (mostly) by tmpfs (Shmem in /proc/meminfo,
on kernels 2.6.32, displayed as zero if not available)buffers Memory used by kernel buffers (Buffers in /proc/meminfo)
cache Memory used by the page cache and slabs (Cached and Slab in
/proc/meminfo)buff / cache Sum of buffers and cache
available Estimation of how much memory is available for starting new applications, without swapping. Unlike the data provided by the cache or free fields, this field takes into account page cache and also that not all reclaimable memory slabs will be reclaimed due to items being in use (MemAvailable in /proc/meminfo, available on kernels 3.14, emulated on kernels 2.6.27+, otherwise the same as free)
In your case,
873224(used) + 389320(free) + 25493068(buff/cache) = 26755612(total)
free command: Which column is most relevant?
Memory that is free is completely unused at this point. This number will generally and ideally be very low, since the OS tries to use as much of this memory as possible for buffering and caching.
The memory that is freely available to your application is, in fact, mentioned in the buffering/cached column.
If your program ran out of memory, it would try to free memory by using swap to outsource data to HDD and free up memory for usage. Considering there's only 20K of swap space used is another indicator that your program is not running out of memory.
How to monitor free memory ( including buffers and cache) in java?
If you are trying to get memory statistics for the OS itself (not the JVM), you can use JNA or JNI to make the platform-specific native API calls directly to the OS.
Related Topics
Find All Files Matching 'Name' on Linux System, and Search with Them for 'Text'
How to Program for Linux's New 'Fanotify' File System Monitoring Feature
Accessing the Gpio (Of a Raspberry Pi) Without ''Sudo''
Linux Kernel - Add System Call Dynamically Through Module
Setup Cron Tab to Specific Time of During Weekdays
Linux Command to Delete All Files Except .Git Folder
/Usr/Bin/Perl: Bad Interpreter: Text File Busy
Add Blank Line After Every Result in Grep
Open a File Directly from a Gitlab Private Repository
Disabling Apache Logging to Access.Log
Use Sed with Ignore Case While Adding Text Before Some Pattern
Merging Two Files by a Single Column in Unix