I’d be concerned about memory leaks, but not memory usage in general.
Java Virtual Machine Memory
---------------------------
CS-Studio/Phoebus is a plain Java application, with memory managed by the JVM.
See also https://urldefense.us/v3/__https://developers.redhat.com/articles/2021/09/09/how-jvm-uses-and-allocates-memory__;!!G_uCfscf7eWS!ahLPSop-9LD061W5kvdbPA8dXGJtKpt5ZPEVh5Eb840RChNtxJwLEvssj80Omtc6FxQWZEUmnEjHAastIo_1btiQEg$ <https://urldefense.us/v3/__https://developers.redhat.com/articles/2021/09/09/how-jvm-uses-and-allocates-memory__;!!G_uCfscf7eWS!eMPX4b_BmFqjCFGXz0Lw2r6T_s-9oURGcJkqEWUtMmUZ5sujgZ8JUIYfxChOJs9xFUdEFqYo6FvgxP7T7vNd4pE$>
When you launch the applications, the JVM option `-Xmx` sets the maximum amount of memory that the JVM will use, and `-Xms` sets the initial amount.
For example,
```
export JDK_JAVA_OPTIONS="-Xms500M -Xmx2G"
java -jar product.jar
```
will start the JVM will 500MB of memory, and it will allocate up to 2GB.
A tool like VisualVM (free, https://urldefense.us/v3/__https://visualvm.github.io__;!!G_uCfscf7eWS!ahLPSop-9LD061W5kvdbPA8dXGJtKpt5ZPEVh5Eb840RChNtxJwLEvssj80Omtc6FxQWZEUmnEjHAastIo89zayEjQ$ <https://urldefense.us/v3/__https://visualvm.github.io__;!!G_uCfscf7eWS!eMPX4b_BmFqjCFGXz0Lw2r6T_s-9oURGcJkqEWUtMmUZ5sujgZ8JUIYfxChOJs9xFUdEFqYo6FvgxP7TY0pTgm4$>) or JProfiler (very good but not free, https://urldefense.us/v3/__https://www.ej-technologies.com/products/jprofiler/overview.html__;!!G_uCfscf7eWS!ahLPSop-9LD061W5kvdbPA8dXGJtKpt5ZPEVh5Eb840RChNtxJwLEvssj80Omtc6FxQWZEUmnEjHAastIo_LXqREKw$ <https://urldefense.us/v3/__https://www.ej-technologies.com/products/jprofiler/overview.html__;!!G_uCfscf7eWS!eMPX4b_BmFqjCFGXz0Lw2r6T_s-9oURGcJkqEWUtMmUZ5sujgZ8JUIYfxChOJs9xFUdEFqYo6FvgxP7TRoDJyCM$>) can be used to track memory usage over time.
What you should see is a sawtooth-type pattern where the application uses more and more memory, maybe up to the `-Xmx` limit, then frees it.
When you open several displays, the sawtooth pattern may ramp up more rapidly, and when you then close those displays, it should free memory and return to a slower/longer sawtooth pattern. If you find a scenario where the memory keeps increasing until running out of memory, you may have spotted a memory leak that should should report, ideally with a reproducible recipe.
Linux Memory
------------
It can be confusing to compare memory usage as reported by the JVM with the memory usage reported by the Linux OS.
Especially the "VIRT" virtual memory indicated in for example `top` may appear huge, but that tends to have no
practical significance, see for example https://urldefense.us/v3/__https://stackoverflow.com/questions/561245/virtual-memory-usage-from-java-under-linux-too-much-memory-used__;!!G_uCfscf7eWS!ahLPSop-9LD061W5kvdbPA8dXGJtKpt5ZPEVh5Eb840RChNtxJwLEvssj80Omtc6FxQWZEUmnEjHAastIo8i7Vg-4w$ <https://urldefense.us/v3/__https://stackoverflow.com/questions/561245/virtual-memory-usage-from-java-under-linux-too-much-memory-used__;!!G_uCfscf7eWS!eMPX4b_BmFqjCFGXz0Lw2r6T_s-9oURGcJkqEWUtMmUZ5sujgZ8JUIYfxChOJs9xFUdEFqYo6FvgxP7TXiL_1Bc$>, which also points to related discussions of the glibc `MALLOC_ARENA_MAX` setting.
*From: *Tech-talk <tech-talk-bounces at aps.anl.gov> on behalf of Xiao, Lingran via Tech-talk <tech-talk at aps.anl.gov>
*Date: *Monday, July 29, 2024 at 1:51 PM
*To: *tech-talk at aps.anl.gov <tech-talk at aps.anl.gov>
*Subject: *[EXTERNAL] tune CSS Phoebus's memory usage
Hi all,
We're concerned about CSS Phoebus's high memory usages. I was wondering do you have the same concerns. And did you take any actions to minimize the memory usages while maintaining Phoebus's performance? Any inputs are welcome.
Thanks a lot,
Lingran