2 What are the main differences between Contiguous and Nonco
2. What are the main differences between Contiguous and Non-contiguous memory allocation techniques? Explain and include two examples. (3 pts)
Solution
The primary role of the memory management system is to satisfy requests for memory
 allocation. Sometimes this is implicit, as when a new process is created. Either way, the system must locate enough unallo-
 cated memory and assign it to the process.
Contagious memory allocation techniques:
Free Space Management
 :
Before we can allocate memory, we must locate the free memory. Naturally, we want to
 represent the free memory blocks in a way that makes the search efficient.
 Before getting into the details, however, we should ask whether we are talking about
 locating free memory in the physical memory space or the virtual memory space. However, many
 of these techniques can also be used to manage virtual memory space. Like application-level
 dynamic memory allocation, using familiar operations such as the malloc( ) call in C or the
 new operator in C++, often allocate large blocks from the OS and then subdivide them
 into smaller allocations. They may well use some of these same techniques to manage
 their own usage of memory.
Free Bitmaps
 :
If we are operating in an environment with fixed-sized pages, then the search becomes
 easy. We don’t care which page, because they’re all the same size. It’s quite common in
 this case to simply store one bit per page frame, which is set to one if the page frame is
 free, and zero if it is allocated. With this representation, we can mark a page as either
 free or allocated in constant time by just indexing into this free bitmap. Finding a free
 page is simply a matter of locating the first nonzero bit in the map. To make this search
 easier, we often keep track of the first available page. When we allocate it, we search from
 that point on to find the next available one.
 The memory overhead for a free bitmap representation is quite small.
Example:
If we have pages that are 4096 bytes each, the bitmap uses 1 bit for each 32,768 bits of
 memory, a 0.003% overhead.
Non contagious memory allocation techniques:
Fragmentation
 :.
When allocating memory, we can end up with some wasted space. This happens in two
 ways. First, if we allocate memory in such a way that we actually allocate more than
 is requested, some of the allocated block will go unused. This type of waste is called
 internal fragmentation. The other type of waste is unused memory outside of any
 allocated unit. This can happen if there are available free blocks that are too small to
 satisfy any request. Wasted memory that lies outside allocation units is called external
 fragmentation.
Partitioning
 :
The simplest methods of allocating memory are based on dividing memory into areas with
 fixed partitions. Typically, we administratively define fixed partitions between blocks of
 varying size. These partitions are in effect from the time the system starts to the time it
 is shut down. Memory requests are all satisfied from the fixed set of defined partitions.
Example:
 Although fixed partitioning is not commonly found in modern, general-purpose systems,
 it is seeing a sort of revival. Some of the virtualization systems use simple, fixed partitions
 between the various virtual systems. One good example of this is Xen. In Xen, the memory
 used by the OS identified as the Domain 0 OS is specified with the option dom0 mem in
 whatever boot loader is used to load the Xen hypervisor into memory. Example:
 when
 using grub, the line
 kernel=/xen.gz dom0 mem=262144 console=vga
 declares that the Domain 0 OS has 256 MB reserved for it. For OSs run in other domains,
 the line
 memory = 128
 in a configuration file reserves 128 MB for the corresponding domain.


