How Does an Operating System Manage Memory?
A computer’s memory must accommodate both the operating system’s processes and user processes. The following outline describes what happens when a user starts a program such as MATLAB: • User starts the program. • The operating system creates an address space for the program to run in, which involves setting up appropriate page tables. • The program’s text and data segments are mapped from the executable file on disk to the virtual address space; the former being mapped as read only, the latter being mapped as read-write. • The stack and heap are initialized. • Control is transferred to the program. • The CPU tries to access the first instruction. Since it is not in memory, a page fault is generated. – This causes the operating system to intervene and allocate one or more pages of physical memory and to copy the code from the file, hence the name “Demand Paged Virtual Memory.” • The CPU then returns control to the program, which continues executing until it encounters another page faul