5
  • 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

mangusta
  • 3,470
  • 5
  • 24
  • 47

1 Answers1

3

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. ;)
BjoernD
  • 4,720
  • 27
  • 32
  • thanks for reply, I have a couple of questions: in question 2, you mention position-independent code, does it mean that this code expects to be relocated once again at load time by the loader, i.e. load-time relocation? in question 3, so those addresses assigned to executable by linker at link-time relocation, will be used as physical addresses at load time? in question 5, by paging I meant bringing the page from secondary memory into RAM on demand, as a result of page fault, but as you mention in 4, there is no page fault without virtual memory, hence there is no demand paging as well? – mangusta Aug 05 '12 at 07:42
  • 2. PIC code: yes, relocation is done by the dynamic linker (libld.so in Linux). 3. Yes. 5. Demand paging is hard if you don't have page faults as an indicator for actual demand. Your application would have to take care of everything itself. – BjoernD Aug 05 '12 at 09:20
  • 5. I guess, that's the reason why the executable usually has to be loaded into memory completely, if no virtual memory is used – mangusta Aug 05 '12 at 09:31
  • 1
    Well, depends. You will at least need to load the code that is then responsible for loading all other code (for instance a disk driver + binary loader + all the components they need). – BjoernD Aug 05 '12 at 09:35
  • one more question if you don't mind :) you've probably heard about vxworks os, it may use one of two virtual memory models: flat, which assigns every process a specific range of virtual address space, and overlapped, which assigns the same ranges of virtual address space for all processes. I don't really understand flat VM model: it seems to behave as if there is no virtual memory at all, then what's the point of using this model? – mangusta Aug 05 '12 at 09:44
  • if hardware supports virtual memory then does OS necessarily have to support VM as well? if it does, then we can justify the use of flat model: we use VM, though we don't actually get any benefit from it, we just have to use it because the hardware has been designed to use VM – mangusta Aug 05 '12 at 09:54
  • No idea about vxWorks. But your description of the 'flat' model sounds like a "Single Address Space Operating System" -- web-search for it if you mind. – BjoernD Aug 05 '12 at 10:42