UNIVERSITY OF WISCONSIN-MADISON
Computer Sciences Department | ||
CS 537
Spring 2000 | A. Arpaci-Dusseau | |
Solutions to Quiz #6: Wednesday, March 29 |
a)Show how a First-Fit allocation algorithm would assign the requests to free memory. (Do NOT assume rotating First-Fit). Clearly show the size of each piece of memory after each request arrives.
Original: 100KB 500KB 200KB 300KB 600KB 212KB: 100KB *288KB* 200KB 300KB 600KB 417KB: 100KB 288KB 200KB 300KB *183KB* 112KB: 100KB *176KB* 200KB 300KB 183KB 426KB: FAILS: Cannot be allocatedb)Show how a Best-Fit allocation algorithm would assign the same requests. Clearly show the size of each piece of memory after each request arrives.
Original: 100KB 500KB 200KB 300KB 600KB 212KB: 100KB 500KB 200KB *88KB* 600KB 417KB: 100KB *83KB* 200KB 88KB 600KB 112KB: 100KB 83KB *88KB* 88KB 600KB 426KB: 100KB 83KB 88KB 88KB *174KB*c)Show how a Worst-Fit allocation algorithm would assign the same requests. Clearly show the size of each piece of memory after each request arrives.
Original: 100KB 500KB 200KB 300KB 600KB 212KB: 100KB 500KB 200KB 300KB *388KB* 417KB: 100KB *83KB* 200KB 300KB 388KB 112KB: 100KB 83KB 200KB 300KB *276KB* 426KB: FAILS: Cannot be allocated
XXXX indicates that the block of the size above has been allocated Original : 1MB 42KB --> 64KB : 64KB 64KB 128KB 256KB 512KB XXXX 396KB -->512KB: 64KB 64KB 128KB 256KB 512KB XXXX XXXX 10KB --> 16KB: 64KB 16KB 16KB 32KB 128KB 256KB 512KB XXXX XXXX XXXX 28KB --> 32KB: 64KB 16KB 16KB 32KB 128KB 256KB 512KB XXXX XXXX XXXX XXXXb)Why does internal fragmentation occur with buddy allocation? How much internal fragmentation exists in this scenario?
Internal fragmentation is wasted memory visible only to the process making the memory request. Internal fragmentation occurs in buddy allocation because memory requests must be rounded up to the nearest power of 2.
Amount: (64-42) + (512-396) + (16-10) + (32 - 28) = 148KB
c)Why does external fragmentation occur with buddy allocation? How much external fragmentation exists in this scenario?
External fragmentation is wasted memory visible to the system outside of the requesting processes. External fragmentation occurs because not all requests (even after they've been rounded up to the nearest power of two) are the same size; therefore, it is possible that a memory request will not be able to satisfied, even when there is enough total free memory in the system.
Amount: 16 + 128 + 256 = 400KB
As a check, the amount of fragmentation in the system and the usefully allocated memory should equal 1MB:
148KB + 400KB + 42KB + 396KB + 10KB +28KB = 1024KB = 1MB
as desired.