chapter 9 memory questions
play

Chapter 9: Memory Questions? What is main memory? CSCI [4|6]730 - PDF document

Chapter 9: Memory Questions? What is main memory? CSCI [4|6]730 How does multiple processes share memory Operating Systems space? What is static and dynamic allocation? What is segmentation ? Main Memory 2 Maria


  1. Chapter 9: Memory Questions? � � What is main memory? CSCI [4|6]730 � � How does multiple processes share memory Operating Systems space? � � What is static and dynamic allocation? � � What is segmentation ? Main Memory 2 Maria Hybinette, UGA Maria Hybinette, UGA Review: Motivation for Multiprogramming Multiprogramming Goals Uniprocessing: One process runs at a time Low Address 2 n -1 � � Sharing (0x00000000) 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: High Address » � Do not waste CPU or memory resources (0x7fffffff) » � Only one process runs at a time » � Keep fragmentation low (later) » � Process can destroy OS 3 4 Maria Hybinette, UGA Maria Hybinette, UGA Static Relocation Static Reallocation System Memory System Memory � � Goal: Allow transparent sharing - � � Disadvantages: Each address space may be » � No protection Initial P 0 Initial P 0 placed anywhere in memory – � Process can destroy OS or other processes » � OS finds free space for new process Process P 3 Process P 3 – � No privacy » � Modify addresses statically (similar » � Address space must be allocated to linker) when loading process contiguously Process P 2 Process P 2 � � Advantages: – � Allocate space for worst-case stack and heap » � Allows multiple processes to run – � Processes may not grow » � Requires no hardware support » � Cannot move process after they are placed Process P 1 Process P 1 » � Fragmentation (later) 5 6 Maria Hybinette, UGA Maria Hybinette, UGA

  2. Hardware Support for Dynamic Relocation Dynamic Relocation � � Goal: Protect processes from one another � � Two operating modes � � Requires hardware support » � Privileged (protected, kernel) mode: OS runs » � Memory Management Unit (MMU) – � When enter OS (trap, system calls, interrupts, exceptions) � � MMU dynamically changes process address at every – � Allows certain instructions to be executed memory reference (compute address on-the-fly) � � Can manipulate contents of MMU – � Allows OS to access all of physical memory » � Process generates logical or virtual addresses » � User mode: User processes run » � Memory hardware uses physical or real addresses – � Perform translation of logical address to physical address Process runs here � � MMU contains base and bounds registers OS can control MMU » � base: start location for address space CPU MMU Memory » � bounds: size limit of address space 7 8 Logical address Physical address Maria Hybinette, UGA Maria Hybinette, UGA Implementation of Dynamic Relocation Example of Dynamic Relocation � � Translation on every memory access of user process � � What are the physical addresses for the following 16- » � MMU compares logical address to bounds register bit logical addresses (Hex: highest F:1111)? – � if logical address is greater, then generate error � � Process 1: base: 0x4320 , bounds: 0x2220 � » � MMU adds base register to logical address to form physical address » � 0x0000: � » � 0x1110: � » � 0x3000: � logical mode � no � physical � � Process 2: base: 0x8540 , bounds: 0x3330 � = � address user? � address » � 0x0000: � Registers: � » � 0x1110: � mode � 1 bit � yes � » � 0x3000: � � � Operating System bounds � no � + � 32 < � error bounds? � » � 0x0000: � bits � base � base � 9 10 Maria Hybinette, UGA Maria Hybinette, UGA Managing Processes with Base and Bounds Base and Bounds Discussion 0 � � � Advantages Operating � � Context-switch » � Provides protection (both read and System write) across address spaces » � Add base and bounds registers to PCB » � Supports dynamic relocation » � Steps 30004 � 30004 � – � Can move address spaces 1. Change to privileged mode Process base � – � Why might you want to do this? 2. Save base and bounds registers of old process 42094 � 12090 � » � Simple, inexpensive: Few registers, 3. Load base and bounds registers of new process bound � little logic in MMU Process 4. Change to user mode and jump to new process » � Fast: Add and compare can be done in � � What if don’t change base and bounds registers when parallel switch? � � Disadvantages � � Protection requirement » � Each process must be allocated » � User process cannot change base and bounds registers contiguously in physical memory Process » � User process cannot change to privileged mode – � Must allocate memory that may not be used by process » � No partial sharing: Cannot share limited parts of address space 11 12 Maria Hybinette, UGA Maria Hybinette, UGA

  3. Segmentation Segmented Addressing heap � � � Divide address space into � � How does process designate a particular logical segments stacj � segment? » � Each segment symbol � corresponds to logical subroutine � » � Use part of logical address table � entity in address space – � Top bits of logical address select segment – � code, stack, heap – � Low bits of logical address select offset within � � Each segment can symbol � subroutine � segment table � main � independently: table � program � » � be placed separately in physical memory stack � » � grow and shrink main � program � » � be protected (separate heap � read/write/execute protection bits) Logical Address Physical Address 13 14 Maria Hybinette, UGA Space Space Maria Hybinette, UGA Segmentation Implementation Discussion of Segmentation � � MMU contains Segment Table (per process) � � Advantages » � Each segment has own base and bounds, protection bits » � Example: 14 bit logical address, 4 segments » � Enables sparse allocation of address space – � Stack and heap can grow independently Segment Base Bounds R W – � Heap: If no data on free list, dynamic memory allocator requests more from OS (e.g., UNIX: malloc calls sbrk()) 0 0x2000 0x06ff 1 0 – � Stack: OS recognizes reference outside legal segment, 1 0x0000 0x04ff 1 0 extends stack implicitly » � Different protection for different segments 2 0x3000 0x0fff 1 1 – � Read-only status for code 3 0x0000 0xffff 0 0 » � Enables sharing of selected segments » � Supports dynamic relocation of each segment � � Translate logical addresses � physical addresses: � � Disadvantages » � 0x0240: 0 th segment 240 internal address within segment � what address? � » � Each segment must be allocated contiguously » � 0x1108: � – � May not have sufficient physical memory for large segments » � 0x265c: � » � 0x3002: � 15 16 Maria Hybinette, UGA Maria Hybinette, UGA When to Bind Physical & Logical Addresses Motivation for Dynamic Memory Source � Program � � � Compile time: If memory location � � Why do processes need dynamic allocation of memory? known a priori, absolute code can be » � Do not know amount of memory needed at compile time Compiler or generated; must recompile code if Assembler » � Must be pessimistic when allocate memory statically starting location changes – � Allocate enough for worst possible case � � Load time: Must generate Object � – � Storage is used inefficiently Other � Module � Object � relocatable code if memory location � � Recursive procedures Modules � is not known at compile time » � Do not know how many times procedure will be nested Linkage � � Execution time: Binding delayed editor � � Complex data structures: lists and trees until run time if the process can be System � » � struct my_t Library � Load � moved during its execution from module � *p = (struct my_t *)malloc(sizeof(struct one memory segment to another. my_t)); Need hardware support for address � � Two types of dynamic allocation loader System � maps (e.g., base and limit registers) Library � » � Stack In-memory » � Heap 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