Search code examples
operating-systempagingstatic-linkingdynamic-linkingvirtual-memory

linking and paging in the system without virtual memory support


  • First of all, is virtual memory a hardware feature of the system, or is it implemented solely by OS?

During link-time relocation, the linker assigns run-time addresses to each section and each symbol, in the generated executable

  • Do those run-time addresses correspond to virtual addresses?

  • What if the system for which the executable is generated, does not use virtual memory?

Next, if virtual memory is not used, then the application's address space is limited to the physical address space allocated for it by OS after load-time relocation

  • Does page fault occur if no virtual memory is used?

I think, it does: in case if the physical page containing the requested physical address has not yet been stored in RAM, then page fault should occur, which is serviced by OS page fault handler

  • Finally, is paging possible without virtual memory?

I'm asking because paging is always mentioned together with virtual memory, but it seems that the presence of virtual memory is not required to do paging

Thanks


Solution

  • Wow, a lot of questions.

    • Where is virtual memory implemented? The underlying hardware needs to support virtual memory. Remember, when you access a memory address in your program, the CPU needs some way to obtain the data belonging to this address. If you only have physical access, then the operation is directly sent to the memory controller. In systems with virtual memory you have an MMU (memory management unit), which translates a virtual address into a physical one. (Note, that some microcontrollers provide a stripped-down version, called a Memory-Protection Unit (MPU), which does not provide this translation step, but at least allows access rights checking.)
    • Do link-time addresses correspond to virtual addresses at runtime? In general, link-time addresses correspond to runtime virtual addresses. However, there is a mode where this is not the case: position-independent code. Here, the virtual addresses are determined at load time by a dynamic linker. This approach is usually used to load dynamically linked libraries (DLL / .so) to an application. For more details on that topic, you migth want to check out "Linkers and Loaders".
    • What if my target system does not have virtual memory? If your system does not support virtual memory, from the compiler's/loader's perspective nothing really changes: you still need to generate code to access memory. The only difference is that your CPU does no additional translation from a virtual to a physical address anymore.
    • Are there page faults if there is no virtual memory? There are no page faults if you don't have virtual memory. However, in case of an MPU you might still see access violations reported by the hardware, if your application tries to access an address it is not supposed to read/write. Note, that physical addresses (better: data pointed to by physical addresses) don't need to be loaded into RAM. They are just pointers into the RAM which is already there.
    • Is paging possible without virtual memory? 'Paging' and 'Virtual Memory' are often used to denote the same thing. However, paging may also refer to the concept of splitting memory into chunks of the same size - pages. The answer to your question depends on what you mean by paging. ;)