Presentation is loading. Please wait.

Presentation is loading. Please wait.

External fragmentation in a paging system Use paging circuitry to map groups of noncontiguous free pages into logically contiguous addresses (remap your.

Similar presentations


Presentation on theme: "External fragmentation in a paging system Use paging circuitry to map groups of noncontiguous free pages into logically contiguous addresses (remap your."— Presentation transcript:

1 External fragmentation in a paging system Use paging circuitry to map groups of noncontiguous free pages into logically contiguous addresses (remap your addresses to make them contiguous) use a “best fit” algorithm when allocating contiguous frames of memory (Linux uses this approach)

2 The Buddy System Algorithm 1 2 4 8 16 32 64 128 256 512 Lists of free Frames All free page frames are grouped into one of 10 lists of blocks. The physical address of the first frame of a given block (of frames) is a multiple of the size of that block. (For example, the initial address of a 16-page frame block is a multiple of 16 x 2 12 )

3 The Buddy System Algorithm When a request for a contiguous block comes in, the OS searches the list for the smallest block bigger than the request. If nothing is available, it searches the next larger block list and continues this process iteratively until it either finds a block to allocate or discovers that the request cannot be granted. If a block is bigger than the request, it is split into pieces which are put into their appropriate lists.

4 The Buddy System Algorithm (Deallocation) The algorithm gets it name from its reclaiming technique: Because of the addressing scheme (The physical address of the first frame of a given block is a multiple of the size of that block) each block is associated with an adjacent block of the same size. Upon deallocation, if the “buddy” block is free, we can collapse the two blocks into one of twice the size. We then repeat this process iteratively until a “buddy” block is not free:

5 The Buddy System Algorithm (Deallocation) ffffufufufuuuuu u f = used = free u We’re going to deallocate this one

6 The Buddy System Algorithm (Deallocation) ffffufffufuuuuu u f = used = free u New contiguous block Next, deallocate this block

7 The Buddy System Algorithm (Deallocation) ffffffffufuuuuu u f = used = free f New contiguous block

8 The Buddy System Algorithm (Deallocation) ffffffffufuuuuu u f = used = free f New contiguous block

9 Handling Internal Fragmentation The original solution: allocate memory size by powers of 2, instead of by the size of the data to be stored. Why? How does this work?

10 Internal Fragmentation: slab allocation Often, memory allocation requests are for the same type of objects such as process control blocks, file descriptors, etc. The kernel can use this fact by storing memory that has been used and released (called a slab) in a cache where, when a similar request comes in for the same type of object, the kernel does not have to reallocate that memory, it just returns a previously-used slab. The slab allocater does not handle deallocation on its own.


Download ppt "External fragmentation in a paging system Use paging circuitry to map groups of noncontiguous free pages into logically contiguous addresses (remap your."

Similar presentations


Ads by Google