4 ms·
Swapping (in the context of old Unix) is always replacing (copying) an entire process address space (or at least the non-shareable read-write segments such as .
by johndoe0815 3y ago
Swapping (in the context of old Unix) is always replacing (copying) an entire process address space (or at least the non-shareable read-write segments such as .data), out to the swap device, or back, in one go.
Paging is more advanced as it allows to keep only a part of the memory required by a process in RAM and contents can be loaded or moved to secondary storage on the granularity of single pages (typically 4 kB, but larger pages are also common nowadays). So a typical exec(2) system call in Unix could set up a new page table which contains no single byte of the executable in the beginning and then jump to the executable's entry point. This, in turn, results in a page fault, in turn, the OS can then load the requested page into RAM.
Paging is more efficient since control/data flow analyses show that something similar to the Pareto rule (or 80/20 rule) also applies to programs which are executed - 80% of the time, only 20% of the address range (for instructions and/or data) is used. With paging, the OS won't need to load any code or data from disk that is never used (and can load it on demand later).
What's probably confusing is that the area reserved on disk for storing RAM contents (a partition or a file) is still called "swap partition/file". This is an old term that refuses to die, I guess...
- jonstewart 3y agoSo “old” swapping is taking low priority processes and putting all of their memory out to disk, almost (but obviously not quite) as though you’re suspending them. Got it!
- deleted 3y ago[deleted]