CST334 - Week 3

Week 3 Reflection

We learned about virtual memory and how to translate it into physical memory.  

    The two memory types that we use in our programs is stack memory and heap memory. The stack is managed mostly by the compiler while the heap is long-lived and only allocated/deallocated by the programmer. The heap is allocated near the base of the address space (0) and grows outward, while the stack is allocated at the end of the address space (size_of) and grows downward towards the heap/program code.We used two methods of memory address translation - base and bounds (aka dynamic relocation), and paging.  

    Base and bounds uses two registers: the base register and the bound (aka limit) register. With these two registers, a program can be translated to physical memory using its virtual address + this base register. However, the free memory between the stack and heap is wasteful and prevents other larger address spaces to fit in despite having enough memory to do so.

    Segmentation is the answer to this issue, where we can place segments of virtual memory into physical memory, instead of an entire address space. We need to be mindful not to reference addresses that are out of bounds of the address space, which causes a segmentation fault to occur. To know which segment a virtual address is in, we can attempt either an explicit approach or implicit approach. 

    The explicit approach looks at the topmost two bits of a virtual address (in binary) to know which segment it is in. Since the code segment starts from 0 first, if the top two bits are 00, this address is in the code segment. The heap next with two bits at 01, and the stack at 11.

    The implicit approach has the hardware examine how the address was formed to determine where it is. If the address was created from the program counter or instructions, then this address was created in the code segment (makes sense). If the address is from a stack or base pointer, it is in the stack segment. If an address does not match these, then it is in the heap.

     Paging divides an address space into fixed-size pages, and uses a page table to keep track of what each page contains.

    I was not able to understand how to translate a page table entry (PTE) into a page frame number (PFN). I assumed I needed to shift-right the PTE by the number of metadata bits, but my tests still failed. I tried shifting using other bits like VPN, PFN, etc. but those did not work either. Most of my code in PA3 is failing because of this single function not working properly.

 

Comments

Popular posts from this blog

CST300 - Week 4

CST300 - Week 2

CST300 - Week 5