p5 Managing memory
p5 Managing memory
memory
Mosab_2802
objectives
● First fit: Allocate the first hole that is big enough. 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.
● Best fit: Allocate the smallest hole that is big enough. We must search the entire list,
unless the list is ordered by size. This strategy produces the smallest leftover hole.
● Worst fit: Allocate the largest hole. 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.
● 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.
Explain the distinction between external
and internal fragmentation
External fragmentation
External fragmentation exists when there is enough total memory space
to satisfy a request but the available spaces are not contiguous: storage is
fragmented into a large number of small holes. This fragmentation
problem can be severe. In the worst case, we could have a block of free
(or wasted) memory between every two processes. If all these small
pieces of memory were in one big free block instead, we might be able to
run several more processes.
Internal fragmentation
Consider a multiple-partition allocation scheme with a hole of
18,464 bytes. Suppose that the next process requests 18,462
bytes. If we allocate exactly the requested block, we are left with
a hole of 2 bytes. The overhead to keep track of this hole will be
substantially larger than the hole itself. The general approach to
avoiding this problem is to break the physical memory into fixed-
sized blocks and allocate memory in units based on block size.
With this approach, the memory allocated to a process may be
slightly larger than the requested memory. The difference
between these two numbers is internal fragmentation—
unused memory that is internal to a partition.
Describe hierarchical paging, hashed
page, and inverted page tables
hierarchical paging
• Break up the logical address space into multiple page
tables
• A simple technique is a two-level page table
• We then page the page table
A logical address (on 32-bit machine with 1K page size) is
divided into:
a page number consisting of 22 bits
a page offset consisting of 10 bits
Describe hierarchical paging, hashed
page, and inverted page tables
Since the page table is paged, the page number is further
divided into:
a 12-bit page number
a 10-bit page offset
Thus, a logical address is as follows:
Address-Translation Scheme
where p1 is an index into the outer page table, and p2 is the
displacement within the page of the inner page table
Known as forward-mapped page table
Describe hierarchical paging, hashed page,
and inverted page tables
● Common in address spaces > 32 bits
● The virtual page number is hashed into a page table
● This page table contains a chain of elements hashing to the
same location
● Each element contains (1) the virtual page number (2) the
value of the mapped page frame (3) a pointer to the next
element
● Virtual page numbers are compared in this chain searching
for a match
● If a match is found, the corresponding physical frame is
extracted
● Variation for 64-bit addresses is clustered page tables
● Similar to hashed but each entry refers to several pages
(such as 16) rather than 1
● Especially useful for address spaces (where memory
references are non-contiguous and scattered)
Describe hierarchical paging, hashed
page, and inverted page tables