]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc-top: show kernel memory being used if available
authorDwight Engen <dwight.engen@gmail.com>
Thu, 31 Oct 2013 20:38:36 +0000 (16:38 -0400)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Mon, 4 Nov 2013 12:37:11 +0000 (06:37 -0600)
- Also removed duplicate stats_clear lua function

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
doc/lxc-top.sgml.in
src/lua-lxc/lxc.lua
src/lxc/lxc-top

index 0021154957a4027430c8c2e25a01ecc74e8c190d..ba727c57144958bc00c9ca3b0ee96d0509f85e9c 100644 (file)
@@ -58,11 +58,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     <title>Description</title>
     <para>
       <command>lxc-top</command> displays container statistics. The output
-        is updated every <replaceable>delay</replaceable> seconds, and is
-        ordered according to the <replaceable>sortby</replaceable> value
-        given. Specifying <replaceable>count</replaceable> will limit the
-        number of containers displayed, otherwise <command>lxc-top</command>
-        will display as many containers as can fit in your terminal.
+      is updated every <replaceable>delay</replaceable> seconds, and is
+      ordered according to the <replaceable>sortby</replaceable> value
+      given. Specifying <replaceable>count</replaceable> will limit the
+      number of containers displayed, otherwise <command>lxc-top</command>
+      will display as many containers as can fit in your terminal.
     </para>
   </refsect1>
 
@@ -103,8 +103,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
           <para>
             Sort the containers by name, cpu use, or memory use. The
             <replaceable>sortby</replaceable> argument should be one of
-            the letters n,c,d,m to sort by name, cpu use, disk I/O, or
-            memory use respectively. The default is 'n'.
+            the letters n,c,d,m,k to sort by name, cpu use, disk I/O, memory,
+            or kernel memory use respectively. The default is 'n'.
           </para>
         </listitem>
       </varlistentry>
@@ -137,6 +137,25 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     </variablelist>
   </refsect1>
 
+  <refsect1>
+    <title>Notes</title>
+    <para>
+      For performance reasons the kernel does not account kernel memory use
+      unless a kernel memory limit is set. If a limit is not set, <command>
+      lxc-top</command> will display kernel memory use as 0. If no containers
+      are being accounted, the KMem column will not be displayed. A limit can
+      be set by specifying
+      <programlisting>
+      lxc.cgroup.memory.kmem.limit_in_bytes = <replaceable>number</replaceable>
+      </programlisting>
+      in your container configuration file, see
+      <citerefentry>
+        <refentrytitle>lxc.conf</refentrytitle>
+        <manvolnum>5</manvolnum>
+      </citerefentry>.
+    </para>
+  </refsect1>
+
   &seealso;
 
   <refsect1>
index 5a3b49e2c900b4a1a45eb88baeaceee0c2acd707..265e991ad10ffe5e5b18338f66ba82d974f38bc9 100755 (executable)
@@ -289,6 +289,8 @@ function container:stats_get(total)
     stat.mem_limit     = self:stat_get_int("memory.limit_in_bytes")
     stat.memsw_used    = self:stat_get_int("memory.memsw.usage_in_bytes")
     stat.memsw_limit   = self:stat_get_int("memory.memsw.limit_in_bytes")
+    stat.kmem_used     = self:stat_get_int("memory.kmem.usage_in_bytes")
+    stat.kmem_limit    = self:stat_get_int("memory.kmem.limit_in_bytes")
     stat.cpu_use_nanos = self:stat_get_int("cpuacct.usage")
     stat.cpu_use_user,
     stat.cpu_use_sys   = self:stat_get_ints("cpuacct.stat", {{1, 2}, {2, 2}})
@@ -299,6 +301,8 @@ function container:stats_get(total)
        total.mem_limit     = total.mem_limit     + stat.mem_limit
        total.memsw_used    = total.memsw_used    + stat.memsw_used
        total.memsw_limit   = total.memsw_limit   + stat.memsw_limit
+       total.kmem_used     = total.kmem_used     + stat.kmem_used
+       total.kmem_limit    = total.kmem_limit    + stat.kmem_limit
        total.cpu_use_nanos = total.cpu_use_nanos + stat.cpu_use_nanos
        total.cpu_use_user  = total.cpu_use_user  + stat.cpu_use_user
        total.cpu_use_sys   = total.cpu_use_sys   + stat.cpu_use_sys
@@ -314,17 +318,8 @@ function M.stats_clear(stat)
     stat.mem_limit     = 0
     stat.memsw_used    = 0
     stat.memsw_limit   = 0
