Memory Main Memory

Memory Main Memory

Main Memory Electrical and Computer Engineering Stephen Kim ([email protected]) ECE/IUPUI RTOS & APPS 1 Main Memory n Background n Swapping n Contiguous allocation n Paging n Segmentation n Segmentation with paging ECE/IUPUI RTOS & APPS 2 1 Background n Program must be brought into memory and placed within a process for it to be run. n Input queue – collection of processes on the disk that are waiting to be brought into memory to run the program. n User programs go through several steps before being run. n From the memory-unit viewpoint, a CPU generate a stream of memory address. u It doesn’t matter how they were generated or what they are for. ECE/IUPUI RTOS & APPS 3 Binding of Instructions and Data to Memory n Most systems allow a user program to reside in any part of the physical memory. u How can a user program know where its data are? n Address binding of instructions and data to memory addresses can happen at three different stages u Compile time : if memory location known a priori, absolute code can be generated; Must recompile code if starting location changes. u Load time: must generate relocatable code if memory location is not known at compile time. u Execution time : binding delayed until run time if the process can be moved during its execution from one memory segment to another. Need hardware support for address maps (e.g., Base and limit registers). ECE/IUPUI RTOS & APPS 4 2 Multistep Processing of a User Program ECE/IUPUI RTOS & APPS 5 Logical vs. Physical Address Space n The concept of a logical address space that is bound to a separate physical address space is central to proper memory management. u Logical address – generated by the CPU; also referred to as virtual address. u Physical address – address seen by the memory unit. n Logical and physical addresses are the same in compile-time and load-time address-binding schemes; logical (virtual) and physical addresses differ in execution-time address-binding scheme. ECE/IUPUI RTOS & APPS 6 3 Memory-Management Unit (MMU) n Hardware device that maps virtual to physical address. n In MMU scheme, the value in the relocation register is added to every address generated by a user process at the time it is sent to memory. n The user program deals with logical addresses; it never sees the real physical addresses. ECE/IUPUI RTOS & APPS 7 Dynamic relocation using a relocation register ECE/IUPUI RTOS & APPS 8 4 Dynamic Loading n Routine is not loaded until it is called n Better memory-space utilization; Unused routine is never loaded. u All routines are staying on disk in a relocatable load format. The main program is loaded into memory and is executed. When a routine needs to call another routine, the calling routine first check to see whether the other routine has been loaded. If not, the relocatable linking loader is called to load the desired routine into memory and to update the program’s address table to reflect this change. Then, control is passed to the newly loaded routine. n Useful when large amounts of code are needed to handle infrequently occurring cases. (eg. Error handling routines) n No special support from the operating system is required implemented through program design. u It is the responsibility of the user to design their program to take advantage of such a method. ECE/IUPUI RTOS & APPS 9 Dynamic Linking n Similar to dynamic loading. Linking postponed until execution time. n Small piece of code, stub, used to locate the appropriate memory-resident library routine. n Stub replaces itself with the address of the routine, and executes the routine. n All processes that use a language library execute only one copy of the library code. n Operating system needed to check if routine is in processes’ memory address. n Dynamic linking is particularly useful for libraries. u A library may be replaced by a new version, and all programs that references the library will automatically use the new version. ECE/IUPUI RTOS & APPS 10 5 Overlays n To make a process larger than an allocated memory n Keep in memory only those instructions and data that are needed at any given time. n Implemented by user, no special support needed from operating system, programming design of overlay structure is complex n Example) u Pass1 70 KB, Pass2 80 KB, Symbol Table 20KB, Common routine 30KB u Without overlay, 200KB is required u The overlay itself needs some memory space, says 10KB ECE/IUPUI RTOS & APPS 11 Overlays for a Two-Pass Assembler With the overlay, 140KB is enough ECE/IUPUI RTOS & APPS 12 6 Swapping (1) n A process can be swapped temporarily out of memory to a backing store, and then brought back into memory for continued execution. n Backing store – fast disk large enough to accommodate copies of all memory images for all users; must provide direct access to these memory images. ECE/IUPUI RTOS & APPS 13 Swapping (2) n Major part of swap time is transfer time; total transfer time is directly proportional to the amount of memory swapped. u For example, 1 MB process, 5MB / sec hard-disk, no head seeks, average latency 8 msec. u The total swap time is ( swap-out and swap-in) 2 * (1MB / (5 MB/sec) + 8 msec)=416 msec u If the system uses Round-robin, the time quantum must be much larger than 416 msec. n Modified versions of swapping are found on many systems, i.e., UNIX, Linux, and Windows. ECE/IUPUI RTOS & APPS 14 7 Schemes of Memory Allocation n Contiguous Allocation n Paging n Segmentation n Segmentation with Paging ECE/IUPUI RTOS & APPS 15 Contiguous Allocation n Main memory usually into two partitions: u Resident operating system, usually held in low memory u User processes then held in high memory. n Why an OS in low memory? u location of interrupt vector table n Single-partition allocation u Relocation-register scheme used to protect user processes from each other, and from changing operating-system code and data. u Relocation register contains value of smallest physical address; limit register contains range of logical addresses – each logical address must be less than the limit register. ECE/IUPUI RTOS & APPS 16 8 CA, Hardware Support for Relocation and Limit Registers n MMU maps the logical address dynamically by adding the value in the relocation register. Memory Management Unit limit relocation register register logical physical address yes address CPU < + Memory no trap: addressing error ECE/IUPUI RTOS & APPS 17 CA, Memory Allocation n OS maintains a table for allocated memory block and available memory block n Initially, all memory is available, so there is one large block of available memory, or one big hole n Holes of various size are scattered throughout memory. u When a process arrives, it is allocated memory from a hole large enough to accommodate it. u If a hole is large, it is split into two segments, t one for allocating to a new process, t the other hole is returned to the pool of holes. u When a process terminates, it releases its block which is placed to the pool of holes. ECE/IUPUI RTOS & APPS 18 9 CA, Dynamic Storage-Allocation Problem n How to satisfy a request from the set of available holes u Random-fit: choose an arbitrary hole among those large enough; not good utilization u First-fit: Allocate the first hole of the table that is big enough. Time complexity is O(N/2), where N is the number of holes. u Best-fit: Allocate the smallest hole that is big enough; must search entire list, unless ordered by size. Produces the smallest leftover hole. Time complexity is O(N). u Worst-fit: Allocate the largest hole; must also search entire list. Produces the largest leftover hole. utilization is worse than FF & BF. u Next-fit: Like FF, but start the search at the hole where the last placement was made and treat the list of holes as a circular lis t. Time complexity O(N) n utilization = occupied_memory / total_memory ECE/IUPUI RTOS & APPS 19 CA, Knuth Foundings n For most placement policies including BF&FF, the number of holes is, on average, approximately equal to one half the number of segments u N segments u N/2 unusable holes n BF & FF had about the same utilization ECE/IUPUI RTOS & APPS 20 10 CA, Fragmentation n External Fragmentation– total memory space exists to satisfy a request, but there is no single hole to hold the request n Internal Fragmentation u To solve the external fragmentation, the memory is partitioned into a fixed-size block. u Then, allocate memory in unit of block size, but not in byte. u Allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used. ECE/IUPUI RTOS & APPS 21 CA, Compaction n Reduce external fragmentation by compaction n Shuffle memory contents to place all free memory together in one large block. n Compaction is possible only if relocation is dynamic, and is done at execution time. ECE/IUPUI RTOS & APPS 22 11 CA, Binary Buddy Systems, Method n The system keeps the lists of holes, one list for each of the size 2m, 2m+1,… ,2n, where 2m is the smallest segment size. n A request to place a segment of size s k k-1 k u Round s upto the next power of 2, ie. 2 such that 2 <s£2 k u Look in the free list for size 2 .

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    34 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us