Memory Management in Operating System



o      As a result of CPU scheduling there is an improvement in CPU utilization and the speed of the computers response to its users.
o      Memory is central to the operation of modern computer system.
o      It consists of large array of words or bits each with its own address.
o      The CPU fetches the instruction from memory according to the value of the program counter.
o      This instruction may cause additional loading from and restoring to specific address.
o      The typical instruction execution cycle ex. Fetching instruction from memory then decode & also the operands to be fetched from memory.
o      After the instruction has been executed on these operands result again back in memory.

Address Binding: -

o      Program reads on disk as a binary executable file the program must be brought in to memory for its execution.
o      Depending on memory management approach the process may be moved between disk & memory during its execution.
o      The collection of processes on the disk waiting to the brought into the memory for the execution forms the input queue.
o      The normal procedure is to select one of the processes from the input queue and they load that process in to memory.
o      As the process is executed it excess instruction and data from memory.
o      Eventually process terminated memory space is declared available for other processes.
o      Addresses may be represented in different way during these steps.
o      Addresses in source program are, as a symbolic constant a compiler will typically bind these Symbolic addresses in re-locatable addresses or code. (14 bytes of the beginning of the program)
o      The linkage editor or loader will in turn bind these re-locatable addresses to absolute address. (Such as 74014)
Each binding is a mapping from one address space to another


Address Binding Schemes:-

Compile Time:-

o      If you know of compile where the process will reside in memory them absolute code can be generated.
o      If you know advance that a user process besides starting from location R, that the generated code will start at that location and extend up from there.
o      If at some later time starting location changes will be necessary to recompile this code.
o      Ms-dos based dot com format programs are absolute code and bound at compile time.

Load Time:-

o      It is not known at compile time where the process will reside in memory when the compiler will generate re-locatable code to find the address. In this case final binding is delayed until load time.

Execution Time: -

o      If the process can be moved during its execution from one memory segment to another then binding must be delay until run time.
o      Towards the scheme special hardware is required and that is MMU (Memory Management Unit).

Logical Address V/S Physical Address

o       Address generated by the CPU is commonly referred as logical address.
o       Where as an address seen by the MMU that is loaded in to Memory Address Register.
o       It is commonly referred as physical address.
o      The compile time and load time address binding method generate same logical and physical address
o      Execution time address binding mechanism does not generate physical address.
o      In this case it generates logical or virtual address.
o      The set of physical addresses correspond to each logical address is physical address space.
o      The mapping from virtual address to physical address is done by hardware device called MMU.
o      Deferent Methods are to accomplice to get this mapping.
o        In this scheme based register is used. It is also call a re-location register.
o      The value in base register is added to every address generated by a user and then it is sent to the memory.
o      Ex. Base Register = 14,000
User Address =      346

o      Physical Address = 14,346
 

o      The Ms-dos operating system running in 80*86 Intel family of processor users for relocation register for running processes.
o      The user program never sees the real physical address, only user deals with logical address.
o      If logical address are in the range from 0 to max than all corresponding physical address are in the range of R to R + Max.
     (Where R= address of base register)
o      The user generates only logical addresses and things and the process run in 0 to Max.

Memory-Management Unit (MMU)

o      Hardware device that maps virtual to physical address.
o      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.
o      The user program deals with logical addresses; it never sees the real physical addresses.


Swapping: -

o      A process needs to be in memory to be executed.
o      A process, how ever can be swap temporarily out of memory to a backing store and than brought get in to the memory for continue execution.
o      Assume a multi-programming environment with a round robin algorithm.
When a time quantum value expires, memory manager will start to swap out the process that just finished and swap in another process to the memory

