Yuv
Yuv

Reputation: 71

Does each process have its own virtual address space when running in parallel?

In a multiprocessor environment, there might be processes that might be running in parallel in a given instant. Since the virtual address space is divided into user space and kernel space, I am assuming as the processes are being scheduled they might be swapped in and out of the VAS.

But when two or more processes are running in parallel, do they have their own VASes? As in for each processor? Or do all the parallel processes share the same VAS?

VAS-> Virtual Address Space.

Upvotes: 1

Views: 2186

Answers (1)

Nate Eldredge
Nate Eldredge

Reputation: 58132

Each process always has its own virtual address space, and that address space will be used by any processor that is executing that process. In particular, different processors may be using different address spaces at the same time.

More concretely, virtual addressing is implemented via a page table: a structure in memory that specifies how to translate a virtual address to a physical address. The kernel will maintain a separate page table for every process. Each CPU has its own page table register that points to the page table it should be using to translate addresses at this instant. When the scheduler chooses to run process X1 on CPU Y1, part of the context switch process will be to have CPU Y1 load its page table register with a pointer to the page table for process X1. Then CPU Y1 will effectively be using X1's virtual address space until it performs another context switch.

It makes no difference what other CPUs may be doing during this time. CPU Y2 might be using the X1 page tables as well (if it's executing another thread of process X1), or it might be using a completely different set of page tables for process X2. There could even be overlap between their page tables, if X1 and X2 are using shared memory or something like that.

Upvotes: 3

Related Questions