SHREE LEARNING ACADEMY
Operating System | Computer Hardware - Memory
The second most important component in any computer is memory. A memory must be much faster than the CPU so that the CPU does not slow down due to memory, in the same way the memory should be big and cheap. No current technology can fulfill all these conditions, that's why we will solve this problem in a different way. We have divided the memory system into layers, as shown in the figure below. Speed in the top layers is very high, their size is small and their cost is very high.
Registers
The top most layer is register, which is placed inside the CPU. The material that is used to make the Registers is the same material that is used to make the CPU so that it is as fast as the CPU. There is no delay in accessing them.
Their storage capacity is normally 32 x 32 bits in a 32 bit CPU and 64 x 64 bits in a 64 bit CPU. In both cases, their size is less than 1 KB. Registers are managed by programs, programs decide which data should be inserted in the registers as the size of the registers is very small.
Cache Memory
After this comes cache memory, which is mostly controlled by hardware. Primary memory is divided into cache lines, normally 64 bytes, with addresses 0 to 63 in cache line 0 and 64 to 127 in cache line 1 and so on. The most commonly used cache lines are placed in a high-speed cache that is very close to or inside the CPU. When the program needs to read the memory word, the cache hardware checks whether the word is in cache or not. If it is found in the cache, then it is called cache hit, and then that request is served directly from the cache itself and memory is not requested. Cache hits normally take 2 clock cycles. And if the cache is missed, then that request has to go to memory, which takes a lot of time. The size of cache memory is very small because its cost is very high. Some machines also have 2 or 3 levels of cache in which each layer is slower and larger than the previous layer.
Operating systems use caching extensively. For example, OS stores some files which are used more in RAM so that the OS doesn't have to fetch those files from the disk again and again. If there is a long path, then its disk address is also stored in cache so that the path does not have to be converted to disk address repeatedly. Similarly, the URL of the web page is also converted to IP address, so the result of this conversion is also cached so that the time of convertion is saved in future.
There are some questions that come to the mind of people like
1. When to put any new item in cache?
Generally after any cache miss, that item is put in cache.
2. Which item should be removed from the cache when a slot is required?
In this case, the previous item is removed from the same slot in which the new item is inserted. but it is not necessary for all systems to work like that.
Modern CPUs have two level caches, the first one is L1 cache or Level 1 cache which is always inside the CPU and stores the decoded instructions of the CPU. Most of the chips also have a second L1 cache in which they store the most used words. The size of L1 caches is normally 16 KB.
The second level cache is called as L2 cache. It can store data up to a few MBs and they are also used to store the most used words.
Now you may be wondering what is the difference between L1 and L2 cache as both are used to store the most used words. Well the difference is timing. We can access the L1 cache without any delay but there is usually a slight delay in accessing the L2 cache normally 1 or 2 clock cycles.
The designers of multicore chips have to decide where to place the caches. As you can see in figure A, all the cores are sharing the L2 cache among themselves. It is used in multicore chips designed by Intel and in figure B you can see that all the cores have their own L2 cache. This design is used in AMD processors. Actually both designs have their own advantages and disadvantages, such as Intel's design requires more complicated cache controller and it becomes difficult to keep caches consistent in AMD's design.
Main Memory
Next layer is main memory. This is one of the most important memory. Main memory is normally called RAM, whose full form is Random Access Memory. Memory size nowadays goes up to multiple giga bytes such as 2 4 8 or 16 GB RAM is a normal thing. All the CPU's requests which cannot be fulfilled in cache, goes into main memory.
Along with main memory, non-volatile random access memory is also used in most computers. RAM is a volatile memory, which means that when the power supply of the system is turned off then all the data stored in the memory will be deleted. And non-volatile memory means that the data will not be deleted from the memory even when the power supply is turned off.
Read Only Memory
ROM i.e. Read Only Memory is programmed in the factory itself and then it cannot be changed later. ROM is fast and inexpensive. In some computers, the bootstrap loader that is used to start the computer is stored in ROM. Some input output cards also come with ROM so that they can handle low level device control.
Electrically Erasable Programmable Read Only Memory
EEPROM i.e. Electrically Erasable Programmable Read Only Memory and flash memory are also non volatile. We can rewrite the EEPROM however ROM cannot be rewritten. EEPROM takes longer time to write than RAM. That is why we use them just like ROM, just an additional feature is that now the bugs that occur within the programs can be corrected.
Flash memory
Flash memory is also commonly used as a storage medium in portable electronic devices. It works like a film in digital cameras and works like a disk in music players. The speed of flash memory is between RAM and disk. But compared to disk, if you erase flash memory very often, then it gets damaged while the disks does not.
CMOS
There is another type of memory called CMOS. It is a volatile memory and computers use it to store current date and time. The CMOS memory gets power from a small battery so that the date and time are not lost even when the power supply is turned off. CMOS memory can also hold some configuration parameters such as from which disk to boot from. It uses so little power that the same battery that is put in the factory, lasts for years. But if that battery starts failing, then your computer will have forget some things that it was remembering for so long, such as date and time and which disk to boot from. If you see such symptoms in your computer, then you may have to change the battery.
Disks
The next layer in the layers of memory is magnetic disk or hard disk. Disks are cheaper and larger than RAM. But at the same time it is also slower. There can be a reason as it is a mechanical device.
There are 1 or more metal platters inside a disk which rotate at 5400, 7200, 10,800 or more RPM i.e. Rotation Per Minute.
Inside it, information is written as series in concentric circles. They have mechanical arms that can read and write data, this is somewhat similar to the earlier phonograph that used to play vinyl records. On any arm position, the head of the arm, can read a region which we call as the track and all the tracks on any arm postion are called together as the cylinder. We divide each track into some sectors, mostly 512 bytes per sector. In modern disks outer cylinders contain more sectors as compared to inner cylinders. Average reading and writing speed of disks is 50 MBPS to 160 MBPS.
Sometimes you hear people talking about disks which are not really disks like SSDs which we call Solid State Disks. SSDs do not have any moving parts nor do they have platters inside them which are in the shape of disks and store the data like flash memory. The only similarity is that both SSDs and disks are used to store large amount of data and data is not lost when power is turned off.
Many computers support virtual memory which we will discuss in detail in the upcoming chapters. With the help of virtual memory, we can run programs that are larger than physical memory. To do this work, we place programs in disk and use main memory as a cache memory in which we will store most used parts.
Test Yourself
Take Free Quiz