user247763
user247763

Reputation: 261

How does the kernel access the memory of other processes?

I have read the following in here:

the kernel has access to all of the memory

What I want to know is, how does the kernel access the memory of other processes.

What I am almost sure of is that the kernel cannot access physical memory, it can only access virtual memory.

Now each process has a page table that is used to convert virtual addresses to physical addresses. And since the kernel have access to all of the page tables for all processes (the page tables exist in the kernel space I suppose), then if the kernel wants to access the memory of Process A for example, it can use the page table of Process A and access Process A's memory through this page table.

Am I correct?

Upvotes: 2

Views: 2332

Answers (1)

user4822941
user4822941

Reputation:

What are "other processes" in this case?

If a thread is executing and it goes to the kernel for whatever reason and the kernel wants to read its memory, it can "just" do that on architectures where both userspace and kernelspace are mapped into one giant address space. In particular this is the case on x86.

Typically the kernel does not go around accessing memory mapped by a thread different than the one which switched into the kernel.

If such access is needed, the kernel walks the relevant page table "by hand". It finds what physical page is needed and just maps it so it can read. It most certainly does not switch page tables for this purpose.

As a fun fact, since the address space on x86-64 is so vast (256TB) compared to physically installable memroy, the entire physical memory is always mapped. Thus on this architecture the kernel just computes where the relevant page is within this area.

Upvotes: 2

Related Questions