Advanced System Software and Security: Question 3
Syllabus 16.1
A laptop has 8 GB of physical RAM installed. Its user opens a video editor, several browser windows and a virtual machine at the same time, so that the total memory demanded by every currently open process is far larger than the 8 GB of RAM actually fitted, yet the operating system continues to run every one of these processes without crashing or refusing to open any of them.
(a) Explain, referring to pages, frames and a backing store, how virtual memory allows the laptop to run processes whose combined memory demand exceeds the size of its physical RAM. [3]
(b) State one difference between how paging and segmentation divide up a process's memory. [2]
(c) After a while, the user notices the laptop has become extremely slow: the hard disk activity light is almost constantly lit, yet very little visible progress is being made in any of the open applications. Name this phenomenon, explain why it is happening, and suggest one way the user could reduce it. [3]
Show worked solution Hide worked solution
Worked solution
Part (a): How virtual memory extends RAM
Virtual memory lets the operating system treat disk space as if it were an extension of physical RAM. A process’s logical memory space is divided into fixed-size blocks called pages, and physical RAM is divided into blocks of the same fixed size, called frames.
At any one time, only the pages a process is actually using need to occupy a frame in RAM. The rest of that process’s pages can be kept out on disk, in an area called the backing store. The operating system maintains a page table for each process, mapping its logical pages to whichever physical frame currently holds them (if any).
If a process tries to access a page that is not currently loaded into a frame, a page fault occurs: the operating system pauses that access, locates the page on the backing store, and swaps it into a free frame in RAM (swapping a different, less recently used page back out to disk first, if every frame is already occupied). Because the combined size of RAM plus the backing store is much bigger than physical RAM alone, and only the pages actually needed at any moment have to be resident in RAM, the laptop can keep several memory-hungry processes open at once even though their combined memory demand exceeds 8 GB. [3 marks]: [1] for pages/frames being fixed-size blocks of logical/physical memory, [1] for pages being swapped between RAM and the backing store (disk) as needed, [1] for explaining that this allows total memory demand to exceed physical RAM because only currently needed pages must be resident.
Part (b): Paging vs segmentation
Paging divides a process’s memory into equal, fixed-size pages (matched to same-size physical frames). This division is purely administrative and has no connection to the logical structure of the program being run. Segmentation, by contrast, divides a program into variable-size segments, where each segment corresponds to a logical unit of the program itself, such as a code segment, a data segment or a stack segment, so segments can be different sizes depending on what part of the program they represent. [2 marks]: [1] for identifying fixed size (paging) vs variable size (segmentation), [1] for linking this to physical/arbitrary division (paging) versus a division based on the program’s logical structure (segmentation).
Part (c): Disk thrashing
The phenomenon is disk thrashing.
With a video editor, several browsers and a virtual machine all open together, the total number of pages these processes need active at once is far greater than the number of frames available in the laptop’s 8 GB of RAM. As a result, the operating system is constantly having to swap a page out to the backing store to free up a frame, only to immediately need to swap a different page back in moments later, and often, the page it just swapped out turns out to be needed again almost straight away, forcing yet another swap. The CPU ends up spending nearly all of its time managing this constant back-and-forth movement of pages between RAM and disk (which is why the disk light stays lit), rather than actually executing the instructions of any application, so hardly any useful progress gets made even though the computer looks “busy”.
One way to reduce this is for the user to close some of the open applications, reducing the total number of pages competing for the laptop’s limited RAM frames (adding more physical RAM would have the same effect, by giving more frames to go around). [3 marks]: [1] for naming disk thrashing, [1] for explaining the cause (too many pages/processes competing for too few RAM frames, causing pages to be repeatedly swapped in and out), [1] for a valid way to reduce it.
Final answers
- (a) Virtual memory divides memory into fixed-size pages/frames, keeps only needed pages in RAM, and swaps pages to/from the backing store (disk) via page faults, so total demand can exceed physical RAM.
- (b) Paging uses fixed-size, logically-unrelated blocks; segmentation uses variable-size blocks matched to the program’s logical structure.
- (c) Disk thrashing, caused by too many pages competing for too few RAM frames, causing constant swapping instead of useful execution; reduce by closing applications or adding RAM.