0

I have a thread logging variables' values to a file, something similar to this:

fp = fopen("log.txt", "a");

fprintf(fp, "%d,", var1);
fprintf(fp, "%d,", var2);
fprintf(fp, "%d,", var3);
...
fprintf(fp, "\n");

fclose(fp);

I noticed that MemFree in /proc/meminfo is rapidly decreasing, I suspect because of my output being buffered. To my suprise, MemFree is not recovered after killing the process. This lead me to these questions:

  1. Can having low (or no) MemFree cause issues?
  2. How can I avoid "loosing" memory?

Thank you in advance.

godo
  • 195
  • 1
  • 11
  • The proc stats need to be carefully interpreted. MemFree means the current size of RAM that is unused. Note that "used" includes memory that hasn't been freed by the OS but can be if needed. So arguably a better value for you to look at is MemAvailable. That value is generally larger than MemFree because it includes memory that can be reclaimed/freed if needed (e,g. buffers and caches). – kaylum Apr 14 '21 at 10:34
  • Okay, thanks. So should I do something else in my code and ignore the fact that MemFree is decreasing? – godo Apr 14 '21 at 13:05
  • The point is until you are sure something is wrong there is nothing to do in the code. Is there some reason that you are looking at these stats in the first place? If you really want/need to troubleshoot this then you need to read up on the memory stats first before trying to reach conclusions from them. – kaylum Apr 14 '21 at 20:55

0 Answers0