Sunday, July 11, 2021

CST 334 - Week 3

Memory Virtualization



This week we went a bit further into memory virtualization. Each running process has a private copy of memory that only it can access. However, the memory addresses available for each process are exactly the same. How is that possible? Through the memory management unit (MMU), a piece of hardware that helps the operating system translate virtual addresses into physical addresses. Each process is granted a slice* of physical memory, which is calculated by adding its virtual address to a base value that is unique to the process. For example, if a process is trying to write to virtual address 100, and it has been assigned base address 13000, then the operating system would actually write to address 13000+100 (base+offset) = 13100. 

An additional value, called the limit, marks the boundary of each process's address space. This ensures no process enters another process's physical address space. Operating systems keep track of free spaces in physical memory using a free list, but external fragmentation is bound to happen due to holes in between processes that are too small to be reallocated. For example, a process may require 20KB of memory, and the system may actually have enough, but if it's split up into small parts then the process can't fit into it. One potential solution is compaction, which repositions processes so that they are in succession. External fragmentation can be minimized by using an algorithm called worst-fit allocation, which places new processes in the largest available memory gap.

* Each process can actually be granted many slices of memory. This is called segmentation and is a commonly implemented memory management technique. Since the memory granted to each process is implicitly split into discrete segments (i.e. stack, heap, data, code), segmentation explicitly separates these structures in the memory. The reason for this is to prevent waste from sparse address spaces. Without segmentation, the heap and stack are connected by a contiguous block of memory and grow towards each other. If too much memory is allocated for the process, there can be a lot of unused memory between the stack and heap. This is known as internal fragmentation. Since it is not reachable by other processes, it goes to waste. Segmentation allows processes to be allocated varying amounts of memory (just the amount needed). As a side note, whether a system has segmentation or not, illegal memory access exceptions are usually called segmentation faults.

No comments:

Post a Comment

CST499 - Week 8

The End? I made it. This is my final week in the CS Online program here at CSUMB. I still have one final hurdle in the form of a mock techni...