src/hotspot/os/linux/os_linux.cpp
changeset 49175 6a5decfc5574
parent 48865 53427ddce0a0
child 49193 c3ec048aad63
equal deleted inserted replaced
49174:f842bb1e3885 49175:6a5decfc5574
   175   struct sysinfo si;
   175   struct sysinfo si;
   176   julong avail_mem;
   176   julong avail_mem;
   177 
   177 
   178   if (OSContainer::is_containerized()) {
   178   if (OSContainer::is_containerized()) {
   179     jlong mem_limit, mem_usage;
   179     jlong mem_limit, mem_usage;
   180     if ((mem_limit = OSContainer::memory_limit_in_bytes()) > 0) {
   180     if ((mem_limit = OSContainer::memory_limit_in_bytes()) < 1) {
   181       if ((mem_usage = OSContainer::memory_usage_in_bytes()) > 0) {
   181       log_debug(os, container)("container memory limit %s: " JLONG_FORMAT ", using host value",
   182         if (mem_limit > mem_usage) {
   182                              mem_limit == OSCONTAINER_ERROR ? "failed" : "unlimited", mem_limit);
   183           avail_mem = (julong)mem_limit - (julong)mem_usage;
   183     }
   184         } else {
   184     if (mem_limit > 0 && (mem_usage = OSContainer::memory_usage_in_bytes()) < 1) {
   185           avail_mem = 0;
   185       log_debug(os, container)("container memory usage failed: " JLONG_FORMAT ", using host value", mem_usage);
   186         }
   186     }
   187         log_trace(os)("available container memory: " JULONG_FORMAT, avail_mem);
   187     if (mem_limit > 0 && mem_usage > 0 ) {
   188         return avail_mem;
   188       avail_mem = mem_limit > mem_usage ? (julong)mem_limit - (julong)mem_usage : 0;
   189       } else {
   189       log_trace(os)("available container memory: " JULONG_FORMAT, avail_mem);
   190         log_debug(os,container)("container memory usage call failed: " JLONG_FORMAT, mem_usage);
   190       return avail_mem;
   191       }
       
   192     } else {
       
   193       log_debug(os,container)("container memory unlimited or failed: " JLONG_FORMAT, mem_limit);
       
   194     }
   191     }
   195   }
   192   }
   196 
   193 
   197   sysinfo(&si);
   194   sysinfo(&si);
   198   avail_mem = (julong)si.freeram * si.mem_unit;
   195   avail_mem = (julong)si.freeram * si.mem_unit;
   199   log_trace(os)("available memory: " JULONG_FORMAT, avail_mem);
   196   log_trace(os)("available memory: " JULONG_FORMAT, avail_mem);
   200   return avail_mem;
   197   return avail_mem;
   201 }
   198 }
   202 
   199 
   203 julong os::physical_memory() {
   200 julong os::physical_memory() {
       
   201   jlong phys_mem = 0;
   204   if (OSContainer::is_containerized()) {
   202   if (OSContainer::is_containerized()) {
   205     jlong mem_limit;
   203     jlong mem_limit;
   206     if ((mem_limit = OSContainer::memory_limit_in_bytes()) > 0) {
   204     if ((mem_limit = OSContainer::memory_limit_in_bytes()) > 0) {
   207       log_trace(os)("total container memory: " JLONG_FORMAT, mem_limit);
   205       log_trace(os)("total container memory: " JLONG_FORMAT, mem_limit);
   208       return (julong)mem_limit;
   206       return phys_mem;
   209     } else {
   207     }
   210       if (mem_limit == OSCONTAINER_ERROR) {
   208     log_debug(os, container)("container memory limit %s: " JLONG_FORMAT ", using host value",
   211         log_debug(os,container)("container memory limit call failed");
   209                             mem_limit == OSCONTAINER_ERROR ? "failed" : "unlimited", mem_limit);
   212       }
   210   }
   213       if (mem_limit == -1) {
   211 
   214         log_debug(os,container)("container memory unlimited, using host value");
   212   phys_mem = Linux::physical_memory();
   215       }
       
   216     }
       
   217   }
       
   218 
       
   219   jlong phys_mem = Linux::physical_memory();
       
   220   log_trace(os)("total system memory: " JLONG_FORMAT, phys_mem);
   213   log_trace(os)("total system memory: " JLONG_FORMAT, phys_mem);
   221   return phys_mem;
   214   return phys_mem;
   222 }
   215 }
   223 
   216 
   224 // Return true if user is running as root.
   217 // Return true if user is running as root.
  2133   _print_ascii_file("/proc/meminfo", st);
  2126   _print_ascii_file("/proc/meminfo", st);
  2134   st->cr();
  2127   st->cr();
  2135 }
  2128 }
  2136 
  2129 
  2137 void os::Linux::print_container_info(outputStream* st) {
  2130 void os::Linux::print_container_info(outputStream* st) {
  2138   if (OSContainer::is_containerized()) {
  2131   if (!OSContainer::is_containerized()) {
  2139     st->print("container (cgroup) information:\n");
  2132     return;
  2140 
  2133   }
  2141     char *p = OSContainer::container_type();
  2134 
  2142     if (p == NULL)
  2135   st->print("container (cgroup) information:\n");
  2143       st->print("container_type() failed\n");
  2136 
  2144     else {
  2137   const char *p_ct = OSContainer::container_type();
  2145       st->print("container_type: %s\n", p);
  2138   st->print("container_type: %s\n", p_ct != NULL ? p_ct : "failed");
  2146     }
  2139 
  2147 
  2140   char *p = OSContainer::cpu_cpuset_cpus();
  2148     p = OSContainer::cpu_cpuset_cpus();
  2141   st->print("cpu_cpuset_cpus: %s\n", p != NULL ? p : "failed");
  2149     if (p == NULL)
  2142   free(p);
  2150       st->print("cpu_cpuset_cpus() failed\n");
  2143 
  2151     else {
  2144   p = OSContainer::cpu_cpuset_memory_nodes();
  2152       st->print("cpu_cpuset_cpus: %s\n", p);
  2145   st->print("cpu_memory_nodes: %s\n", p != NULL ? p : "failed");
  2153       free(p);
  2146   free(p);
  2154     }
  2147 
  2155 
  2148   int i = OSContainer::active_processor_count();
  2156     p = OSContainer::cpu_cpuset_memory_nodes();
  2149   if (i > 0) {
  2157     if (p < 0)
  2150     st->print("active_processor_count: %d\n", i);
  2158       st->print("cpu_memory_nodes() failed\n");
  2151   } else {
  2159     else {
  2152     st->print("active_processor_count: failed\n");
  2160       st->print("cpu_memory_nodes: %s\n", p);
  2153   }
  2161       free(p);
  2154 
  2162     }
  2155   i = OSContainer::cpu_quota();
  2163 
  2156   st->print("cpu_quota: %d\n", i);
  2164     int i = OSContainer::active_processor_count();
  2157 
  2165     if (i < 0)
  2158   i = OSContainer::cpu_period();
  2166       st->print("active_processor_count() failed\n");
  2159   st->print("cpu_period: %d\n", i);
  2167     else
  2160 
  2168       st->print("active_processor_count: %d\n", i);
  2161   i = OSContainer::cpu_shares();
  2169 
  2162   st->print("cpu_shares: %d\n", i);
  2170     i = OSContainer::cpu_quota();
  2163 
  2171     st->print("cpu_quota: %d\n", i);
  2164   jlong j = OSContainer::memory_limit_in_bytes();
  2172 
  2165   st->print("memory_limit_in_bytes: " JLONG_FORMAT "\n", j);
  2173     i = OSContainer::cpu_period();
  2166 
  2174     st->print("cpu_period: %d\n", i);
  2167   j = OSContainer::memory_and_swap_limit_in_bytes();
  2175 
  2168   st->print("memory_and_swap_limit_in_bytes: " JLONG_FORMAT "\n", j);
  2176     i = OSContainer::cpu_shares();
  2169 
  2177     st->print("cpu_shares: %d\n", i);
  2170   j = OSContainer::memory_soft_limit_in_bytes();
  2178 
  2171   st->print("memory_soft_limit_in_bytes: " JLONG_FORMAT "\n", j);
  2179     jlong j = OSContainer::memory_limit_in_bytes();
  2172 
  2180     st->print("memory_limit_in_bytes: " JLONG_FORMAT "\n", j);
  2173   j = OSContainer::OSContainer::memory_usage_in_bytes();
  2181 
  2174   st->print("memory_usage_in_bytes: " JLONG_FORMAT "\n", j);
  2182     j = OSContainer::memory_and_swap_limit_in_bytes();
  2175 
  2183     st->print("memory_and_swap_limit_in_bytes: " JLONG_FORMAT "\n", j);
  2176   j = OSContainer::OSContainer::memory_max_usage_in_bytes();
  2184 
  2177   st->print("memory_max_usage_in_bytes: " JLONG_FORMAT "\n", j);
  2185     j = OSContainer::memory_soft_limit_in_bytes();
  2178   st->cr();
  2186     st->print("memory_soft_limit_in_bytes: " JLONG_FORMAT "\n", j);
       
  2187 
       
  2188     j = OSContainer::OSContainer::memory_usage_in_bytes();
       
  2189     st->print("memory_usage_in_bytes: " JLONG_FORMAT "\n", j);
       
  2190 
       
  2191     j = OSContainer::OSContainer::memory_max_usage_in_bytes();
       
  2192     st->print("memory_max_usage_in_bytes: " JLONG_FORMAT "\n", j);
       
  2193     st->cr();
       
  2194   }
       
  2195 }
  2179 }
  2196 
  2180 
  2197 void os::print_memory_info(outputStream* st) {
  2181 void os::print_memory_info(outputStream* st) {
  2198 
  2182 
  2199   st->print("Memory:");
  2183   st->print("Memory:");