Skip to content
Advertisement

How does java guarateee reserved memory

Checking for memory usage by stack using this command:

jcmd $pid VM.native_memory summary

I can see that reserved memory is different from committed.

  •                Thread (reserved=18561KB, committed=1085KB)
                          (thread #18)
                          (stack: reserved=18476KB, committed=1000KB)
                          (malloc=63KB #99) 
                          (arena=22KB #35)
    

Reserved is about 1MB (default for stack). Committed in fact is physical reserved. I read that java save memory for stack while is not totally used.

Running command like top I can see just committed usage.

What does java/SO do in order to reserve this memory without being counted by RSS (linux memory measure) statistics?

Could other process use this memory due that is no physically reserved?

Note: jdk11 SO Linux

Advertisement

Answer

What does java/SO do in order to reserve this memory without being counted by RSS (linux memory measure) statistics?

This kind of “reservation” is based on the concept of Virtual Memory. The JVM calls mmap to reserve an address space. Initially these addresses are just numbers not backed by physical pages. On the first access to a virtual page, a page fault happens, and the OS handles it by allocating the backing storage (physical RAM or a swap space).

Could other process use this memory due that is no physically reserved?

In short, yes. A longer answer – depends on the OS settings, specifically, vm.overcommit_memory and vm.overcommit_ratio sysctls. The default settings allow overcommitment – i.e. it’s possible to allocate more virtual memory than available physical RAM + swap (because applications often do not use all virtual memory they reserve).

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement