Why would top show the processes are using swap when there is no swap space? - Linux

This is a discussion on Why would top show the processes are using swap when there is no swap space? - Linux ; My system has 4GB of RAM so I decided that I don't need to have swap space. However, in "top", I can still see that processes's virtual memory is the sum of the residential and swap memory. For example: Swap: ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: Why would top show the processes are using swap when there is no swap space?

  1. Why would top show the processes are using swap when there is no swap space?

    My system has 4GB of RAM so I decided that I don't need to have swap
    space.
    However, in "top", I can still see that processes's virtual memory is
    the
    sum of the residential and swap memory. For example:
    Swap: 0k total, 0k used, 0k free, 1189192k
    cached

    PID USER PR NI VIRT RES SWAP SHR S %CPU %MEM TIME+
    COMMAND
    9580 seki 15 0 2164 1160 1004 856 R 0.3 0.0 0:00.04 top

    This is part of the output from "top".
    We can confirm that no swap space is used.
    However, VIRT=RES+SWAP and SWAP is not zero:
    VIRT=2164, RES=1144, SWAP=1020 and 2164=1144+1020

    My question is: since there is no space disk, where to swap to pages
    to?
    Thanks a lot.


  2. Re: Why would top show the processes are using swap when there is no swap space?

    jinzishuai@gmail.com wrote in part:
    > This is part of the output from "top".
    > We can confirm that no swap space is used.
    > However, VIRT=RES+SWAP and SWAP is not zero:
    > VIRT=2164, RES=1144, SWAP=1020 and 2164=1144+1020
    >
    > My question is: since there is no space disk, where to swap
    > to pages to? Thanks a lot.


    Two things -- first, did you positively turnoff swap
    with `swapoff` and /etc/fstab and `mount` show no swap?

    The other is that VIRT=RES+SWAP+MAPPED .
    MAPPED is mostly codepages that haven't been
    accessed, so don't need to be loaded.

    SHR can also make memory accounting difficult.

    -- Robert




  3. Re: Why would top show the processes are using swap when there isno swap space?

    "jinzishuai@gmail.com" wrote:
    >This is part of the output from "top".
    >We can confirm that no swap space is used.
    >However, VIRT=RES+SWAP and SWAP is not zero:
    >VIRT=2164, RES=1144, SWAP=1020 and 2164=1144+1020
    >
    >My question is: since there is no space disk, where to swap to pages
    >to?
    >Thanks a lot.


    I'm not sure if this is what you are seeing... but not all
    virtual memory is RAM or SWAP! The only thing written to actual
    swap space is data, not program code.

    An ELF executable binary has code pages that are non-writeable
    and can be shared between different processes. That means the
    disk file can be, and is, used instead of swap space. When
    program code is "swapped out", the RAM is merely marked as
    available, but nothing is saved to disk because it is already on
    disk. If part of it needs to be paged in it is read from the
    original executable binary file, not from you swap space.

    I don't know if it works this way, but if the program code for
    your above program takes up 2164K, and only 1144K has been paged
    in, it probably will show 1020K as in "SWAP".

    --
    Floyd L. Davidson
    Ukpeagvik (Barrow, Alaska) floyd@apaflo.com

  4. Re: Why would top show the processes are using swap when there is no swap space?

    Thank you both.
    I am 100% sure that there is no swap space used. The /proc/swaps file
    is empty and free shows 0 for swap also.

    I think Floyd's idea about the code may be the case.
    There are times that when I recompiled the running code, the running
    code crashed.
    This shouldn't happen if the whole code is loaded into the RAM at the
    beginning.
    But if it is as described "swapped out", then deleting the binary file
    on disk would make the swap in impossible and thus I got a crash.
    Thank you very much.

    Shi

    > I'm not sure if this is what you are seeing... but not all
    > virtual memory is RAM or SWAP! The only thing written to actual
    > swap space is data, not program code.
    >
    > An ELF executable binary has code pages that are non-writeable
    > and can be shared between different processes. That means the
    > disk file can be, and is, used instead of swap space. When
    > program code is "swapped out", the RAM is merely marked as
    > available, but nothing is saved to disk because it is already on
    > disk. If part of it needs to be paged in it is read from the
    > original executable binary file, not from you swap space.
    >
    > I don't know if it works this way, but if the program code for
    > your above program takes up 2164K, and only 1144K has been paged
    > in, it probably will show 1020K as in "SWAP".
    >
    > --
    > Floyd L. Davidson
    > Ukpeagvik (Barrow, Alaska) f...@apaflo.com




  5. Re: Why would top show the processes are using swap when there is no swap space?

    On Mar 23, 9:05 am, "jinzish...@gmail.com"
    wrote:
    > My system has 4GB of RAM so I decided that I don't need to have swap
    > space.
    > However, in "top", I can still see that processes's virtual memory is
    > the
    > sum of the residential and swap memory. For example:
    > Swap: 0k total, 0k used, 0k free, 1189192k
    > cached
    >
    > PID USER PR NI VIRT RES SWAP SHR S %CPU %MEM TIME+
    > COMMAND
    > 9580 seki 15 0 2164 1160 1004 856 R 0.3 0.0 0:00.04 top
    >
    > This is part of the output from "top".
    > We can confirm that no swap space is used.


    Note that VIRT = RES + SWAP. SWAP is that part of the process which
    isn't present in memory. This is pages which were never executed, or
    perhaps which were scavenged to create free memory.

    Even without swap configured, a process need not be all loaded into
    memory at once.

    > However, VIRT=RES+SWAP and SWAP is not zero:
    > VIRT=2164, RES=1144, SWAP=1020 and 2164=1144+1020
    >
    > My question is: since there is no space disk, where to swap to pages
    > to?


    Pages of executables which are not locked into memory, and which are
    not dirty, can be scavenged by the swapper. This simply means that
    they are marked not-present, and the underlying memory frames are made
    available for allocation. There is no need to write anything to
    storage. (And in fact, that can't happen because executables and
    shared libraries are mapped private).


  6. Re: Why would top show the processes are using swap when there isno swap space?

    "jinzishuai@gmail.com" wrote:
    >Thank you both.
    >I am 100% sure that there is no swap space used. The /proc/swaps file
    >is empty and free shows 0 for swap also.
    >
    >I think Floyd's idea about the code may be the case.
    >There are times that when I recompiled the running code, the running
    >code crashed.
    >This shouldn't happen if the whole code is loaded into the RAM at the
    >beginning.
    >But if it is as described "swapped out", then deleting the binary file
    >on disk would make the swap in impossible and thus I got a crash.
    >Thank you very much.


    As Bill Marcum points out, the file will not actually be removed
    and the disk space freed until all references to it are closed.

    However, recompiling it and replacing it with a different binary
    can indeed have the effect you are describing. I'm not sure
    exactly how it works, because the compiler will (or used) refuse
    to overwrite the old binary, stating that it was "busy".
    However, when the binary is overwritten using cp, install, or
    some other mechanisms it appears that it can happen.

    --
    Floyd L. Davidson
    Ukpeagvik (Barrow, Alaska) floyd@apaflo.com

+ Reply to Thread