In this video, we're going to talk about memory or RAM and swap space.
First of all, a little history.
What is memory?
Well, there are really two types of memory,
there's persistent storage, for instance, Hard disks,
EMMC, SD cards, and there's temporary storage,
this is the dynamic random access memory.
The temporary storage will lose all of its information when the board is powered down.
So, the board must remain powered up in order to keep the information in RAM.
So, a little bit about dynamic random access memory.
When I was a little younger,
I spent five years working for a company that designed a dynamic random access memories.
The company I worked for designed
approximately 70 percent of all the DRAMs on the planet.
So, it didn't matter who was manufacturing the DRAM,
the design came out of one company.
So all DRAMS are very similar.
They have very similar structures,
very similar details, and they all have the,
I don't know, feature, is that the right word?
Of losing storage when they're powered down.
So, why do we use dynamic random access memory.
The advantage to dynamic random access memory over the others storage,
persistent storage techniques, is you can
access a very small amount of data very quickly.
So a dynamic random access memory is between 10
and 1,000 times faster than any of the persistent storage systems.
So, you want to use as much of your program in dynamic random access memory or DRAM,
so that you can get at it as quickly as possible.
This allows your programs to execute instructions very quickly.
So each time a processor wants the next instruction,
it fetches it from DRAM.
Unfortunately, not all of your instructions are stored in DRAM.
When the system starts because the DRAM was empty,
it had forgotten everything from the previous time,
so the operating system as you start each program
brings a small portion of the program into DRAM.
And as you execute down through the program,
each time you come to the end of the boundary that has been pulled in,
the operating system pause in the next boundary.
All of this happens behind the scenes without you seeing it.
To you, as a programmer,
It looks like all of the information is in memory.
The DragonBoard itself has one gigabyte of DRAM and usually, for most programs,
that is enough, that is certainly enough for all of
the operating system and most programs to sit in.
But occasionally, you want to run a program that is bigger than
one gigabyte but that's all the DRAM you have. So, what do you do?
Well, the operating system has ways to deal with this.
The operating system says,
"I've run a previous set of instructions and I no longer need those instructions.
I'm going to move them back to the persistent storage."
So, it moves those back to the persistent storage,
frees up some space in the DRAM,
and then brings in the next block of instructions.
But this can only go on so far,
until you still run out of space.
So, what we do is we allocate a block of persistent storage and call it a swap space,
in which the operating system can move active pages of DRAM out to the swap space,
store them, and then bring them back later.
This makes your program run slower than if it was running in DRAM but to you,
the programmer, it still appears as if your program is running.
And often, the swap space is fast enough that you don't notice
the slowdown of the operating system moving pages out and back from swap space.
So in a later lesson, we will teach you how to increase the swap space and
use EEMC as swap space or if you need much larger programs,
you can use the SD card as swap space or you could
even use a spinning magnetic drive connected to USB as swap space.
The operating system doesn't care where the swap space is or what the storage media,
is as long as you tell it where to find it and how much there is been allocated there.
If you want to know more about swap space,
feel free to browse the internet and look up swap space,
look up the properties of DRAM,
look up the properties of persistent storage.
This is a short introduction to get you familiar with
the idea of a swap space and dynamic random access memory.