0
$\begingroup$

The Galvin OS text says that on older systems, there used to be a method, where the entire running process (when in idle state) was moved from the main memory (when main memory ran low) to the disk which acted as a backing store.

enter image description here

The text says that whatever processes we swap out are placed in the "swap space" of the disk.

Now as time passed the concept of swapping was used with paged processes as well:

enter image description here

Now I want to know when an executable is run where is the "process image" created and stored? In the picture below, the a.out is executable and I know that the executable is just a binary containing the machine instructions and data and relocation information for the target machine. But the virtual memory of this executable is yet to be formed, or rather the "process" is different from executable, where there is specific: code, static/global variable section, heap section, and stack section.

enter image description here

The diagram below shows that "new process" having 4 pages is in the disk, but wherein the disk is it kept? Under file system or the swap space?

enter image description here

In the demand paging section the text says:

enter image description here

enter image description here

Now the above picture is concerning demand paging. Where in the disk are the pages A, B, C, D, E, F, G, H are placed is it in the swap space or in the file system? Is it so that the system uses swap space only for those dirty pages which are flushed out of the main memory, (while keeping the actual pages of the process under file system) and read them later subsequently, but if that is the case we could as such just switch off the swap space and work with the file system version of the process on disk. I was having this doubt because the text in a section says :

In Solaris 1 (SunOS), the designers changed standard UNIX methods to improve efficiency and reflect technological developments. When a process executes, text-segment pages containing code are brought in from the file system, accessed in main memory, and thrown away if selected for page out. It is more efficient to reread a page from the file system than to write it to swap space and then reread it from there. Swap space is only used as a backing store for pages of anonymous memory (memory not backed by any file), which includes memory allocated for the stack, heap, and uninitialized data of a process.


This is how the text defines virtual memory and demand paging:

Virtual memory involves the separation of logical memory as perceived by developers from physical memory. This separation allows an extremely large virtual memory to be provided for programmers when only a smaller physical memory is available. Virtual memory makes the task of programming much easier, because the programmer no longer needs to worry about the amount of physical memory available; she can concentrate instead on programming the problem that is to be solved. The virtual address space of a process refers to the logical (or virtual) view of how a process is stored in memory. Typically, this view is that a process begins at a certain logical address—say, address 0 - and exists in contiguous memory. In fact, physical memory is organized in page frames, and that the physical page frames assigned to a process may not be contiguous. It is up to the memory-management unit (MMU) to map logical pages to physical page frames in memory.

The demand paging and is commonly used in virtual memory systems. With demand-paged virtual memory, pages are loaded only when they are demanded during program execution. Pages that are never accessed are thus never loaded into physical memory. A demand-paging system is similar to a paging system with swapping where processes reside in secondary memory (usually an HDD or NVM device).

$\endgroup$

1 Answer 1

0
$\begingroup$

I guess, I have understood it: It goes something like this, if we have demand paging, the usual concept, [from where textbook questions are made, we talk about a page being brought from memory and writing back a page to disk using one of the many page replacement algorithms] all that works with SWAP SPACE on the disk [the place where this pages of a process are stored]. For demand paging to work in our usual intuition we need to have swap space [file or partition] on the disk. But suppose we do not have the swap space, then ALL the pages of the process are supposed to be in memory, and process pages can be only moved out when the process is still running, if the page which is to be removed is backed by some file [opened for reading, possibly in shared memory mode] or the code section of the process. [Then if need be, we can later read them back from the file system]. But if no such pages are available to be removed from the physical memory, we shall have an Out Of Memory (OOM) situation, and then the kernel works accordingly [like it might decide to kill a process].

Here is a nice answer.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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