CST-334 Week 3

 This week I learned about address spaces, techniques for translating virtual addresses to physical memory, and some C apis for allocating and deallocating memory. An address space is a running program's view of its memory in the system. This program's address space will not be the same as its exact space in physical memory due to virtualization. The purpose of virtualizing the program's memory is that it allows for transparency, efficiency, and protection from other processes or the OS from processes. The program will think its address space starts at 0 (and so will the CPU), but the MMU will translate the program's address space into physical memory by techniques such as, base-and-bounds, segmentation, and paging. 

Base-and-bounds translation is a technique for translating virtual addresses into physical ones by having the CPU assign a process a base register and a bounds register. The base register will be its actual location in memory, and the bounds register will be its limit in virtual memory. The physical memory address can be simply calculated by adding the value in the base register to the virtual address. This technique is not very efficient as unallocated memory will take up space in physical memory.

Segmentation is another technique which can resolve some of the issues with base-and-bounds. A process's address space can be divided into multiple segments and be stored into physical memory. Instead of storing the entire address space (code, heap, free, and stack) into physical memory, only some of it (code, heap, and stack) will be stored. The physical address will then be simply calculated with base[segment] + offset. A problem with segmentation is that it can cause external fragmentation as one segment grows or shrinks.

Paging is another technique which can be used to solve some of the issues with segmentation by chopping up space in virtual memory into fixed-size pieces. Virtual memory will be divided up into pages and physical memory will be divided into page frames (with both being the same size). A page table will be used to find the physical address by having the virtual page number correspond with the physical frame number.

In C programs, memory can be allocated on the heap by using malloc(). Allocated memory will need to be freed using free() or risk running into memory leaks. This may not be a problem for small programs, but as a program gets larger, they will run into the risk of running out of memory due to not freeing allocated memory on the heap.

I think one of the easiest topics for me this week was translating virtual addresses into physical ones by using base-and-bounds. I was a bit confused before on how programs could have the "same" address space, but it seems intuitive to just keep track of the base address in physical memory and add it the program's virtual address to find the actual location of a certain address.

Comments

Popular posts from this blog

Week 4

Week 5

Week 2