Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two Identical Linear Addresses of two different Processes?

Hello everyone,

I am a newbie to Linux-Kernel and I'm presently referring to the book Understanding Linux Kernel.I read about the memory management where everything is given well about the paging and segmentation but my question is not answered yet. If two different processes have same Linear Addresses then can they be different locations in Physical Addresses .Because since each CPU has only one Global Page Directory which is mapped again to the physical addresses by observing the 32 bits Linear Address.But how does two processes can have memory upto 4GB .Please explain.

like image 306
jack wilson Avatar asked Dec 20 '25 23:12

jack wilson


1 Answers

Yes, two different processes can both be using the same linear pointer, but it can dereference to two different locations in physical memory. That is because each process has its own page tables, and when switching from one process to another, the CPU's page table register is also switched to point to the page tables of the new process.

Have you cloned your own local copy of the Linux source code yet? If not, go and do it right now. You'll need to refer to it as you read your book.

Cloned now? Good. Go to the cloned working directory and open up arch/x86/include/asm/mm_context.h. Go down to line 51, you'll find static inline void switch_mm. This is the function which switches the CPU from the virtual memory space of one process to another. (I'm assuming you are most interested in x86.) Look down now to line 64: load_cr3(next->pgd). That's where the magic happens: the page tables are switched and now the CPU will interpret all pointers using the new process' page tables.

like image 179
Alex D Avatar answered Dec 23 '25 15:12

Alex D