1

I'm using the function rosbag of ROS. rosbag can record lots of data from other ROS nodes. In a word, it will generate a huge file, such as a file of 200MB.

After generating such a file, I found that the buff/cache of the system increases a lot. Here is my capture:

Before rosbag: enter image description here

After rosbag: enter image description here

You can see that after rosbag, buff/cache increased a lot, at the same time, free decreased from 19983 to 10896.

I can't understand. As my understanding, free means the free size of RAM, buff/cache is the size of cache. Why can cache use the size of RAM? And I've also found that if I deleted the file generated by rosbag, the buff/cache would get back from 17999 to 8925. Is this the action of the system? When will the buff/cache increase? When will the buff/cache decrease?

3

In free’s output:

  • “free” represents memory which is unused;
  • “buff/cache” represents memory used by buffers (data in memory which is waiting to be written to disk) and cache (data on disk which is also available in memory);
  • “available” represents the amount of memory a process can allocate and use without hitting swap (most of the time it’s this value you should care about).

When a process writes a large amount of data, that data goes to buffers before being written to disk. Those buffers take up room in memory, so the amount of unused memory goes down. But that memory can be made available, so the amount of available memory doesn’t go down.

When you delete the file, the buffers are no longer needed and are reclaimed (there’s no point in even keeping them as cache).

Buffers increase when processes write data; they decrease when that data is written to disk. Cache increases when on-disk data is made available in memory (either by reading it from disk, or converting buffers into cache); it decreases when memory pressure means it’s no longer useful to keep it around. Both live in memory, so their size affects the amount of free memory; but both can be reclaimed, so their size doesn’t affect the amount of available memory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.