[lxc-devel] [PATCH] lxc-ls: Fix memory reporting

Serge Hallyn serge.hallyn at ubuntu.com
Mon Mar 24 18:47:13 UTC 2014


Quoting Stéphane Graber (stgraber at ubuntu.com):
> 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 at ubuntu.com>

Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>

> ---
>  src/lxc/lxc-ls.in | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/src/lxc/lxc-ls.in b/src/lxc/lxc-ls.in
> index 7e35ab2..19fbfb8 100755
> --- a/src/lxc/lxc-ls.in
> +++ b/src/lxc/lxc-ls.in
> @@ -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'] = "-"
>  
> @@ -330,8 +331,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)
> -- 
> 1.9.1
> 
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel


More information about the lxc-devel mailing list