-    stat.cpu_use_nanos = 0
-    stat.cpu_use_user  = 0
-    stat.cpu_use_sys   = 0
-    stat.blkio         = 0
-end
-
-function M.stats_clear(stat)
-    stat.mem_used      = 0
-    stat.mem_limit     = 0
-    stat.memsw_used    = 0
-    stat.memsw_limit   = 0
+    stat.kmem_used     = 0
+    stat.kmem_limit    = 0
     stat.cpu_use_nanos = 0
     stat.cpu_use_user  = 0
     stat.cpu_use_sys   = 0
index 35d7e02ac3a506670eeb811900a3bb5ebebd4ca4..a1f025010ff86d4979058c717a0237f4228076e3 100755 (executable)
@@ -117,12 +117,14 @@ function container_sort(a, b)
        elseif (optarg["s"] == "c") then return (stats[a].cpu_use_nanos < stats[b].cpu_use_nanos)
        elseif (optarg["s"] == "d") then return (stats[a].blkio < stats[b].blkio)
        elseif (optarg["s"] == "m") then return (stats[a].mem_used < stats[b].mem_used)
+       elseif (optarg["s"] == "k") then return (stats[a].kmem_used < stats[b].kmem_used)
        end
     else
        if     (optarg["s"] == "n") then return (a < b)
        elseif (optarg["s"] == "c") then return (stats[a].cpu_use_nanos > stats[b].cpu_use_nanos)
        elseif (optarg["s"] == "d") then return (stats[a].blkio > stats[b].blkio)
        elseif (optarg["s"] == "m") then return (stats[a].mem_used > stats[b].mem_used)
+       elseif (optarg["s"] == "k") then return (stats[a].kmem_used > stats[b].kmem_used)
        end
     end
 end
@@ -163,14 +165,19 @@ function container_list_update()
     table.sort(containers, container_sort)
 end
 
-function stats_print_header()
+function stats_print_header(stats_total)
     printf(TERMRVRS .. TERMBOLD)
-    printf("%-15s %8s %8s %8s %10s %10s\n", "Container", "CPU",  "CPU",  "CPU",  "BlkIO", "Mem")
-    printf("%-15s %8s %8s %8s %10s %10s\n", "Name",      "Used", "Sys",  "User", "Total", "Used")
+    printf("%-15s %8s %8s %8s %10s %10s", "Container", "CPU",  "CPU",  "CPU",  "BlkIO", "Mem")
+    if (stats_total.kmem_used > 0) then printf(" %10s", "KMem") end
+    printf("\n")
+
+    printf("%-15s %8s %8s %8s %10s %10s", "Name",      "Used", "Sys",  "User", "Total", "Used")
+    if (stats_total.kmem_used > 0) then printf(" %10s", "Used") end
+    printf("\n")
     printf(TERMNORM)
 end
 
-function stats_print(name, stats)
+function stats_print(name, stats, stats_total)
     printf("%-15s %8.2f %8.2f %8.2f %10s %10s",
           name,
           stats.cpu_use_nanos / 1000000000,
@@ -178,6 +185,9 @@ function stats_print(name, stats)
           stats.cpu_use_user / USER_HZ,
           strsisize(stats.blkio),
           strsisize(stats.mem_used))
+    if (stats_total.kmem_used > 0) then
+       printf(" %10s", strsisize(stats.kmem_used))
+    end
 end
 
 function usage()
@@ -190,6 +200,7 @@ function usage()
        "                 c = CPU use\n" ..
        "                 d = Disk I/O use\n" ..
        "                 m = Memory use\n" ..
+       "                 k = Kernel memory use\n" ..
        "  -r|--reverse   sort in reverse (descending) order\n"
     )
     os.exit(1)
@@ -219,15 +230,15 @@ do
     -- may fall back to this, or ncurses. ug.
     --os.execute("tput clear")
     printf(TERMCLEAR)
-    stats_print_header()
+    stats_print_header(stats_total)
     for index,ctname in ipairs(containers) do
-       stats_print(ctname, stats[ctname])
+       stats_print(ctname, stats[ctname], stats_total)
        printf("\n")
        if (index >= optarg["m"]) then
            break
        end
     end
-    stats_print(string.format("TOTAL (%-2d)", #containers), stats_total)
+    stats_print(string.format("TOTAL (%-2d)", #containers), stats_total, stats_total)
     io.flush()
     core.usleep(optarg["d"] * 1000000)
 end