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
CodePudding user response:
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).
CodePudding user response:
You need to understand that in any modern operating system, "memory" is virtual.
"Reserved" memory is actually just address space that is assigned to a particular use. What this means is mostly just some adjustment of data structures that track address-space use.
"Committed" memory is a little more wiggly. Mostly it just means that the physical memory that could be needed is tracked against some notion of the maximum commit that is available. There's generally no notion that actual physical RAM is somehow allocated to the process at this point; at best, pagefile space may be reserved.
(If you want actual for-sure RAM, you need to "pin" committed pages into physical memory).
Actual RAM isn't assigned until a page is touched; and even after that, it can be taken away again, by the dynamics of paged virtual memory, in part depending on what else is happening on the hardware.
CodePudding user response:
Yes, other processes can use this memory whenever since they are out of the scope of the JVM.
References: