Week 3 - Virtual Memory

After learning about virtualization of the CPU in last week's class, this week I was introduced to how we virtualize memory. Before going into how virtualization of memory is accomplished, the lecture and the book first introduced the concept or abstraction called address space. Address spaces are the running program's view of memory and it consists of three segments which are the program code, the heap, and the stack. Each running program or process needs memory or some chunk of RAM to work with or in this case the physical address. Though there is only a limited resource of RAM to share among processes. In order to create this sharing of memory there needs to be a focus on three concepts which are transparency where the programs shouldn't be away of any changes to their memory, efficiency where reduction of overhead by looking at computation power and memory usage together, and lastly protection which is the processes shouldn't be able to access other memory, or the OS access to the processes

A way to achieve this sharing is through virtualization of memory which introduces virtual addresses from compiled code and translating these virtual addresses to physical addresses. The physical addresses are created by adding the virtual address with the base and the bounds as the limit. When translating it makes sure to check if it's in bounds by the limit register, if not then a trap will be issued. When undergoing these instructions the hardware will have to do some background work like preventing the user-mode processes from executing privileged operations, circuitry to check limits and translations, and many more like raising exceptions in case memory is out of bounds. The problem with base and bounds is that it only works with contiguous memory, and can easily fragment the memory. The fragmentation can happen with internal fragmentation where there are spaces in each address space between the heap and stack, or external fragmentation where free space occurs between each address space on the physical memory because of the size of the allocated spaces. Another step that comes in to solve this problem of fragmentation is a thing called segmentation which now involves more base and bound registers. It essentially takes each segment of the address space and creates a base and bound around that. So in this case the code will have its own base and bound, and the heap and stack will each have their own. Each can be placed separately along the physical memory. This may solve the internal fragmentation between the heap and the stack but will still contain some external fragmentation. I thoroughly enjoyed this topic this week and hope to gain more experience in this part of the course specifically about operating systems memory management.

Comments