Let's get into how Virtual Memory Systems
implement all these nice features for our
processes.
let's review the problems that virtual
memory is trying to address.
First problem is we have to fit a huge
memory address base into a tiny physical
memory.
again physical memory does not have 16
exabytes of space, typically it's just a
few gigabytes, so how do we think about
that?
then how do we manage the memory spaces
for multiple processes, make the problem
even harder.
Now it's not just 16 exabytes but it's 16
exabytes for each process.
and then how do we protect processes from
stepping on each other's each other's
memory.
At the same time, we want to allow
processes to share common parts of memory
so that we can be more efficient with
this little physical memory that we do
have.
So how would you go about solving these
problems?
it turns out there's one there's one
important technique that comes up over
and over again in computer science, that
can help us with all of these.
And that technique is called indirection.
The quote you see at the top of this
slide.
any problem in computer science can be
solved by adding another level of
indirection is a common thing you'll hear
people say.
Sometimes jokingly, but really seriously,
that almost anything can be addressed by
this particular technique.
And it's an important technique for
referring to objects, in in memory in and
how to point to them.
let's take a look at what we mean by,
pointing to an object.
So if I have a name for something like,
lets say I've, I've stored a pointer in a
variable.
a pointer type.
I can have it to point to something in
memory.
Okay, and without indirection, I have a
direct link, in that namely this variable
stores a particular address that points
directly to that memory location.
That works great until I decide that I
want to move this thing in memory and put
it somewhere else.
And, if I want to do that, I have a
problem in that I have to go find every
single variable that might have pointed
to that object.
And changed the address stored at that
variable.
Well, that can be a very burdensome and
hard to keep track of.
So, what indirection does.
Is it says you know what?
Instead of having a direct link between
the two.
Let's add something in the middle.
That will serve kind of as a directory.
some, a look up table if you will.
So that when I have a particular pointer
to an object.
I won't have the direct pointer to it,
I'll have an indirect point to it.
That namely goes into this directory and
says you know, the third thing I was
referring to.
So that now I will look it up in that
directory in the third slot for example,
and find the address of the thing.
Now that involves an extra step.
I have to first go to this place in
memory.
Find the directory, look up the third
element of of the directory, and then
I'll get the address in memory that I,
I'm, I really want.
So it's a little bit of extra cost
because I have to do that second memory
access.
However, if I change the position of the
thing or I just want to point to
something else using that same original
variable name.
Well then that's really easy to do,
because all I have to do is change the
directory to point to point here now.
And not have to worry about what
variables might I have to go back and
change.
Anything that referred to the third slot
in that memory is in our as in our
example, can now just point to that.
Because I'll find a new address in that
third slot in my lookup table, in my
directory.
Alright, so this is how indirection
works, and there's lots and lots of
examples of this that rely on this
ability to have a flexible mapping.
Between a variable or that stores a
pointer and the actual object in memory.
So that I can easily switch between what
things I'm pointing to.
and examples of these include things like
the domain name service that helps you
find the actual machines that hosts your
websites on the web.
the phone system.
things that allow cell phone portability.
Or find your cell phone depending on
which cell tower you happen to be near.
mail forwarding at the post office is an
example of indirection.
lots and lots of things that we use in
our daily lives.
rely on this ability to go and look up
things in a directory and then as a
second step, find the actual thing if
interest.
Rather than having a direct name for it
in the first place, and this is going to
be fundamental.
to how we build virtual memory.
namely we're going to add a level of
indirection to our address mapping to
physical memory.
So our processes here are going to be
generating virtual memory addresses and
we're going to put a big directory in the
middle.
to take that virtual memory address and
turn it into a physical memory address.
To find the spot in physical memory where
we've actually put that thing.
This is how we're going to give each
process the illusion of having their own
physical memory.
even though there, they are not aware of
each other and they're generating
potentially the same address, internally,
to a process.
but it's going, potentially be mapped to
a different place in physical memory.
This is going to be useful to solve all
of those problems that we had.
So let, let's go a little bit more into
detail on this.
So let's remind ourselves about the
address spaces that we have.
Our virtual address space, what our
processes generate as address is 2 to the
n, where n is the number of bits in our
address.
In the case of our 64 bit machines that's
2 to the 64.
Our, our physical address base is 2 to
the M, typically where M is much, much
smaller than N.
So we might have a physical address base
that is only, really 34 bits or, 38 bits.
But not 64.
64 would be just a huge address space to
implement physical memory.
Alright?
Now our mapping, since we have all of
these virtual address in our process, is
we can only fit some of them in the
actual physical memory.
Which again is much smaller.
The rest will have to be stored on disk.
In other words rather than having those
values be in physical memory we're
going to put them on a slower but much
larger storage device, namely a hard
drive.
Or these days a an S, an SD card or a a
solid state drive.
But it's not going to be in our fast
physical, faster physical memory.
It's going to be on a slower device out
on a disk.
Alright?
So what we'll want to do is as we execute
our program, we may need memory that is
stored on disk.
At that point, we'll want to get it and
bring it into physical memory so we can
access it there.
And we'll see the details of that in a
little bit.
So let's just remind ourselves if we were
just using physical addressing.
What we would have is our CPU, would
generate a physical address, it would go
directly to main memory.
Find the location in the main memory
where that address is.
And get the value there and bring it,
back into the CPU.
Right?
In this case reading four bytes out of
the memory.
This is the standard approach for very
simple computer systems like embedded
micro controllers.
things you might find in an elevator or
microwave oven.
Things like that.
where it is well know and advance how
much memory we'll actually need.
It's a single or a few function device,
it's not going to get new apps loaded
into it.
So, we don;t have to worry about
allocating that memory in in very,
flexible ways.
Because we won't have a lot of different
processes running.
In fact for the most part in these small
embedded systems, we'll have a single
process.
And it can have full use of that physical
memory, directly using a physical
address.
However, in, larger systems.
things like our desktops, our laptops,
even our cell phones these days and
certainly servers.
We will have a CPU not generate a direct
physical address but a virtual address.
that will then go through a mapping
function here labeled an MMU.
Or memory management unit that will keep
track of where those pieces of memory
are.
Are they in physical memory?
Are they on disk?
and we have to bring them into the
physical memory before we can access
them.
All those sorts of things will be one
inside of this memory management unit.
Which will then generate a physical
address that will be used to actually
used to access the physical memory.
And again, just get that data and bring
it around back into the CPU as before.
But that mapping function in between, is
that level of indirection.
And that is one of those great ideas in
computer science that is used to solve
many, many problems.
And in the next few videos we'll go into
the details of how this is implemented
for virtual memory
Wyszukiwarka
Podobne podstrony:
Margit Sandemo Cykl Saga o czarnoksiężniku (02) Blask twoich oczut informatyk12[01] 02 101introligators4[02] z2 01 n02 martenzytyczne1OBRECZE MS OK 0202 Gametogeneza02 07Wyk ad 02r01 02 popr (2)1) 25 02 2012TRiBO Transport 02więcej podobnych podstron