CentOS memory availability

1.1k views Asked by At

My system has 8GB ram and my system is CentOS 7. The system info shows the following memory usage.

Memory Information
Total memory (RAM):  7.6 GB
  Free memory:  143.4 MB (+ 6.1 GB Caches)
  Free swap:  7.8 GB

Does this mean free memory is only 143.4MB, or 143.4 + 6.1BG? Why is it caches? Is this normal? I am asking this because I am running a Java problem but received an OutOfMemory exception. I am thinking whether there is any problem with my operating system.

2

There are 2 answers

0
Brian Agnew On BEST ANSWER

It's more likely that you need to run your JVM with an increased maximum memory setting. The JVM will run with it's own limit on memory usage (subject to that available from the OS).

e.g.

$ java -Xmx2048m ...

will run the JVM with a maximum memory setting of 2Gb. See here for more information.

If you suffer from an OutOfMemoryException, then it's likely that you need to tweak this setting. It is also possible that the JVM can't allocate that memory from the OS, or that your program suffers from a memory leak, but setting -Xmx is a reasonable first approach to resolving such an issue. Note that setting -Xms in a similar fashion will force the JVM to allocate the memory upon startup, and is useful not only as an optimisation, but also as an early warning for the lack of allocatbale memory. See here for more info.

0
Stephen C On

I am thinking whether there is any problem with my operating system.

Nope. The problem is either in your program (it uses too much memory or has a memory leak) or the way that you are running it (the heap is too small). Brian's answer explains, and provides some solutions.

Does this mean free memory is only 143.4MB, or 143.4 + 6.1BG? Why is it caches? Is this normal?

Yes it is normal.

The "free memory" is RAM pages that are currently not being used for anything else, and can immediately be handed out to applications that need them.

The "disk cache" is RAM pages that are currently holding copies of file-system disk blocks. They are used to make file reading faster (a LOT faster). The reason that they count as free memory is that they can reclaimed by the OS at almost zero cost. And indeed, if launch more applications, you will find that the disk cache reduces in size automatically.