Saturday, March 19, 2011

Memory Management


  • effective memory management is vital in a multiprogramming system.
  • if only a few processes are in memory, then for much of the time of the processes will be waiting for input output and the processors will be idle.
  • thus, memory needs to be allocated efficiently to pack as many processors into memory possible.

Objectives
While surveying the various mechanisms and policies associated with
memory management, it is well to keep in mind the requirements that
memory management is intended to satisfy. It suggests five requirements:
  • Relocation
  • Protection
  • Sharing
  • Logical organization
  • Physical organization

Relocation
  • in a multiprogramming system, the available main memory is generally shared among a number of processes.
  • typically it is not possible for programmer to know in advance which are the programs that will reside in the memory during the execution time of a program.
  • able to swap active processes in and out of main memory to maximize processors usage by providing a large pool of ready processes to execute.
  • once a program has been swapped to disk, it would be quite limiting to declare that when it is next swapped back in it must be placed in the same main memory region as before.

Protection
·        each process should be protected against unwanted interference by other processes, whether accidental or intentional.
·        programs in other processes should not be able to reference memory locations in a process, for reading and writing purposes without permission.
·        in one sense, satisfaction of the relocation requirement increases under difficulty of satisfying the protection requirement.
·        because the location of a program in main memory is unknown, it is possible to check absolute addresses at compile time to assure protection.



Sharing
  • any protection mechanisms that are implemented must have the
flexibility to allow several processors to access the same portion of main memory.
  • for example, if a number of processes are executing the same program, it is advantageous to allow each process to access the same copy of the program rather than have it on separate copy.
  • processes that are cooperating on some task may need to share access to the same data structure.
  • the memory management system must therefore allow control access to shared areas of memory without compromising essential protection.

Logical Organization
  • almost invariably, main memory in a computer system is organized as a linear, or one-dimensional, address space that consists of sequence of byte or words.
  • secondary memory, at its physical level, is similarly organized.
  • although the organization closely mirrors the actual machine hardware, it does not correspond to the way in which program are typically instructed.

Physical Organization
  • computer memory is organized into at least two levels: main memory and secondary memory.
  • main memory provides fast access at relatively high cost.
  • main memory is volatile; that is, it does not provide permanent storage.
  • Secondary memory is slower and cheaper than main memory, and it is usually not volatile.
  • secondary memory’s large capacity can be provided to allow long term storage of programs and data, while a smaller main memory holds programs and data currently in use.

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

Segmentation
  • Memory-management scheme that supports user view of memory
  • A program is a collection of segments. A segment is a logical unit
such as:

main program,
procedure,
function,
method,
object,
local variables, global variables,
common block,
stack,
symbol table, arrays


Relocation policy
  • before consider ways of dealing with the shortcomings of partitioning, we must clear up one loose end, which relates to the placement of processes in memory.
  • when the fix partition scheme is used, we can expect that a process will always be a sign to the same partition.
  • that is, the partition that is selected when a new process is loaded will always be used to swapped the process back into memory after it has been swapped up.
  • when the process is first loaded all relative memory references in the code are replaced by absolute main memory addresess determine by the base address of the loaded process.
  • in the case of equal size partitions and in the case of a single process queue for unequal size partitions, a process may occupied different partitions during the course of its life.
  • when a process image is first created, it is loaded into some partitions in main memory.
  • Later, the process may be swapped out; when it is subsequently swapped back in, it may be assigned to a partition different from the previous one.
  • The same is true for dynamic partitioning.


Relocation of paging system - Least Recently Used (LRU), First In First Out (FIFO)

Least Recently Used (LRU):

  •       Removes page least recently accessed
  •       Efficiency
  •       Causes either decrease in or same number of interrupts
  •       Slightly better (compared to FIFO): 8/11 or 73%
  •       LRU is a stack algorithm removal policy
  •       Increasing main memory will cause either a decrease in or the same number of page    interrupts
  •       Does not experience FIFO anomaly

Two variations:

  •          Clock replacement technique
  •          Paced according to the computer’s clock cycle
  •          Bit-shifting technique
  •          Uses 8-bit reference byte and bit-shifting technique
  •          Tracks usage of each page currently in memory

First In First Out (FIFO):

  •          Removes page in memory the longest
  •          Efficiency
  •          Ratio of page interrupts to page requests
  •          FIFO example: not so good
  •          Efficiency is 9/11 or 82%

No comments:

Post a Comment