Learning about virtual memory with an program assignment. Currently this is what I have:
Main memory has 60 bytes and virtual memory another 60 bytes. The size of a frame/page is 10 bytes. So there are 6 frames for main and 6 for virtual memory.
I have a process that uses 40 bytes, so it needs 4 pages. By assignment specifications, when I load a process its four pages must be allocated randomly, so suppose this is how it looks now:
I've managed to do most things, like paging something, restoring a page with LFU and LRU, loading more processes etc. But there is one particular point that confuses me:
Given an offset for your process, you must return the physical address. You must verify that the offset is within the size of your process.
As far as I am concerned, you can calculate a physical address if you are given an offset AND a page number. But I am only given an offset number.
My guess is that you can get the page number using this same offset number too. For instance, if the offset is 36, then the page number would be 3 (because each page is 10 bytes large) with an offset of 6 bytes. Therefore the physical address would be 56? But then I have a bigger question:
What if I am given the number 25? It would be page 2 with offset 5. But such page is in virtual memory. Do I have to MOVE this page to main memory first?