Question

Sorry if this is a basic question, I'm studying for my operating systems class and compiler theory class at the same time and this is confusing me. From what I do understand, virtual memory is larger than RAM and the virtual memory of a process looks like this:

[stack][heap][uninitialized data segment][initialized data][text segment]

where the text segment basically contains the code that needs to be run. Anything that the CPU needs from the virtual address will be loaded into the RAM when needed.

And the relocatable machine code is code that can be ran from any address. Does this mean it can be pretty much anythere in the virtual address (if that address is not already used by another section)?

Thanks

Was it helpful?

Solution

Anything that the CPU needs from the virtual address will be loaded into the RAM when needed.

Data is not loaded/written into RAM when the CPU reads data at some address (there is actually usually a swapping mechanism and swap space that loads into physical memory when reading, but I assume this is not what you are looking for). A process can write data at some virtual address and that data is written in RAM (physical memory) somewhere. Virtual memory is usually implemented using segmentation or paging or a hybrid. In these methods, the virtual addresses of a process is mapped to a physical address. So, data written by a process is always stored in physical memory, not written when it is to be read. The virtual memory implementations are therefore responsible for the mapping from virtual addresses to physical address. You can read about this is chapters 15, 16 and 18 in http://pages.cs.wisc.edu/~remzi/OSTEP/.

And the relocatable machine code is code that can be ran from any address. Does this mean it can be pretty much anythere in the virtual address (if that address is not already used by another section)?

Yes. In fact, this is actually done from time to time by many operating systems to avoid external fragmentation. Fragmentation is when there are chunks of free memory in between used memory. This is a problem since small chunks might not provide enough memory. It is therefore desirable to move these chunks closer together to make more space.

Licensed under: CC-BY-SA with attribution
scroll top