Module 5 - Memory Organization - Final
Module 5 - Memory Organization - Final
Page 1
Introduction to Memory and Memory parameters
What is Memory?
• Computer Memory is very important part of computer.
• Memory is a computer chip or device that is used to hold data and instructions which are used by computer during the
processing.
• We can say that computer memory is the storage space for data and instruction in computer system.
Page 2
Why memory is required in computer?
Page 3
Parameter in choosing memory
Capacity
The size of computer depends on its memory capacity.
Memory can be seen as a storage unit containing x number of locations, each of which stores y number of bits.
The total capacity of memory can be calculated as x*y-bit or x-word memory.
Bandwidth
Bandwidth of the memory indicates the maximum amount of information that can be transferred to or from the
memory per unit time.
It is expressed as number of bytes or words per second.
Speed
The speed of operation of the memory is very important parameter.
The speed simply indicates the time between start of an operation and end of that operation.
Speed of memory is measured in two parameters:
access time (ta)
cycle time (tc)
Page 4
Characteristics of memory system
1. Location:
CPU: This includes CPU registers and On-chip cache memory
Internal .· This includes the memory that the processor can directly access.
External : This is normally removable or virtual memory and hence access is slower.
2. Capacity : It is measured in terms of the word size and the number of words.
Word size is the size of each location. Number of words is the number of locations.
3. Unit of transfer :This refers to the size of the data that is transferred in one clock
cycle. lt mainly depends on the data bus size.
a. Internal :It is related to the communication of data with the memory directly
accessible. It is usually governed by data bus width.
b. External : This is the data communication with the external removable memory
or virtual memory. It is usually a block which is much larger than a word.
Page 5
4. Access method : There are various methods of accessing the memory based on the memory organization. These
methods are listed below with examples :
• Sequential access : memories whose storage location can be accessed in certain pre-determined sequence is called
serial access memory.
• Direct access : access storage location directly
• Random access : if storage location access in any order and access time is independent of the physical location
being accessed i. e to access any memory location of memory it takes same amount of time e.g. RAM.
• Associative access :Here the data is located by a comparison with contents of a portion of the stored data(address).
Hence the access time is independent of location or previous access.
5. Performance : The performance of the memory depends on its speed of operation or the data transfer rate. The
data transfer rate is the rate at which the data is transferred The speed of operation depends on two things ;
a. Access time :The time between providing the address and getting the valid data from memory is called as its
access time i.e. the address to data time.
b. Memory cycle time :The time that is required for the memory to "recover" before next access Le. the time
between two addresses is called as memory cycle time.
Page 6
6. Physical type: The physical material using which the memory is made can be different like:
• Semiconductor: Memory can be made using semiconductor material I.e IC`s
• Magnetic : Memory can also be made using magnetic read and write mechanism for e.g. Magnetic disk and
M agnetic tape.
• Optical : Optical memories 1.e. memories that use optical methods to read and write have become famous these
days, for e.g. CD and DVD
7. Physical characteristics :The physical characteristics of memory is also an important aspect to be considered This
includes the volatile/Non Volatile , consumption, erasable / not erasable, etc.
8. Organisation :It is not that always the memory will be organized sequentially. There are some other types of
memory organization like interleaved memory etc.
Page 7
Classification of computer memory
Based on the type of use and feature memory unit of computer is categorized as:
•Primary Memory - It is also known as internal memory or Main memory.
•Secondary Memory - It is also known as auxiliary memory.
Page 8
Random Access Memory (RAM) – Primary Memory
•It is also called read-write memory or the main memory or the primary memory.
•The programs and data that the CPU requires during the execution of a program are stored in this memory.
•It is a volatile memory as the data is lost when the power is turned off.
•RAM is further classified into two types- SRAM (Static Random Access Memory) and DRAM (Dynamic Random
Access Memory).
Page 9
Page 10
Read-Only Memory (ROM)
•Stores crucial information essential to operate the system, like the program essential to boot the computer.
•It is non-volatile.
•Always retains its data.
•Used in embedded systems or where the programming needs no change.
•Used in calculators and peripheral devices.
•ROM is further classified into four types- MROM, PROM, EPROM, and EEPROM.
•PROM (Programmable read-only memory) – It can be programmed by the user. Once programmed, the data
and instructions in it cannot be changed.
•EPROM (Erasable Programmable read-only memory) – It can be reprogrammed. To erase data from it,
expose it to ultraviolet light. To reprogram it, erase all the previous data.
•EEPROM (Electrically erasable programmable read-only memory) – The data can be erased by applying an
electric field, with no need for ultraviolet light. We can erase only portions of the chip.
Page 11
Compare
Page 12
Volatile memory and Non Volatile Memory.
Page 13
Memory Hierarchy
OR
Page 14
Memory hierarchy
A 'memory hierarchy' in computer storage distinguishes each level in the 'hierarchy' by response time. Since
response time, complexity, and capacity are related, the levels may also be distinguished by the controlling
technology.
The many trade-offs in designing for high performance will include the structure of the memory hierarchy,
i.e. the size and technology of each component.
There are four major storage levels.
This is a most general memory hierarchy structuring. Many other structures are useful. For example, a paging
algorithm may be considered as a level for virtual memory when designing a computer architecture.
Page 15
Cache Memory in Computer Organization
Page 16
Levels of Cache Memory
Page 17
Cache Performance
When the processor needs to read or write a location in main memory, it first checks for a corresponding
entry in the cache.
•If the processor finds that the memory location is in the cache, a cache hit has occurred and data is read
from the cache.
•If the processor does not find the memory location in the cache, a cache miss has occurred. Furthermore,
during cache miss, the cache allows the entry of data and then reads data from the main memory.
•Therefore, we can define the hit ratio as the number of hits divided by the sum of hits and misses.
hit ratio = hit / (hit + miss)
= number of hits/total accesses
Page 18
Page Replacement Techniques:
• Page replacement occurs due to page faults.
• Page replacement algorithms help to decide which page must be swapped out from the main memory to create a
room for the incoming page.
• Page replacement algorithm is needed to decide which page needs to be replaced when a new page comes in.
• In Virtual Memory Management, Page Replacement Algorithms play an important role. The main objective of all
the Page replacement policies is to decrease the maximum number of page faults.
Page 19
Page Replacement Algorithms: FIFO
1. First In First Out (FIFO): This is the simplest page replacement algorithm. In this algorithm, the operating
system keeps track of all pages in the memory in a queue, the oldest page is in the front of the queue.
When a page needs to be replaced page in the front of the queue is selected for removal.
Example: Calculate the number of page hits and faults using FIFO, LRU, Optimal page replacement algorithms
for the following page frame sequence:
2,3,1,2,4,3,2,5,3,6,7,9,3,7 (Frame size:3)
Advantages
•Simple and easy to implement.
•Low overhead.
Disadvantages
•Poor performance.
•Doesn’t consider the frequency of use or last
used time, simply replaces the oldest page.
•Suffers from Belady’s Anomaly(i.e. more page
faults when we increase the number of page
frames).
Page 20
Page Replacement Algorithms: LRU
2. Least Recently Used: In this algorithm, page will be replaced which is least recently used.
Example: Calculate the number of page hits and faults using FIFO, LRU, Optimal page replacement algorithms for the
following page frame sequence:
2,3,1,2,4,3,2,5,3,6,7,9,3,7 (Frame size:3)
Advantages
•Efficient.
•Doesn't suffer from Belady’s Anomaly.
Disadvantages
•Complex Implementation.
•Expensive.
•Requires hardware support.
Page 21
Page Replacement Algorithms: OPR
3. Optimal Page replacement: In this algorithm, pages are replaced which would not be used for the longest
duration of time in the future.
Example: Calculate the number of page hits and faults using FIFO, LRU, Optimal page replacement algorithms for
the following page frame sequence:
2,3,1,2,4,3,2,5,3,6,7,9,3,7 (Frame size:3)
Advantages
•Easy to Implement.
•Simple data structures are used.
•Highly efficient.
Disadvantages
•Requires future knowledge of the program.
•Time-consuming.
Page 22
Page Replacement Techniques: Example
Page 23
Allocation Policies:
• As available memory blocks comprised of a set of holes of various sizes that scattered throughout the memory.
Whenever a process arrives and needs memory, the system searches the set for a hole that is large enough for
the arrived process.
• Memory allocation is the process of assigning blocks of memory on request. Typically the allocator receives
memory from the operating system in a small number of large blocks that it must divide up to satisfy the
requests for smaller blocks.
• Memory allocation is a process by which computer programs and services are assigned with physical or virtual
memory space. Memory allocation is the process of reserving a partial or complete portion of computer
memory for the execution of programs and processes. Memory allocation is achieved through a process known
as memory management.
There are different ways of implementing allocation of partitions from a list of free holes, such as:
• first-fit:
• best-fit:
• Worst fit:
Page 24
Allocation Policies : First Fit, Best Fit , Worst Fit
Page 25
First Fit, Best Fit , Worst Fit Example
Page 26
First Fit, Best Fit , Worst Fit Example
Page 27
Interleaved memory
• Interleaved memory implements the concept of accessing more words in single memory access cycle
• Memory can be partitioned into N separate memory modules.
• These N accesses can be carried out simultaneously
• Access to multiple words can be done simultaneously or in a pipelined fashion.
• Maximum bandwidth is N words per cycle
• Example:
Page 28
Fig: Low-order m-way interleaving Fig: Eight way Low-order interleaving(absolute address shown
in each memory word)
Page 29
Page 30
Associative memory
• An associative memory can be considered as a memory unit whose stored data can be identified for
access by the content of the data itself rather than by an address or memory location.
• When a write operation is performed on associative memory, no address or memory location is given to
the word. The memory itself is capable of finding an empty unused location to store the word.
• On the other hand, when the word is to be read from an associative memory, the content of the word, or
part of the word, is specified. The words which match the specified content are located by the memory
and are marked for reading.
Page 31
• associative memory consists of a memory array and logic for
'm' words with 'n' bits per word.
Page 32
Page 33
Cache Coherency
• Cache coherency is a situation where multiple processor cores share the same memory hierarchy, but have their
own L1 data and instruction caches.
• The practice of cache coherence makes sure that alterations in the contents of associated operands are quickly
transmitted across the system.
• In case, the processor P1 modifies the copy
of shared memory block X present in its
cache. It would result in data inconsistency.
• As the processor P1 will have the modified
copy of the shared memory block i.e. X1. But,
the main memory and other
processors’ cache will have the old copy of
the shared memory block X. And this
problem is the cache coherence problem.
Page 34
Cache Coherence Protocols : Write-Through Protocol
The easiest and most popular method is to write through. Every memory write operation updates the main
memory. If the word is present in the cache memory at the requested address, the cache memory is also updated
simultaneously with the main memory. So, the main memory here always has consistent data.
Page 35
Cache Coherence Protocols : Write-Back Protocol
This protocol permits the processor to modify a data block only if it acquires ownership.
Page 36
Virtual memory
• Virtual memory is a common technique used in a computer's operating system (OS).
• Virtual memory is a method that computers use to manage storage space to keep systems running quickly and
efficiently.
• Using the technique, operating systems can transfer data between different types of storage, such as random-
access memory (RAM), also known as main memory, and hard drive or solid-state disk storage.
• Virtual memory is a memory management technique where secondary memory can be used as if it were a part of
the main memory.
• A programmer can write a program which requires more memory then the capacity of main memory such a
program is executed by virtual memory techniques.
• Virtual memory is important for improving system performance, multitasking and using large programs.
Page 37
virtual memory
Page 38
2 types of virtual memory - 1. Paging
• Paging is a virtual memory technique that separates memory into sections called paging files.
• When a computer reaches its RAM limits, it transfers any currently unused pages into the part of its hard drive used
for virtual memory. The computer performs this process using a swap file, a designated space within its hard drive for
extending the virtual memory of the computer's RAM.
• By moving unused files into its hard drive, the computer frees its RAM space for other memory tasks and ensures that
it doesn't run out of real memory.
• As part of this process, the computer uses page tables, which translate virtual addresses into the physical addresses
that the computer's memory management unit (MMU) uses to process instructions.
• The MMU communicates between the computer's OS and its page tables. When the user performs a task, the OS
searches its RAM for the processes to conduct the task.
Page 39
2 types of virtual memory - 2. Segmenting
• A segmentation system divides virtual memory into varying lengths and moves any segments that aren't in use
from the computer's virtual memory space to its hard drive.
• Like page tables, segment tables track whether the computer stores the segment in memory or a physical address.
Segmentation differs from paging because it divides memory into sections of varying lengths, while paging divides
memory into units of equal size.
• With paging, the hardware determines the size of a section, but the user can select the length of a segment in a
segmentation system.
• Segmentation is often slower than paging, but it offers the user more control over how to divide memory and may
make it easier to share data between processes.
Page 40
Advantages and Disadvantages of Virtual Memory
Page 41
Cache Mapping
• Cache Mapping is a technique by which content of Main Memory is Brought into the Cache memory.
• It is a transformation of data from main memory to cache memory.
• There are three different types of mapping used for the purpose of cache memory which is as follows:
Direct mapping, Associative mapping, and Set-Associative mapping. These are explained below.
Page 42
Cache Mapping: 1. Direct Mapping
A. Direct Mapping
The simplest technique, known as direct mapping, maps each block of main memory into only one possible cache
line. or In Direct mapping, assign each memory block to a specific line in the cache.
i = j modulo m
where
i=cache line number
j= main memory block number
m=number of lines in the cache
Page 43
Direct Mapping conti….
Page 44
Advantages and Disadvantages of direct mapping
• It is easy to implement.
• Direct mapping is simplest type of cache memory mapping.
• Here only tag field is required to match while searching word that is why it fastest cache.
• Direct mapping cache is less expensive compared to associative cache mapping.
• The performance of direct mapping cache is not good as requires replacement for data-tag value.
• It is not very flexible.
Page 45
(2) Associative Mapping:-
Page 46
Advantages and Disadvantages of associative mapping
Page 47
(3) Set-Associated Mapping:-
Page 48
Advantages and Disadvantages of Set-Associative mapping
Page 49
Example:
Page 50