La columna SWAP en el comando top

Por defecto no aparece, pero como vimos en la entrada «añadir más columnas a la salida del comando TOP» es posible añadir una columna para la visualización de la memoria Swap, presionando «O» y eligiendo las columnas correspondientes:

p: SWAP       = Swapped size (kb)

Pasamos a ver la columna  y ordenar por ella si seleccionamos «p»:

top - 19:43:06 up  2:05,  1 user,  load average: 0.64, 1.14, 1.41
Tasks: 140 total,   1 running, 138 sleeping,   0 stopped,   1 zombie
Cpu0  :  9.7%us,  2.8%sy,  0.0%ni, 86.5%id,  0.7%wa,  0.0%hi,  0.3%si,  0.0%st
Cpu1  :  6.8%us,  2.7%sy,  0.0%ni, 90.4%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   2052544k total,  1909184k used,   143360k free,    12968k buffers
Swap:  2084860k total,    30828k used,  2054032k free,  1181436k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  SWAP COMMAND
 1880 alex      20   0 1045m 3248 2320 S    0  0.2   0:00.01 1.0g nacl_helper_boo
 2118 alex      20   0  423m  22m  10m S    0  1.1  19:13.70 401m chrome
 1869 alex      20   0  511m 151m  30m S    1  7.6  12:51.97 359m chrome
 1725 alex      20   0  263m 7916 5100 S    0  0.4   0:00.47 256m xfce4-volumed
 1734 alex       9 -11  161m 4684 3200 S    2  0.2   2:55.23 156m pulseaudio
 1781 alex      20   0  218m  62m  14m S    6  3.1   5:24.10 155m gmusicbrowser
 1904 alex      20   0  267m 115m  23m S    0  5.8   2:00.31 151m chrome
 1910 alex      20   0  214m  64m  21m S    0  3.2   2:07.24 149m chrome
 2184 alex      20   0  193m  47m  20m S    0  2.4   0:23.45 146m chrome
 4549 alex      20   0  201m  56m  23m S    0  2.8   0:12.45 144m chrome
 1942 alex      20   0  205m  61m  19m S    0  3.1   0:03.91 144m chrome
 4480 alex      20   0  253m 112m  21m S    0  5.6   0:11.17 141m chrome
 4532 alex      20   0  188m  47m  21m S    0  2.4   0:02.92 140m chrome
 1935 alex      20   0  184m  45m  20m S    0  2.3   0:02.40 139m chrome
 1881 alex      20   0  133m 4868  744 S    0  0.2   0:00.16 128m chrome
 1876 alex      20   0  125m 9356 5244 S    0  0.5   0:00.06 116m chrome
 1874 alex      20   0 97688 5284 2260 S    0  0.3   0:08.01  90m chrome

Pero ojo, veréis que los datos obtenidos no cuadran, en el caso anterior sólo está swapeando 30828k y ya sólo el primer proceso muestra 1.0g de swap… según la documentación:

      p: SWAP  --  Swapped size (kb)
          Memory that is not resident but is present in a task.
          This is memory that has been swapped out  but  could include
          additional non-resident memory.  This column is calculated by
          subtracting physical memory from vir‐tual memory.

Parece ser que top muestra el valor de memoria que el proceso llegaría a utilizar si toda le memoria utilizada fuera swap (algo controlable a través de swappiness, recordad), pero no la memoria swap utilizada por el proceso en ese momento, lo que hace es calcularlo del siguiente modo: SWAP = VIRT – RES.

Mirad por ejemplo lo que comenta el creador de htop en las FAQ del sitio web oficial:

Why doesn’t htop feature a SWAP column, like top?

It is not possible to get the exact size of used swap space of a process. Top fakes this information by making SWAP = VIRT – RES, but that is not a good metric, because other stuff such as video memory counts on VIRT as well (for example: top says my X process is using 81M of swap, but it also reports my system as a whole is using only 2M of swap. Therefore, I will not add a similar Swap column to htop because I don’t know a reliable way to get this information (actually, I don’t think it’s possible to get an exact number, because of shared pages).

Así que ya sabéis, no os fiéis de este valor del comando top para calcular el uso de memoria swap de un proceso.

Un comentario en “La columna SWAP en el comando top

  1. Es interesante ese dato. A veces saber la memoria libre u ocupada en un sistema linux tiene su dificultad. Supongo que será por la cantidad de trucos que usa el kernel para optimizarla. Lo más dificil debe se ser tener en cuenta la memoria compartida por varios procesos.

    Muy buena página. Saludos.

Comments are closed.