Skip to main content
added 589 characters in body
Source Link
user10489
  • 11.1k
  • 1
  • 16
  • 37

If linux is running on a cpu with a memory management unit (MMU) then virtual memory is always in use.

The term "virtual memory" has two meanings here that are entangled. It could refer to the virtual assignment of memory addresses within a process that may or may not correspond to physical memory. It can also refer to disk blocks that are available to expand memory space beyond what is physically available as ram by mapping them to process virtual memory.

Linux (and unix in general) is demand paged, meaning pages are loaded from disk or allocated from the free memory pool on demand.

Pages in a process can be in multiple states from multiple sources:

  • An executable page most likely is associated with a program or shared library on disk. There is a copy of this page on disk, and possibly a (read only) copy of this page in physical ram. These pages may be shared (read only) by all processes using the files in question.
  • A data page for the process may be in physical ram. If it is in ram, it may be clean or dirty. A clean data page has a copy in swap (and could be released if needed). A dirty page either has no copy in swap, or the page has been modified (and the swap page released). It may also be swapped out, with no copy in physical ram.
  • A file on disk can be mmap'ed into virtual memory for the process. Executable pages are mmaped read only (described above). But it is also possible to mmap a writable file as a data page, and then it is saved to the file instead of swap. When a mmaped data page is dirtied, it will be opportunistically written back to the file shortly. As above, a mmaped page can be on disk only or duplicated in ram (clean or dirty).
  • A page can also be allocated in virtual memory, but with no corresponding data either in physical ram or on disk. This happens when a process requests more memory but hasn't (yet?) used it. A read from such a page will return zeros. A write will cause a physical page to be zeroed, assigned to the process, and then the write will complete. (Or, the process will be killed with an out of memory error if this isn't possible.)

So if there is no swap, there still is virtual (non-physical) memory used for empty uninitialized pages, executable pages, and there can also be mmaped data pages. Also, physical memory is included in virtual memory, with or without disk backing.

The difference is that without swap, when the system runs short on memory, read only pages will be flushed frequently to load other pages, and unless associated with a file (mmaped or not), dirty pages have no where to go and are locked in physical memory.

This oversimplifies things slightly, as there are also cached pages of disk files that are not assigned to any process's virtual memory but still involved in the virtual memory system. Also the implementation details may order some of the above described operations differently.

Note that older unix systems required enough swap space to back all physical memory pages, so swap was typically at least twice the size of ram. Linux abandoned this strategy very early on, and doesn't require any swap.

If linux is running on a cpu with a memory management unit (MMU) then virtual memory is always in use.

Linux (and unix in general) is demand paged, meaning pages are loaded from disk or allocated from the free memory pool on demand.

Pages in a process can be in multiple states from multiple sources:

  • An executable page most likely is associated with a program or shared library on disk. There is a copy of this page on disk, and possibly a (read only) copy of this page in physical ram. These pages may be shared (read only) by all processes using the files in question.
  • A data page for the process may be in physical ram. If it is in ram, it may be clean or dirty. A clean data page has a copy in swap (and could be released if needed). A dirty page either has no copy in swap, or the page has been modified (and the swap page released). It may also be swapped out, with no copy in physical ram.
  • A file on disk can be mmap'ed into virtual memory for the process. Executable pages are mmaped read only (described above). But it is also possible to mmap a writable file as a data page, and then it is saved to the file instead of swap. When a mmaped data page is dirtied, it will be opportunistically written back to the file shortly. As above, a mmaped page can be on disk only or duplicated in ram (clean or dirty).
  • A page can also be allocated in virtual memory, but with no corresponding data either in physical ram or on disk. This happens when a process requests more memory but hasn't (yet?) used it. A read from such a page will return zeros. A write will cause a physical page to be zeroed, assigned to the process, and then the write will complete. (Or, the process will be killed with an out of memory error if this isn't possible.)

So if there is no swap, there still is virtual (non-physical) memory used for empty uninitialized pages, executable pages, and there can also be mmaped data pages. Also, physical memory is included in virtual memory, with or without disk backing.

The difference is that without swap, when the system runs short on memory, read only pages will be flushed frequently to load other pages, and unless associated with a file (mmaped or not), dirty pages have no where to go and are locked in physical memory.

This oversimplifies things slightly, as there are also cached pages of disk files that are not assigned to any process's virtual memory but still involved in the virtual memory system. Also the implementation details may order some of the above described operations differently.

If linux is running on a cpu with a memory management unit (MMU) then virtual memory is always in use.

