2

I'm trying to host Swing Java application for a lengthy period on VPS at "always-on" mode and am willing to fit it into 1GB shape (Ubuntu as host OS).

Application is started with "-Xmx500m -XX:+UseConcMarkSweepGC" and it seems reasonable that it should fit (with all other supplementary staff) into 1GB of total RAM, but ... after running application for 2-3 days top says that java application alone eats almost 1GB (see USED column) - it is twice more than specified "-Xmx500m":

KiB Mem :  1009136 total,    66084 free,   867128 used,    75924 buff/cache
KiB Swap:   716796 total,     9388 free,   707408 used.    28472 avail Mem

  PID    VIRT    RES   SWAP   USED    SHR S %CPU %MEM     TIME+ COMMAND
 2401 3076084 529648 467832 997480   1900 S 31.0 52.5 916:05.68 java
 2218  285544  37548  74720 112268   8800 S  6.9  3.7 269:12.60 Xvnc4
 2388  709104  11448   9744  21192   7760 S  6.9  1.1  24:45.88 mate-terminal
  883  643820  10932   2540  13472   5624 S  0.0  1.1   1:48.43 do-agent
 2327  544648   4092   5992  10084   2436 S  3.4  0.4   6:38.31 clock-applet

Actual 'Heap usage' within application is around 350MB (displayed by application itself).

From jstat -gc 2401 I see usage only of around 630MB. Where are other ~360MB? What I'm missing? Is it possible to reduce memory usage via some JVM options?

S0C    S1C     S0U   S1U    EC       EU        OC         OU     
8512.0 8512.0  0.0   2161.2 68160.0  67668.5   426816.0   249483.9  

MC       MU       CCSC    CCSU     YGC   YGCT      FGC   FGCT    GCT
112464.0 108027.1 14160.0 13222.6  48701 1484.856  124   590.113 2074.968

https://docs.oracle.com/javase/8/docs/technotes/tools/unix/jstat.html

S0C - Current survivor space 0 - 8MB
S1C - Current survivor space 1 - 8MB
EU - Current eden space capacity - 68 MB
OC - Current old space capacity - 426 MB
MC - Metaspace capacity - 112 MB
CCSC - Compressed class space capacity - 14 MB
--> 636 MB

1 Answer 1

1

USED is the sum of RES + SWAP.
You only have +500Mb in your real memory, and +400Mb in the swap so it's the normal behaviour.

Here is the manual of top and more explanations about the swap.

4
  • I know that USED = RES + SWAP. The question is about what in Java is consuming 250M, which is (USED=997MB) - (Xmx=500MB) - (MC=112MB) - (CCSU =132MB).
    – Xtra Coder
    Commented Jul 19, 2019 at 13:30
  • Indeed, I misunderstood your question. Well, the JVM doesn't always release memoy to the OS. Maybe your application had a peak of memory usage and the used memory has not been release after. Commented Jul 19, 2019 at 13:45
  • To my knowledge - once JVM grabs memory for Heap space, it will not be released to parent OS, but that kind of memory is visible in jstat. 30% of actual memory usage is hiding somewhere - that is the point of interest ... Note: I copy-pasted wrong value - CCSU =132MB is actually CCSU =13MB.
    – Xtra Coder
    Commented Jul 19, 2019 at 16:17
  • @XtraCoder Do you have the PermGen stat ? Looks like it's not on a special heap. dzone.com/articles/permgen-and-metaspace Commented Jul 19, 2019 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.