0% found this document useful (0 votes)
7 views14 pages

Coa Unit4

Memory hierarchy is the organization of computer memory systems arranged by speed and capacity, balancing performance and cost. It consists of two main types: external (secondary) memory and internal (primary) memory, with various components like registers, cache, main memory, and secondary storage. Key concepts include locality of reference, virtual memory, and cache optimization techniques to enhance data access speed and efficiency.

Uploaded by

csef006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views14 pages

Coa Unit4

Memory hierarchy is the organization of computer memory systems arranged by speed and capacity, balancing performance and cost. It consists of two main types: external (secondary) memory and internal (primary) memory, with various components like registers, cache, main memory, and secondary storage. Key concepts include locality of reference, virtual memory, and cache optimization techniques to enhance data access speed and efficiency.

Uploaded by

csef006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Q.1) What is memory hierarchy?

Memory hierarchy refers to the organization of computer memory systems,


where different types of memory are arranged based on speed and
capacity, with faster, more expensive memory at the top and slower, less
expensive memory at the bottom. This structure allows for a balance
between performance and cost. The primary goal of memory hierarchy is to
minimize the average access time to data by using faster memory to store
frequently accessed data.
Types of Memory Hierarchy
This Memory Hierarchy Design is divided into 2 main types:
• External Memory or Secondary Memory: Comprising of
Magnetic Disk, Optical Disk, and Magnetic Tape i.e. peripheral
storage devices which are accessible by the processor via an I/O
Module.
• Internal Memory or Primary Memory: Comprising of Main
Memory, Cache Memory & CPU registers. This is directly
accessible by the processor.

Memory Hierarchy Design


1. Registers
Registers are small, high-speed memory units located in the CPU. They
are used to store the most frequently used data and
instructions. Registers have the fastest access time and the smallest
storage capacity, typically ranging from 16 to 64 bits.
2. Cache Memory
Cache memory is a small, fast memory unit located close to the CPU. It
stores frequently used data and instructions that have been recently
accessed from the main memory. Cache memory is designed to minimize
the time it takes to access data by providing the CPU with quick access to
frequently used data.
3. Main Memory
Main memory, also known as RAM (Random Access Memory), is the
primary memory of a computer system. It has a larger storage capacity
than cache memory, but it is slower. Main memory is used to store data
and instructions that are currently in use by the CPU.
Types of Main Memory
• Static RAM: Static RAM stores the binary information in flip
flops and information remains valid until power is
supplied. Static RAM has a faster access time and is used in
implementing cache memory.
• Dynamic RAM: It stores the binary information as a charge on
the capacitor. It requires refreshing circuitry to maintain the
charge on the capacitors after a few milliseconds. It contains
more memory cells per unit area as compared to SRAM.
read more about – Different Types of RAM (Random Access Memory)
4. Secondary Storage
Secondary storage, such as hard disk drives (HDD) and solid-state drives
(SSD) , is a non-volatile memory unit that has a larger storage capacity
than main memory. It is used to store data and instructions that are not
currently in use by the CPU. Secondary storage has the slowest access
time and is typically the least expensive type of memory in the memory
hierarchy.
5. Magnetic Disk
Magnetic Disks are simply circular plates that are fabricated with either a
metal or a plastic or a magnetized material. The Magnetic disks work at a
high speed inside the computer and these are frequently used.
6. Magnetic Tape
Magnetic Tape is simply a magnetic recording device that is covered with
a plastic film. Magnetic Tape is generally used for the backup of data. In
the case of a magnetic tape, the access time for a computer is a little
slower and therefore, it requires some amount of time for accessing the
strip.
Characteristics of Memory Hierarchy
Characteristics of Memory Hierarchy:
• Speed: Access time decreases as you move down the hierarchy.
• Capacity: Capacity increases as you move down the hierarchy.
• Cost: Cost per unit of memory decreases as you move down the hierarchy

Advantages of Memory Hierarchy


The need for a memory hierarchy includes the following.

• Memory distributing is simple and economical


• Removes external destruction
• Data can be spread all over
• Permits demand paging & pre-paging
• Swapping will be more proficient

Q.2) Differentiate between main memory and


auxiliary memory

Auxiliary Memory (Secondary


Feature Main Memory (Primary Memory)
Memory)
Location Directly accessible by the CPU Not directly accessible by the CPU
Very fast (compared to auxiliary
Speed Slower than main memory
memory)
Non-volatile (data is retained after
Volatility Volatile (data lost when power is off)
power-off)
RAM (Random Access Memory),
Examples Hard drives, SSDs, CDs, USB drives
ROM
Temporarily holds data/programs in
Purpose Stores data and programs permanently
use
Cost More expensive per GB Cheaper per GB
Size Smaller in capacity Much larger capacity
Access
Random access Sequential or random access (slower)
Type
Q.3) What is cache memory? Mention its types

