Fri, 06 Jul 2018 18:50:13 +0000
8146115: Improve docker container detection and resource configuration usage
Reviewed-by: bobv, dbuck
poonam@9348 | 1 | /* |
poonam@9348 | 2 | * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
poonam@9348 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
poonam@9348 | 4 | * |
poonam@9348 | 5 | * This code is free software; you can redistribute it and/or modify it |
poonam@9348 | 6 | * under the terms of the GNU General Public License version 2 only, as |
poonam@9348 | 7 | * published by the Free Software Foundation. |
poonam@9348 | 8 | * |
poonam@9348 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
poonam@9348 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
poonam@9348 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
poonam@9348 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
poonam@9348 | 13 | * accompanied this code). |
poonam@9348 | 14 | * |
poonam@9348 | 15 | * You should have received a copy of the GNU General Public License version |
poonam@9348 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
poonam@9348 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
poonam@9348 | 18 | * |
poonam@9348 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
poonam@9348 | 20 | * or visit www.oracle.com if you need additional information or have any |
poonam@9348 | 21 | * questions. |
poonam@9348 | 22 | * |
poonam@9348 | 23 | */ |
poonam@9348 | 24 | |
poonam@9348 | 25 | #ifndef OS_LINUX_VM_OSCONTAINER_LINUX_HPP |
poonam@9348 | 26 | #define OS_LINUX_VM_OSCONTAINER_LINUX_HPP |
poonam@9348 | 27 | |
poonam@9348 | 28 | #include "utilities/globalDefinitions.hpp" |
poonam@9348 | 29 | #include "utilities/macros.hpp" |
poonam@9348 | 30 | #include "memory/allocation.hpp" |
poonam@9348 | 31 | |
poonam@9348 | 32 | #define OSCONTAINER_ERROR (-2) |
poonam@9348 | 33 | |
poonam@9348 | 34 | class OSContainer: AllStatic { |
poonam@9348 | 35 | |
poonam@9348 | 36 | private: |
poonam@9348 | 37 | static bool _is_initialized; |
poonam@9348 | 38 | static bool _is_containerized; |
poonam@9348 | 39 | |
poonam@9348 | 40 | public: |
poonam@9348 | 41 | static void init(); |
poonam@9348 | 42 | static inline bool is_containerized(); |
poonam@9348 | 43 | static const char * container_type(); |
poonam@9348 | 44 | |
poonam@9348 | 45 | static jlong memory_limit_in_bytes(); |
poonam@9348 | 46 | static jlong memory_and_swap_limit_in_bytes(); |
poonam@9348 | 47 | static jlong memory_soft_limit_in_bytes(); |
poonam@9348 | 48 | static jlong memory_usage_in_bytes(); |
poonam@9348 | 49 | static jlong memory_max_usage_in_bytes(); |
poonam@9348 | 50 | |
poonam@9348 | 51 | static int active_processor_count(); |
poonam@9348 | 52 | |
poonam@9348 | 53 | static char * cpu_cpuset_cpus(); |
poonam@9348 | 54 | static char * cpu_cpuset_memory_nodes(); |
poonam@9348 | 55 | |
poonam@9348 | 56 | static int cpu_quota(); |
poonam@9348 | 57 | static int cpu_period(); |
poonam@9348 | 58 | |
poonam@9348 | 59 | static int cpu_shares(); |
poonam@9348 | 60 | |
poonam@9348 | 61 | }; |
poonam@9348 | 62 | |
poonam@9348 | 63 | inline bool OSContainer::is_containerized() { |
poonam@9348 | 64 | assert(_is_initialized, "OSContainer not initialized"); |
poonam@9348 | 65 | return _is_containerized; |
poonam@9348 | 66 | } |
poonam@9348 | 67 | |
poonam@9348 | 68 | #endif // OS_LINUX_VM_OSCONTAINER_LINUX_HPP |