The term "virtual memory" has two meanings here that are entangled. It could refer to the virtual assignment of memory addresses within a process that may or may not correspond to physical memory. It can also refer to disk blocks that are available to expand memory space beyond what is physically available as ram by mapping them to process virtual memory.

Linux (and unix in general) is demand paged, meaning pages are loaded from disk or allocated from the free memory pool on demand.

Pages in a process can be in multiple states from multiple sources:

  • An executable page most likely is associated with a program or shared library on disk. There is a copy of this page on disk, and possibly a (read only) copy of this page in physical ram. These pages may be shared (read only) by all processes using the files in question.
  • A data page for the process may be in physical ram. If it is in ram, it may be clean or dirty. A clean data page has a copy in swap (and could be released if needed). A dirty page either has no copy in swap, or the page has been modified (and the swap page released). It may also be swapped out, with no copy in physical ram.
  • A file on disk can be mmap'ed into virtual memory for the process. Executable pages are mmaped read only (described above). But it is also possible to mmap a writable file as a data page, and then it is saved to the file instead of swap. When a mmaped data page is dirtied, it will be opportunistically written back to the file shortly. As above, a mmaped page can be on disk only or duplicated in ram (clean or dirty).
  • A page can also be allocated in virtual memory, but with no corresponding data either in physical ram or on disk. This happens when a process requests more memory but hasn't (yet?) used it. A read from such a page will return zeros. A write will cause a physical page to be zeroed, assigned to the process, and then the write will complete. (Or, the process will be killed with an out of memory error if this isn't possible.)

So if there is no swap, there still is virtual (non-physical) memory used for empty uninitialized pages, executable pages, and there can also be mmaped data pages. Also, physical memory is included in virtual memory, with or without disk backing.

The difference is that without swap, when the system runs short on memory, read only pages will be flushed frequently to load other pages, and unless associated with a file (mmaped or not), dirty pages have no where to go and are locked in physical memory.

This oversimplifies things slightly, as there are also cached pages of disk files that are not assigned to any process's virtual memory but still involved in the virtual memory system. Also the implementation details may order some of the above described operations differently.

Note that older unix systems required enough swap space to back all physical memory pages, so swap was typically at least twice the size of ram. Linux abandoned this strategy very early on, and doesn't require any swap.

added 228 characters in body
Source Link
user10489
  • 11.1k
  • 1
  • 16
  • 37

If linux is running on a cpu with a memory management unit (MMU) then virtual memory is always in use.

Linux (and unix in general) is demand paged, meaning pages are loaded from disk or allocated from the free memory pool on demand.

Pages in a process can be in multiple states from multiple sources:

  • An executable page most likely is associated with a program or shared library on disk. There is a copy of this page on disk, and possibly a (read only) copy of this page in physical ram. These pages may be shared (read only) by all processes using the files in question.
  • A data page for the process may be in physical ram. If it is in ram, it may be clean or dirty. A clean data page has a copy in swap (and could be released if needed). A dirty page either has no copy in swap, or the page has been modified (and the swap page released). It may also be swapped out, with no copy in physical ram.
  • A file on disk can be mmap'ed into virtual memory for the process. Executable pages are mmaped read only (described above). But it is also possible to mmap a writable file as a data page, and then it is saved to the file instead of swap. When a mmaped data page is dirtied, it will be opportunistically written back to the file shortly. As above, a mmaped page can be on disk only or duplicated in ram (clean or dirty).
  • A page can also be allocated in virtual memory, but with no corresponding data either in physical ram or on disk. This happens when a process requests more memory but hasn't (yet?) used it. A read from such a page will return zeros. A write will cause a physical page to be zeroed, assigned to the process, and then the write will complete. (Or, the process will be killed with an out of memory error if this isn't possible.)

So if there is no swap, there still is virtual (non-physical) memory used for empty uninitialized pages, executable pages, and there can also be mmaped data pages. Also, physical memory is included in virtual memory, with or without disk backing.

The difference is that without swap, when the system runs short on memory, read only pages will be flushed frequently to load other pages, and unless mmapedassociated with a file (mmaped or not), dirty pages of a process have no where to go and are locked in physical memory.

This oversimplifies things slightly, as there are also cached pages of disk files that are not assigned to any process's virtual memory but still involved in the virtual memory system. Also the implementation details may order some of the above described operations differently.

If linux is running on a cpu with a memory management unit (MMU) then virtual memory is always in use.

Linux (and unix in general) is demand paged, meaning pages are loaded from disk or allocated from the free memory pool on demand.

