Key Terms

  • Virtual Memory
    • Virtual Memory is the illusion of having more available memory than may exist in reality. This is achieved through mapping sections of virtual memory to either physical RAM or secondary storage (as temporary store). It provides an idealised abstraction of storage resources.
    • Page
      • A page is a fixed-length contiguous block of virtual memory. It’s a unit of data for memory management in an operating system. Pages are moved between physical memory and disk storage.
    • Dirty Page
      • A dirty page is a page that has been modified (written to) after being loaded into RAM, and therefore, the version in RAM is different from that on disk. Before such a page can be replaced or removed from RAM, it must be written back (flushed) to disk to ensure data integrity.
    • Page Frame
      • Physical memory is organised into page frames. Pages are allocated to page frames when they need to be accessed by the CPU
    • Page Table
      • A page table is a data structure used by a virtual memory system in an operating system to store the mapping between virtual addresses and physical addresses. It helps in translating and locating the physical frame of a page in the RAM.
    • Page Fault
      • A page fault occurs when a program tries to access a page that is not currently mapped to a physical memory (RAM). The operating system then handles this fault, typically by loading the required page into memory and updating the page table.
  • Page/Memory Optimisation
    • The process of determining which processes should be in memory and where they should be stored
  • Contagious memory
    • Consecutive (one after the other) blocks of memory allocated to user processes are called contagious memory

Memory Allocation

The aim of these methods is to reduce wasted space

Segmented memory

  • Segmented memory builds on partitioning, but to split a process into different segments (each can vary in size)
    • Each segment was loaded into a dynamic partition in memory
  • A segment table maps logical address into physical address
  • Each table entry has:
    • Base Address: It contains the starting physical address where the segments reside in memory
    • Limit: It specifies the length of the segment
  • A downside to this approach is that as segments are loaded and released from memory, fragmentation can build up

Paged memory

  • Is like a book, memory is divided into equally sized page frames

  • A process is split into equally sized pages and allocated one or more page frames, depending on its requirement

  • Paged memory (popular in modern OS) splits programs into fixed size units, called pages. A process therefore occupies one or more pages

    • For security, a page can never be shared between processes
    • A typical page size might be 4K
  • Memory is split into units of the same size called page frames

    • One page occupies a page frame
    • A process’s pages may be scattered around the page frames
  • The memory management maintains a mapping of pages to page frames called a page (management) table

    • Other metadata is also kept, such as:
      • Time loaded
      • # accesses
      • etc.
  • A benefit of paging, is that not all pages need to be loaded at the start of execution

    • A special flag can be set that indicated that the page is not loaded
  • Due to this, paging is more effcient that segmented memory, as RAM is more efficiently managed (segmenting requires loading the whole process)

  • Logical addresses of a process’s instruction is expressed as page number + Offset

    • e.g. 256 is the 256th byte from the start of page 3
      • When looking at low level code in P4 this is overlooked

Logical Memory

  • When your program runs, the OS makes it believe it has all the memory just for itself
    • e.g. Addresses 1 to 10,000. All empty and ready for use
    • If you run two programs, each one of them gets its own space - each one

Virtual Memory

  • Virtual memory is a “memory management technique that provides abstraction of the storage resources available on a given machine”
    • It creates the illusion to users (processes) of a very large main memory
  • In reality the virutal memory is mapped to either physical RAM or secondary storage to form a large range of contiguous addresses
  • It allows us to run more applications on the system that we have enough physical memory to support

  • Each process (running program) has its own allocation of Virtual Memory
    • To the process, it can feel like it has all the RAM to itself
  • That extra memory doesn’t actually exist in the RAM (it’s an abstraction). It’s the storage space on the hard drive
    • Virtual memory can work with segmentation or paging.

Swapping

  • Ideally, all pages are allocated a page frame, but RAM is limited
    • Therefore, some pages are stored in secondary memory (e.g. in a page file -Windows)
  • With virtual memory we use a process called swapping
    • The process of moving data RAM to disk and back, is known as swapping or more formally as page swapping
    • The memory management controls the swapping data between physical memory and the hard disk
  • When a page is referenced (e.g. the MAR points to an instruction in a given page) and that page is not mapped to a page frame, a page fault is raised
    • The appropriate interrupt service routine (ISR) then runs and swaps or loads in the appropriate page
    • If this happens a lot, we get thrashing. This reduces system performance.