Conceptual Introduction to Memory in Computers

Not all memory is created equal.

For Hanu (only)

Background

Computer’s processing power increases as an exponential rate (the famous Moore’s Law) but memory technology is not as promising.

Memory performance measures not just volume but also how fast the memory can be accessed

For computers to truly do their computation fast, the memory does need to complement the processors. It’s no good if you have the potential to do the calculation but it takes too long to actually load up the data. In other words, memory should not be a bottleneck.

This is achieved by a clever application of different types of memory.

The types of memory

In memory technology, there is a trade-off between 1)how fast the memory can be read/written and 2)the cost of the memory. More expensive the memory, less it is used(less volume of it) so the real trade-off can be seen as memory speed vs memory size.

A computer normally has different types of memory working together. They are usually in a hierarchy like this:

  • Registers (~few KB in size)
  • Cache (~128–512 KB, few hundred GB/sec)
  • Main memory (RAM) (~4–16 GB, few GB/sec)
  • Disk storage (eg Hard Disk Drives) (~250GB-1 TB, at best 1–2 GB/sec)

Everything is stored in the Disk storage, booted into Main memory when in use, and loaded in the registers and caches when specific parts of that data need to be calculated upon. Eg. Your homework from last semester is on your disk storage. The data on this webpage is in your main memory as it is being read right now. Lots of things different go in and our of your cache and registers in any given second. Disk storage is the only memory that still stores the memory once the computer is shut down.

Registers store data being used in computation at that very moment.

Caches store data that are likely to be loaded into the registers next.

Main memory stores things in current use eg. the data pertaining to all running processes.

Disk storage is perhaps the most well understood among them all.

You can see how the more likely something is to be used, the higher up the memory hierarchy it will be stored so that it can be accessed more efficiently. With this diversity in memory types we can both quickly access what we need now and store lots of things we might need later.

Virtual memory

When you run many applications at the same time, your RAM (Main memory) begins to fill up. You can fill the whole thing up by running enough processes.

The question is: what happens when it is full?

One option is that the computer could just complain: “Sorry, not enough RAM!”. But what if we really wanted it to still work?

This is where virtual memory comes in.

If your RAM gets too full, your computer will start using some of the disk space as if it were RAM. There is no reason it cannot do this, but of course this has one limitation. Memory in RAM is accessed fairly often(by the active processes) so if some part of the disk space is used like RAM, it means a lot of read/write operations taking place on the slow disk space. So although this solution can accommodate more RAM when needed, this more RAM will be very slow.

This is what virtual memory is. The provision of extra memory (beyond the RAM) by using some disk space.

Virtual memory vs swap memory

Virtual memory refers to the original RAM and the memory on the disk allocated for active processes.

Swap memory refers to just the memory on the disk made available for active processes.