in the memory commands output such as 'vmstat', the item buffers or cached is sometimes confusing.
let's do some testings to show what is the difference:
what is buffers:
Here is the output after I did the ‘ls –al ’ command. You will see the buffer information increased a little. It is because the ls –al will get the directory content (not the file content) which is the meta data of the file system.
Another example is
free //check the current memory usage including buffers and cached
time find . >
/dev/null //print whole
files name and checked the time usage
free //check
the current memory usage again
time find . >
/dev/null // print whole
files name and checked the time usage again
free //check
the current memory usage again
here are the testing results:
1.
In step 2, lots of buffers
are used and the find command used about 9 seconds. No cached memory is used.
2.
In step 4, same commands neither
buffers nor cached is used as the results is stored in buffers. The find
command is much quicker (0.2 seconds).
what is cached:
Then let’s check how the cached is used. Testing scripts are
free //check
the current memory usage including buffers and cached
man pwd // check
the man page for ps command
free //check
the current memory usage including buffers and cached again
man pwd // check
the man page for ps command again
free //check
the current memory usage including buffers and cached again
here are the testing results:
1.
In step 2, a little cached is
used no buffers memory is used.
2.
In step 4, same commands neither
buffers nor cached is used as the results is stored in cached.
So there is the conclusion:
Buffers are associated with a specific block device, and cover
caching of filesystem metadata as well as tracking in-flight pages. The cache
only contains parked file data. That is, the buffers remember what's in
directories, what file permissions are, and keep track of what memory is being
written from or read to for a particular block device. The cache only contains
the contents of the files themselves.
No comments:
Post a Comment