Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
502 views
in Technique[技术] by (71.8m points)

operating system - Virtual Memory?

I am very much confused with these questions.

  1. On a 32 bit processor, every process has 4 GB virtual memory. But, if evey process has 4gb space than it will be every huge amount if 100 process is running - this is greater than swap area. Can someone please explain this; I am very confused.

  2. How does the operating system allocate the memory to a process? Suppose a process has a = malloc(2). Who will allocate this memory to the process? Will the OS give these 2 Bytes memory to the process.
    (We access the a[2] it generate the segmentation error).

  3. Where do the different parts of the process remains ( Code , Data , Stack, Heap ) in Main Memory or in secondary memory.

Please give me some good link so that I can also understand the virtual memory and its whole mechanism as the links I've found are not fully explaining the virtual memory.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  1. Who cares whether virtual memory is greater or less than swap area? What difference does that make? (If you, say, map a 2GB file read-only, that uses 2GB of virtual memory, but no swap space and only trivial amounts of physical memory is needed.)

  2. The OS simply extends the process' virtual memory space. It's just changing an accounting entry. Physical memory is not needed until an attempt is made to modify the contents of the address space. (Actually, the process will likely do this itself, only asking the OS to extend its virtual memory space when it needs larger chunks.)

  3. They remain in physical memory (assuming they faulted in to begin with) until the operating system elects to move them elsewhere or discard them. If they are moved elsewhere or discarded, they are paged back in or recreated when they are accessed through page faults. (The OS manages physical memory as a precious resource, granting it as it thinks best.)

By the way, on most 32-bit OSes, the OS itself takes 1GB or 2GB of that virtual memory space, leaving only 2GB or 3GB truly usable by the process. On 64-bit OSes, the OS doesn't take any of that space, so the full 4GB is available to 32-bit processes.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...