Reputation: 1621
When does the OS actually divide the address space of the process into pages ?
Suppose I write a program and save it. Will the OS divide the address space of the program into pages even if it is not executing and sitting idle in the hard disk ?
I read that we have portion known as swap space or page file residing inside hard disk whose size can be configured and it contains unused pages or pages which have been swapped from physical memory to hard disk.
So before the execution of the program, is the entire program copied to swap space or can it execute from any portion of hard disk?
Upvotes: 1
Views: 1006
Reputation: 21607
When does the OS actually divide the address space of the process into pages ?
Usually the LINKER divides the application into pages to establish the initial state of the program/process and writes the instructions for doing so into the executable file. The program loader allocates pages as directed by the executable.
Suppose I write a program and save it. Will the OS divide the address space of the program into pages even if it is not executing and sitting idle in the hard disk ?
See above. The linker divides what you write into pages.
So before the execution of the program, is the entire program copied to swap space or can it execute from any portion of hard disk?
On any virtual memory system (that functions), every page allocated to a process will have a corresponding location in a page file. On some systems, there can be multiple page files. For example, the executable file can become the page file for static data and code.
Upvotes: 1
Reputation: 364000
Swap space is the backing store for anonymous pages, or dirty pages in "private" mappings (e.g. the data segment of an executable: it was read from the executable, but changes don't update the file).
Non-modified pages in the virtual address space of a process are still backed by the executable file on disk (or any libraries).
Most modern OSes don't actually do strict accounting to make sure there is enough swap for all the virtual memory pages they let processes allocate (this is called overcommit), but the traditional model is that the OS does reserve swap when virtual memory is allocated.
Will the OS divide the address space of the program into pages even if it is not executing and sitting idle in the hard disk ?
I barely know where to start answering this part. Go find an operating-systems textbook (or wikipedia) and look up:
If a program isn't executing, there is no process and no address space. If it is executing, each process has its own virtual address space. (And the read-only pages are all backed by the same file on disk.)
Upvotes: 1