So, let's understand exactly what happens during a
page fault service. So when a thread is executing
on the CPU, it generates a virtual address and
the hardware takes that virtual page number and looks
up the TLB to see if it can translate
that virtual page to a physical page frame that
contains the contents of that page. Now the TLB
look up fails, that's a miss in the TLB.
At that point, the hardware, if the hardware is doing
the page table lookup, it'll go to the page table
and look up the page table to see if the
mapping between the virtual page and the physical page is in
the page table. And this would have been there if
the operating system has already put the contents of the
page in physical memory. But if the operating system has
not brought in that page from the disk into physical memory
then when the hardware goes and looks into, into the page
table, it may not find the mapping between the virtual page
and the physical frame. And so that will deserve a page
table miss. And that miss is the point at which you have
a page fold. So you have a page fold now that
says that I don't have the page in physical memory. And so
what the operating system at that point in the handler, what
it has to do is to locate where on the disk that
particular page, which were pages residing on the
disk, and as part of the page fold
service, the operating system has to allocate a
physical page frame, because it's now missing in
physical memory. And do the I/O to move the virtual page from the disk into the
page frame that is allocated. And once it has done the I/O, the I/O is complete.
Then at that point the operating system can update the
page table to indicate now it has a mapping between
that virtual page and the physical frame number, which was
missing in the original scheme of things, and that's the
reason that we have this fault. And we handle the
fault by bringing in the missing page from the disc
into physical memory. And we update the page table to
indicate that the mapping is now established between the virtual
page and the physical frame number. And then
we can update the TLB to indicate that
now we have the mapping between VPN and
PFN, and once the TLB is also been updated,
the page fault service is complete, and life
is good. So that's the whole workflow in taking
a virtual page and mapping it to a
physical frame when there's a miss. Now let's analyze
this picture and ask the question, where
are potential points of bottlenecks? Now what
I'm showing you here is thread specific. A thread is executing on the CPU. And
looking up the virtual page, advance leading
that to physical frame. It's entirely local
to a particular thread and local to
the processor on which that thread is executing.
No problem with that. No serialization at that point.
Now, moving over here, once the page fault has
been serviced, updating the TLB to indicate that there
is a mapping now, a valid mapping between the virtual
page number and the physical page number, that is
done on the TLB that is local to a
particular processor and therefore it processes a specific action
that's going on in terms of updating this TLB. Now,
let's come to the middle structure here. This is
where all the problem is. So what we have
here, is the situation where we have to first
allocate a physical page frame. That's an operating system function,
in order to allocate a physical page frame. You
have to update the page table to indicate now, that
the IO has been complete and now we can
have a mapping between virtual plane and physical frame. And
I told you that the page table data structure
is a common data structure that might be shared by
the threads in which case all of these things, what
I've shown you here can lead to serialization. So this
is what we want to avoid. We want to avoid
the serialization that is possible in allocating data structures, allocating
physical resources in order to serve as a page fault.
So what we are seeing here is entirely lookup, and
that can be done in parallel. No problem with that.
Reading is something that you can do in parallel. And similarly
what is happening over here is we are updating the
tlb but it is local to a processor. There's no serialization
that's going to happen here. But here we can have serialization
if you're not careful. So, as an OS designer and designing
this particular service, page fault service, this is what you
have to focus on to make sure that you avoid serialization.