]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc-ls: Fix memory reporting
authorStéphane Graber <stgraber@ubuntu.com>
Sat, 22 Mar 2014 23:17:36 +0000 (19:17 -0400)
committerStéphane Graber <stgraber@ubuntu.com>
Mon, 24 Mar 2014 22:29:23 +0000 (18:29 -0400)
This resolves the memory math when memsw is enabled and fixes reporting
of nested containers memory when using cgmanager.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
src/lxc/lxc-ls.in

index 908a64a50826824539047df56d37e5bd01809de2..600085728d8f5fc6e0dbb96b95e730981fb0fb20 100755 (executable)
@@ -272,20 +272,22 @@ def get_containers(fd=None, base="/", root=False):
 
                 if container.running:
                     try:
-                        memory_total = int(container.get_cgroup_item(
+                        memory_ram = int(container.get_cgroup_item(
                             "memory.usage_in_bytes"))
                     except:
-                        memory_total = 0
+                        memory_ram = 0
 
                     try:
                         memory_swap = int(container.get_cgroup_item(
-                            "memory.memsw.usage_in_bytes"))
+                            "memory.memsw.usage_in_bytes")) - memory_ram
                     except:
                         memory_swap = 0
                 else:
-                    memory_total = 0
+                    memory_ram = 0
                     memory_swap = 0
 
+                memory_total = memory_ram + memory_swap
+
             if 'memory' in args.fancy_format:
                 if container.running:
                     entry['memory'] = "%sMB" % round(memory_total / 1048576, 2)
@@ -294,8 +296,7 @@ def get_containers(fd=None, base="/", root=False):
 
             if 'ram' in args.fancy_format:
                 if container.running:
-                    entry['ram'] = "%sMB" % round(
-                        (memory_total - memory_swap) / 1048576, 2)
+                    entry['ram'] = "%sMB" % round(memory_ram / 1048576, 2)
                 else:
                     entry['ram'] = "-"
 
@@ -342,8 +343,7 @@ def get_containers(fd=None, base="/", root=False):
                     temp_fd, temp_file = tempfile.mkstemp()
                     os.remove(temp_file)
 
-                    container.attach_wait(get_containers, temp_fd,
-                                          attach_flags=0)
+                    container.attach_wait(get_containers, temp_fd)
 
                     json_file = os.fdopen(temp_fd, "r")
                     json_file.seek(0)