Sunday, September 1, 2019
Memory Management Strategies
ITCS 343 Opera-ng System Principles Memory Management Strategies Virtualizing Resources â⬠¢? Physical Reality: Di? erent Processes/Threads share the same hardware ââ¬â? Need to mul-plex CPU (Just ?nished: scheduling) ââ¬â? Need to mul-plex use of Memory (Today) ââ¬â? Need to mul-plex disk and devices (later in term) ââ¬â? The complete working state of a process and/or kernel is de? ned by its data in memory (and registers) ââ¬â? Consequently, cannot just let di? erent threads of control use the same memory ââ¬â? Probably donââ¬â¢t want di? erent threads to even have access to each otherââ¬â¢s memory (protec-on) â⬠¢?Physics: two di? erent pieces of data cannot occupy the same loca-ons in memory â⬠¢? Why worry about memory sharing? Memory Hierarchy of a Modern Computer System â⬠¢? Take advantage of the principle of locality to: ââ¬â? Present as much memory as in the cheapest technology ââ¬â? Provide access at speed o? ered by the fa stest technology Processor Control Second Level Cache (SRAM) Main Memory (DRAM) Secondary Storage (Disk) Tertiary Storage (Tape) On-Chip Cache Registers 1s 100s Datapath Speed (ns): Size (bytes): 10s-à ? 100s Ks-à ? Ms 100s Ms 10,000,000s 10,000,000,000s (10s ms) (10s sec) Gs Ts Background ? Program must be brought (from disk) into memory and placed within a process for it to be run â⬠¢? CPU can access directly to registers and main memory ââ¬â? Register access in one CPU clock (or less) ââ¬â? Main memory can take many cycles â⬠¢? Cache sits between main memory and CPU registers -à ? to reduce CPU idle .me and make the available data faster to access. â⬠¢? Protec-on of memory ensures correct opera-on ââ¬â? to protect the opera. ng system from access by user processes and, ââ¬â? to protect user processes from one another. ââ¬â? One simple implementa. on is through base and limit registers Mulââ¬âà ? stepProcessing of a Program for Execu-on â⬠¢? Prepara-on of a program for execu-on involves components at: â⬠¢? Addresses can be bound to ?nal values anywhere in this path â⬠¢? Dynamic Libraries ââ¬â? Compile -me (i. e. ââ¬Å"gccâ⬠) ââ¬â? Link/Load -me (unix ââ¬Å"ldâ⬠does link) ââ¬â? Execu-on -me (e. g. dynamic libs) ââ¬â? Depends on hardware support ââ¬â? Also depends on opera-ng system ââ¬â? Linking postponed un-l execu-on ââ¬â? Small piece of code, stub, used to locate the appropriate memory-à ? resident library rou-ne ââ¬â? Stub replaces itself with the address of the rou-ne, and executes rou-ne Mulââ¬âà ? step Processing of a Program or Execu-on â⬠¢? User programs go through several steps before being able to run. â⬠¢? This mulââ¬âà ? step processing of the program invokes â⬠¢? The appropriate u-lity (the rectangle) â⬠¢? Generates the required module at each step (the circle) â⬠¢? Basically, it is all about bind ââ¬â addres s mapping. Binding of Instruc9ons and Data to Memory â⬠¢? Address binding of instruc-ons and data to memory addresses can happen at three di? erent stages ââ¬â? Compile 9me: If memory loca-on known a priori, absolute code can be generated; must recompile code if star-ng loca-on changes ââ¬â? Load 9me: Must generate relocatable ode if memory loca-on is not known at compile -me ââ¬â? Execu9on 9me: Binding delayed un-l run -me if the process can be moved during its execu-on from one memory segment to another. Need hardware support for address maps (e. g. , base and limit registers) â⬠¢? Controlled overlap: â⬠¢? Address Type: ââ¬â? Separate state of threads should not collide in physical memory. Obviously, unexpected overlap causes chaos! ââ¬â? Conversely, would like the ability to overlap when desired (for communica-on) ââ¬â? A physical (absolute) address is a physical loca-on in main memory. ââ¬â? A logical (virtual) address is a eference to a m emory loca-on that is independent of the physical organiza-on of memory. ââ¬â? All memory references in user process are logical addresses. ââ¬â? A rela-ve address is an example of logical address in which the address is expressed as a loca-on rela-ve to some known point in the program (ex: the beginning address). â⬠¢? Transla-on: â⬠¢? Protec-on: ââ¬â? Ability to translate accesses from one address space (virtual) to a di? erent one (physical) ââ¬â? When transla-on exists, processor uses virtual addresses, physical memory uses physical addresses ââ¬â? Side e? ects: Can be used to avoid overlap,Can be used to give uniform view of memory to programs ââ¬â? Prevent access to private memory of other processes â⬠¢? Di? erent pages of memory can be given special behavior (Read Only, Invisible to user programs, etc). â⬠¢? Kernel data protected from User programs â⬠¢? Programs protected from themselves Base and Limit Registers â⬠¢? Each process has a separate memory space (logical/user address space). â⬠¢? A pair of base and limit registers de? ne the logical address space ââ¬â? base register holds the smallest legal physical address ââ¬â? limit register speci? es the size of the range of a process â⬠¢? Could se base/limit for dynamic address transla9on (oBen called ââ¬Å"segmenta9onâ⬠): ââ¬â? Alter address of every load/store by adding ââ¬Å"baseâ⬠ââ¬â? User allowed to read/write within segment à »? Accesses are rela9ve to segment so donââ¬â¢t have to be relocated when program moved to di? erent segment ââ¬â? User may have mul9ple segments available (e. g x86) à »? Loads and stores include segment ID in opcode: x86 Example: mov [es:bx],ax. à »? Opera9ng system moves around segment base pointers as necessary Mul-programming â⬠¢? Problem: Run mul-ple applica-ons in such a way that they are protected from one another â⬠¢? Goals: ââ¬â?Isolate processes and kernel fro m one another ââ¬â? Allow ?exible transla-on that: â⬠¢? Doesnââ¬â¢t lead to fragmenta-on â⬠¢? Allows easy sharing between processes â⬠¢? Allows only part of process to be resident in physical memory â⬠¢? (Some of the required) Hardware Mechanisms: ââ¬â? General Address Transla-on ââ¬â? Dual Mode Opera-on â⬠¢? Flexible: Can ?t physical chunks of memory into arbitrary places in users address space â⬠¢? Not limited to small number of segments â⬠¢? Think of this as providing a large number (thousands) of ?xed-à ? sized segments (called ââ¬Å"pagesâ⬠) â⬠¢? Protec-on base involving kernel/user dis-nc-on
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.