Wednesday, November 28, 2012

Memory Management


Introduction:

This topic describe how operating system manages for memory, and which types of managing its use and what is the best way of managing memory.


                             Basic requirements that drive memory designs

 


  •  The primary memory access time must be as small as possible. This need  influences both software and hardware desig
  • The primary memory must be as large as possible. Using virtual memory, software and hardware can make the memory appear to be larger than it actually is
  • The primary memory must be cost-effective. The cost cannot be more than a small percentage of the total cost of the computer.


Memory Manager  The purpose of the memory manager is :


  • To allocate primary memory space to processes
  • To map the process address space into the allocated portion of the primary memory
  • To minimize access times using a cost-effective amount of primary memory


   


This video helps you to understand the main idea for memory management in OS 
    Memory Management Algorithms


                In an environment that supports dynamic memory allocation, the memory manager must keep a record of the usage of each allocatable block of memory. This record could be kept by using almost any data structure that implements linked lists. An obvious implementation is to define a free list of block descriptors, with each descriptor containing a pointer to the next descriptor, a pointer to the block, and the length of the block. The memory manager keeps a free list pointer and inserts entries into the list in some order conducive to its allocation strategy. A number of strategies are used to allocate space to the processes that are competing for memory. 

    • Best Fit
 The allocator places a process in the smallest block of unallocated memory in which it will fit. 
Problems:


    It requires an expensive search of the entire free list to find the best hole. More importantly, it leads to the creation of lots of little holes that are not big enough to satisfy any requests. This situation is called fragmentation, and is a problem for all memory-management strategies, although it is particularly bad for best-fit.

    Solution:  One way to avoid making little holes is to give the client a bigger block than it asked for. For example, we might round all requests up to the next larger multiple of 64 bytes. That doesn't make the fragmentation go away, it just hides it. 

    • Worst Fit
 The memory manager places process in the largest block of unallocated memory available. The ides is that this placement will create the largest hole after the allocations, thus increasing the possibility that, compared to best fit, another process can use the hole created as a result of external fragmentation. 

    • First Fit
 Another strategy is first fit, which simply scans the free list until a large enough hole is found. Despite the name, first-fit is generally better than best-fit because it leads to less fragmentation. 
Problems:
    Small holes tend to accumulate near the beginning of the free list, making the memory allocator search farther and farther each time.
    • Next Fit
 :The first fit approach tends to fragment the blocks near the beginning of the list without considering blocks further down the list. Next fit is a variant of the first-fit strategy. The problem of small holes accumulating is solved with next fit algorithm, which starts each search where the last one left off, wrapping around to the beginning when the end of the list is reached (a form of one-way elevator) 
    • Compaction:  
Compaction attacks the problem of fragmentation by moving all the allocated blocks to one end of memory, thus combining all the holes. Aside from the obvious cost of all that copying, there is an important limitation to compaction: Any pointers to a block need to be updated when the block is moved. Unless it is possible to find all such pointers, compaction is not possible.
    • Managing Virtual Memory Normally, blocks of information are taken from the disk and placed in the memory of the processor. 
    The most common ways of determining the sizes of the blocks to be moved into and out of memory are:

    1. Swapping
    2. Paging
    3. Segmentation


    Question and answer
     - The memory allocation scheme subject to “external” fragmentation is
    (A) Segmentation
    (B) Swapping
    (C) Pure demand paging
    (D) Multiple fixed contiguous partitions


    Correct Answer : A


    Now in your comments box down the code you must write five sentences about what did yuo learned With writing yourname and academic number


      No comments:

      Post a Comment