< prev index next >

src/hotspot/os/linux/osContainer_linux.cpp

Print this page




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include <string.h>
  26 #include <math.h>
  27 #include <errno.h>
  28 #include "utilities/globalDefinitions.hpp"
  29 #include "memory/allocation.hpp"
  30 #include "runtime/globals.hpp"
  31 #include "runtime/os.hpp"
  32 #include "logging/log.hpp"
  33 #include "osContainer_linux.hpp"
  34 
  35 /*
  36  * PER_CPU_SHARES has been set to 1024 because CPU shares' quota
  37  * is commonly used in cloud frameworks like Kubernetes[1],
  38  * AWS[2] and Mesos[3] in a similar way. They spawn containers with
  39  * --cpu-shares option values scaled by PER_CPU_SHARES. Thus, we do
  40  * the inverse for determining the number of possible available
  41  * CPUs to the JVM inside a container. See JDK-8216366.
  42  *
  43  * [1] https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#meaning-of-cpu
  44  *     In particular:
  45  *        When using Docker:
  46  *          The spec.containers[].resources.requests.cpu is converted to its core value, which is potentially
  47  *          fractional, and multiplied by 1024. The greater of this number or 2 is used as the value of the
  48  *          --cpu-shares flag in the docker run command.
  49  * [2] https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerDefinition.html
  50  * [3] https://github.com/apache/mesos/blob/3478e344fb77d931f6122980c6e94cd3913c441d/src/docker/docker.cpp#L648


 657 }
 658 
 659 /* cpu_shares
 660  *
 661  * Return the amount of cpu shares available to the process
 662  *
 663  * return:
 664  *    Share number (typically a number relative to 1024)
 665  *                 (2048 typically expresses 2 CPUs worth of processing)
 666  *    -1 for no share setup
 667  *    OSCONTAINER_ERROR for not supported
 668  */
 669 int OSContainer::cpu_shares() {
 670   GET_CONTAINER_INFO(int, cpu, "/cpu.shares",
 671                      "CPU Shares is: %d", "%d", shares);
 672   // Convert 1024 to no shares setup
 673   if (shares == 1024) return -1;
 674 
 675   return shares;
 676 }



  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include <string.h>
  26 #include <math.h>
  27 #include <errno.h>
  28 #include "utilities/globalDefinitions.hpp"
  29 #include "memory/allocation.hpp"

  30 #include "runtime/os.hpp"
  31 #include "logging/log.hpp"
  32 #include "osContainer_linux.hpp"
  33 
  34 /*
  35  * PER_CPU_SHARES has been set to 1024 because CPU shares' quota
  36  * is commonly used in cloud frameworks like Kubernetes[1],
  37  * AWS[2] and Mesos[3] in a similar way. They spawn containers with
  38  * --cpu-shares option values scaled by PER_CPU_SHARES. Thus, we do
  39  * the inverse for determining the number of possible available
  40  * CPUs to the JVM inside a container. See JDK-8216366.
  41  *
  42  * [1] https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#meaning-of-cpu
  43  *     In particular:
  44  *        When using Docker:
  45  *          The spec.containers[].resources.requests.cpu is converted to its core value, which is potentially
  46  *          fractional, and multiplied by 1024. The greater of this number or 2 is used as the value of the
  47  *          --cpu-shares flag in the docker run command.
  48  * [2] https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerDefinition.html
  49  * [3] https://github.com/apache/mesos/blob/3478e344fb77d931f6122980c6e94cd3913c441d/src/docker/docker.cpp#L648


 656 }
 657 
 658 /* cpu_shares
 659  *
 660  * Return the amount of cpu shares available to the process
 661  *
 662  * return:
 663  *    Share number (typically a number relative to 1024)
 664  *                 (2048 typically expresses 2 CPUs worth of processing)
 665  *    -1 for no share setup
 666  *    OSCONTAINER_ERROR for not supported
 667  */
 668 int OSContainer::cpu_shares() {
 669   GET_CONTAINER_INFO(int, cpu, "/cpu.shares",
 670                      "CPU Shares is: %d", "%d", shares);
 671   // Convert 1024 to no shares setup
 672   if (shares == 1024) return -1;
 673 
 674   return shares;
 675 }
 676 
< prev index next >