W6 - Memory Management (Part I) Flashcards
(34 cards)
Why is memory management necessary?
The computer memory is shared by many processes.
The compiler has to produce code without knowing how many other processes there are, and where they are in memory.
Main requirements for memory management
1) Relocation
2) Protection & Sharing
3) Each process working in its own address space.
What is meant by relocation in memory management?
The ability to move the program from one place in memory to another.
How many bytes does the stack pointer move when pushing or popping data?
4 bytes on a 32-bit system (e.g., x86)
8 bytes on a 64-bit system (e.g., x86-64)
Because the stack stores word-sized values:
Word = 4 bytes (32-bit)
Word = 8 bytes (64-bit)
What is a virtual/logical address space in a process?
It’s the range of virtual memory addresses a process can use, which are translated to actual physical memory by the OS.
Each process gets a large, private virtual address space (e.g. too little on 16-bit, 4 GB on 32-bit, many TB on 64-bit).
Base and limit registers
Base: Smallest legal physical memory address for a process.
Limit: The size of the range.
These two form a section of physical memory a process is allowed to occupy, and if this process attempts to access something outside the range an addressing error occurs (it causes a trap, so we switch into kernel mode).
Logical/Virtual Address
Reference to a memory location, independent of the current use of memory. Instructions issued by CPU reference logical addresses (e.g. arguments for LOAD)
Physical/Absolute Address
The actual location in memory. It’s physical memory.
Address translation
Translating logical address into physical address using the page table.
Who can check the page table
The CPU and the OS
How does fixed partitioning work
Memory is divided into contiguous blocks at boot time, which don’t change. Requires a base register, which gets loaded by OS at context switch.
Problems with fixed partitioning.
Since partitions are fixed, programs can potentially run out of space. You also deal with internal fragmentation, where memory is reserved for a process which we are not fully using.
How does dynamic partitioning work
Partitions are created as programs are loaded. Requires a base register and limit register.
What kind of fragmentation do we encounter with dynamic partitioning?
External fragmentation. Unused memory is broken up into small regions that are unuasble. We don’t get internal fragmentation though!
What’s a better solution over partitioning?
Pages.
How does paging work?
Physical address space is split into equal sized frames.
Logical address space is divided into equal size pages.
Page size = Frame size.
Program gets loaded into available pages. Pages get mapped to frames, this is recorded on the page table.
Describe the uniqueness of page numbers.
Unique for each process, since each process gets its own page table.
What kind of fragmentation do we get with paging?
Some internal fragmentation. This gets worse if you pick larger frame sizes / page sizes.
How does swapping a page out of main memory work?
The page no longer corresponds to the frame in memory. It corresponds to a specific location in the disk instead, being stored in one or more blocks.
In the context of paging, what do physical addresses and logical addresses represent?
Physical -> Frame
Logical -> Page
Advantages of paging
We eliminate external fragmentation. If a process needs another page, just give it any frame in memory. This is only possible because its Random Access Memory, optimized to be accessed anywhere. (In a disk you’d have to rotate, seek, …).
It’s easy to implement.
Easy to model protection and sharing.
Easy to allocate physical memory.
Naturally opens up the possibility for Virtual Memory (swapping pages to disk).
Why is page size a trade off?
Too big and internal fragmentation becomes more problematic.
Too small and we end up with too many pages. We need to store data in memory for them (page table), and CPU spends time translating too.
As memory gets cheaper, we can increase it
Page table
Maps logical addresses (pages) to physical addresses (frames). It is indexed by page number.
How would memory sharing work?
Multiple processes each have pages that translate to the exact same frames, letting them access the same data.