1
votes

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?

1
The kernel certainly can access physical memory if it wants to. But you're correct about how it accesses process memories.Barmar
This isn't really a proper SO question. SO is for questions about programs you're trying to write, not about the design of operating systems.Barmar
@Barmar "The kernel certainly can access physical memory if it wants to" I believe that the CPU can't access physical addresses in protected mode, so in order for the kernel to access physical memory, it has to switch the CPU to protected mode first, correct?user247763
1. Protected mode does not imply usign virtual memory (paging) - you can go into PM and still use direct access to memory. 2. Kernels (most if not all) run in PM and VM by design. 3. You can map virtual addresses to real addresses 1:1Anty

1 Answers

2
votes

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.