4

When I launch php-script and do ps aux and have huge number for VSZ, about 450MB. Whilst RSS -- Resident set size -- is about 10MB. From wikipedia, Resident set size is is the portion of a process's memory that is held in RAM. But does Virtual memory size include memory held somewhere else, say in filesystem? What exactly does Virtual memory consist of?

2 Answers 2

4

Virtual memory (as the name implies) is an abstraction over the underlying physical memory architecture. Each process gets its own virtual address space, and when virtual adresses are accesses, they are first converted to hardware addresses by the Memory Management Unit(MMU). Data in the virtual address space of a process may be either in main memory, on disk, both or some other external memory. However, every page that is not allready in main memory (MM) is loaded into MM when they are accessed by a process. Thus, processes do not read directly from disk, but some or most of their resources may reside on external memory at any given time, as pages can be swapped out to make place for others.

6

Virtual memory might be:

  • on RAM if the data has been accessed recently or if there is no pressure to release RAM
  • on the swap area (swap partition or swap file) if it has been paginated out
  • on the file system if the data correspond to memory mapped files (eg: shared libraries)
  • nowhere (i.e. use no resource, especially on systems over-committing memory like Linux) if allocated pages have not been accessed yet

The fourth point is often overlooked.

2
  • "paging" is different from "swapping". As the kernel knows which executable/library has been mapped into which RAM pages (their "immutable" or text segments), it can simply "forget" those of currently unused executables if there is memory pressure. "Paging out" simply means to mark them as free, but not moving them to swap space. Since there is still the locked executable's file on disk, why filling swap with useless copies? If the affected (paged-out) executable is to be used again, the kernel simply "pages in" (re-map to RAM) those parts from the executable's file on disk.
    – Christian
    Jan 5, 2023 at 12:30
  • @Christian Paging is indeed different from swapping but you seem to restrict paging to non-anonymous pages while they are usually only a tiny fraction of the total number of pages on a system. Anonymous pages that need to be paged-out are stored on the swap area. They can't be just forgotten otherwise the program will crash when trying to access them again later.
    – jlliagre
    Jan 5, 2023 at 12:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .