1

I have been working with Linux for quite sometime and when we say virtual memory are we referring to swap space? Say for instance in the top command we have a separate column for VIRT(virtual memory), does it refer to the swap space of the linux machine.I want to know whether virtual memory and swap space are the same thing? can someone help me clear out this confusion?

1
  • They are not the same. Wikipedia and other google search results have very good explanations. Even an image search on virtual memory will give you an idea.
    – Citylight
    Nov 29 '19 at 5:51
2

The top manpage distinguishes them as follows:

For our purposes there are three types of memory, and one is optional. First is physical memory, a limited resource where code and data must reside when executed or referenced. Next is the optional swap file, where modified (dirty) memory can be saved and later retrieved if too many demands are made on physical memory. Lastly we have virtual memory, a nearly unlimited resource serving the following goals:

  1. abstraction, free from physical memory addresses/limits
  2. isolation, every process in a separate address space
  3. sharing, a single mapping can serve multiple needs
  4. flexibility, assign a virtual address to a file

The VIRT column in top shows how much address space a process has allocated. Much of that is typically unused. When it is used, the kernel has to make physical memory available to the process. Ideally, this physical memory can be taken from the pool of free memory, and nothing else is affected. If however there isn’t enough free physical memory, the kernel has to get rid of some other data in memory, and that is where swap space comes in: one of the ways the kernel can make memory available is by writing its contents to swap.

Virtual memory is a somewhat abstract concept: as represented by the VIRT column in top, it’s all the memory a process has said it could potentially use. Swap space is one way of helping the kernel make memory available when a process needs to use it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.