7 Replies Latest reply: Jun 10, 2011 6:19 PM by jschellSomeoneStoleMyAlias RSS

    Does CMS give back memory to OS

    811912
      JRE: JRE1.6_19
      OS: Solaris 10
      Hardware: N240 and T5220

      VM Options:
      -Xms256M -Xmx256M -XX:CMSInitiatingOccupancyFraction=50 -XX:+CMSIncrementalMode -XX:+CMSUseOldDefaults -XX:+ExplicitGCInvokesConcurrent -XX:MaxGCPauseMillis=3000 -XX:GCTimeRatio=19 -XX:+UseConcMarkSweepGC

      Question:

      Very simple question

      ~ Does ever CMS collector give back memory to OS. Is that a feature of CMS or not?

      ~ In Solaris we have not seen CMS ever give back memory to OS. At some time when application needed memory it reached its max and then thats all, there is nothing wrong in it. Application required so jvm took from OS. But later GC cleaned up and when used heap is only 200M , remaining 2.2G from my memory still with JVM, it is not used also. Never went back to OS.

      ~ We saw lot of people talk about these attributes which makes jvm to shrink MaxHeapFreeRatio, MinHeapFreeRatio . We did tried with these but no use at all. Does CMS use these two attributes?

      But we saw memory giving back to OS by using UseParallelGC , here are the VM options used

      -XX:MaxGCPauseMillis=3000 -XX:GCTimeRatio=19 -XX:+UseParallelGC -XX:+UseParallelOldGC"


      We were trying to see the same with CMS, never happened.

      Can some one help me here.

      Regards
      Sai.

      Edited by: 808909 on Jun 3, 2011 12:53 PM
        • 1. Re: Does CMS give back memory to OS
          802316
          808909 wrote:
          ~ Does ever CMS collector give back memory to OS. Is that a feature of CMS or not?
          The JVM allocates continuous virtual memory at the start of the program and only releases it when it exits.
          This virtual memory is populated with resident memory when it is used. This is not something the application manages, but the OS.
          ~ In Solaris we have not seen CMS ever give back memory to OS. At some time when application needed memory it reached its max and then thats all, there is nothing wrong in it. Application required so jvm took from OS. But later GC cleaned up and when used heap is only 200M , remaining 2.2G from my memory still with JVM, it is not used also. Never went back to OS.
          The OS can reclaim memory by swapping out the unused pages of application, however this can hurt performance if you ever need the memory again. If you don't see the application being swapped out, that is because the memory wasn't needed.
          ~ We saw lot of people talk about these attributes which makes jvm to shrink MaxHeapFreeRatio, MinHeapFreeRatio . We did tried with these but no use at all. Does CMS use these two attributes?
          It does use them, but it controls when it should run. It doesn't control any interaction with the OS.
          But we saw memory giving back to OS by using UseParallelGC , here are the VM options used
          -XX:MaxGCPauseMillis=3000 -XX:GCTimeRatio=19 -XX:+UseParallelGC -XX:+UseParallelOldGC"
          I don't believe it does. You may have seen the resident memory reducing because the demands of another application pushed the memory out or your file cache grew.

          BTW: It might be worth upgrading your Java to update 25 as update 19 is fairly old. (Though it won't make any difference to this question)
          • 2. Re: Does CMS give back memory to OS
            jschellSomeoneStoleMyAlias
            808909 wrote:
            Can some one help me here.
            There is some option that will allow the Sun (Oracle) VM to give memory back to the OS at some point.

            The question however would be why you think that matters?
            • 3. Re: Does CMS give back memory to OS
              811912
              Can you list those vm parameters what you are talking.
              • 4. Re: Does CMS give back memory to OS
                jschellSomeoneStoleMyAlias
                808909 wrote:
                Can you list those vm parameters what you are talking.
                You could google for it.

                You haven't answered why you think it matters.
                • 5. Re: Does CMS give back memory to OS
                  811912
                  Its not a question of how does it matter. We want to know the behavior CMS collector. I have a situation where I am using CMS and some point of time app needs more memory its takes from OS. Thats very good no issues with that. But it never give's back to OS.

                  I did lot of google before coming here. most of the people are talking about -XX:MaxHeapFreeRatio=<value> and -XX:MinHeapFreeRatio=<value>. I don't see these two attributes are doing that.

                  Thanks for your reply
                  • 6. Re: Does CMS give back memory to OS
                    811912
                    Pete

                    See this link where I shared a memory comparison between CMS and ParallelGC. I used VisualVM for this. You can clearly see in ParallelGC graph total heap size certainly came down. The same I never saw with CMS. Do you agree?

                    http://siddsai.wordpress.com/2011/06/10/does-cms-gc-collector-give-back-memory-to-os/
                    • 7. Re: Does CMS give back memory to OS
                      jschellSomeoneStoleMyAlias
                      808909 wrote:
                      But it never give's back to OS.
                      Often on this site the implication from the above is that because it does that that this means it is not available to other processes. And that is false.

                      There are however some reasons why this might be relevant.