/* cpu_shares * *Returntheamountofcpusharesavailabletotheprocess * *return: *Sharenumber(typicallyanumberrelativeto1024) *(2048typicallyexpresses2CPUsworthofprocessing) *-1fornosharesetup *OSCONTAINER_ERRORfornotsupported
*/ int CgroupV2Subsystem::cpu_shares() {
GET_CONTAINER_INFO(int, _unified, "/cpu.weight", "Raw value for CPU Shares is: %d", "%d", shares); // Convert default value of 100 to no shares setup if (shares == 100) {
log_debug(os, container)("CPU Shares is: %d", -1); return -1;
}
// CPU shares (OCI) value needs to get translated into // a proper Cgroups v2 value. See: // https://github.com/containers/crun/blob/master/crun.1.md#cpu-controller // // Use the inverse of (x == OCI value, y == cgroupsv2 value): // ((262142 * y - 1)/9999) + 2 = x // int x = 262142 * shares - 1; double frac = x/9999.0;
x = ((int)frac) + 2;
log_trace(os, container)("Scaled CPU shares value is: %d", x); // Since the scaled value is not precise, return the closest // multiple of PER_CPU_SHARES for a more conservative mapping if ( x <= PER_CPU_SHARES ) { // will always map to 1 CPU
log_debug(os, container)("CPU Shares is: %d", x); return x;
} int f = x/PER_CPU_SHARES; int lower_multiple = f * PER_CPU_SHARES; int upper_multiple = (f + 1) * PER_CPU_SHARES; int distance_lower = MAX2(lower_multiple, x) - MIN2(lower_multiple, x); int distance_upper = MAX2(upper_multiple, x) - MIN2(upper_multiple, x);
x = distance_lower <= distance_upper ? lower_multiple : upper_multiple;
log_trace(os, container)("Closest multiple of %d of the CPU Shares value is: %d", PER_CPU_SHARES, x);
log_debug(os, container)("CPU Shares is: %d", x); return x;
}
char* CgroupV2Subsystem::cpu_quota_val() {
GET_CONTAINER_INFO_CPTR(cptr, _unified, "/cpu.max", "Raw value for CPU quota is: %s", "%1023s %*d", quota, 1024); return os::strdup(quota);
}
jlong CgroupV2Subsystem::memory_max_usage_in_bytes() { // Log this string at trace level so as to make tests happy.
log_trace(os, container)("Maximum Memory Usage is not supported."); return OSCONTAINER_ERROR; // not supported
}
// Note that for cgroups v2 the actual limits set for swap and // memory live in two different files, memory.swap.max and memory.max // respectively. In order to properly report a cgroup v1 like // compound value we need to sum the two values. Setting a swap limit // without also setting a memory limit is not allowed.
jlong CgroupV2Subsystem::memory_and_swap_limit_in_bytes() { char* mem_swp_limit_str = mem_swp_limit_val();
jlong swap_limit = limit_from_str(mem_swp_limit_str); if (swap_limit >= 0) {
jlong memory_limit = read_memory_limit_in_bytes();
assert(memory_limit >= 0, "swap limit without memory limit?"); return memory_limit + swap_limit;
} return swap_limit;
}
char* CgroupV2Subsystem::mem_swp_limit_val() {
GET_CONTAINER_INFO_CPTR(cptr, _unified, "/memory.swap.max", "Memory and Swap Limit is: %s", "%1023s", mem_swp_limit_str, 1024); return os::strdup(mem_swp_limit_str);
}
// memory.swap.current : total amount of swap currently used by the cgroup and its descendants char* CgroupV2Subsystem::mem_swp_current_val() {
GET_CONTAINER_INFO_CPTR(cptr, _unified, "/memory.swap.current", "Swap currently used is: %s", "%1023s", mem_swp_current_str, 1024); return os::strdup(mem_swp_current_str);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.