2323 */
2424
2525#include " cgroupUtil_linux.hpp"
26- #include " os_linux.hpp"
2726
2827bool CgroupUtil::processor_count (CgroupCpuController* cpu_ctrl, int upper_bound, int & value) {
2928 assert (upper_bound > 0 , " upper bound of cpus must be positive" );
@@ -87,7 +86,7 @@ int CgroupUtil::get_updated_cpu_limit(CgroupCpuController* cpu,
8786 return lowest;
8887}
8988
90- void CgroupUtil::adjust_controller (CgroupMemoryController* mem) {
89+ void CgroupUtil::adjust_controller (CgroupMemoryController* mem, physical_memory_size_type upper_bound ) {
9190 assert (mem->cgroup_path () != nullptr , " invariant" );
9291 if (strstr (mem->cgroup_path (), " ../" ) != nullptr ) {
9392 log_warning (os, container)(" Cgroup memory controller path at '%s' seems to have moved "
@@ -105,17 +104,16 @@ void CgroupUtil::adjust_controller(CgroupMemoryController* mem) {
105104 char * cg_path = os::strdup (orig);
106105 char * last_slash;
107106 assert (cg_path[0 ] == ' /' , " cgroup path must start with '/'" );
108- physical_memory_size_type phys_mem = os::Linux::physical_memory ();
109107 char * limit_cg_path = nullptr ;
110108 physical_memory_size_type limit = value_unlimited;
111- physical_memory_size_type lowest_limit = phys_mem ;
112- lowest_limit = get_updated_mem_limit (mem, lowest_limit, phys_mem );
113- physical_memory_size_type orig_limit = lowest_limit != phys_mem ? lowest_limit : phys_mem ;
109+ physical_memory_size_type lowest_limit = upper_bound ;
110+ lowest_limit = get_updated_mem_limit (mem, lowest_limit, upper_bound );
111+ physical_memory_size_type orig_limit = lowest_limit != upper_bound ? lowest_limit : upper_bound ;
114112 while ((last_slash = strrchr (cg_path, ' /' )) != cg_path) {
115113 *last_slash = ' \0 ' ; // strip path
116114 // update to shortened path and try again
117115 mem->set_subsystem_path (cg_path);
118- limit = get_updated_mem_limit (mem, lowest_limit, phys_mem );
116+ limit = get_updated_mem_limit (mem, lowest_limit, upper_bound );
119117 if (limit < lowest_limit) {
120118 lowest_limit = limit;
121119 os::free (limit_cg_path); // handles nullptr
@@ -124,13 +122,13 @@ void CgroupUtil::adjust_controller(CgroupMemoryController* mem) {
124122 }
125123 // need to check limit at mount point
126124 mem->set_subsystem_path (" /" );
127- limit = get_updated_mem_limit (mem, lowest_limit, phys_mem );
125+ limit = get_updated_mem_limit (mem, lowest_limit, upper_bound );
128126 if (limit < lowest_limit) {
129127 lowest_limit = limit;
130128 os::free (limit_cg_path); // handles nullptr
131129 limit_cg_path = os::strdup (" /" );
132130 }
133- assert (lowest_limit <= phys_mem , " limit must not exceed host memory " );
131+ assert (lowest_limit <= upper_bound , " limit must not exceed upper bound " );
134132 if (lowest_limit != orig_limit) {
135133 // we've found a lower limit anywhere in the hierarchy,
136134 // set the path to the limit path
@@ -152,7 +150,7 @@ void CgroupUtil::adjust_controller(CgroupMemoryController* mem) {
152150 os::free (limit_cg_path);
153151}
154152
155- void CgroupUtil::adjust_controller (CgroupCpuController* cpu) {
153+ void CgroupUtil::adjust_controller (CgroupCpuController* cpu, int upper_bound ) {
156154 assert (cpu->cgroup_path () != nullptr , " invariant" );
157155 if (strstr (cpu->cgroup_path (), " ../" ) != nullptr ) {
158156 log_warning (os, container)(" Cgroup cpu controller path at '%s' seems to have moved "
@@ -170,26 +168,25 @@ void CgroupUtil::adjust_controller(CgroupCpuController* cpu) {
170168 char * cg_path = os::strdup (orig);
171169 char * last_slash;
172170 assert (cg_path[0 ] == ' /' , " cgroup path must start with '/'" );
173- int host_cpus = os::Linux::active_processor_count ();
174- int lowest_limit = host_cpus;
175- int cpus = get_updated_cpu_limit (cpu, lowest_limit, host_cpus);
176- int orig_limit = lowest_limit != host_cpus ? lowest_limit : host_cpus;
171+ int lowest_limit = upper_bound;
172+ int cpus = get_updated_cpu_limit (cpu, lowest_limit, upper_bound);
173+ int orig_limit = lowest_limit != upper_bound ? lowest_limit : upper_bound;
177174 char * limit_cg_path = nullptr ;
178175 while ((last_slash = strrchr (cg_path, ' /' )) != cg_path) {
179176 *last_slash = ' \0 ' ; // strip path
180177 // update to shortened path and try again
181178 cpu->set_subsystem_path (cg_path);
182- cpus = get_updated_cpu_limit (cpu, lowest_limit, host_cpus );
183- if (cpus != host_cpus && cpus < lowest_limit) {
179+ cpus = get_updated_cpu_limit (cpu, lowest_limit, upper_bound );
180+ if (cpus != upper_bound && cpus < lowest_limit) {
184181 lowest_limit = cpus;
185182 os::free (limit_cg_path); // handles nullptr
186183 limit_cg_path = os::strdup (cg_path);
187184 }
188185 }
189186 // need to check limit at mount point
190187 cpu->set_subsystem_path (" /" );
191- cpus = get_updated_cpu_limit (cpu, lowest_limit, host_cpus );
192- if (cpus != host_cpus && cpus < lowest_limit) {
188+ cpus = get_updated_cpu_limit (cpu, lowest_limit, upper_bound );
189+ if (cpus != upper_bound && cpus < lowest_limit) {
193190 lowest_limit = cpus;
194191 os::free (limit_cg_path); // handles nullptr
195192 limit_cg_path = os::strdup (cg_path);
0 commit comments