Operating Systems 1

Tutorial 4

  1. What is priority aging? What effect does it have on low-priority processes?
    Priority aging is gradually increasing the priority of tasks which have not yet had much CPU time---or decreasing the priority of the currently-running task (amounts to the same thing).

    It allows even very low-priority processes a chance to be scheduled once in a while. Stops them from starving.

  2. The Amiga operating system relocates program code in software, when it is loaded. What additional information must be present in executable files to allow this to happen? What are potential disadvantages with this approach?

    Additional information: each executable file must contain a table of addresses to be relocated.

    Potential disadvantages: Code may not be easily moved later (without reference to the relocation table). (Additional points for saying: text segment could not be directly mapped from the executable file, using the paging hardware.)

  3. Name two solutions to the problem of memory fragmentation.
    1. Compaction: shuffle around allocated blocks in memory to move the 'holes' together, and create enough space to use.
    2. Swapping: (in a system which partitions memory among different processes) Swap some processes out to disk to create enough space. Swap them back in at different (less fragmentary) positions later on.
  4. What are two reasons for not trusting processes to stick to their own areas of memory (two reasons we need memory protection)?
    • Processes may be malicious. They may be attempting to illicitly obtain secret information from other users on the system. They may be viral code wishing to infect other software on the system.
    • Code may be buggy.

    (Mentioned in the lectures that it is impossible for the OS to predict in advance which areas of memory a particular piece of code will visit, in general.)

  5. A common memory management scheme is to have the stack at the top of the address space and the heap at the bottom. Why is this a good scheme with a single-process system?
    Maximum utilisation of memory. The area between the stack and the heap can be used by whichever grows fastest. (In this case, the stack would grow downwards, the stack grow upwards.)
  6. Which is more efficient in terms of disk accesses: process swapping or overlays?
    Overlays. Swapping swaps entire process at a time. Overlays only swap in and out sections of program text.

    But! They are not quite the same: overlays only apply to executable code (the text segment); swapping a process out of memory removes the text, stack and data segments.

  7. The Linux operating system uses paging. Sometimes pages must be evicted from memory to make room for pages which should be swapped in. If the OS evicts a page which is part of the text segment of a process, it discards the page, without writing it to disk first. What will Linux do when it once again needs the pages it has discarded (when a process attempts to reference that particular page of its text segment)?
    Pages from text segments need not be written to disk when they are evicted from memory, because they can be read back in from the executable file.
  8. A certain processor uses 32-bit memory addresses, and 2K pages. The top 2G (2048M) of memory is unavailable for user processes. How many bits are used to reference the page tables? Potentially, how many pages could a process have?

    211 = 2K : offset into page is 11 bits.

    Effective size of address space is

    232 - 2G
    = 4G - 2G
    = 2G = 231

    Number of pages is

    2G ÷ 2K
    = 231 ÷ 211 = 220

    220 = 1M pages (1048576 pages).

  9. Many general-purpose processors support the use of a 'physical access' mode whereby the CPU's memory accesses go straight to memory, bypassing the MMU, in addition to a 'virtual access' mode, using the paging hardware. Why would 'physical access' mode be important to someone writing an operating system kernel? (For extra brownie points: how might an OS simulate 'physical access' mode using the MMU?)
    The kernel has got to be able to access all processes' memory. It must also be able to access memory which is private to the OS, and not mapped to any process's virtual memory (for example, the page tables themselves).

    To simulate physical access mode, the OS might set up a page table for itself, which maps page 0 to frame 0, page 1 to frame 1, etc.