o      A swapping policy is used for priority based scheduling algorithm.
o      If higher priority process arrives and wants service on memory management can swap out the lower priority process so that it can load and execute the higher priority process.
o      When the higher priority process finishes, the lower priority process can be swap backing and continue. This type of swapping is called roll out and roll in.
o      Normally a process that is swapped out will be swapped back in to the same memory space that is occupied sequentially.
o      This restriction is determined by the method of address binding.
o      If binding scheme is compile or load time then the process can’t be moved to deferent location.
o      If execution time binding is used the process can be swapped in to different memory space, because physical address are computed during execution time.
o      Swapping requires a backing store it is commonly referred as hard disk.
o      It must be large enough to accommodate copies of all memory images for all users.
o      When CPU scheduler decides to execute a process it calls dispatcher.
o      A dispatcher check to see whether the next process is in the queue or in main memory.
o      If not and that is no memory region, the dispatcher swap out the process currently in and swaps in the desired process.
o      If we want to swap a process, it must be completely ideal.
o      A process waiting for an IO operation when we want to swap that process to free up its memory.
o      If we want to swap out process p1 and swap in process p2.
o      The IO operation of process p1 might attempt to use memory that belongs to process p2.
o      Main solution of this problems are never to swap a process with pending IO or the execute an IO operation only in to operating system buffers.
o      Standard swapping is used in few systems.
o      Any swapped up process remains swapped out until user select that process to run.






Memory Protection: -

o      It is protection the O/S from user processes and protecting user process from one another.
o      Protection is given by using of re-location register and limit register to separate each program memory space. we give ability to determine the range of legal addresses that the program may access and to protect the memory out side that space.
o      The base register holds the smallest physical memory address.
o      The limit register contains the size of the range.
o      If base register holds this value 300040 and limit register holds this value 120900 than the program can legally access addresses from this inclusive 300040 to 420940.
o      With relocation and limit register each logical address must be less than the limit register.
o      When the CPU scheduler selects process for execution the dispatcher holds the relocation and limit register with correct value as a part of contents switch.
o      The relocation register scheme provides an effective way allow to operating system size to change dynamically.
o      The flexibility is desirable in many situations.
o      Ex. The operating system contains code & buffer space for each device driver.
If a device driver (OS service) is not commonly used, we did not want to keep the code and data in memory as we might use that space for other purpose.
Such code is sometimes called transient operating system it comes and goes as needed. Thus, using this code changes the size of the operating system during execution.



Memory Allocation: -

o      One of the simplest for memory allocation is to divide memory in to several fixed size partition.
o      Each partition may contain exactly 1 process.
o      In this multiple partition method when partition is free, a process is selected from the input queue and is loaded in to free partition.
o      When the process terminates partition becomes available for another process.
o      IBM36 OS originally used this method.
o      Operating System keeps a table indicating which parts of memory are available and which are occupied.
o      Initially all memory is available for user processes and it’s considered as one large block of memory called hole.
o      When a process arrives and needs memory, allocate a hole that is large enough for the process.
o      we allocate only as much memory as needed. Keeping the rest available to satisfied further request.

Dynamic Storage-Allocation Problem

o      First-fit:  Allocate the first hole that is big enough.

o      Best-fit:  Allocate the smallest hole that is big enough; must search entire list, unless ordered by size.  Produces the smallest leftover hole.

o      Worst-fit:  Allocate the largest hole; must also search entire list.  Produces the largest leftover hole.
o      First-fit and best-fit better than worst-fit in terms of speed and storage utilization




Fragmentation

o      External Fragmentation – total memory space exists to satisfy a request, but it is not contiguous.
o      Internal Fragmentation – allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used.
o      Reduce external fragmentation by compaction
o   Shuffle memory contents to place all free memory together in one large block.
o   Compaction is possible only if relocation is dynamic, and is done at execution time.


Paging

o      Logical address space of a process can be noncontiguous; process is allocated physical memory whenever the latter is available.
o      Divide physical memory into fixed-sized blocks called frames (size is power of 2, between 512 bytes and 8192 bytes).
o      Divide logical memory into blocks of same size called pages.
o      Keep track of all free frames.
o      To run a program of size n pages, need to find n free frames and load program.
o      Set up a page table to translate logical to physical addresses.
o      Internal fragmentation.

 

 
Memory Management in Operating System Memory Management in Operating System Reviewed by Unknown on 7:54:00 AM Rating: 5

No comments:

Powered by Blogger.