Chapter 9: Main Memory PDF
Document Details
Uploaded by StableBigBen
Brandon University
2018
Tags
Related
- Operating System PDF
- Artificial Intelligence & Data Science S.E. Operating Systems Past Paper PDF - 2019 Pattern
- Module 5 Memory Management PDF
- Operating System Concepts - Chapter 9: Main Memory PDF
- Computer Science: Chapter 3 - Operating Systems (PDF)
- OCR Computer Science A Level 1.2.1 Systems Software Notes PDF
Summary
This document is chapter 9 of an operating systems textbook focusing on main memory. It covers concepts such as background information, contiguous memory allocation, paging, structure of page tables and swapping. Included are illustrative diagrams, examples, and definitions of different concepts related to main memory.
Full Transcript
Chapter 9: Main Memory Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 Chapter 9: Memory Management Background Contiguous Memory Allocation Paging Structure of the Page Table...
Chapter 9: Main Memory Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 Chapter 9: Memory Management Background Contiguous Memory Allocation Paging Structure of the Page Table Swapping Operating System Concepts – 10th Edition 9.2 Silberschatz, Galvin and Gagne ©2018 Role of Memory in Program Execution Memory is central to the operation of a modern computer system. Main memory and registers are only storage CPU can access directly Machine instructions take memory address or registers as arguments, but none takes disk address memory address: memory consists of a large array of bytes, each with its own address called as memory address Any instruction or data must be moved into one of these direct- access storage devices before the CPU can operate In the Von-Neuman architecture, an instruction-execution cycle First fetches an instruction from memory. Then, the instruction is decoded It may cause operands to be fetched from memory Finally, the instruction is executed on the operands, results may be stored back in memory. The memory unit sees only a stream of memory addresses; it does not know how they are generated Operating System Concepts – 10th Edition 9.3 Silberschatz, Galvin and Gagne ©2018 Relative Speed Issue with Memory Register access is done in one CPU clock (or less) Main memory, accessed via memory bus, can take many clock cycles, causing a memory stall for the CPU The required data may still be unavailable even if CPU is free Relative speed of memory is slower than CPU (known as Von- Neuman bottleneck) During a memory stall, a multithreaded core can switch from the stalled hardware thread to another hardware thread The remedy is to add fast memory called as Cache between the CPU and main memory Cache typically built on the CPU chip for fast access, can be accessed without OS control Operating System Concepts – 10th Edition 9.4 Silberschatz, Galvin and Gagne ©2018 Protection Issue with Shared Memory In modern computing, many processes share the memory and reside on the memory at the same time while they are being executed This is to speed up the performance The OS program must be protected from access by user processes, User processes must be protected from one another The basic protection is typically done by hardware implementation rather than OS OS intervention would impact negative performance Operating System Concepts – 10th Edition 9.5 Silberschatz, Galvin and Gagne ©2018 Protection by Hardware Need to ensure that a process can access only those addresses in its address space. We can provide this protection by using a pair of base and limit registers define the logical address space of a process Operating System Concepts – 10th Edition 9.6 Silberschatz, Galvin and Gagne ©2018 Hardware Address Protection Each process has a separate memory address space. Separate per-process memory space protects the processes from each other fundamental to having multiple processes loaded in memory for concurrent execution Implementation: Two registers are used: Base and Limit The base register holds the smallest legal physical memory address; the limit register specifies the size of the range. For a program with base: 300040 and limit:120900, – It can legally access all addresses 300040 – 420939 (inclusive). Operating System Concepts – 10th Edition 9.7 Silberschatz, Galvin and Gagne ©2018 Hardware Address Protection CPU must check every memory address generated in user mode to be sure it is between base and limit for that user Instructions to loading the base and limit registers are privileged Operating System Concepts – 10th Edition 9.8 Silberschatz, Galvin and Gagne ©2018 Address Binding Address binding is a mapping from one address space to another Usually, a program resides on a hard disk as a binary executable file or a source file requiring compilation To run, the executable file must be brought into (called loading) memory and placed within the context of a process to execute on the CPU As the process executes by CPU (called run), it accesses instructions and data from memory A user program goes through several steps before being executed (see next slide) Memory addresses of instruction and data are represented in different ways during these steps Addresses in the source code usually are symbolic, e.g., var salary Compiled code addresses are bound to relocatable addresses, i.e., “14 bytes from beginning of this module” Linker or loader will bind relocatable addresses to absolute addresses, i.e., 74014 Operating System Concepts – 10th Edition 9.9 Silberschatz, Galvin and Gagne ©2018 Multi-Steps Processing of a Program Operating System Concepts – 10th Edition 9.10 Silberschatz, Galvin and Gagne ©2018 Address Binding Time Address binding of instructions and data to memory addresses can happen either of three different stages Compile time: If starting memory location of a process is known a priori, then absolute code can be generated by the compiler; Only recompile code if starting location changes Load time: Must generate relocatable code if memory location is not known at compile time If starting address changes, needs to reload it to reflecting changes Execution time: Binding delayed until run time if the process can be moved during its execution from one memory segment to another Need hardware support for address maps (e.g., base and limit registers) Operating System Concepts – 10th Edition 9.11 Silberschatz, Galvin and Gagne ©2018 Logical vs. Physical Address Space The concept of a logical address space that is bound to a separate physical address space is central to proper memory management Logical address – the memory addresses generated by the CPU Logical address space is the set of all logical addresses generated by a program Physical address – memory address seen by the memory unit through the memory-address register of the memory Physical address space is the set of all physical addresses generated by a program In compile-time and load-time address-binding schemes, logical addresses and physical addresses are identical In execution-time address-binding scheme, generated logical and physical addresses differ The logical address hence is called virtual address However, many textbook often interchangeably use logical and virtual address Operating System Concepts – 10th Edition 9.12 Silberschatz, Galvin and Gagne ©2018 Memory-Management Unit (MMU) The run-time mapping from virtual to physical addresses is done by a hardware device called the memory-management unit (MMU) Many MMU methods possible, base-register scheme is the simplest implementation The user program only deals with logical addresses as it never sees the real physical addresses Execution-time binding, i.e., logical addresses get bound to physical addresses, occurs when a reference is made to the data Operating System Concepts – 10th Edition 9.13 Silberschatz, Galvin and Gagne ©2018 Base-Register Scheme of MMU The base-register scheme is the simplest implementation of the many methods to memory management In this scheme, the base register is regarded as the relocation register The value in the relocation register is added to every address generated by a user process at the time it is sent to memory If the base is at 14000, then an attempt to access the location 346 is mapped to location 14346 by the MMU. Operating System Concepts – 10th Edition 9.14 Silberschatz, Galvin and Gagne ©2018 Logical vs Physical Address We now have two different types of addresses: logical addresses range: 0 to max physical addresses range: (R + 0) to (R + max) where base value R The user program generates only logical addresses and thinks that the process runs in memory locations from 0 to max However, these logical addresses must be mapped to physical addresses by the MMU before they are used. Operating System Concepts – 10th Edition 9.15 Silberschatz, Galvin and Gagne ©2018 Dynamic Loading All programs and data of a process need to be in memory to execute The size and number of processes is restricted by memory size Dynamic loading enhances memory-space utilization With dynamic loading, a routine is not loaded until it is called. All routines are kept on disk in a relocatable load format but only the main program is loaded into memory and is executed. When a routine needs to call another routine, the calling routine first checks to see whether the other routine has been loaded. If it has not, the relocatable linking loader is called to load the desired routine into memory Operating System Concepts – 10th Edition 9.16 Silberschatz, Galvin and Gagne ©2018 Benefits of Dynamic Loading 1. Better memory space utilization is achieved as unused routine is never loaded into memory Useful when large amounts of code are needed to handle infrequently occurring cases, e.g., error handling routines. 2. No special support from the operating system is required Implemented is done through program design that utilizes dynamic loading (i.e., by declaring a non-static variable) OS can help by providing libraries that can be used to implement dynamic loading Operating System Concepts – 10th Edition 9.17 Silberschatz, Galvin and Gagne ©2018 Dynamic Linking Static linking – system libraries like any other object module are combined by the loader into the binary program image Dynamic linking – linking of system libraries into the main program is not done during loading but is postponed until execution time Dynamically linked libraries (DLLs) are system libraries that are linked to user programs when the programs are run E.g., standard C language library. When a program references a routine that is in a dynamic library, the loader locates the DLL, loading it into memory if necessary. It then adjusts addresses that reference functions in the dynamic library to the location in memory where the DLL is stored. Operating System Concepts – 10th Edition 9.18 Silberschatz, Galvin and Gagne ©2018 Dynamic Linking Without dynamic linking, each program on a system must include a copy of its language library or at least the routines referenced by the program, in the executable image. This requirement not only increases the size of an executable image but also may waste main memory DLLs libraries can be shared among multiple processes, so that only one instance of the DLL in main memory Also known as shared libraries Operating System Concepts – 10th Edition 9.19 Silberschatz, Galvin and Gagne ©2018 MEMORY PROTECTION – HARDWARE MEANS The relocation register contains the value of the smallest physical address WHILE The limit register contains the range of logical addresses For example, relocation = 100040 and limit = 74600. Each logical address must fall within the range set by the limit register. The MMU maps the logical address dynamically by adding the value in the relocation register. This mapped address (physical address) is sent to memory by MMU Operating System Concepts – 10th Edition 9.20 Silberschatz, Galvin and Gagne ©2018 End of Chapter 9 Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018