Memory Allocation Flashcards

1
Q

what does a dynamic memory allocator do?

A
  • initially has a pool of free memory
  • needs to satisfy arbitrary allocate and free requests from that pool
  • can’t control the order or the number of requests
  • can’t move allocated regions (no compaction!)
  • needs to track which parts are in use and which parts are free
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Three factors required for fragmentation to occur

A
  1. different lifetimes
  2. different sizes
  3. inability to relocate previous allocations
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Best-fit

A

Idea: tries to avoid breaking up large contiguous areas
-> Allocate the smallest free block that is large enough to fulfill the allocation request, during free coalesce adjacent blocks
- must search entire list
- Sawdust: external fragments of allocations are so small that over time leftovers with unusable sawdust are everywhere

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Worst-fit

A

Idea: minimize sawdust by turning best-fit strategy around
-> Allocate the largest free block
- must search the entire list
- worse fragmentation that best-fit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

First-fit

A

Idea: if you produce fragmentation anyway, try to optimize for allocation speed
-> Allocate the first hole that is big enough
-fastest allocation policy
-produces leftovers of variable size

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Buddy Allocator

A
  • to dynamically allocate contiguous chunks of fixed-size elements
  • allocates memory in powers of 2
  • if no sufficiently small memory block is available, select larger available chunk and split it into two equal-sized buddies
  • if two buddies are both free, merge them
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

SLAB allocator

A
  • a slab is made up of multiple pages of contiguous physical memory
  • a cache consists of one or multiple slabs
  • each cache stores only one kind of object (fixed-size)
  • Linux uses Buddy Allocator as the underlying allocator for slabs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why can’t you easily mitigate external fragmentation on the heap with compactification?

A

There is no memory translation on the heap, so compactification would break allocated areas- it would change start and other addresses referring to the allocated area and we can’t change pointers once they have been handed out

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which information can’t be extracted from the bitmap and needs to be kept separately?

A

A bitmap doesn’t store the length of an allocation: one can’t decide whether two adjacent allocations belong together or not from a bitmap alone.
A heap allocator need this info to release allocations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly