@@ -123,6 +123,12 @@ void CgroupV1Controller::set_subsystem_path(const char* cgroup_path) {
123123 }
124124}
125125
126+ jlong CgroupV1MemoryController::uses_mem_hierarchy () {
127+ julong use_hierarchy;
128+ CONTAINER_READ_NUMBER_CHECKED (reader (), " /memory.use_hierarchy" , " Use Hierarchy" , use_hierarchy);
129+ return (jlong)use_hierarchy;
130+ }
131+
126132/*
127133 * The common case, containers, we have _root == _cgroup_path, and thus set the
128134 * controller path to the _mount_point. This is where the limits are exposed in
@@ -159,13 +165,13 @@ void verbose_log(julong read_mem_limit, julong host_mem) {
159165jlong CgroupV1MemoryController::read_memory_limit_in_bytes (julong phys_mem) {
160166 julong memlimit;
161167 CONTAINER_READ_NUMBER_CHECKED (reader (), " /memory.limit_in_bytes" , " Memory Limit" , memlimit);
162- if (memlimit >= phys_mem) {
163- verbose_log (memlimit, phys_mem);
164- return (jlong)-1 ;
165- } else {
166- verbose_log (memlimit, phys_mem);
167- return (jlong)memlimit;
168+ if (memlimit >= phys_mem && uses_mem_hierarchy ()) {
169+ CONTAINER_READ_NUMERICAL_KEY_VALUE_CHECKED (reader (), " /memory.stat" ,
170+ " hierarchical_memory_limit" , " Hierarchical Memory Limit" ,
171+ memlimit);
168172 }
173+ verbose_log (memlimit, phys_mem);
174+ return (jlong)((memlimit < phys_mem) ? memlimit : -1 );
169175}
170176
171177/* read_mem_swap
@@ -183,12 +189,13 @@ jlong CgroupV1MemoryController::read_memory_limit_in_bytes(julong phys_mem) {
183189jlong CgroupV1MemoryController::read_mem_swap (julong host_total_memsw) {
184190 julong memswlimit;
185191 CONTAINER_READ_NUMBER_CHECKED (reader (), " /memory.memsw.limit_in_bytes" , " Memory and Swap Limit" , memswlimit);
186- if (memswlimit >= host_total_memsw) {
187- log_trace (os, container)(" Memory and Swap Limit is: Unlimited" );
188- return (jlong)-1 ;
189- } else {
190- return (jlong)memswlimit;
192+ if (memswlimit >= host_total_memsw && uses_mem_hierarchy ()) {
193+ CONTAINER_READ_NUMERICAL_KEY_VALUE_CHECKED (reader (), " /memory.stat" ,
194+ " hierarchical_memsw_limit" , " Hierarchical Memory and Swap Limit" ,
195+ memswlimit);
191196 }
197+ verbose_log (memswlimit, host_total_memsw);
198+ return (jlong)((memswlimit < host_total_memsw) ? memswlimit : -1 );
192199}
193200
194201jlong CgroupV1MemoryController::memory_and_swap_limit_in_bytes (julong host_mem, julong host_swap) {
0 commit comments