Cache memory is a small, high-speed memory component that acts as a


buffer between the CPU and main memory, storing frequently accessed data
for faster retrieval. It's typically divided into hierarchical levels (L1, L2, L3),
each with different sizes, speeds, and functionalities.

Types of Cache Memory


1. L1 or Level 1 Cache: It is the first level of cache memory that is
present inside the processor. It is present in a small amount
inside every core of the processor separately. The size of this
memory ranges from 2KB to 64 KB.
2. L2 or Level 2 Cache: It is the second level of cache memory that
may present inside or outside the CPU. If not present inside the
core, It can be shared between two cores depending upon the
architecture and is connected to a processor with the high-
speed bus. The size of memory ranges from 256 KB to 512 KB.
3. L3 or Level 3 Cache: It is the third level of cache memory that is
present outside the CPU and is shared by all the cores of the
CPU. Some high processors may have this cache. This cache is
used to increase the performance of the L2 and L1 cache. The
size of this memory ranges from 1 MB to 8MB.

Q.4) Define locality of reference in memory


systems.

Locality of reference refers to the tendency of a computer program to


access the same set of memory locations repeatedly within a short period
of time. This principle is crucial for optimizing memory performance,
particularly in cache memory systems. It's divided into two main types:
temporal and spatial locality.
• Temporal Locality:
This refers to the reuse of the same data or instructions within a short time
interval. If a piece of data is accessed, it's likely to be accessed again soon.
• Spatial Locality:
This refers to the tendency of a program to access data elements that are
physically close to each other in memory. For example, if a program accesses
one element in an array, it's likely to access nearby elements soon after.

Q.5) What is virtual memory?

Virtual memory is a memory management technique that allows a


computer to run programs larger than the available physical RAM by
temporarily storing data on the hard drive or SSD. It acts as an extension of
RAM, enabling the system to work with a larger amount of memory than
physically available.
• How it works:
When a computer's RAM is full, the operating system moves less frequently
used data from RAM to a section of the hard drive or SSD, which is designated
as virtual memory. This frees up RAM for more active processes.
• Advantages:
o Larger programs: Virtual memory allows you to run programs that would
otherwise exceed the capacity of your RAM.
o Multitasking: By managing memory efficiently, virtual memory helps the
system handle multiple tasks simultaneously without crashing.
o Cost-effective: It's a more economical way to manage memory than
constantly upgrading RAM.
• Drawbacks:
o Slower access: Accessing data from the hard drive or SSD is slower
than accessing it from RAM, potentially leading to performance
slowdowns, especially when virtual memory is heavily used.
o Gaming impact: If a game relies heavily on virtual memory due to
insufficient RAM, it can lead to lag and reduced performance.

Q.7) Describe the properties of memory


inclusion, coherence, and locality

In a memory hierarchy, inclusion means that if a data item is present in a


lower level of the hierarchy, it must also be present in all higher
levels. Coherence ensures that all copies of the same data item across
different levels are consistent. Locality of reference is the principle that
programs tend to access the same set of memory locations repeatedly, or
locations near each other, which is crucial for optimizing memory access in
a hierarchy.
• Inclusion:
This property dictates that a data item must be mirrored across multiple levels of
the memory hierarchy. If a piece of data exists in a slower, lower-level memory
(like main memory or a disk), it must also be present in all faster, higher-level
memories (like caches). This ensures that a data item can be accessed from the
fastest available memory, whether it's the CPU's cache or the slower main
memory.
• Coherence:
Coherence addresses the issue of maintaining consistency when multiple copies
of the same data item exist in different levels of the memory hierarchy. For
example, if a data item is modified in a lower-level memory, it must also be
updated in all other levels that contain a copy of that data. This ensures that all
processors or components accessing that data see a consistent view of the
information.
• Locality of Reference:
This principle describes the behavior of computer programs to access a limited
set of memory locations repeatedly or in close proximity within a specific
timeframe. Programs tend to access the same data or nearby data locations
rather than randomly accessing memory. This tendency is crucial for memory
hierarchy design because it allows for efficient use of caches. By storing
frequently accessed data in the faster cache levels, the program can
significantly reduce the average time it takes to access data from the slower,
larger memory levels.

Q.8) Discuss the organization and working of


cache memory.

Cache memory is a small, fast memory that sits between the CPU and
main memory (RAM), acting as a buffer to improve data access speed. It
stores frequently accessed data and instructions, allowing the CPU to
retrieve them quickly, reducing the time spent waiting for main
memory. Cache memory is organized into levels (L1, L2, L3) and uses
different mapping techniques to manage data storage and retrieval.

