Learning Journal - Week 30
From this past week in CST-334, we spent more time focusing on virtual memory and translations. It helped to solidify my understanding of concepts like paging from last week, and elaborated on concepts like Memory Allocation in C.
Recap
One of the first things we went over was free space management, which focuses specifically on how C functions like malloc() and free() work under the hood: the operating system tracks a large block of all the free space, and as memory-allocation is called then a header is set at the beginning position tracking how much space it takes up. The chunks of free space separated by chunks of allocated space ends up in a data structure called the free list, which keeps track of the starting address of the unallocated memory and its size (how many bytes it has available adjacent to it). When the allocation function is called, it can either grab from the free region it finds first (first fit), from the region with the closest amount of free space to the desired amount (best fit), or the region with the largest amount of available space (worst fit).
Branching off of this subject, we then dive a bit deeper into an add-on for paging. While paging was good because it avoided fragmentation (empty space between memory chunks), it required a rather large page table to keep track of all the slices of memory, and required a slow method of translation. The solution is the introduction to the Translation Lookaside Buffer (TLB), which is a way to cache recently interacted-with memory locations, since recently accessed addresses tend to be accessed in similar time intervals. Caching allows us to temporarily store previously accessed memory locations to make it much faster to re-access. Whenever a virtual page number is looked up and translated to a physical frame, the Lookaside Buffer keeps track of the VPN and the corresponding PFN in hopes that it gets accessed again at a soon time. Then, as more data gets introduced, it will use a policy to determine what elements to keep in the buffer. The buffer is a limited size, as to avoid it getting as big as the page table, and has the ultimate goal of maximizing hits (successful cache lookups) and minimizing misses (not being able to find the address in the cache and forcing it to be saved).
We also briefly went over the concept of Multi-Level paging to help expand on our understanding of paging. It helps solve the complexity of large page tables since there is still the possibility of programs only using small portions of memory, and a quick fix is by splitting up the table into smaller chunks.
We also looked into another modern solution for memory limitations: swapping. Swapping is a strategy where we move down the storage hierarchy in order to move some data in the RAM to hard drive space, which has more availability but works at a much slower rate. We also give the operating system control of what to keep in RAM (quick, volatile storage), and what to move down temporarily to hard drive space. We track which pages are available in memory by assigning a bit to represent if it's in RAM or in hard drive space, i.e. 1 if it's in RAM and 0 if it's in HDD. Adding this onto the concept of the TLB, we raise a hardware fault if we try to access a page that is in disk and we need to bring it up to RAM. Then suddenly, RAM becomes more like a cache, and we can use any of a variety of page replacement policies to determine which data to keep in memory and which data to keep in storage.
Reflection
Of these concepts, I'm still trying to wrap my head around free space management and how the malloc() works under the hood. I still have yet to do the related programming assignment for it, but I feel confident that after I complete that programming assignment that I will grasp the concept a lot better.
Something that I did feel very comfortable recapping was swapping and following the different policies, such as First-In First-Out, Least Recently Used, Random, and Optimal. After completing the lab assignments and quizzes I felt extremely comfortable with the material.
Looking ahead at the upcoming material, it looks like we're going to dive deeper into concurrency and threads, which will show how the operating system interacts with a more true form of multitasking which will be interesting to see!
Comments
Post a Comment