src/hotspot/os/linux/osContainer_linux.hpp
author bobv
Thu, 31 Oct 2019 19:32:41 +0000
changeset 58874 c440a6b4e096
parent 58655 21a92562f0c2
permissions -rw-r--r--
8227006: [linux] Runtime.availableProcessors execution time increased by factor of 100 Reviewed-by: dholmes, sgehwolf, redestad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47903
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49175
diff changeset
     2
 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
47903
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
     4
 *
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
     7
 * published by the Free Software Foundation.
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
     8
 *
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    13
 * accompanied this code).
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    14
 *
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    18
 *
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    21
 * questions.
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    22
 *
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    23
 */
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49175
diff changeset
    25
#ifndef OS_LINUX_OSCONTAINER_LINUX_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49175
diff changeset
    26
#define OS_LINUX_OSCONTAINER_LINUX_HPP
47903
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    27
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    28
#include "utilities/globalDefinitions.hpp"
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    29
#include "utilities/macros.hpp"
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    30
#include "memory/allocation.hpp"
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    31
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    32
#define OSCONTAINER_ERROR (-2)
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    33
58874
c440a6b4e096 8227006: [linux] Runtime.availableProcessors execution time increased by factor of 100
bobv
parents: 58655
diff changeset
    34
// 20ms timeout between re-reads of memory limit and _active_processor_count.
c440a6b4e096 8227006: [linux] Runtime.availableProcessors execution time increased by factor of 100
bobv
parents: 58655
diff changeset
    35
#define OSCONTAINER_CACHE_TIMEOUT (NANOSECS_PER_SEC/50)
c440a6b4e096 8227006: [linux] Runtime.availableProcessors execution time increased by factor of 100
bobv
parents: 58655
diff changeset
    36
47903
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    37
class OSContainer: AllStatic {
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    38
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    39
 private:
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    40
  static bool   _is_initialized;
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    41
  static bool   _is_containerized;
58874
c440a6b4e096 8227006: [linux] Runtime.availableProcessors execution time increased by factor of 100
bobv
parents: 58655
diff changeset
    42
  static int    _active_processor_count;
c440a6b4e096 8227006: [linux] Runtime.availableProcessors execution time increased by factor of 100
bobv
parents: 58655
diff changeset
    43
58655
21a92562f0c2 8232207: Linux os::available_memory re-reads cgroup configuration on every invocation
redestad
parents: 58087
diff changeset
    44
  static jlong read_memory_limit_in_bytes();
47903
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    45
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    46
 public:
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    47
  static void init();
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    48
  static inline bool is_containerized();
49175
6a5decfc5574 8197408: Bad pointer comparison and small cleanup in os_linux.cpp
rehn
parents: 47903
diff changeset
    49
  static const char * container_type();
47903
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    50
54577
1c242c2d037f 8217338: [Containers] Improve systemd slice memory limit support
sgehwolf
parents: 53244
diff changeset
    51
  static jlong uses_mem_hierarchy();
47903
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    52
  static jlong memory_limit_in_bytes();
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    53
  static jlong memory_and_swap_limit_in_bytes();
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    54
  static jlong memory_soft_limit_in_bytes();
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    55
  static jlong memory_usage_in_bytes();
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    56
  static jlong memory_max_usage_in_bytes();
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    57
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    58
  static int active_processor_count();
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    59
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    60
  static char * cpu_cpuset_cpus();
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    61
  static char * cpu_cpuset_memory_nodes();
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    62
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    63
  static int cpu_quota();
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    64
  static int cpu_period();
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    65
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    66
  static int cpu_shares();
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    67
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    68
};
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    69
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    70
inline bool OSContainer::is_containerized() {
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    71
  return _is_containerized;
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    72
}
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents:
diff changeset
    73
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49175
diff changeset
    74
#endif // OS_LINUX_OSCONTAINER_LINUX_HPP