class: center, middle, title-slide ## CSCI 340 Operating Systems
## Chapter 9: Main Memory .author[ Stewart Weiss
] .license[ Copyright 2020-22 Stewart Weiss. Unless noted otherwise all content is released under a [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/). ] --- name: cc-notice template: default layout: true .bottom-left[© Stewart Weiss. CC-BY-SA.] --- name: tinted-slide template: cc-notice layout: true class: tinted --- name:toc ### Table of Contents [Prerequisite Reading](#prereqs)
[About This Chapter](#about-chapter)
[Chapter Objectives](#objectives)
--- name: prereqs ### Prerequisite Reading Before reading these slides, you should be familiar with - Computer and CPU Organization ([Chapter 1](chapter01.html)) - Process Representation ([Chapter 3](chapter03.html)) --- name: about-chapter ### About This Chapter After our brief overview of operating systems and review of underlying hardware in Chapter 1, we turned our attention to software: operating system structures, processes, and threads, and to issues related to software. A computer system is like a building: - The software entities (e.g., processes and threads) .greenbold[ are the occupants of the building.] - Storage, memory, devices, and their interconnections .greenbold[constitute the structure of that building.] - The building and its inhabitants interact with each other: - What the inhabitants do influences how the building should be built, and - How the building is built sets limitations on what its inhabitants can do. How memory is organized and managed has major impact on the performance of the software that runs in the computer, and the structure and organization of that software influences memory organization and design. This chapter examines .bluebold[memory] organization and management. It is the first of two chapters related to memory. --- name: objectives ### Chapter Objectives Having read and understood the content of this chapter, you should be able to - understand how memory is managed at the hardware level and the operating system level; - explain the difference between logical and physical addresses and the role of the memory management unit in address translation; - translate a logical to a physical address in a paging system both with and without translation-lookaside buffers; - describe different methods of implementing page tables; - explain how different ways of organizing memory affect program execution time; - explain the difference between internal and external fragmentation. --- name: background ### Background Following are the premises that underlie our study of main memory. 1. Executable code is stored on disk and brought into memory to be executed. 1. Processes running in the CPU can access only registers and main memory, not disks or I/O devices. 1. Register accesses are fast - they take place in a single clock cycle. 1. Memory accesses take much, much longer, requiring bus transactions, and result in processor .bluebold[stalls]. 1. .bluebold[Cache] is added to processor chips to speed up access to frequently used data and instructions (see [Chapter 1, Processor Cache ](chapter01.html#processor-cache)) --- name: model-1 ### The Memory Model In conventional computers, program code and data are stored in main memory. Processes run in the CPU and execute instructions. Instructions and their data are fetched during the instruction execution cycle: - Instructions are fetched first, followed by any operands that come from memory. In ```armasm mov r1, [r3] ``` the `mov` instruction is fetched, decoded, and then the contents of the address stored in `r3` are fetched from memory. -- - Some instructions may require writing results back to memory during the cycle. In ```armasm str r1, [sp #12] ``` the `store` instruction stores a result into an address stored at a 12-byte offset from the stack pointer `sp`. --- name: model-2 ### The Memory Model The memory unit sees only a sequence of fetch and store operations. It does not know if they are instructions or data. It does not matter. .bluebold[A process is simply a conceptual generator of memory addresses:] a1, a2, a3, a4, a5, ... The role of the memory unit is to access the addresses it is given and either retrieve data stored there or replace data stored there. -- Memory must also provide protection against unauthorized access, primarily: - the operating system's executable code and data must be protected from access by user processes, and - user processes must be protected from each other. These protections are provided in hardware rather than software for performance reasons. --- name: simple-protection ### Simple Protection Schemes A very simple method of preventing processes from accessing addresses that they should not access is to use a pair of registers called base and limit registers. - The base register stores the lowest legal address that the process can access. - The limit register stores an address just past the largest legal address that the process can access. - Each address generated by the CPU is compared to both and if it fails, it causes a trap to the OS. - When a process is started, the registers are loaded by the operating system. .center[
] This method is not used in any modern systems, although variations of it are used. --- --- name: references ### References