@@ -124,6 +124,12 @@ void CgroupV1Controller::set_subsystem_path(const char* cgroup_path) {
124124 }
125125}
126126
127+ jlong CgroupV1MemoryController::uses_mem_hierarchy () {
128+ julong use_hierarchy;
129+ CONTAINER_READ_NUMBER_CHECKED (reader (), " /memory.use_hierarchy" , " Use Hierarchy" , use_hierarchy);
130+ return (jlong)use_hierarchy;
131+ }
132+
127133/*
128134 * The common case, containers, we have _root == _cgroup_path, and thus set the
129135 * controller path to the _mount_point. This is where the limits are exposed in
@@ -160,13 +166,13 @@ void verbose_log(julong read_mem_limit, julong upper_mem_bound) {
160166jlong CgroupV1MemoryController::read_memory_limit_in_bytes (julong upper_bound) {
161167 julong memlimit;
162168 CONTAINER_READ_NUMBER_CHECKED (reader (), " /memory.limit_in_bytes" , " Memory Limit" , memlimit);
163- if (memlimit >= upper_bound) {
164- verbose_log (memlimit, upper_bound);
165- return (jlong)-1 ;
166- } else {
167- verbose_log (memlimit, upper_bound);
168- return (jlong)memlimit;
169+ if (memlimit >= upper_bound && uses_mem_hierarchy ()) {
170+ CONTAINER_READ_NUMERICAL_KEY_VALUE_CHECKED (reader (), " /memory.stat" ,
171+ " hierarchical_memory_limit" , " Hierarchical Memory Limit" ,
172+ memlimit);
169173 }
174+ verbose_log (memlimit, upper_bound);
175+ return (jlong)((memlimit < upper_bound) ? memlimit : -1 );
170176}
171177
172178/* read_mem_swap
@@ -184,12 +190,13 @@ jlong CgroupV1MemoryController::read_memory_limit_in_bytes(julong upper_bound) {
184190jlong CgroupV1MemoryController::read_mem_swap (julong upper_memsw_bound) {
185191 julong memswlimit;
186192 CONTAINER_READ_NUMBER_CHECKED (reader (), " /memory.memsw.limit_in_bytes" , " Memory and Swap Limit" , memswlimit);
187- if (memswlimit >= upper_memsw_bound) {
188- log_trace (os, container)(" Memory and Swap Limit is: Unlimited" );
189- return (jlong)-1 ;
190- } else {
191- return (jlong)memswlimit;
193+ if (memswlimit >= upper_memsw_bound && uses_mem_hierarchy ()) {
194+ CONTAINER_READ_NUMERICAL_KEY_VALUE_CHECKED (reader (), " /memory.stat" ,
195+ " hierarchical_memsw_limit" , " Hierarchical Memory and Swap Limit" ,
196+ memswlimit);
192197 }
198+ verbose_log (memswlimit, upper_memsw_bound);
199+ return (jlong)((memswlimit < upper_memsw_bound) ? memswlimit : -1 );
193200}
194201
195202jlong CgroupV1MemoryController::memory_and_swap_limit_in_bytes (julong upper_mem_bound, julong upper_swap_bound) {
0 commit comments