Organization:
• Hierarchical Structure:
Cache memory is often organized in a hierarchical manner, with multiple levels
(L1, L2, L3, etc.).
o L1 Cache: The smallest and fastest cache, often located directly on the
CPU chip.
o L2 Cache: Larger and slower than L1, typically shared by multiple CPU
cores.
o L3 Cache: The largest and slowest, may be shared by all CPU cores or
even multiple processors.
• Cache Lines:
Cache memory is organized into blocks called cache lines, which are groups of
bytes that are transferred between the cache and main memory.
• Cache Mapping:
Determines how data is mapped from main memory into the cache lines.
o Direct Mapping: Each memory block can only be stored in one specific
cache line.
o Associative Mapping: Any memory block can be stored in any cache
line.
o Set-Associative Mapping: Combines features of direct and associative
mapping, dividing the cache into sets, and allowing blocks to map to any
line within a set.
Working:
1. 1. CPU Request:
When the CPU needs data or instructions, it first checks the cache memory.
2. 2. Cache Hit:
If the requested data is found in the cache (a "cache hit"), it's retrieved quickly.
3. 3. Cache Miss:
If the data is not in the cache (a "cache miss"), the CPU must fetch it from main
memory, which is slower.
4. 4. Data Transfer:
When a cache miss occurs, the required data is fetched from main memory and
copied into the cache line, along with surrounding data, to improve the chances
of future hits.
5. 5. Replace Data:
If the cache is full, a replacement algorithm is used to determine which data to
replace.
o Write-Through: Changes in the cache are immediately written to main
memory.
o Write-Back: Changes are made in the cache and written to main memory
later, possibly when the cache line is replaced.
6. 6. Locality of Reference:
The cache's effectiveness relies on the principle of locality of reference, where
programs tend to access the same data or nearby data repeatedly. This allows
the cache to store the most frequently used data and instructions, maximizing its
performance.

Q.9) Explain various cache memory mapping


techniques

Cache Mapping Techniques


There are three types of cache mappings namely:
• Direct Mapping
• Fully Associative Mapping
• Set Associative Mapping

Direct Mapping
In direct mapping physical address is divided into three parts i.e., Tag bits,
Cache Line Number and Byte offset. The bits in the cache line number
represents the cache line in which the content is present whereas the bits
in tag are the identification bits that represents which block of main
memory is present in cache. The bits in the byte offset decides in which
byte of the identified block the required content is present.
Tag Number of Cache Lines Byte Offset

Fully Associative Mapping


In fully associative mapping address is divided into two parts i.e., Tag bits
and Byte offset. The tag bits identify that which memory block is present
and bits in the byte offset field decides in which byte of the block the
required content is present.
Tag Byte Offset
Set Associative Mapping
In set associative mapping the cache blocks are divided in sets. It divides
address into three parts i.e., Tag bits, set number and byte offset. The bits
in set number decides that in which set of the cache the required block is
present and tag bits identify which block of the main memory is present.
The bits in the byte offset field gives us the byte of the block in which the
content is present.
Tag Set Number Byte Offset

Q.10) Discuss optimization techniques used in


cache memory systems
Cache memory optimization techniques aim to improve performance by
minimizing memory access latency. Key strategies include reducing the
time it takes to access data in the cache (hit time), lowering the frequency
of misses, and decreasing the penalty associated with a miss. These
techniques are crucial for overall system performance, especially in
processor-intensive tasks.

Techniques for Reducing Hit Time:


• Small and Simple Caches:
Smaller caches with simpler organization (e.g., direct mapping) generally have
lower hit times because the logic for finding data is less complex.
• Avoiding Address Translation:
Ideally, cache indexing should not require translating memory addresses, as this
adds latency.
• Pipelined Cache Access:
Breaking down cache access into stages (pipelining) allows for parallel
operations and reduces the overall time to retrieve data.
Techniques for Reducing Miss Rate:
• Larger Block Sizes:
Storing larger blocks of data together in the cache increases the likelihood that a
subsequent access will find the data in the cache.
• Larger Cache Sizes:
A larger cache can hold more data, reducing the chances of a miss when the
processor requests information.
• Higher Associativity:
Using set-associative mapping, where a block of data can be stored in multiple
cache lines within a set, allows for more flexibility in placing data and reduces
conflicts, ultimately decreasing the miss rate.
• Compiler Optimizations:
Compilers can be optimized to rearrange code and data access patterns in a
way that improves cache utilization and reduces misses.
Techniques for Reducing Miss Penalty:
• Multi-level Caches:
Using multiple levels of caches, with the fastest and smallest cache at the
highest level, minimizes the penalty associated with a miss by allowing the
processor to potentially access the next-level cache.
• Critical Word First:
When a cache miss occurs, retrieving the requested word (critical word) first and
providing it to the processor while the rest of the block is fetched can
significantly reduce the perceived miss penalty.
• Victim Caches:
A small, fast cache that holds recently evicted cache lines can help reduce
misses by providing a quick lookup for recently accessed data.
Other Important Considerations:
• Non-Blocking Caches:
Caches that can continue to supply hits even during a miss allow the processor
to continue executing without stalling, further minimizing the effective miss
penalty.
• Way Prediction:
Techniques that predict which cache way a data block is likely to be stored in
can help reduce the time to access the data, particularly in set-associative
caches.
• Hardware Prefetching:
Prefetching data into the cache before the processor needs it can significantly
reduce the miss rate and improve performance.
• Loop Transformations:
Transforming loop structures to access data sequentially can improve cache
utilization and reduce misses.

