Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8284900

Check InitialHeapSize and container memory limits before startup

XMLWordPrintable

    • gc

      The server memory is 8 GB
      Set the memory upper limit of the Cgroup to 60m

      The cgroup create operations:
      cgcreate -g memory:foo
      cd /sys/fs/cgroup/memory/foo
      echo 52428800 > memory.limit_in_bytes
      echo 62914560 > memory.memsw.limit_in_bytes


      $ cgexec -g memory:foo java -XshowSettings:system --version
      Operating System Metrics:
          Provider: cgroupv1
          Effective CPU Count: 8
          CPU Period: 100000us
          CPU Quota: -1
          CPU Shares: -1
          List of Processors, 8 total:
          0 1 2 3 4 5 6 7
          List of Effective Processors: N/A
          List of Memory Nodes, 1 total:
          0
          List of Available Memory Nodes: N/A
          Memory Limit: 50.00M
          Memory Soft Limit: Unlimited
          Memory & Swap Limit: 60.00M
          Maximum Processes Limit: 4194305

      $ cgexec -g memory:foo java -Xms60m Main

      The program started successfully with InitialHeapSize larger than the memory limit
      After running for some time, the program memory exceeds the limit and is killed

      By adding -XX:+AlwaysPreTouch, the VM will try to commit 60MB when the heap is initialized to its minimum size, and will be killed immediately by cgroups:

      $ cgexec -g memory:foo java -XshowSettings:system -Xms60m -XX:+AlwaysPreTouch -version

            pxie Peng Xie
            pxie Peng Xie
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: