Chapter 3 PDF
Chapter 3 PDF
Chapter 3 PDF
CHAPTER 3
Memory Concepts
Register: This is a part of Central Processor Unit, so they reside inside the CPU. The information
from main memory is brought to CPU and keep the information in register. These are basically faster
devices.
Cache Memory: Cache memory is a storage device placed in between CPU and main memory.
These are semiconductor memories. These are basically fast memory device, faster than main
memory. Due to higher cost we cannot replace the whole main memory by faster memory. Generally,
the most recently used information is kept in the cache memory. It is brought from the main memory
and placed in the cache memory.
Main Memory: Like cache memory, main memory is also semiconductor memory. But the main
memory is relatively slower memory. We have to first bring the information (whether it is data or
program), to main memory. CPU can work with the information available in main memory only.
Magnetic Disk: This is bulk storage device. We have to deal with huge amount of data in many
application. But we don't have so much semiconductor memory to keep these information in our
computer. On the other hand, semiconductor memories are volatile in nature. It loses its content
once we switch off the computer. For permanent storage, we use magnetic disk. The storage
capacity of magnetic disk is very high.
Removable media: For different application, we use different data. It may not be possible to keep
all the information in magnetic disk. So, whichever data we are not using currently, can be kept in
removable media. Magnetic tape is one kind of removable medium. CD is also a removable media,
which is an optical device.
Register, cache memory and main memory are internal memory. Magnetic Disk, removable media
are external memory. Internal memories are semiconductor memory. Semiconductor memories are
categorised as volatile memory and non-volatile memory.
RAM: Random Access Memories are volatile in nature. As soon as the computer is switched off,
the contents of memory are also lost.
ROM: Read only memories are non-volatile in nature.
Several types of ROM are available:
PROM: Programmable Read Only Memory; it can be programmed once as per user
requirements.
EPROM: Erasable Programmable Read Only Memory; the contents of the memory can be
erased and store new data into the memory. In this case, we have to erase whole information.
EEPROM: Electrically Erasable Programmable Read Only Memory; in this type of memory the
contents of a particular location can be changed without effecting the contents of other
location.
2. Main Memory
The main memory of a computer is semiconductor memory. The main memory unit of computer is
basically consists of two kinds of memory:
RAM: Random access memory; which is volatile in nature.
ROM: Read only memory; which is non-volatile.
The permanent information are kept in ROM and the user space is basically in RAM. The maximum
size of main memory that can be used in any computer is determined by the addressing scheme.
The main memory is usually designed to store and retrieve data in word length quantities. The word
length of a computer is generally defined by the number of bits actually stored or retrieved in one
main memory access.
The data transfer between main memory and the CPU takes place through two CPU registers.
MAR: Memory Address Register MBR: Memory Buffer Register.
The transfer of data takes place through memory bus. It also includes control lines like Read, Write
and Memory Function Complete (MFC) for coordinating data transfer.
For memory operation, the CPU initiates a memory operation by loading the appropriate data i.e.,
address to MAR.
For Memory Read Operation For Memory Write Operation
It sets the read memory control line to 1. Then The CPU places the data into MBR and sets the
the contents of the memory location is brought write memory control line to 1. Once the
to MBR and the memory control circuitry contents of MBR are stored in specified
indicates this to the CPU by setting MFC to 1 memory location, then the memory control
circuitry indicates the end of operation by
setting MFC to 1.
A useful measure of the speed of memory unit is the time that elapses between the initiation of an
operation and the completion of the operation. This is referred to as Memory Access Time. Another
measure is memory cycle time. This is the minimum time delay between the initiation two
independent memory operations. Memory cycle time is slightly larger than memory access time.
The memory constructed with the help of transistors is known as semiconductor memory. The
semiconductor memories are termed as Random Access Memory (RAM), because it is possible
to access any memory location in random.
Depending on the technology used to construct a RAM, there are two types of RAM -
SRAM: Static Random Access Memory.
DRAM: Dynamic Random Access Memory.
DRAM requires the supporting refresh circuitry. For larger memories, the fixed cost of the refresh
circuitry is more than compensated for by the less cost of DRAM cells
SRAM cells are generally faster than the DRAM cells. Therefore, to construct faster memory modules
(like cache memory) SRAM is used.
Each row of cells constitutes a memory word, and all cell of a row are connected to a common line
which is referred as word line. An address decoder is used to drive the word line. At a particular
instant, one word line is enabled depending on the address present in the address bus. The cells in
each column are connected by two lines. These are known as bit lines. These bit lines are
connected to data input line and data output line through a Sense/Write circuit.
A memory chip consisting of 16 words of 8 bits each, usually referred to as 16 x 8 organization. The
data input and data output line of each Sense/Write circuit are connected to a single bidirectional
data line in order to reduce the pin required. For 16 words, we need an address bus of size 4. In
addition to address and data lines, two control lines, R| and Chip Select (CS), are provided. The
R| line is to use to specify the required operation about read or write. The CS line is required to
select a given chip in a multi-chip memory system.
3. Cache Memory
We know that a number of instructions are
executed repeatedly. This may be in the
form of a simple loops, nested loops, or a
few procedures that repeatedly call each
other. It is observed that many instructions
in each of a few localized areas of the
program are repeatedly executed, while the remainder of the program is accessed relatively less.
This phenomenon is referred to as locality of reference.
Memory access is the main bottleneck for the performance efficiency. If a faster memory device can
be inserted between main memory and CPU, the efficiency can be increased. The faster memory
that is inserted between CPU and Main Memory is termed as Cache memory. To make this
arrangement effective, the cache must be considerably faster than the main memory, and typically
it is 5 to 10 time faster than the main memory.
a word within a block. Next 7 bits are used to select a block out of 128 blocks (which is the capacity
of the cache). The remaining 4 bits are used as a TAG to identify the proper block of main memory
that is mapped to cache.
When a new block is first brought into
the cache, the high order 4 bits of the
main memory address are stored in
four TAG bits associated with its
location in the cache. When the CPU
generates a memory request, the 7-bit
block address determines the
corresponding cache block. The TAG
field of that block is compared to the
TAG field of the address. If they match,
the desired word specified by the low-
order 5 bits of the address is in that
block of the cache.
If there is no match, the required word must be accessed from the main memory, that is, the contents
of that block of the cache is replaced by the new block that is specified by the new address generated
by the CPU and correspondingly the TAG bit will also be changed by the high order 4 bits of the
address. The whole arrangement for direct mapping technique is shown in the figure.
In the associative mapping, any block of main memory can go to any block of cache, so it has got
the complete flexibility and we have to use proper replacement policy to replace a block from cache
if the currently accessed block of main memory is not present in cache. It might not be practical to
use this complete flexibility of associative mapping technique due to searching overhead, because
the TAG field of main memory address has to be compared with the TAG field of all the cache block.
In this example, there are 128 blocks in cache and the size of TAG is 11 bits. The whole arrangement
of Associative Mapping Technique is shown in the above figure.
set is not full, the new block is put into an empty block and the counter values of the occupied block
will be increment by one. When a miss occurs and the set is full, the block with highest counter value
is replaced by new block and counter is set to 0, counter value of all other blocks of that set is
incremented by 1. The overhead of the policy is less, since no updation is required during hit.
4. Memory Management
We have to keep all the information in some storage, mainly known as main
memory, and CPU interacts with the main memory only. Therefore, memory
management is an important issue while designing a computer system. The main
memory of a computer is divided into two parts. One part is reserved for operating
system. The other part is for user program. The program currently being executed
by the CPU is loaded into the user part of the memory.
In a uniprogramming system, the program currently being executed is loaded into the user part of
the memory. In a multiprogramming system, the user part of memory is subdivided to accommodate
multiple process. The task of subdivision is carried out dynamically by operating system and is
known as memory management.
There are five defined state of a process as
shown in the figure.
When we start to execute a process, it is placed
in the process queue and it is in the new state.
As resources become available, then the
process is placed in the ready queue.
1. New: A program is admitted by the scheduler, but not yet ready to execute. The operating system
will initialize the process by moving it to the ready state.
2. Ready: The process is ready to execute and is waiting access to the processor.
3. Running: The process is being executed by the processor. At any given time, only one process
is in running state.
4. Waiting: The process is suspended from execution, waiting for some system resource, such as
I/O.
5. Exit: The process has terminated and will be destroyed by the operating system.
4.1 Swapping:
Since the size of main memory is fixed, it is possible to accommodate only few process in the main
memory. If all are waiting for I/O operation, then again CPU remains idle. To utilize the idle time of
CPU, some of the process must be off loaded from the memory and new process must be brought
to this memory place. This is known swapping. In swapping
1. The process waiting for some I/O to complete, must store back in disk.
4.2 Partitioning
Partitioning is the process of splitting of memory into
sections to allocate processes including operating
system. There are two scheme for partitioning:
Fixed size partitions
Variable size partitions
Variable size Partition: When a processes is brought into memory, it is allocated exactly as much
memory as it requires and no more. In this process it leads to a hole at the end of the memory, which
is too small to use. It seems that there will be only one hole at the end, so the waste is less.
But, this is not the only hole that will be present in variable size partition. When all processes are
blocked then swap out a process and bring in another process. The new swapped in process may
be smaller than the swapped out process. Most likely we will not get two process of same size. So,
it will create another hole. If the swap- out and swap-in is occurring more time, then more and more
hole will be created, which will lead to more wastage of memory.
There are two simple ways to slightly remove the problem of memory wastage:
Coalesce: Join the adjacent holes into one large hole, so that some process can be accommodated
into the hole.
Compaction: From time to time go through memory and move all hole into one free block of memory.
4.3 Paging
Both unequal fixed size and variable size partitions are inefficient in the use of memory and lead to
memory wastage. There is another scheme for use of memory which is known as paging.
In this scheme, the memory is partitioned into equal fixed size chunks that are relatively small. This
chunk of memory is known as frames or page frames. Each process is also divided into small fixed
chunks of same size. The chunks of a program is known as pages. A page of a program could be
assigned to available page frame. At a given point of time some of the frames in memory are in use
and some are free. The list of free frame is maintained by the operating system.
As shown in below given figure, Process A, stored in disk, consists of pages. At the time of execution
of the process A, the operating system finds six free frames and loads the six pages of the process
A into six frames. These six frames need not be contiguous frames in main memory. The operating
system maintains a page table for each process.
Within the program, each logical address consists of page number and a relative address within the
page. The process uses the page table to produce the physical address which consists of frame
number and relative address within the frame.
The following figure shows the allocation of frames to a new process in the main memory. A page
table is maintained for each process. This page table helps us to find the physical address in a frame
which corresponds to a logical address within a process.
The conversion of logical address to physical address is shown in the figure for the Process A.
5. Virtual Memory
Instead of loading all the pages of a process, each page of process is brought in only when it is
needed, i.e. on demand. This scheme is known as demand paging. Demand paging also allows us
to accommodate more process in the main memory.
Virtual memory involves the separation of logical memory as
perceived by users from physical memory. This separation, allows an
extremely large virtual memory to be provided for programmers when
only a smaller physical memory is available. Virtual memory makes
the task of programming much easier, because the programmer no
longer needs to worry about the amount of physical memory
available; and can concentrate instead on the problem to be
programmed.
The virtual address space is used to develop a process. The special hardware unit, called Memory
Management Unit (MMU) translates virtual address to physical address. When the desired data is
in the main memory, the CPU can work with these data. If the data are not in the main memory, the
MMU causes the operating system to bring into the memory from the disk.
Most virtual memory scheme store page table in virtual memory rather than in real memory. This
means that the page table is subject to paging just as other pages are. When a process is running,
at least a part of its page table must be in main memory, including the page table entry of the
currently executing page.
Each virtual address generated by the processor is interpreted as virtual page number (high order
list) followed by an offset (lower order bits) that specifies the location of a particular word within a
page. Information about the main memory location of each page kept in a page table.
6. Magnetic Disk
A disk is a circular platter constructed of nonmagnetic
material, called the substrate, coated with a magnetisable
material. Traditionally, the substrate has been an aluminium
or aluminium alloy material.
7. Magnetic Tape
Tape systems use the same reading and recording techniques as disk systems. The medium is
flexible polyester tape coated with magnetizable material. The coating may consist of particles of
pure metal in special binders or vapor-plated metal films.
Data on the tape are structured as a number of parallel tracks running lengthwise. Modern systems
use serial recording, in which data are laid out as a sequence of bits along each track. Data are read
and written in contiguous blocks, called physical records, on a tape. Blocks on the tape are separated
by gaps referred to as interrecord gaps.