Pages in a process can be in multiple states from multiple sources:

  • An executable page most likely is associated with a program or shared library on disk. There is a copy of this page on disk, and possibly a (read only) copy of this page in physical ram. These pages may be shared (read only) by all processes using the files in question.
  • A data page for the process may be in physical ram. If it is in ram, it may be clean or dirty. A clean data page has a copy in swap (and could be released if needed). A dirty page either has no copy in swap, or the page has been modified (and the swap page released). It may also be swapped out, with no copy in physical ram.
  • A file on disk can be mmap'ed into virtual memory for the process. Executable pages are mmaped read only (described above). But it is also possible to mmap a writable file as a data page, and then it is saved to the file instead of swap. When a mmaped data page is dirtied, it will be opportunistically written back to the file shortly. As above, a mmaped page can be on disk only or duplicated in ram (clean or dirty).
  • A page can also be allocated in virtual memory, but with no corresponding data either in physical ram or on disk. This happens when a process requests more memory but hasn't (yet?) used it. A read from such a page will return zeros. A write will cause a physical page to be zeroed, assigned to the process, and then the write will complete. (Or, the process will be killed with an out of memory error if this isn't possible.)

So if there is no swap, there still is virtual (non-physical) memory used for empty uninitialized pages, executable pages, and there can also be mmaped data pages.

The difference is that without swap, when the system runs short on memory, read only pages will be flushed frequently to load other pages, and unless mmaped, dirty pages of a process have no where to go and are locked in physical memory.

This oversimplifies things slightly, as there are also cached pages of disk files that are not assigned to any process's virtual memory but still involved in the virtual memory system. Also the implementation details may order some of the above described operations differently.

If linux is running on a cpu with a memory management unit (MMU) then virtual memory is always in use.

Linux (and unix in general) is demand paged, meaning pages are loaded from disk or allocated from the free memory pool on demand.

Pages in a process can be in multiple states from multiple sources:

  • An executable page most likely is associated with a program or shared library on disk. There is a copy of this page on disk, and possibly a (read only) copy of this page in physical ram. These pages may be shared (read only) by all processes using the files in question.
  • A data page for the process may be in physical ram. If it is in ram, it may be clean or dirty. A clean data page has a copy in swap (and could be released if needed). A dirty page either has no copy in swap, or the page has been modified (and the swap page released). It may also be swapped out, with no copy in physical ram.
  • A file on disk can be mmap'ed into virtual memory for the process. Executable pages are mmaped read only (described above). But it is also possible to mmap a writable file as a data page, and then it is saved to the file instead of swap. When a mmaped data page is dirtied, it will be opportunistically written back to the file shortly. As above, a mmaped page can be on disk only or duplicated in ram (clean or dirty).
  • A page can also be allocated in virtual memory, but with no corresponding data either in physical ram or on disk. This happens when a process requests more memory but hasn't (yet?) used it. A read from such a page will return zeros. A write will cause a physical page to be zeroed, assigned to the process, and then the write will complete. (Or, the process will be killed with an out of memory error if this isn't possible.)

So if there is no swap, there still is virtual (non-physical) memory used for empty uninitialized pages, executable pages, and there can also be mmaped data pages. Also, physical memory is included in virtual memory, with or without disk backing.

The difference is that without swap, when the system runs short on memory, read only pages will be flushed frequently to load other pages, and unless associated with a file (mmaped or not), dirty pages have no where to go and are locked in physical memory.

This oversimplifies things slightly, as there are also cached pages of disk files that are not assigned to any process's virtual memory but still involved in the virtual memory system. Also the implementation details may order some of the above described operations differently.

added 228 characters in body
Source Link
user10489
  • 11.1k
  • 1
  • 16
  • 37

If linux is running on a cpu with a memory management unit (MMU) then virtual memory is always in use.

Linux (and unix in general) is demand paged, meaning pages are loaded from disk or allocated from the free memory pool on demand.

Pages in a process can be in multiple states from multiple sources:

  • An executable page most likely is associated with a program or shared library on disk. There is a copy of this page on disk, and possibly a (read only) copy of this page in physical ram. These pages may be shared (read only) by all processes using the files in question.
  • A data page for the process may be in physical ram. If it is in ram, it may be clean or dirty. A clean data page has a copy in swap (and could be released if needed). A dirty page either has no copy in swap, or the page has been modified (and the swap page released). It may also be swapped out, with no copy in physical ram.
  • A file on disk can be mmap'ed into virtual memory for the process. Executable pages are mmaped read only (described above). But it is also possible to mmap a writable file as a data page, and then it is saved to the file instead of swap. When a mmaped data page is dirtied, it will be opportunistically written back to the file shortly. As above, a mmaped page can be on disk only or duplicated in ram (clean or dirty).
  • A page can also be allocated in virtual memory, but with no corresponding data either in physical ram or on disk. This happens when a process requests more memory but hasn't (yet?) used it. A read from such a page will return zeros. A write will cause a physical page to be zeroed, assigned to the process, and then the write will complete. (Or, the process will be killed with an out of memory error if this isn't possible.)

