memory questions
play

Memory Questions? ! What is main memory? CSCI [4|6]730 ! How does - PDF document

Memory Questions? ! What is main memory? CSCI [4|6]730 ! How does multiple processes share memory Operating Systems space? Key is how do they refer to memory addresses? ! What is static and dynamic allocation? Main Memory ! What is


  1. Memory Questions? ! What is main memory? CSCI [4|6]730 ! How does multiple processes share memory Operating Systems space? » Key is how do they refer to memory addresses? ! What is static and dynamic allocation? Main Memory ! What is segmentation ? Maria Hybinette, UGA Maria Hybinette, UGA Review: Motivation for Multiprogramming Multiprogramming Goals Uniprocessing: One process runs at a time High Address (0x7fffffff) 2 n -1 ! Sharing Physical » Several processes coexist in main memory Memory OS Stack » Cooperating processes can share portions of address space ! Transparency » Processes are not aware that memory is shared » Works regardless of number and/or location of processes User Address ! Protection Space Heap Process » Cannot corrupt OS or other processes » Privacy: Cannot read data of other processes Code 0 ! Efficiency ! Disadvantages: Low Address » Do not waste CPU or memory resources (0x00000000) » Only one process runs at a time » Keep fragmentation low (later) » Process can destroy OS Maria Hybinette, UGA Maria Hybinette, UGA Memory Addresses Static Relocation (after loading) System Memory ! Address space ! Goal: Allow transparent sharing - Each address space may be » What we go so far: Initial P 0 placed anywhere in memory – Physical addresses Process P 1 » OS finds free space for new process » Modify addresses statically (similar Process P 2 to linker) when loading the process » Fixed addresses. Process P 3 ! Advantages: » Allows multiple processes to run » Requires no hardware support Maria Hybinette, UGA Maria Hybinette, UGA

  2. Static Reallocation Dynamic Relocation System Memory ! Disadvantages: ! Goal: Protect processes from one another » No protection ! Requires hardware support Initial P 0 – Process can destroy OS or other » Memory Management Unit (MMU) processes ! MMU dynamically changes process address at every Process P 1 – No privacy memory reference (compute address on-the-fly) » Address space must be allocated Process P 2 » Process generates logical or virtual addresses contiguously » Memory hardware uses physical or real addresses – Allocate space for worst-case stack and heap Process P 3 Process runs here – Processes may not grow OS can control MMU » Cannot move process after they are CPU MMU placed or loaded (static addresses) Memory Process P 4 » Fragmentation (later) Logical address Physical address Maria Hybinette, UGA Maria Hybinette, UGA Hardware Support for Implementation of Dynamic Relocation Dynamic Relocation ! Translation on every memory access of user process ! Two operating modes » MMU compares logical address to bounds register » Privileged (protected, kernel) mode: OS runs – if logical address is greater, then generate error – When enter OS (trap, system calls, interrupts, exceptions) » MMU adds base register to logical address to form physical address – Allows certain instructions to be executed ! Can manipulate contents of MMU – Allows OS to access all of physical memory logical » User mode: User processes run mode ! no " physical = ! address user? " address – Perform translation of logical address to physical address Registers: " ! MMU contains base and bounds registers mode ! 1 bit " yes " » base: start location for address space (physical address) » bounds: size limit of address space (memory span) bounds ! no " + ! 32 < " error bounds? " bits " base ! base ! 10 Maria Hybinette, UGA Maria Hybinette, UGA Managing Processes Example of Dynamic Relocation with Base and Bounds ! What are the physical addresses for the following 16- ! Context-switch bit logical addresses (HEX: highest F:1111)? » Add base and bounds registers to PCB ! Process 1: base: 0x4320 , bounds: 0x2220 (in HEX) � » Steps: » 0x0000: � 1. Change to privileged mode 2. Save base and bounds registers of old process » 0x1110: � 3. Load base and bounds registers of new process » 0x3000: � 4. Change to user mode and jump to new process ! Process 2: base: 0x8540 , bounds: 0x3330 � ! What if don ’ t change base and bounds registers when » 0x0000: � switch? » 0x1110: � ! Protection requirement » 0x3000: � » User process cannot change base and bounds registers ! Operating System » User process cannot change to privileged mode » 0x0000: � » 0x5FFF: � 12 Maria Hybinette, UGA Maria Hybinette, UGA

  3. Base and Bounds Discussion Segmentation 0 " ! Advantages heap " ! Divide address space into Operating » Provides protection (both read and System logical segments write) across address spaces stacj " » Each segment » Supports dynamic relocation 30004 " 30004 " symbol " corresponds to logical subroutine " – Can move address spaces Process base " table " entity in address space – Why might you want to do this? 42094 " 12090 " – code, stack, heap » Simple, inexpensive: Few registers, bound " little logic in MMU Process ! Each segment can symbol " subroutine " table " » Fast: Add and compare can be done in independently: main " table " program " parallel » be placed separately in ! Disadvantages physical memory stack " » Each process must be allocated » grow and shrink main " contiguously in physical memory Process program " » be protected (separate – Must allocate memory that may not be heap " read/write/execute used by process protection bits) » No partial sharing: Cannot share limited parts of address space Logical Address Physical Address 13 14 Space Space Maria Hybinette, UGA Maria Hybinette, UGA Segmented Addressing Segmentation Implementation ! MMU contains Segment Table (per process) ! How does process designate a particular » Each segment has own base and bounds, protection bits » Example: 14 bit logical address, 4 segments segment? Segment Base Bounds R W » Use part of logical address – Top bits of logical address select segment 0 0x2000 0x06ff 1 0 – Low bits of logical address select offset within 1 0x0000 0x04ff 1 0 segment 2 0x3000 0x0fff 1 1 3 0x1000 0x0fff 0 0 ! Translate logical addresses ! physical addresses: » 0x0240: 0 th segment 240 internal address within segment ! what address? � » 0x1108: � » 0x265c: � » 0x3002: � 15 16 Maria Hybinette, UGA Maria Hybinette, UGA When to Bind Discussion of Segmentation Physical & Logical Addresses Source " Program " ! Compile time: If memory location ! Advantages known a priori, absolute code can be » Enables sparse allocation of address space Compiler or generated; must recompile code if Assembler – Stack and heap can grow independently starting location changes – Heap: If no data on free list, dynamic memory allocator requests more from OS (e.g., UNIX: malloc calls sbrk()) ! Load time: Must generate Object " Other " – Stack: OS recognizes reference outside legal segment, Module " relocatable code if memory location Object " extends stack implicitly Modules " is not known at compile time » Different protection for different segments Linkage ! Execution time: Binding delayed editor – Read-only status for code until run time if the process can be System " » Enables sharing of selected segments Library " Load " moved during its execution from » Supports dynamic relocation of each segment module " one memory segment to another. ! Disadvantages Need hardware support for address » Each segment must be allocated contiguously loader System " maps (e.g., base and limit registers) Library " – May not have sufficient physical memory for large segments In-memory Binary 17 18 Memory image Maria Hybinette, UGA Maria Hybinette, UGA

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend