Click here to load reader

Memory Management 1. Address Binding The normal procedures is to select one of the processes in the input queue and to load that process into memory

Embed Size (px)

Citation preview

Memory Management

Memory Management1Address BindingThe normal procedures is to select one of the processes in the input queue and to load that process into memory.As the process executed, it accesses instructions and data from memory, when the process terminates, and its memory space is declared available.Most systems allow a user process to reside in any part of the physical memory.Address space of the computer starts at 00000, addresses may be represented in different ways.

23

4Addresses in the source program are generally symbolic. A compiler will typically bind these symbolic addresses to re-locatable addresses.The linkage editor or loader will in turn bind these re-locatable addresses to absolute addresses.Each binding is a mapping from one address space to another.5The binding instruction and data to memory address can be done at any step along the way:

Compile timeLoad timeExecution timeCompile Time6If you compile time where the process will reside in memory, the absolute code can be generated. For example, if you know a priori that a user process resides starting at location R, then the generated compile time will start at that location and extend up from there.Absolute code : - A code used when the addresses in a program are to be written in machine language exactly as they will appear when the instructions are executed by the control circuits. Load time7If it is not known at compile time where the process will reside in memory, then the compiler must generate re-locatable code.In this case, final binding is delayed until load time. If the starting address changes, we need only to reload the user code to incorporate this changed value.Execution time8If the process can be moved during its execution from one memory segment to another, then binding must be delayed until run time.Dynamic Loading9The entire program and data of a process must be in physical memory for the process to execute.To obtain better memory-space utilization, we can use dynamic loading.With dynamic loading, a routing is not loaded until it is called.All routines are kept on disk in re-locatable load format. The main program is loaded into memory and is executed.When routine needs to call another routine, the calling routine first checks to see whether the other routine has been loaded. 10If not, the re-locatable linking loader is called to load the desired routine into memory and to update the programs address tables to reflect this change.The advantage of dynamic loading is that an unused routines is never load.Useful when large amounts of code are needed to handle infrequently occurring cases.Dynamic loading does not require support from operating system. The designer job is to design their program to take advantage of such method.Logical vs. Physical Address Space11The concept of a logical address space that is bound to a separate physical address space is central to proper memory managementLogical address generated by the CPU; also referred to as virtual addressPhysical address address seen by the memory unitThe compile time and load-time address binding generate identical logical and physical address.However, the execution-time address binding scheme results in differing logical and physical addresses.We usually refer to the logical address as a virtual address

Memory Management Unit (MMU)12The run-time mapping from virtual to physical addresses is done by a hardware called the memory-management unit(MMU).

Swapping13A process can be swapped temporarily out of memory to a backing store, and then brought back into memory for continued execution.For example, a round robin scheduling algorithm. When quantum expires, the memory manager will start to swap out the process that just finished, and to swap in another process to the memory space that has been freed.( see figure on next slide).Schematic View of Swapping14

15Roll out, roll in swapping variant used for priority-based scheduling algorithms; lower-priority process is swapped out so higher-priority process can be loaded and executed.A process that is swapped out will swapped back into memory at same location that previously occupied.This restriction is dictated by the method of address binding.If binding is done at assembly or load time, then process can not move at different location but binding is done at execution time then a process can be swapped into a different memory space.16Swapping requires a backing store. Fast disk large enough to accommodate copies of all memory images for all users; must provide direct access to these memory images.

Contiguous Memory Allocation17The main memory must accommodate both the operating system and the various user processes.Main memory usually into two partitions:Resident operating system, usually held in low memory with interrupt vectorUser processes then held in high memory.

Concept(Base & Limit Register)18To separate each programs memory space, we need the ability to determine the range of legal addresses that the program may access, and to protect the memory outside the space.We can provide this protection by using two registers. i.e. Base register and Limit register.The base register hold the smallest legal physical memory address; the limit register contains the size of range.For example, if the base register holds 300040 and limit register is 120900 then the program can legally access all addresses from 300040 through 420940 inclusive.19This protection is accomplished by the CPU hardware comparing every address generated in user mode with registers.Any attempt by a program executing in user node to access monitor memory or other users memory results in trap to the monitor, which treats the attempts as a fatal error.This scheme prevents the user program from modifying the code or data structure of either the operating system or other users.Memory Protection20Protecting the operating system from user processes, and protecting user processes from one another.The relocation register contains the value of smallest physical address; the limit register contains the range of logical addresses.With relocation and limit register , each logical address must be less than limit register.The MMU maps the logical address dynamically by adding the value in the relocation register.

21When the CPU scheduler selects a process for execution, the dispatcher load the relocation and limit registers with correct values.Every address generated by the CPU is checked against these registers.The relocation register scheme provides an effective way to allow the OS size to change dynamically.For example, the OS contains code and buffer space for device drivers. If a device driver not in used, we do not need to keep the code and data in memory so we can able to allocate the space for another purpose.Such code is some times called transient OS code.22CPUMEMORYLimit RegisterRelocationRegister+