So if there is no swap, there still is virtual (non-physical) memory used for empty uninitialized pages, executable pages, and there can also be mmaped data pages.

The difference is that without swap, when the system runs short on memory, read only pages will be flushed frequently to load other pages, and unless mmaped, dirty pages of a process have no where to go and are locked in physical memory.

This oversimplifies things slightly, as there are also cached pages of disk files that are not assigned to any process's virtual memory but still involved in the virtual memory system. Also the implementation details may order some of the above described operations differently.

If linux is running on a cpu with a memory management unit (MMU) then virtual memory is always in use.

Linux (and unix in general) is demand paged, meaning pages are loaded from disk or allocated from the free memory pool on demand.

Pages in a process can be in multiple states from multiple sources:

  • An executable page most likely is associated with a program or shared library on disk. There is a copy of this page on disk, and possibly a (read only) copy of this page in physical ram. These pages may be shared (read only) by all processes using the files in question.
  • A data page for the process may be in physical ram. If it is in ram, it may be clean or dirty. A clean data page has a copy in swap (and could be released if needed). A dirty page either has no copy in swap, or the page has been modified (and the swap page released). It may also be swapped out, with no copy in physical ram.
  • A file on disk can be mmap'ed into virtual memory for the process. Executable pages are mmaped read only (described above). But it is also possible to mmap a writable file as a data page, and then it is saved to the file instead of swap. When a mmaped data page is dirtied, it will be opportunistically written back to the file shortly. As above, a mmaped page can be on disk only or duplicated in ram (clean or dirty).
  • A page can also be allocated in virtual memory, but with no corresponding data either in physical ram or on disk. This happens when a process requests more memory but hasn't (yet?) used it. A read from such a page will return zeros. A write will cause a physical page to be zeroed, assigned to the process, and then the write will complete. (Or, the process will be killed with an out of memory error if this isn't possible.)

So if there is no swap, there still is virtual (non-physical) memory used for empty uninitialized pages, executable pages, and there can also be mmaped data pages.

If linux is running on a cpu with a memory management unit (MMU) then virtual memory is always in use.

Linux (and unix in general) is demand paged, meaning pages are loaded from disk or allocated from the free memory pool on demand.

Pages in a process can be in multiple states from multiple sources:

  • An executable page most likely is associated with a program or shared library on disk. There is a copy of this page on disk, and possibly a (read only) copy of this page in physical ram. These pages may be shared (read only) by all processes using the files in question.
  • A data page for the process may be in physical ram. If it is in ram, it may be clean or dirty. A clean data page has a copy in swap (and could be released if needed). A dirty page either has no copy in swap, or the page has been modified (and the swap page released). It may also be swapped out, with no copy in physical ram.
  • A file on disk can be mmap'ed into virtual memory for the process. Executable pages are mmaped read only (described above). But it is also possible to mmap a writable file as a data page, and then it is saved to the file instead of swap. When a mmaped data page is dirtied, it will be opportunistically written back to the file shortly. As above, a mmaped page can be on disk only or duplicated in ram (clean or dirty).
  • A page can also be allocated in virtual memory, but with no corresponding data either in physical ram or on disk. This happens when a process requests more memory but hasn't (yet?) used it. A read from such a page will return zeros. A write will cause a physical page to be zeroed, assigned to the process, and then the write will complete. (Or, the process will be killed with an out of memory error if this isn't possible.)

So if there is no swap, there still is virtual (non-physical) memory used for empty uninitialized pages, executable pages, and there can also be mmaped data pages.

The difference is that without swap, when the system runs short on memory, read only pages will be flushed frequently to load other pages, and unless mmaped, dirty pages of a process have no where to go and are locked in physical memory.

This oversimplifies things slightly, as there are also cached pages of disk files that are not assigned to any process's virtual memory but still involved in the virtual memory system. Also the implementation details may order some of the above described operations differently.

Source Link
user10489
  • 11.1k
  • 1
  • 16
  • 37
Loading