[Autogenerated] we know that Windows had various kernels through its
history starting with the very first original 32-bit kernel that
supported up to four gigabytes of physical memory as this is what was
supported on intel processors at the time Now,
although this kind of Kernel is no longer used by Windows,
definitely not the Windows 11 still it's worthwhile starting with
how virtual translation work in those days because it's slightly
easier to understand and then we'll gradually move to what we have
in today's 64-bit systems.
So here's how that would look like.
The first thing we see here is that there's the 32 bit
address needs to be translated somehow to another 32 bit
address in physical memory in RAM.
So we have ram right here.
Now the address is comprised of these three pieces,
the 1st 12 beats as the lower bits,
we know that they never actually get translated so this
will be copied or used as the offset to the final address
from the beginning of some page.
So we only need to concern or served with the other 20 bits and
then logically separated to these two chunks of 10 beats each
and we'll see in a moment why So in order to start the
conversion or translation process,
we have to start somewhere and this starts with
something called the page directly,
there's just one of those pair process on this scheme of these
32-bit kernel the original kernel Windows words working with and
this page directory consists of 1024 entries each run four bytes
in size and this page.
Director is always in physical memory because if it's not in physical memory,
how would the CPU find that we have to start somewhere?
And so the Page Director is never paged out.
It's always in physical memory and its address is known to the processor.
So now the process stories trying to translate an address
that is being used by some thread running some code in that
thread is part of some process.
And so the address of the Page Director is always stored in the K
process data structure for that particular process.
Remember the K process is one of the kernel structures used to manage a process.
And while the CPU is working to translate something from that process,
it's going to be loaded into a CPU register.
That register is called CR three.
So C 03 knows where the page directory is and C 03 is used
as the basis of the translation process.
So now what happens,
the most significant 10 bits are going to select one of
these entries within that page directory.
And since the page directory has 1024 entries, that two to the 10th power.
It makes perfect sense.
And so what we have here is a particular entry called page directory entry or P.
D.
The P.
D would point to a particular page table.
That page table looks exactly like a page directory.
From the perspective of having just 1024 entries,
each,
14 bytes in size And then the next 10 bits will select a particular page table.
How many page tables will we have in the process?
It really depends on how much memories being committed in the process,
the more memory being committed and more address ranges are being used.
More page tables might have to be created based on the actual address
that is being used because the address map the PD and the PD points
to a very particular specific page table And so the skin continues in
essentially the same way.
The next 10 bits will select a specific page table entry or PT from the
currently selected page table and that one would finally point to the
beginning of a page in physical memory,
All that's left to do now in order to access a particular bite,
which is the smallest piece of memory that the CPU support we just
need to add in the 12 beat offset so we get to a particular bite
that is now is the target of the particular instruction that the
CPU is trying to to execute,
tries to get to some address in memory and this is
the basic translation process.
So obviously you might have some questions at this point.
For example, how come this always seems to succeed?
I mean where is the page fault coming here into the picture?
I mean the CPU will just go to these data structures
in memory and simply march on.
So the way this works is it's not quite 32-bit that we
actually need here for the address.
If you think about it.
The PTS 32 bits, let's just focus on the PT for a moment.
However,
how many beads do we actually need to point to the beginning of the page?
I suggest you pause the video and think about it for a little bit.
So here's the answer.
Since 12 bits are always coming off the offset,
only 20 beats are actually needed in the PT in order to point to
the beginning of a page in physical memory,
which means that we have 12 bits here which are essentially free and
can be used for other purposes and one of those purposes is to
indicate whether the PT is in fact valid in the first place and that
bit is bit zero on x 64 processors or on internet and d processors and
so bit zero if it is one,
It means the page is valid and everything else I said applies,
which means that the other 20 bits that are being stored actually here in
the later part of the PT in the highest bit will be pointing to the
beginning of a page in physical memory and the 12 bits are going to be
added from the offset if the beat however,
here the valid bit is zero, the CPI will say okay,
I have no idea what to do with that, I'm not going to continue,
I'm going to raise the page fault exception and let someone else deal with that.
That's the basic idea here.
This is how the CPU knows whether to move forward or
to raise a page fault exception.
Now you also might be wondering why do we have the scheme?
Why not just use these 20 bits um together as one big array that would simply
will not work properly because we would have a million or so page tables that
would have to be existing in in contagious memory,
which doesn't make sense.
So this scheme will have of having these two levels allows us to
conserve page tables only create them is needed.
The only thing that is all always there is the page Director.
This never goes away.
It's always in physical memory and its physical address is known to
cr three and it's also stored in the K process,
it has to be the physical address otherwise,
how would we translate that?
We have to start somewhere.
It's like the chicken and the egg problem and you have
to start with the chicken or the egg.
Whatever makes more sense to you but we have to start somewhere.
So this thing is immutable.
Never really goes anywhere