Rectangle 27 0

java Measuring memory usage of a process on Linux?


  • Anything that is dirty or private belongs exclusively to the current process (well, process tree if your program forks without execs). This is more important because the system must save them to swap if it needs to push these pages out of memory.
  • Many of the shared memory mappings in smaps are directly backed by libraries/binaries on disk. While the footprint of these does matter, it's less important as the system can drop these pages at any time and reload them from disk when needed again.
  • What massif is measuring is probably correlated with the latter. However, the memory taken by the JVM itself (without your program) is in both.
  • Yes. Java or a library it uses might adjust its memory model depending on the size of available RAM. On a different architecture, you are using completely different binaries, which may be larger or smaller or arranged differently or using different strategies for JIT and memory management.
Note
Rectangle 27 0

java Measuring memory usage of a process on Linux?


For #1, Shared memory is memory (potentially) used by more than one process. This is basically if you run the same binary file in multiple processes or different processes are using a shared library. The heap is where allocated memory is stored (when you use new in Java). Since Java has its VM, it is allocating a lot of memory on the process level that you don't see in your java code. I think that yes, the majority of that 135 MB is from the JVM code/data itself. However, there is also the memory taken up by the stack (when you make a function call and have local variables) as well.

For #2, different amount of RAM would not affect how much "memory" is used when we let memory equal RAM + swap space. However, different processors (especially if we're talking about 32-bit vs. 64-bit) may use different amount of memory. Also, the way a process is compiled may change the amount of memory used because you can instruct a compiler to optimize for memory footprint over speed, as well as disabling some or all optimization altogether.

Note