Download presentation
Presentation is loading. Please wait.
Published byDustin Patrick Modified over 6 years ago
1
Memory Allocation The main memory must accommodate both:
the operating system and the various user processes. in the most efficient way possible. Memory allocation is needed: When the program loads first to the Memory Also reallocation is needed for swapped processes. Finally deallocation is needed for the terminated processes.
2
Memory Allocation Types
Contiguous Memory Allocation - One process – One piece of memory. Single Partition Allocation. Multiple Partition Allocation Fixed size partitioning (equal size, unequal size) Dynamic Partitioning Non Contiguous Memory Allocation - One process – Many pieces of memory. Paging Segmentation
3
Single Partition Allocation
The memory is usually divided into two partitions: one for the resident operating system, and one for the user processes. Since the interrupt vector is often in low memory, programmers usually place the operating system in low memory as well Old MSDOS used this allocation scheme. Single
4
Multiple-Partition allocation could be done by
We usually want several user processes to reside in memory at the same time. In this contiguous memory allocation, each process is contained in a single contiguous section of memory. Multiple-Partition allocation could be done by Fixed Partitioning (Partition sizes are predefined) Dynamic Partitioning (Partition sizes are dynamically changed)
5
When a partition is free, a process is selected from the input queue and is loaded into the free partition. When the process terminates, the partition becomes available for another process. This method was originally used by the IBM 0S/360 operating system; it is no longer in use.
6
The memory allocated to a process may be slightly larger than the requested memory.
The free fragment after process allocation is internal fragmentation - memory that is internal to a partition but is not being used.
7
Dynamic Partitioning Degree of multiprogramming limited by number of partitions Hole – block of available memory; holes of various size are scattered throughout memory When a process arrives, it is allocated memory from a hole large enough to accommodate it Process exiting frees its partition, adjacent free partitions combined Operating system maintains information about: a) allocated partitions b) free partitions (hole) This procedure is a particular instance of the general dynamic storage allocation problem, which is how to satisfy a request of size n from a list of free holes.
8
Dynamic Storage Allocation Algorithms
Best fit: Allocate the smallest hole that is big enough. The best-fit strategy will allocate 12KB of the 13KB block to the process. We must search the entire list, unless the list is ordered by size. (slow search). This strategy produces the smallest leftover hole (external fragment).
9
Dynamic Storage Allocation Algorithms
Worst fit: Allocate the largest hole. The idea 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 remaining space. Using the same example as above, worst fit will allocate 12KB of the 19KB block to the process, leaving a 7KB block for future use. Again, we must search the entire list, unless it is sorted by size. This strategy produces the largest leftover hole, which may be more useful than the smaller leftover hole from a best-fit approach.
10
Dynamic Storage Allocation Algorithms
First fit: Allocate the first hole that is big enough. (to be fast) Using the same example as above, first fit will allocate 12KB of the 14KB block to the process. Searching can start either at the beginning of the set of holes or at the location where the previous first-fit search ended. We can stop searching as soon as we find a free hole that is large enough.
11
Dynamic Storage Allocation Algorithms
Simulations have shown that both first fit and best fit are better than worst fit in terms of decreasing time and storage utilization. Neither first fit nor best fit is clearly better than the other in terms of storage utilization, but first fit is generally faster. No matter which algorithm is used (first fit, best fit, worst fit), however, external fragmentation will be a problem. Sometimes it could reach the 33% of whole memory.
12
Dynamic Storage Allocation Algorithms
The solution of fragmentation could be: Do memory compaction at runtime (could be complex and expensive taking much runtime). The same fragmentation problem exists when the process is swapped out to the backing store. There compaction is impossible due to slowness. To permit the logical address space of the processes to be noncontiguous Two complementary techniques achieve this solution: paging and segmentation These techniques can also be combined.
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.