提交 1de115b4 编写于 作者: P poonam

8146115: Improve docker container detection and resource configuration usage

Reviewed-by: bobv, dbuck
上级 47268b75
...@@ -4008,6 +4008,16 @@ void os::make_polling_page_readable(void) { ...@@ -4008,6 +4008,16 @@ void os::make_polling_page_readable(void) {
}; };
int os::active_processor_count() { int os::active_processor_count() {
// User has overridden the number of active processors
if (ActiveProcessorCount > 0) {
if (PrintActiveCpus) {
tty->print_cr("active_processor_count: "
"active processor count set by user : %d",
ActiveProcessorCount);
}
return ActiveProcessorCount;
}
int online_cpus = ::sysconf(_SC_NPROCESSORS_ONLN); int online_cpus = ::sysconf(_SC_NPROCESSORS_ONLN);
assert(online_cpus > 0 && online_cpus <= processor_count(), "sanity check"); assert(online_cpus > 0 && online_cpus <= processor_count(), "sanity check");
return online_cpus; return online_cpus;
......
...@@ -3765,6 +3765,16 @@ void os::make_polling_page_readable(void) { ...@@ -3765,6 +3765,16 @@ void os::make_polling_page_readable(void) {
}; };
int os::active_processor_count() { int os::active_processor_count() {
// User has overridden the number of active processors
if (ActiveProcessorCount > 0) {
if (PrintActiveCpus) {
tty->print_cr("active_processor_count: "
"active processor count set by user : %d",
ActiveProcessorCount);
}
return ActiveProcessorCount;
}
return _processor_count; return _processor_count;
} }
......
/* /*
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -49,8 +49,13 @@ ...@@ -49,8 +49,13 @@
product(bool, UseSHM, false, \ product(bool, UseSHM, false, \
"Use SYSV shared memory for large pages") \ "Use SYSV shared memory for large pages") \
\ \
diagnostic(bool, PrintActiveCpus, false, \ product(bool, UseContainerSupport, true, \
"Print the number of CPUs detected in os::active_processor_count") "Enable detection and runtime container configuration support") \
\
product(bool, PreferContainerQuotaForCPUCount, true, \
"Calculate the container CPU availability based on the value" \
" of quotas (if set), when true. Otherwise, use the CPU" \
" shares value, provided it is less than quota.")
// //
// Defines Linux-specific default values. The flags are available on all // Defines Linux-specific default values. The flags are available on all
......
此差异已折叠。
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#ifndef OS_LINUX_VM_OSCONTAINER_LINUX_HPP
#define OS_LINUX_VM_OSCONTAINER_LINUX_HPP
#include "utilities/globalDefinitions.hpp"
#include "utilities/macros.hpp"
#include "memory/allocation.hpp"
#define OSCONTAINER_ERROR (-2)
class OSContainer: AllStatic {
private:
static bool _is_initialized;
static bool _is_containerized;
public:
static void init();
static inline bool is_containerized();
static const char * container_type();
static jlong memory_limit_in_bytes();
static jlong memory_and_swap_limit_in_bytes();
static jlong memory_soft_limit_in_bytes();
static jlong memory_usage_in_bytes();
static jlong memory_max_usage_in_bytes();
static int active_processor_count();
static char * cpu_cpuset_cpus();
static char * cpu_cpuset_memory_nodes();
static int cpu_quota();
static int cpu_period();
static int cpu_shares();
};
inline bool OSContainer::is_containerized() {
assert(_is_initialized, "OSContainer not initialized");
return _is_containerized;
}
#endif // OS_LINUX_VM_OSCONTAINER_LINUX_HPP
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "mutex_linux.inline.hpp" #include "mutex_linux.inline.hpp"
#include "oops/oop.inline.hpp" #include "oops/oop.inline.hpp"
#include "os_share_linux.hpp" #include "os_share_linux.hpp"
#include "osContainer_linux.hpp"
#include "prims/jniFastGetField.hpp" #include "prims/jniFastGetField.hpp"
#include "prims/jvm.h" #include "prims/jvm.h"
#include "prims/jvm_misc.hpp" #include "prims/jvm_misc.hpp"
...@@ -179,13 +180,62 @@ julong os::available_memory() { ...@@ -179,13 +180,62 @@ julong os::available_memory() {
julong os::Linux::available_memory() { julong os::Linux::available_memory() {
// values in struct sysinfo are "unsigned long" // values in struct sysinfo are "unsigned long"
struct sysinfo si; struct sysinfo si;
sysinfo(&si); julong avail_mem;
if (OSContainer::is_containerized()) {
jlong mem_limit, mem_usage;
if ((mem_limit = OSContainer::memory_limit_in_bytes()) < 1) {
if (PrintContainerInfo) {
tty->print_cr("container memory limit %s: " JLONG_FORMAT ", using host value",
mem_limit == OSCONTAINER_ERROR ? "failed" : "unlimited", mem_limit);
}
}
return (julong)si.freeram * si.mem_unit; if (mem_limit > 0 && (mem_usage = OSContainer::memory_usage_in_bytes()) < 1) {
if (PrintContainerInfo) {
tty->print_cr("container memory usage failed: " JLONG_FORMAT ", using host value", mem_usage);
}
}
if (mem_limit > 0 && mem_usage > 0 ) {
avail_mem = mem_limit > mem_usage ? (julong)mem_limit - (julong)mem_usage : 0;
if (PrintContainerInfo) {
tty->print_cr("available container memory: " JULONG_FORMAT, avail_mem);
}
return avail_mem;
}
}
sysinfo(&si);
avail_mem = (julong)si.freeram * si.mem_unit;
if (Verbose) {
tty->print_cr("available memory: " JULONG_FORMAT, avail_mem);
}
return avail_mem;
} }
julong os::physical_memory() { julong os::physical_memory() {
return Linux::physical_memory(); jlong phys_mem = 0;
if (OSContainer::is_containerized()) {
jlong mem_limit;
if ((mem_limit = OSContainer::memory_limit_in_bytes()) > 0) {
if (PrintContainerInfo) {
tty->print_cr("total container memory: " JLONG_FORMAT, mem_limit);
}
return mem_limit;
}
if (PrintContainerInfo) {
tty->print_cr("container memory limit %s: " JLONG_FORMAT ", using host value",
mem_limit == OSCONTAINER_ERROR ? "failed" : "unlimited", mem_limit);
}
}
phys_mem = Linux::physical_memory();
if (Verbose) {
tty->print_cr("total system memory: " JLONG_FORMAT, phys_mem);
}
return phys_mem;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -2114,6 +2164,8 @@ void os::print_os_info(outputStream* st) { ...@@ -2114,6 +2164,8 @@ void os::print_os_info(outputStream* st) {
os::Posix::print_load_average(st); os::Posix::print_load_average(st);
os::Linux::print_full_memory_info(st); os::Linux::print_full_memory_info(st);
os::Linux::print_container_info(st);
} }
// Try to identify popular distros. // Try to identify popular distros.
...@@ -2179,6 +2231,57 @@ void os::Linux::print_full_memory_info(outputStream* st) { ...@@ -2179,6 +2231,57 @@ void os::Linux::print_full_memory_info(outputStream* st) {
st->cr(); st->cr();
} }
void os::Linux::print_container_info(outputStream* st) {
if (!OSContainer::is_containerized()) {
return;
}
st->print("container (cgroup) information:\n");
const char *p_ct = OSContainer::container_type();
st->print("container_type: %s\n", p_ct != NULL ? p_ct : "failed");
char *p = OSContainer::cpu_cpuset_cpus();
st->print("cpu_cpuset_cpus: %s\n", p != NULL ? p : "failed");
free(p);
p = OSContainer::cpu_cpuset_memory_nodes();
st->print("cpu_memory_nodes: %s\n", p != NULL ? p : "failed");
free(p);
int i = OSContainer::active_processor_count();
if (i > 0) {
st->print("active_processor_count: %d\n", i);
} else {
st->print("active_processor_count: failed\n");
}
i = OSContainer::cpu_quota();
st->print("cpu_quota: %d\n", i);
i = OSContainer::cpu_period();
st->print("cpu_period: %d\n", i);
i = OSContainer::cpu_shares();
st->print("cpu_shares: %d\n", i);
jlong j = OSContainer::memory_limit_in_bytes();
st->print("memory_limit_in_bytes: " JLONG_FORMAT "\n", j);
j = OSContainer::memory_and_swap_limit_in_bytes();
st->print("memory_and_swap_limit_in_bytes: " JLONG_FORMAT "\n", j);
j = OSContainer::memory_soft_limit_in_bytes();
st->print("memory_soft_limit_in_bytes: " JLONG_FORMAT "\n", j);
j = OSContainer::OSContainer::memory_usage_in_bytes();
st->print("memory_usage_in_bytes: " JLONG_FORMAT "\n", j);
j = OSContainer::OSContainer::memory_max_usage_in_bytes();
st->print("memory_max_usage_in_bytes: " JLONG_FORMAT "\n", j);
st->cr();
}
void os::print_memory_info(outputStream* st) { void os::print_memory_info(outputStream* st) {
st->print("Memory:"); st->print("Memory:");
...@@ -4951,6 +5054,10 @@ extern "C" { ...@@ -4951,6 +5054,10 @@ extern "C" {
} }
} }
void os::pd_init_container_support() {
OSContainer::init();
}
// this is called _after_ the global arguments have been parsed // this is called _after_ the global arguments have been parsed
jint os::init_2(void) jint os::init_2(void)
{ {
...@@ -5131,7 +5238,7 @@ static int os_cpu_count(const cpu_set_t* cpus) { ...@@ -5131,7 +5238,7 @@ static int os_cpu_count(const cpu_set_t* cpus) {
// sched_getaffinity gives an accurate answer as it accounts for cpusets. // sched_getaffinity gives an accurate answer as it accounts for cpusets.
// If anything goes wrong we fallback to returning the number of online // If anything goes wrong we fallback to returning the number of online
// processors - which can be greater than the number available to the process. // processors - which can be greater than the number available to the process.
int os::active_processor_count() { int os::Linux::active_processor_count() {
cpu_set_t cpus; // can represent at most 1024 (CPU_SETSIZE) processors cpu_set_t cpus; // can represent at most 1024 (CPU_SETSIZE) processors
int cpus_size = sizeof(cpu_set_t); int cpus_size = sizeof(cpu_set_t);
int cpu_count = 0; int cpu_count = 0;
...@@ -5149,10 +5256,48 @@ int os::active_processor_count() { ...@@ -5149,10 +5256,48 @@ int os::active_processor_count() {
"which may exceed available processors", strerror(errno), cpu_count); "which may exceed available processors", strerror(errno), cpu_count);
} }
assert(cpu_count > 0 && cpu_count <= processor_count(), "sanity check"); assert(cpu_count > 0 && cpu_count <= os::processor_count(), "sanity check");
return cpu_count; return cpu_count;
} }
// Determine the active processor count from one of
// three different sources:
//
// 1. User option -XX:ActiveProcessorCount
// 2. kernel os calls (sched_getaffinity or sysconf(_SC_NPROCESSORS_ONLN)
// 3. extracted from cgroup cpu subsystem (shares and quotas)
//
// Option 1, if specified, will always override.
// If the cgroup subsystem is active and configured, we
// will return the min of the cgroup and option 2 results.
// This is required since tools, such as numactl, that
// alter cpu affinity do not update cgroup subsystem
// cpuset configuration files.
int os::active_processor_count() {
// User has overridden the number of active processors
if (ActiveProcessorCount > 0) {
if (PrintActiveCpus) {
tty->print_cr("active_processor_count: "
"active processor count set by user : %d",
ActiveProcessorCount);
}
return ActiveProcessorCount;
}
int active_cpus;
if (OSContainer::is_containerized()) {
active_cpus = OSContainer::active_processor_count();
if (PrintActiveCpus) {
tty->print_cr("active_processor_count: determined by OSContainer: %d",
active_cpus);
}
} else {
active_cpus = os::Linux::active_processor_count();
}
return active_cpus;
}
void os::set_native_thread_name(const char *name) { void os::set_native_thread_name(const char *name) {
// Not yet implemented. // Not yet implemented.
return; return;
......
...@@ -35,6 +35,7 @@ static bool zero_page_read_protected() { return true; } ...@@ -35,6 +35,7 @@ static bool zero_page_read_protected() { return true; }
class Linux { class Linux {
friend class os; friend class os;
friend class OSContainer;
friend class TestReserveMemorySpecial; friend class TestReserveMemorySpecial;
// For signal-chaining // For signal-chaining
...@@ -79,6 +80,9 @@ class Linux { ...@@ -79,6 +80,9 @@ class Linux {
static julong available_memory(); static julong available_memory();
static julong physical_memory() { return _physical_memory; } static julong physical_memory() { return _physical_memory; }
static void set_physical_memory(julong phys_mem) { _physical_memory = phys_mem; }
static int active_processor_count();
static void initialize_system_info(); static void initialize_system_info();
static int commit_memory_impl(char* addr, size_t bytes, bool exec); static int commit_memory_impl(char* addr, size_t bytes, bool exec);
...@@ -116,6 +120,7 @@ class Linux { ...@@ -116,6 +120,7 @@ class Linux {
static bool release_memory_special_huge_tlbfs(char* base, size_t bytes); static bool release_memory_special_huge_tlbfs(char* base, size_t bytes);
static void print_full_memory_info(outputStream* st); static void print_full_memory_info(outputStream* st);
static void print_container_info(outputStream* st);
static void print_distro_info(outputStream* st); static void print_distro_info(outputStream* st);
static void print_libversion_info(outputStream* st); static void print_libversion_info(outputStream* st);
......
...@@ -357,6 +357,16 @@ void os::Solaris::initialize_system_info() { ...@@ -357,6 +357,16 @@ void os::Solaris::initialize_system_info() {
} }
int os::active_processor_count() { int os::active_processor_count() {
// User has overridden the number of active processors
if (ActiveProcessorCount > 0) {
if (Verbose) {
tty->print_cr("active_processor_count: "
"active processor count set by user : %d",
ActiveProcessorCount);
}
return ActiveProcessorCount;
}
int online_cpus = sysconf(_SC_NPROCESSORS_ONLN); int online_cpus = sysconf(_SC_NPROCESSORS_ONLN);
pid_t pid = getpid(); pid_t pid = getpid();
psetid_t pset = PS_NONE; psetid_t pset = PS_NONE;
......
...@@ -716,6 +716,16 @@ typedef UINT_PTR DWORD_PTR; ...@@ -716,6 +716,16 @@ typedef UINT_PTR DWORD_PTR;
#endif #endif
int os::active_processor_count() { int os::active_processor_count() {
// User has overridden the number of active processors
if (ActiveProcessorCount > 0) {
if (PrintActiveCpus) {
tty->print_cr("active_processor_count: "
"active processor count set by user : %d",
ActiveProcessorCount);
}
return ActiveProcessorCount;
}
DWORD_PTR lpProcessAffinityMask = 0; DWORD_PTR lpProcessAffinityMask = 0;
DWORD_PTR lpSystemAffinityMask = 0; DWORD_PTR lpSystemAffinityMask = 0;
int proc_count = processor_count(); int proc_count = processor_count();
......
/* /*
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -1801,20 +1801,34 @@ void Arguments::set_heap_size() { ...@@ -1801,20 +1801,34 @@ void Arguments::set_heap_size() {
} }
} }
// Convert Fraction to Precentage values
if (FLAG_IS_DEFAULT(MaxRAMPercentage) &&
!FLAG_IS_DEFAULT(MaxRAMFraction))
MaxRAMPercentage = 100.0 / MaxRAMFraction;
if (FLAG_IS_DEFAULT(MinRAMPercentage) &&
!FLAG_IS_DEFAULT(MinRAMFraction))
MinRAMPercentage = 100.0 / MinRAMFraction;
if (FLAG_IS_DEFAULT(InitialRAMPercentage) &&
!FLAG_IS_DEFAULT(InitialRAMFraction))
InitialRAMPercentage = 100.0 / InitialRAMFraction;
// If the maximum heap size has not been set with -Xmx, // If the maximum heap size has not been set with -Xmx,
// then set it as fraction of the size of physical memory, // then set it as fraction of the size of physical memory,
// respecting the maximum and minimum sizes of the heap. // respecting the maximum and minimum sizes of the heap.
if (FLAG_IS_DEFAULT(MaxHeapSize)) { if (FLAG_IS_DEFAULT(MaxHeapSize)) {
julong reasonable_max = phys_mem / MaxRAMFraction; julong reasonable_max = (julong)((phys_mem * MaxRAMPercentage) / 100);
const julong reasonable_min = (julong)((phys_mem * MinRAMPercentage) / 100);
if (phys_mem <= MaxHeapSize * MinRAMFraction) { if (reasonable_min < MaxHeapSize) {
// Small physical memory, so use a minimum fraction of it for the heap // Small physical memory, so use a minimum fraction of it for the heap
reasonable_max = phys_mem / MinRAMFraction; reasonable_max = reasonable_min;
} else { } else {
// Not-small physical memory, so require a heap at least // Not-small physical memory, so require a heap at least
// as large as MaxHeapSize // as large as MaxHeapSize
reasonable_max = MAX2(reasonable_max, (julong)MaxHeapSize); reasonable_max = MAX2(reasonable_max, (julong)MaxHeapSize);
} }
if (!FLAG_IS_DEFAULT(ErgoHeapSizeLimit) && ErgoHeapSizeLimit != 0) { if (!FLAG_IS_DEFAULT(ErgoHeapSizeLimit) && ErgoHeapSizeLimit != 0) {
// Limit the heap size to ErgoHeapSizeLimit // Limit the heap size to ErgoHeapSizeLimit
reasonable_max = MIN2(reasonable_max, (julong)ErgoHeapSizeLimit); reasonable_max = MIN2(reasonable_max, (julong)ErgoHeapSizeLimit);
...@@ -1856,7 +1870,7 @@ void Arguments::set_heap_size() { ...@@ -1856,7 +1870,7 @@ void Arguments::set_heap_size() {
reasonable_minimum = limit_by_allocatable_memory(reasonable_minimum); reasonable_minimum = limit_by_allocatable_memory(reasonable_minimum);
if (InitialHeapSize == 0) { if (InitialHeapSize == 0) {
julong reasonable_initial = phys_mem / InitialRAMFraction; julong reasonable_initial = (julong)((phys_mem * InitialRAMPercentage) / 100);
reasonable_initial = MAX3(reasonable_initial, reasonable_minimum, (julong)min_heap_size()); reasonable_initial = MAX3(reasonable_initial, reasonable_minimum, (julong)min_heap_size());
reasonable_initial = MIN2(reasonable_initial, (julong)MaxHeapSize); reasonable_initial = MIN2(reasonable_initial, (julong)MaxHeapSize);
...@@ -1881,6 +1895,94 @@ void Arguments::set_heap_size() { ...@@ -1881,6 +1895,94 @@ void Arguments::set_heap_size() {
} }
} }
// This option inspects the machine and attempts to set various
// parameters to be optimal for long-running, memory allocation
// intensive jobs. It is intended for machines with large
// amounts of cpu and memory.
jint Arguments::set_aggressive_heap_flags() {
// initHeapSize is needed since _initial_heap_size is 4 bytes on a 32 bit
// VM, but we may not be able to represent the total physical memory
// available (like having 8gb of memory on a box but using a 32bit VM).
// Thus, we need to make sure we're using a julong for intermediate
// calculations.
julong initHeapSize;
julong total_memory = os::physical_memory();
if (total_memory < (julong) 256 * M) {
jio_fprintf(defaultStream::error_stream(),
"You need at least 256mb of memory to use -XX:+AggressiveHeap\n");
vm_exit(1);
}
// The heap size is half of available memory, or (at most)
// all of possible memory less 160mb (leaving room for the OS
// when using ISM). This is the maximum; because adaptive sizing
// is turned on below, the actual space used may be smaller.
initHeapSize = MIN2(total_memory / (julong) 2,
total_memory - (julong) 160 * M);
initHeapSize = limit_by_allocatable_memory(initHeapSize);
if (FLAG_IS_DEFAULT(MaxHeapSize)) {
FLAG_SET_CMDLINE(uintx, MaxHeapSize, initHeapSize);
FLAG_SET_CMDLINE(uintx, InitialHeapSize, initHeapSize);
// Currently the minimum size and the initial heap sizes are the same.
set_min_heap_size(initHeapSize);
}
if (FLAG_IS_DEFAULT(NewSize)) {
// Make the young generation 3/8ths of the total heap.
FLAG_SET_CMDLINE(uintx, NewSize,
((julong) MaxHeapSize / (julong) 8) * (julong) 3);
FLAG_SET_CMDLINE(uintx, MaxNewSize, NewSize);
}
#ifndef _ALLBSD_SOURCE // UseLargePages is not yet supported on BSD.
FLAG_SET_DEFAULT(UseLargePages, true);
#endif
// Increase some data structure sizes for efficiency
FLAG_SET_CMDLINE(uintx, BaseFootPrintEstimate, MaxHeapSize);
FLAG_SET_CMDLINE(bool, ResizeTLAB, false);
FLAG_SET_CMDLINE(uintx, TLABSize, 256 * K);
// See the OldPLABSize comment below, but replace 'after promotion'
// with 'after copying'. YoungPLABSize is the size of the survivor
// space per-gc-thread buffers. The default is 4kw.
FLAG_SET_CMDLINE(uintx, YoungPLABSize, 256 * K); // Note: this is in words
// OldPLABSize is the size of the buffers in the old gen that
// UseParallelGC uses to promote live data that doesn't fit in the
// survivor spaces. At any given time, there's one for each gc thread.
// The default size is 1kw. These buffers are rarely used, since the
// survivor spaces are usually big enough. For specjbb, however, there
// are occasions when there's lots of live data in the young gen
// and we end up promoting some of it. We don't have a definite
// explanation for why bumping OldPLABSize helps, but the theory
// is that a bigger PLAB results in retaining something like the
// original allocation order after promotion, which improves mutator
// locality. A minor effect may be that larger PLABs reduce the
// number of PLAB allocation events during gc. The value of 8kw
// was arrived at by experimenting with specjbb.
FLAG_SET_CMDLINE(uintx, OldPLABSize, 8 * K); // Note: this is in words
// Enable parallel GC and adaptive generation sizing
FLAG_SET_CMDLINE(bool, UseParallelGC, true);
// Encourage steady state memory management
FLAG_SET_CMDLINE(uintx, ThresholdTolerance, 100);
// This appears to improve mutator locality
FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false);
// Get around early Solaris scheduling bug
// (affinity vs other jobs on system)
// but disallow DR and offlining (5008695).
FLAG_SET_CMDLINE(bool, BindGCTaskThreadsToCPUs, true);
return JNI_OK;
}
// This must be called after ergonomics because we want bytecode rewriting // This must be called after ergonomics because we want bytecode rewriting
// if the server compiler is used, or if UseSharedSpaces is disabled. // if the server compiler is used, or if UseSharedSpaces is disabled.
void Arguments::set_bytecode_flags() { void Arguments::set_bytecode_flags() {
...@@ -2644,6 +2746,14 @@ jint Arguments::parse_vm_init_args(const JavaVMInitArgs* args) { ...@@ -2644,6 +2746,14 @@ jint Arguments::parse_vm_init_args(const JavaVMInitArgs* args) {
return result; return result;
} }
// We need to ensure processor and memory resources have been properly
// configured - which may rely on arguments we just processed - before
// doing the final argument processing. Any argument processing that
// needs to know about processor and memory resources must occur after
// this point.
os::init_container_support();
// Do final processing now that all arguments have been parsed // Do final processing now that all arguments have been parsed
result = finalize_vm_init_args(&scp, scp_assembly_required); result = finalize_vm_init_args(&scp, scp_assembly_required);
if (result != JNI_OK) { if (result != JNI_OK) {
...@@ -3117,94 +3227,6 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, ...@@ -3117,94 +3227,6 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args,
_exit_hook = CAST_TO_FN_PTR(exit_hook_t, option->extraInfo); _exit_hook = CAST_TO_FN_PTR(exit_hook_t, option->extraInfo);
} else if (match_option(option, "abort", &tail)) { } else if (match_option(option, "abort", &tail)) {
_abort_hook = CAST_TO_FN_PTR(abort_hook_t, option->extraInfo); _abort_hook = CAST_TO_FN_PTR(abort_hook_t, option->extraInfo);
// -XX:+AggressiveHeap
} else if (match_option(option, "-XX:+AggressiveHeap", &tail)) {
// This option inspects the machine and attempts to set various
// parameters to be optimal for long-running, memory allocation
// intensive jobs. It is intended for machines with large
// amounts of cpu and memory.
// initHeapSize is needed since _initial_heap_size is 4 bytes on a 32 bit
// VM, but we may not be able to represent the total physical memory
// available (like having 8gb of memory on a box but using a 32bit VM).
// Thus, we need to make sure we're using a julong for intermediate
// calculations.
julong initHeapSize;
julong total_memory = os::physical_memory();
if (total_memory < (julong)256*M) {
jio_fprintf(defaultStream::error_stream(),
"You need at least 256mb of memory to use -XX:+AggressiveHeap\n");
vm_exit(1);
}
// The heap size is half of available memory, or (at most)
// all of possible memory less 160mb (leaving room for the OS
// when using ISM). This is the maximum; because adaptive sizing
// is turned on below, the actual space used may be smaller.
initHeapSize = MIN2(total_memory / (julong)2,
total_memory - (julong)160*M);
initHeapSize = limit_by_allocatable_memory(initHeapSize);
if (FLAG_IS_DEFAULT(MaxHeapSize)) {
FLAG_SET_CMDLINE(uintx, MaxHeapSize, initHeapSize);
FLAG_SET_CMDLINE(uintx, InitialHeapSize, initHeapSize);
// Currently the minimum size and the initial heap sizes are the same.
set_min_heap_size(initHeapSize);
}
if (FLAG_IS_DEFAULT(NewSize)) {
// Make the young generation 3/8ths of the total heap.
FLAG_SET_CMDLINE(uintx, NewSize,
((julong)MaxHeapSize / (julong)8) * (julong)3);
FLAG_SET_CMDLINE(uintx, MaxNewSize, NewSize);
}
#ifndef _ALLBSD_SOURCE // UseLargePages is not yet supported on BSD.
FLAG_SET_DEFAULT(UseLargePages, true);
#endif
// Increase some data structure sizes for efficiency
FLAG_SET_CMDLINE(uintx, BaseFootPrintEstimate, MaxHeapSize);
FLAG_SET_CMDLINE(bool, ResizeTLAB, false);
FLAG_SET_CMDLINE(uintx, TLABSize, 256*K);
// See the OldPLABSize comment below, but replace 'after promotion'
// with 'after copying'. YoungPLABSize is the size of the survivor
// space per-gc-thread buffers. The default is 4kw.
FLAG_SET_CMDLINE(uintx, YoungPLABSize, 256*K); // Note: this is in words
// OldPLABSize is the size of the buffers in the old gen that
// UseParallelGC uses to promote live data that doesn't fit in the
// survivor spaces. At any given time, there's one for each gc thread.
// The default size is 1kw. These buffers are rarely used, since the
// survivor spaces are usually big enough. For specjbb, however, there
// are occasions when there's lots of live data in the young gen
// and we end up promoting some of it. We don't have a definite
// explanation for why bumping OldPLABSize helps, but the theory
// is that a bigger PLAB results in retaining something like the
// original allocation order after promotion, which improves mutator
// locality. A minor effect may be that larger PLABs reduce the
// number of PLAB allocation events during gc. The value of 8kw
// was arrived at by experimenting with specjbb.
FLAG_SET_CMDLINE(uintx, OldPLABSize, 8*K); // Note: this is in words
// Enable parallel GC and adaptive generation sizing
FLAG_SET_CMDLINE(bool, UseParallelGC, true);
// Encourage steady state memory management
FLAG_SET_CMDLINE(uintx, ThresholdTolerance, 100);
// This appears to improve mutator locality
FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false);
// Get around early Solaris scheduling bug
// (affinity vs other jobs on system)
// but disallow DR and offlining (5008695).
FLAG_SET_CMDLINE(bool, BindGCTaskThreadsToCPUs, true);
} else if (match_option(option, "-XX:+NeverTenure", &tail)) { } else if (match_option(option, "-XX:+NeverTenure", &tail)) {
// The last option must always win. // The last option must always win.
FLAG_SET_CMDLINE(bool, AlwaysTenure, false); FLAG_SET_CMDLINE(bool, AlwaysTenure, false);
...@@ -3605,6 +3627,15 @@ jint Arguments::finalize_vm_init_args(SysClassPath* scp_p, bool scp_assembly_req ...@@ -3605,6 +3627,15 @@ jint Arguments::finalize_vm_init_args(SysClassPath* scp_p, bool scp_assembly_req
return JNI_ERR; return JNI_ERR;
} }
// This must be done after all arguments have been processed
// and the container support has been initialized since AggressiveHeap
// relies on the amount of total memory available.
if (AggressiveHeap) {
jint result = set_aggressive_heap_flags();
if (result != JNI_OK) {
return result;
}
}
// This must be done after all arguments have been processed. // This must be done after all arguments have been processed.
// java_compiler() true means set to "NONE" or empty. // java_compiler() true means set to "NONE" or empty.
if (java_compiler() && !xdebug_mode()) { if (java_compiler() && !xdebug_mode()) {
......
/* /*
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -365,6 +365,8 @@ class Arguments : AllStatic { ...@@ -365,6 +365,8 @@ class Arguments : AllStatic {
// Aggressive optimization flags. // Aggressive optimization flags.
static void set_aggressive_opts_flags(); static void set_aggressive_opts_flags();
static jint set_aggressive_heap_flags();
// Argument parsing // Argument parsing
static void do_pd_flag_adjustments(); static void do_pd_flag_adjustments();
static bool parse_argument(const char* arg, Flag::Flags origin); static bool parse_argument(const char* arg, Flag::Flags origin);
......
...@@ -2064,13 +2064,23 @@ class CommandLineFlags { ...@@ -2064,13 +2064,23 @@ class CommandLineFlags {
product_pd(uint64_t, MaxRAM, \ product_pd(uint64_t, MaxRAM, \
"Real memory size (in bytes) used to set maximum heap size") \ "Real memory size (in bytes) used to set maximum heap size") \
\ \
product(bool, AggressiveHeap, false, \
"Optimize heap options for long-running memory intensive apps") \
\
product(uintx, ErgoHeapSizeLimit, 0, \ product(uintx, ErgoHeapSizeLimit, 0, \
"Maximum ergonomically set heap size (in bytes); zero means use " \ "Maximum ergonomically set heap size (in bytes); zero means use " \
"MaxRAM / MaxRAMFraction") \ "MaxRAM * MaxRAMPercentage / 100") \
\ \
experimental(bool, UseCGroupMemoryLimitForHeap, false, \ experimental(bool, UseCGroupMemoryLimitForHeap, false, \
"Use CGroup memory limit as physical memory limit for heap " \ "Use CGroup memory limit as physical memory limit for heap " \
"sizing") \ "sizing" \
"Deprecated, replaced by container support") \
\
diagnostic(bool, PrintContainerInfo, false, \
"Print container related information") \
\
diagnostic(bool, PrintActiveCpus, false, \
"Print the number of CPUs detected in os::active_processor_count") \
\ \
product(uintx, MaxRAMFraction, 4, \ product(uintx, MaxRAMFraction, 4, \
"Maximum fraction (1/n) of real memory used for maximum heap " \ "Maximum fraction (1/n) of real memory used for maximum heap " \
...@@ -2087,6 +2097,19 @@ class CommandLineFlags { ...@@ -2087,6 +2097,19 @@ class CommandLineFlags {
product(uintx, InitialRAMFraction, 64, \ product(uintx, InitialRAMFraction, 64, \
"Fraction (1/n) of real memory used for initial heap size") \ "Fraction (1/n) of real memory used for initial heap size") \
\ \
product(double, MaxRAMPercentage, 25.0, \
"Maximum percentage of real memory used for maximum heap size") \
\
product(double, MinRAMPercentage, 50.0, \
"Minimum percentage of real memory used for maximum heap" \
"size on systems with small physical memory size") \
\
product(double, InitialRAMPercentage, 1.5625, \
"Percentage of real memory used for initial heap size") \
\
product(intx, ActiveProcessorCount, -1, \
"Specify the CPU count the VM should use and report as active") \
\
develop(uintx, MaxVirtMemFraction, 2, \ develop(uintx, MaxVirtMemFraction, 2, \
"Maximum fraction (1/n) of virtual memory used for ergonomically "\ "Maximum fraction (1/n) of virtual memory used for ergonomically "\
"determining maximum heap size") \ "determining maximum heap size") \
......
...@@ -152,8 +152,16 @@ class os: AllStatic { ...@@ -152,8 +152,16 @@ class os: AllStatic {
static size_t page_size_for_region(size_t region_size, size_t min_pages, bool must_be_aligned); static size_t page_size_for_region(size_t region_size, size_t min_pages, bool must_be_aligned);
static void initialize_initial_active_processor_count(); static void initialize_initial_active_processor_count();
LINUX_ONLY(static void pd_init_container_support();)
public: public:
static void init(void); // Called before command line parsing static void init(void); // Called before command line parsing
static void init_container_support() { // Called during command line parsing.
LINUX_ONLY(pd_init_container_support();)
}
static void init_before_ergo(void); // Called after command line parsing static void init_before_ergo(void); // Called after command line parsing
// before VM ergonomics processing. // before VM ergonomics processing.
static jint init_2(void); // Called after command line parsing static jint init_2(void); // Called after command line parsing
......
...@@ -3335,6 +3335,7 @@ jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) { ...@@ -3335,6 +3335,7 @@ jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) {
Arguments::init_version_specific_system_properties(); Arguments::init_version_specific_system_properties();
// Parse arguments // Parse arguments
// Note: this internally calls os::init_container_support()
jint parse_result = Arguments::parse(args); jint parse_result = Arguments::parse(args);
if (parse_result != JNI_OK) return parse_result; if (parse_result != JNI_OK) return parse_result;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册