P3L2 Memory Management - Memory Allocation Flashcards
Kernel level allocators are responsible for allocating __________________ and for keeping track of ______________ that is available in the system.
User level allocators are used for _____________________________.
Kernel level allocators are responsible for allocating pages for the kernel and for keeping track of the free memory that is available in the system.
User level allocators are used for dynamic process state - the heap.
Name two challenges for the memory allocation system
An allocator must allocate memory in such a way that it can quickly coalesce free page frames when that memory is no longer in use in order to limit external fragmentation.
The linux kernel relies on two main allocators: the _______ allocator, and the ______ allocator.
The linux kernel relies on two main allocators: the buddy allocator, and the slab allocator.
Describe the buddy allocator.
- What’s its advantage?
- Disadvantage?
Subdivides memory into two - finds smallest contiguous chunk that will accomodate the requested memory.
- Advantage: Quickly coalesces free memory
- Disadvantage: Because of the power of 2 structure, causes internal fragementation if object is of a non-power-of-two size.
What is demand paging?
the backing physical page frame can be repeatedly saved and stored to and from some secondary storage, like disk.
present bit in the paging table entry set to 0. When there is a reference to that page, then the MMU will raise an exception - a page fault - and that will cause a trap into the kernel.
When would you disable swapping?
This is useful when the CPU is interacting with devices that support direct memory access (DMA), and therefore don’t pass through the MMU.
When should pages be swapped out of main memory and on to disk? Name 2 conditions
Pages should be swapped when the memory usage in the system exceeds some threshold and the CPU usage is low enough so that this daemon doesn’t cause too much interruption of applications.
Which pages should be swapped out?
Name 3 policies/algorithms
- Least-Recently Used (LRU) policy. This policy uses the access bit that is available on modern hardware to keep track of whether or not the page has been referenced.
- Dirty bit - pages that don’t need to be written (not dirty) can be swapped
- Second chance - variation of the LRU policy, which gives a second chance. It performs two scans before determining which pages are the ones that should be swapped out.
LRU quiz
Suppose you have an array with 11 page size entries which are accessed one by one in a loop. And then they are manipulated again, one by one in a loop (so two loops accessing all 11 entries).
Suppose the system only has 10 pages.
What is the percentage of pages that will be demand swapped?
The answer is 100%,
because the 2nd loop guarantees that all the pages will be swapped out 9 (and the next swapped) in.
So the demand paging covers all the pages.
When we need to create a new process, we need to re-create the entire parent process by copying over its entire address space.
Name the hardware supported mechanism that saves the copy cost
Copy-on-Write
Virtual address in new process’s address space just points to the same physical memory as the parent is pointing.
OS write protects the physical memory
If new process tries to write —> FAULT!
And only then the OS allocates new physical memory.
So that’s why it’s called COPY ON WRITE!!
Checkpointing is a ____________________________ technique. The idea behind checkpointing is to __________________________
Checkpointing is a failure and recovery management technique. The idea behind checkpointing is to periodically save process state.
What are the advantages and disadvantages of frequent checkpointing?
Advantages: more states will be checkpointed, faster recovery from a fault
Disadvantage: Overhead of saving state ..