---------------- Memory Management Chapter 8 ---------------- Address binding Compile time Primitive Compiler generates absolute addresses Requires knowledge of where compilation unit will be loaded and run Rarely used (MSDOS .COM files) Load time Compiler generates relocatable addresses for each compilation unit Linkage editor converts to absolute addr by adding address where unit will load resolves inter-compilation-unit addresses Misnamed loader (ld) by unix Job cannot move Execution time Dynamically during program execution Needs hardware to help with this VIRTUAL to PHYSICAL address translation More later Dynamic Loading When executing a call check if loaded. If not, call linking loader to load it and update user tables Slows down calls (indirection) unless you rewrite code dynamically Dynamic Linking Normal linking is now called static (i.e. statically linked library) For dyn linked library, the routines are just trivial stubs that, when executed, check to see if a copy is already present and load one if it is not. In any case call patched up to go to full routine. Shared libraries (saves memory) A new bug fixed library is immediately used. A new bug-introduced library is immediately used. Needs OS help since two unrealed users accessing the same part of memory (more on this later). Overlays "My" era of programming. Fully under user-mode control. Human user controls when overlays are brought in. No longer used for gen'l purpose computing. Logical and Physical Adresses What the user sees vs what transistors (or capacitors) are used Simple example is relocation (a.k.a base) register Its value is ``added'' to every logical address This is execution time binding. Needs some hardware to translate virt to phy addresses Often called an MMU (mem mgt unit) Simple example is relocation (a.k.a base) register Its value is ``added'' to every logical address HOMEWORK 8.1 ``Honest to goodness'' Swapping Entire job is either in memory or not Bring back to same place unless have execution time binding Version 7 unix did this (Actually a v7 unix job had 3 segments and segments were swapped) Jobs (segments) not brought back to same place (MMU) Swapping Not true swapping if already have job on backing store due to demand paging. Then swapping out means paging out (More late) Fixed partitions At boot time divide real memory into partitions. Run a job in each. Separate job queues for each partition. Relocation register (and limit reg) sufficient MMU. IBM OS/MFT, Multiprogramming with a Fixed number of Tasks (early 360 OS) Can have big INTERNAL fragmentation, i.e. unused space within an allocated region (partition). (book is misleading here it says EXTERNAL but means that only for MVT) Variable Partitions IBM OS/MVT OS records which regions of memory are allocated and which are avail. Available regions called holes Number of partitions and their sizes vary dynamically Cute "Boundary tag" algorithm to keep track (NOT covered) When a memory request comes in, pick a big hole First-fit Normally circular (i.e. start looking where you left off) Best-fit Worst-fit HOMEWORK 8.2 8.5 If no hole big enough? If not enough mem, swap or wait or whatever but can't complain If enough mem but not in ONE hole, complain Called EXTERNAL fragmentation (outside any allocated region) HOMEWORK 8.4 Compaction Requires runtime binding Can be done with roll out / roll in, i.e. swapping with new location different from old. For these schemes the PHYSICAL memory for a job is contiguous What if the PHYSICAL memory for a job can be noncontiguous? Book says LOGICAL, must be a typo Paging Divide the logical address space into FIXED size pieces called pages. PAGESIZE is a power of 2, about 4KB Divide the physical addr space (i.e. real mem) into page frames. Same size as pages Page frames often called simply frames Map each page to a unique frame (same size) Need a PAGE TABLE to say which frame for each page Divide logical addr into page number and page offset (displacement) Often called p,d or p#,o or p#,d The page table is indexed by p# and gives f# (frame number, aka f) The logical addr p,d becomes f,d HOMEWORK 8.7 Can have page 2 assigned to frame 20 and page 3 assigned to frame 10 and page 4 assigned to frame 1111. So the physical addr space is definitely non-contiguous No external fragmentation since all frames are the right size Can have internal frag for last page of region. OS needs to know which frames are free Can have more frames than pages HOMEWORK 8.8 Next chapter will see more pages than frames. What hardware is needed for page tables? Simplest is to just have a page table in memory for each process and to have a single PTBR (page table base register) in the processor. This register, like R5, must be saved on context switch requires 2 memory accesses for each logical access Hopeless Have a "few" table entries in the processor Called TLB (translation look-asside buffer) or TB ASSOCIATIVE lookup on addr ``fancy'' hardware Normally used as a cache (sometimes entries pinned) Flushed when new page table is active (context switch) Some can be avoided with different organizations (not covered) Normally get > 95% HIT RATIO HOMEWORK 8.10