Q.11) Explain demand paging and page


replacement algorithms like FIFO, LRU, and
Optimal.
Demand paging and page replacement algorithms are crucial components
of virtual memory systems in computer architecture. Demand paging loads
pages of a process into main memory only when they are needed, reducing
memory usage and I/O. Page replacement algorithms determine which
page to replace when a new page needs to be loaded but there is no free
space in memory.

Demand Paging:
Demand paging is a memory management technique where a process's
code and data are not loaded into main memory (RAM) when the process
begins execution. Instead, pages are loaded on demand, meaning they are
fetched from secondary storage (e.g., hard disk) only when they are
actually needed by the process. This technique significantly reduces the
memory requirements of a process, as only a portion of the process's code
and data need to be in RAM at any given time.

Page Replacement Algorithms:


When a process tries to access a page that is not currently in main
memory, a page fault occurs. The operating system handles this by loading
the required page from secondary storage and, if necessary, replacing a
page in main memory. Page replacement algorithms determine which page
to replace when a new page needs to be loaded into a full main memory.

Common Page Replacement Algorithms:


1. 1. FIFO (First-In, First-Out):
This algorithm replaces the oldest page in memory, similar to a queue. It's
simple to implement but can lead to poor performance if frequently used pages
are replaced.
2. 2. LRU (Least Recently Used):
LRU replaces the page that has not been accessed for the longest time,
assuming that recently used pages are more likely to be used again in the
future. It generally performs better than FIFO but requires more complex
bookkeeping.
3. 3. Optimal:
This algorithm replaces the page that will not be used for the longest period in
the future. It's the theoretically best algorithm but requires knowledge of the
future, which is not feasible in real-world systems.
Benefits of Demand Paging:
• Reduced Memory Usage: Processes can be larger than the physical
memory available.
• Improved I/O Performance: Only needed pages are loaded, reducing the
amount of I/O required.
• Easier Program Development: Developers can write programs that are
larger than available memory without worrying about memory limitations.
Challenges of Demand Paging:
• Thrashing:
If page faults occur too frequently, the system can spend an excessive amount
of time swapping pages between memory and disk, leading to a significant
decrease in performance.
• Complexity:
Implementing page replacement algorithms, especially LRU, can be complex
and require careful design.

Q.12) What is virtual memory and how does it


work in modern systems?
Virtual memory is a memory management technique that allows a
computer to run programs larger than the physical RAM by using disk
space as an extension of RAM. This is achieved by dividing the logical
address space into pages and mapping them to physical frames, which are
then swapped between RAM and disk as needed.

How Virtual Memory Works:


1. 1. Logical Address Space:
Each process has its own logical address space, which is a set of virtual
addresses that it can use. This address space is typically much larger than
the physical RAM.
2. 2. Paging:
The logical address space is divided into fixed-size blocks called pages, and
the physical RAM is divided into similar-sized blocks called frames.
3. 3. Page Table:
A page table is used to map virtual page numbers to physical frame
numbers. This table is maintained by the operating system.
4. 4. Memory Management Unit (MMU):
The MMU is a hardware component that translates virtual addresses into
physical addresses using the page table. This translation happens
automatically when a process tries to access memory.
5. 5. Swapping:
If a page is not currently in RAM, it can be swapped out to disk and replaced
by another page. When the needed page is accessed again, it is swapped
back into RAM from disk, according to Naukri.com.
Benefits of Virtual Memory:
• Increased Memory Capacity: Allows programs larger than physical RAM to be
executed.

• Efficient Memory Usage: The OS can manage memory efficiently by swapping


pages as needed.

• Process Isolation: Each process has its own virtual address space, protecting
processes from each other.
Drawbacks of Virtual Memory:
• Performance Overhead: Accessing data on disk is much slower than accessing it in
RAM, so virtual memory can lead to performance degradation, especially when
swapping is frequent.

• Complexity: Implementing virtual memory requires complex hardware and software.

• Swapping Issues: If too many pages are swapped, the system can become slow
and unresponsive.

You might also like