Module 4 Memory Organisation
Module 4 Memory Organisation
Memory Interleaving
It is a Technique that divides memory into a number of modules such that Successive
words in the address space are placed in the Different modules. These modules is known
as banks.
Consecutive Word in a Module:
Now again we assume 16 Data’s to be transferred to the Four Module. But Now the
consecutive Data are added in Consecutive Module. That is, 10 [Data] is added in
Module 1, 20 [Data] in Module 2 and So on.
Least Significant Bit (LSB) provides the Address of the Module & Most significant bit
(MSB) provides the address of the data in the module.
For Example, to get 90 (Data) 1000 will be provided by the processor. This 00 will
indicate that the data is in module 00 (module 1) & 10 is the address of 90 in Module 00
(module 1). That is,
We can access all four Modules at the same time thus achieving Parallelism. From
Figure 2 the data can be acquired from the Module using the Higher bits. This method
Uses memory effectively.
Memory Hierarchy
Memory Hierarchy is an enhancement to organize the memory such that it can minimize
the access time. It was developed based on a program behavior known as locality of
references.
The figure below clearly demonstrates the different levels of memory hierarchy:
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(16 to 64 bits).
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.
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.
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.
Optical Disks & Magnetic Tape: The foundational layer used for massive, long-term
data backups.
We can infer the following characteristics of Memory Hierarchy Design from above
figure:
1. Capacity: It is the global volume of information the memory can store. As we move
from top to bottom in the Hierarchy, the capacity increases.
2. Access Time: It is the time interval between the read/write request and the availability
of the data. As we move from top to bottom in the Hierarchy, the access time
increases.
3. Performance: Earlier when the computer system was designed without Memory
Hierarchy design, the speed gap increases between the CPU registers and Main
Memory due to large difference in access time. This results in lower performance of
the system and thus, enhancement was required. This enhancement was made in the
form of Memory Hierarchy Design because of which the performance of the system
increases. One of the most significant ways to increase system performance is
minimizing how far down the memory hierarchy one has to go to manipulate data.
4. Cost per bit: As we move from bottom to top in the Hierarchy, the cost per bit
increases i.e. Internal Memory is costlier than External Memory.
Magnetic Disks
In a computer, the magnetic disks are circular plates that’s fabricated with plastic or metal with a magnetised
material. Two faces of a disk are frequently used, and many disks can be stacked on a single spindle by
read/write heads that are obtainable on every plane. The disks in a computer jointly turn at high speed.
Magnetic Tape
Magnetic tape refers to a normal magnetic recording designed with a slender magnetizable overlay that covers
an extended, thin strip of plastic film. It is used mainly to back up huge chunks of data. When a computer needs
to access a strip, it will first mount it to access the information. Once the information is allowed, it will then be
unmounted. The actual access time of a computer memory would be slower within a magnetic strip, and it will
take a few minutes for us to access a strip.
MAIN Memory
The main memory in a computer is called Random Access Memory. It is also
known as RAM. This is the part of the computer that stores operating system
software, software applications and other information for the central
processing unit (CPU) to have fast and direct access when needed to
perform tasks. It is called "random access" because the CPU can go directly
to any section of main memory, and does not have go about the process in a
sequential order.
RAM is one of the faster types of memory, and has the capacity to allow data
to be read and written. When the computer is shut down, all of the content
held in RAM is purged. Main memory is available in two types: Dynamic
Random Access Memory (DRAM) and Static Random Access Memory
(SRAM).00:30
Process
The central processing unit is one of the most important components in the
computer. It is where various tasks are performed and an output is
generated. When the microprocessor completes the execution of a set of
instructions, and is ready to carry out the next task, it retrieves the
information it needs from RAM. Typically, the directions include the address
where the information, which needs to be read, is located. The CPU
transmits the address to the RAM's controller, which goes through the
process of locating the address and reading the data.
DRAM
Dynamic random access memory (DRAM) is the most common kind of main
memory in a computer. It is a prevalent memory source in PCs, as well as
workstations. Dynamic random access memory is constantly restoring
whatever information is being held in memory. It refreshes the data by
sending millions of pulses per second to the memory storage cell.
SRAM
Static Random Access Memory (SRAM) is the second type of main memory
in a computer. It is commonly used as a source of memory in embedded
devices. Data held in SRAM does not have to be continually refreshed;
information in this main memory remains as a "static image" until it is
overwritten or is deleted when the power is switched off. Since SRAM is less
dense and more power-efficient when it is not in use; therefore, it is a better
choice than DRAM for certain uses like memory caches located in CPUs.
Conversely, DRAM's density makes it a better choice for main memory.
Adequate RAM
The CPU is often considered the most important element in the performance
of a personal computer. RAM probably comes in a close second. Having an
adequate amount of RAM has a direct effect on the speed of the computer. A
system that lacks enough main memory to run its applications must rely on
the operating system to create additional memory resources from the hard
drive by "swapping" data in and out. When the CPU must retrieve data from
the disk instead of RAM, it slows down the performance of the computer.
Many games, video-editing or graphics programs require a significant
amount of memory to function at an optimal level.
System Requirements
Having adequate main memory in a computer starts with meeting the
recommended amount of memory for the operating system. Windows Vista
Basic requires a minimum of 512MB of RAM; many computer experts
suggest at least 1GB. The minimum requirement for Windows Home
Premium, Business and Ultimate is 1GB. MAC OS 10.5 has a minimum
requirement of 1GB of main memory.
While a central processing unit (or CPU) performs the brainy functions of a
computer, carrying out calculations and delegating tasks, memory helps out
with those delegations by holding bits of data temporarily to keep the
programs you have open up and running. Primary storage devices come in a
few different forms, so strap in and put your memory cap on.
Primary Storage Devices
When it comes to examples of primary memory, random access memory (or
RAM) is probably the most commonplace. RAM is computer hardware,
usually in the form of memory modules like DRAM, from which data can be
temporarily stored and retrieved. While a disc or hard drive accesses data in
a specific sequence, RAM – as the name implies – is able to access it at
random, making it a fast and efficient form of primary memory.
computer's operating system to the primary memory, which allows the CPU
to work faster and boot up your PC more quickly. This little microcosm is a
pretty good example of how RAM and primary memory works in a nutshell:
once the computer is up and running, the CPU continues to hand off various
tasks to the memory temporarily until you shut it off. Ideally, you're not
aware of the process but it's largely what keeps your computer running
That means that when your computer is running slow or visibly struggling,
there's a good chance it doesn't have enough memory to tackle all the tasks
you're throwing at it. So close a few programs and trying shutting down at
least most of those 32 browser tabs you have open.
Secondary Storage
Remember that hard drive with the cat GIFs? Yeah, that's a type of
secondary storage. Secondary storage hard drives, which store data for the
long-term (while primary storage stores it for the short-term) include
internal and external types. Smaller hard drives even include USB thumb
drives or your smart phone when you hook it up to your computer for the
express purpose of viewing or transferring files.
Your computer has different kinds of memory, some of which saves its data
when you turn the power off, some which does not. Computer scientists call
the former kind of memory non-volatile and the latter volatile. The reasons
have to do with the electrical properties of the memory. Generally, volatile
memory tends to be fast and expensive, and non-volatile memory tends to
be slow and inexpensive.
Memory Types
When you turn your computer on, the first thing it does is read instructions
from ROM, or read-only memory. This memory, programmed at the factory,
keeps its data without power, but cannot accept new data. The computer
reads and writes into random-access memory, or RAM, at high speeds. Most
RAM is volatile memory. Your computer stores large amounts of data to its
hard drive, which is relatively slow, but keeps its data when you turn the
power off.
Main RAM
Chances are, the computer sitting on your lap has more than one billion
characters of volatile RAM memory. Your browser, word processor and other
programs work in RAM and use it as a "scratch pad," adding, removing and
rewriting data rapidly. This memory consists of millions of tiny transistors
packed into integrated circuit chips. It works at moderately high speed,
reading and writing in 60 to 80 billionths of a second and retailing for about
$15 for a billion characters at 2011 prices.
Cache RAM
In addition to your computer's main RAM memory, its microprocessor has its
own, smaller, memory units, called cache. The microprocessor has up to
three stages of cache, called L1, L2 and L3, which work at speeds up to 1
billionth of a second, or 60 to 80 times faster than normal RAM. Because it is
more expensive than standard RAM, the microprocessor has one million
characters or less of this kind of memory. Like regular RAM, it loses its data
when the power goes off.
Older Technologies
In the 1950s and '60s, before transistors made computers inexpensive and
compact, engineers used other volatile technologies to store data bits. One,
called delay-line memory, stored data as a set of sound pulses in mercury or
quartz. The circuits recirculated the pulses in a continuous loop like cars in a
toy train set. This scheme stored several thousand memory bits at rates
about 1,000 times slower than today's RAM.
The Motherboard
A CPU can't achieve its intended purpose without the assistance of the
motherboard. The motherboard is a printed circuit board, or PCB, found
inside a computer which not only hosts the CPU but also acts as a connected
gateway to various other computer peripherals, including sound cards, hard
drives, video cards and so on. The motherboard hosts a number of sockets
into which microprocessors, such as the CPU, can be plugged. The
motherboard is also connected to the computer's power supply and
distributes electrical voltage to the attached components. Simply put, a
motherboard provides a critical platform on which the rest of a CPU's
hardware can operate. Without the motherboard in place, a computer
couldn't function.
It's somewhat easy to confuse the function of the hard drive with that of
random access memory, or RAM. Unlike a hard drive, RAM is composed of a
series of chips which allow for temporary data storage only. Whereas a hard
drive will continue to store data even after a computer has been powered
off, RAM will be cleared. RAM is often used to act as a holding zone for open
files or critical data that a program may need to access intermittently during
use. RAM should not be thought of as storage, per say, but instead as a
"place holder" for valuable information. Nevertheless, it remains one of the 4
main parts of a computer that is still in use today.
Board
This is the circuit board on which all the hardware components of RAM are
soldered. It features a silicon-based semiconductor integrated circuitry
providing connections between the memory components as well as
interfacing with the computer to allow the processor and memory controller
to access the RAM.
Clock
Unlike conventional (asynchronous) DRAM, SDRAM's memory operations are
synchronized to a clock's signals, simplifying the control interface and
eliminating the need for generating pseudo analog signals required in
conventional DRAM. It also decreases manufacturing costs for the memory's
components because faster memory could be made at the same cost.
Mode Register
This on-chip register's function is the configuration of the basic device
operation. It controls the CAS (column address strobe) latency, burst length
and burst type, and is usually set up while the computer is first powering up.
Memory Banks
This is the section with the actual memory modules--cells--that store data. In
SDRAM, there are always two or more banks, allowing one bank to be
available for access while the other is being pre-charged. This eliminates the
latency caused by precharging a single bank, which results in increased
transfer rates. It also reduces the granularity of each bank, resulting in
higher performances at lower costs for 16MB and higher memory densities.
SPD Chip
SPD stands for serial presence detect. SDRAM features an on-board SPD chip
that contains information about the memory type, size, speed and access
time. This chip lets the computer access this information at start-up while it
goes through its power-on test cycle.
Burst Counter
The burst counter is an on-chip counter that keeps track of column
addresses to enable high speed burst access. It uses two burst types--
sequential and interleaved-- and different burst lengths, and these
parameters can be programmed using the mode register.
The CPU uses a program counter to keep track of which instruction to fetch
next. The counter is the address of the memory location that holds the next
instruction to be executed. It's stored in a register, which is a dedicated
memory location in the CPU itself. The program counter is incremented to
point to the next instruction after each fetch in the instruction cycle.
A component of the CPU known as the control unit is responsible for moving
instructions and data from secondary storage into main memory prior to
instruction execution. The control unit also moves the results of an
instruction to secondary storage.
History
Dr. Robert Dennard invented DRAM in 1967 while working for IBM and
received a patent for this groundbreaking technology in 1968. Known as the
DRAM memory cell, Dennard's invention makes use of a single transistor
that reads from and writes to a capacitor that stores data. Many innovations
sprang from Dennard's single transistor memory cell technology, among
them SDRAM which synchronized to the computer's clock thereby increasing
efficiency when reading from or writing to the random access memory.
Significance
Previous forms of memory storage were as large as a room and required
constant cooling. However, as memory storage technology advanced, these
devices became smaller and cheaper. The invention of DRAM by Dr.
Dennard enabled a large leap forward in making computer technology
smaller, cheaper and therefore more accessible to the average consumer.
Types of Memory
There are several forms of memory storage such as DVDs, CDs, hard disks
and read only memory (ROM), but random access memory (RAM) is a faster
form of storage than most. That is why RAM is utilized as a kind of short
term memory on your computer as oppose to a hard disk which would be
comparable to long term memory. This short term memory is used to run
the operating system and any applications you may use, but once you shut
the computer down the RAM is wiped clean.
Function of DRAM
Dynamic random access memory utilizes one transistor to store data on one
capacitor, but that capacitor will lose the data as it loses its charge unless
the capacitor is periodically recharged. The recharging of the capacitors is
the reason the word dynamic is used in dynamic random access memory.
Once the capacitors no longer receive a charge, the data is lost. DRAM
operates asynchronously with the computer's clock sending instructions as
soon as it receives them from the user's interface instead of waiting to
synchronize with the computer system's clock like SDRAM.
Features of SDRAM
SDRAM is synchronized with the computer's clock to allow it to send
instructions more efficiently by joining a pipeline of other instructions the
computer is processing. The pipelining of information in a computer allows it
to receive another command before it has finished processing the previous
command. This allows SDRAM to operate at much higher speeds, making it
the most popular form of RAM offered on computers.
Difference Between Virtual Memory & Main
Memory
Main memory, also called RAM, is the physical memory unit in the computer.
Virtual memory also serves as computer memory, but is actually hard drive
space acting as temporary storage for computer processes.
Function
Computers use as much main memory as possible when storing data to be
accessed by the processor. When the computer runs out of physical RAM, it
uses virtual memory space set aside on the hard drive.
Benefits
Main memory speeds up a computer, while virtual memory tends to transfer
data at speeds much slower than physical RAM. Thus, you should only use
virtual memory when absolutely necessary.
Types
RAM comes in several different types. Old computers may use SDRAM, while
newer computers (as of 2010) use some form of DDR RAM--either DDR1,
DDR2 or DDR3. There are no different "types" of virtual memory, since it's
all drive space. But you can use just about any storage device for virtual
memory, including a thumb drive.
Multitasking
One important use of virtual memory is multitasking. When a computer user opens multiple
programs at once, the data for these programs must be stored in memory for quick access.
The more programs are open, the more memory is needed. When the computer's physical
memory is full, the excess data is stored in virtual memory.
Large Programs
In addition to multitasking, virtual memory allows programmers to create larger and more
complex applications. When these programs are running, they occupy physical memory as
well as virtual memory.
Flexibility
If computers only relied on memory chips, far less memory would be available and the
usefulness of many software programs would be severely limited. Even though virtual
memory is slower, it is still useful because it greatly expands a computer's functionality.
Changing Times
When virtual memory was first created, solid-state memory chips were much smaller and
more expensive. Today's memory chips can store many gigabytes of data at very low cost.
As memory chips continue to grow in capacity and prices fall, virtual memory is may be less
useful in the future.
Memory Types
In general, memory is of three types:
Primary memory
Secondary memory
Cache memory
Sample Problems
It stands for Random access memory. It stands for read only memory.
In this memory, data will erase when the In this memory, data will not erase even if the
power is off power is off
Associative Memory
Associative memory is also known as content addressable memory (CAM) or associative
storage or associative array. It is a special type of memory that is optimized for performing
searches through data, as opposed to providing a simple direct access to the data based on
the address.
it can store the set of patterns as memories when the associative memory is being presented
with a key pattern, it responds by producing one of the stored pattern which closely
resembles or relates to the key pattern.
it can be viewed as data correlation here. input data is correlated with that of stored data
in the CAM.
it forms of two type:
1. auto associative memory network
2. hetero associative memory network
Associative memory of conventional semiconductor memory (usually RAM) with added
comparison circuity that enables a search operation to complete in a single clock cycle. It is
a hardware search engine, a special type of computer memory used in certain very high
searching applications. Applications of Associative memory :-
1. It can be only used in memory allocation format.
2. It is widely used in the database management systems, etc.
Advantages of Associative memory :-
1. It is used where search time needs to be less or short.
2. It is suitable for parallel searches.
3. It is often used to speedup databases.
4. It is used in page tables used by the virtual memory and used in neural networks.
Disadvantages of Associative memory :-
1. It is more expensive than RAM.
2. Each cell must have storage capability and logical circuits for matching its content with
external argument.
CACHE MEMORY
Cache memory is a chip-based computer component that makes retrieving data from
the computer's memory more efficient. It acts as a temporary storage area that the
computer's processor can retrieve data from easily. This temporary storage area,
known as a cache, is more readily available to the processor than the computer's main
memory source, typically some form of DRAM.
Cache memory is sometimes called CPU (central processing unit) memory because it
is typically integrated directly into the CPU chip or placed on a separate chip that has a
separate bus interconnect with the CPU. Therefore, it is more accessible to the
processor, and able to increase efficiency, because it's physically close to the
processor.
In order to be close to the processor, cache memory needs to be much smaller than
main memory. Consequently, it has less storage space. It is also more expensive than
main memory, as it is a more complex chip that yields higher performance.
What it sacrifices in size and price, it makes up for in speed. Cache memory operates
between 10 to 100 times faster than RAM, requiring only a few nanoseconds to
respond to a CPU request.
The name of the actual hardware that is used for cache memory is high-speed static
random access memory (SRAM). The name of the hardware that is used in a
computer's main memory is dynamic random access memory (DRAM).
Cache memory is not to be confused with the broader term cache. Caches are
temporary stores of data that can exist in both hardware and software. Cache memory
refers to the specific hardware component that allows computers to create caches at
various levels of the network.
L1 cache, or primary cache, is extremely fast but relatively small, and is usually embedded in
the processor chip as CPU cache.
L2 cache, or secondary cache, is often more capacious than L1. L2 cache may be embedded on
the CPU, or it can be on a separate chip or coprocessor and have a high-speed alternative system
bus connecting the cache and CPU. That way it doesn't get slowed by traffic on the main system
bus.
Level 3 (L3) cache is specialized memory developed to improve the performance of L1 and L2.
L1 or L2 can be significantly faster than L3, though L3 is usually double the speed of DRAM.
With multicore processors, each core can have dedicated L1 and L2 cache, but they can share an
L3 cache. If an L3 cache references an instruction, it is usually elevated to a higher level of
cache.
In the past, L1, L2 and L3 caches have been created using combined processor and motherboard
components. Recently, the trend has been toward consolidating all three levels of memory
caching on the CPU itself. That's why the primary means for increasing cache size has begun to
shift from the acquisition of a specific motherboard with different chipsets and bus architectures
to buying a CPU with the right amount of integrated L1, L2 and L3 cache.
Contrary to popular belief, implementing flash or more dynamic RAM (DRAM) on a system
won't increase cache memory. This can be confusing since the terms memory caching (hard disk
buffering) and cache memory are often used interchangeably. Memory caching, using DRAM or
flash to buffer disk reads, is meant to improve storage I/O by caching data that is frequently
referenced in a buffer ahead of slower magnetic disk or tape. Cache memory, on the other hand,
provides read buffering for the CPU.
A
diagram of the architecture and data flow of a typical cache memory unit.
Direct mapped cache has each block mapped to exactly one cache memory location.
Conceptually, a direct mapped cache is like rows in a table with three columns: the cache
block that contains the actual data fetched and stored, a tag with all or part of the address
of the data that was fetched, and a flag bit that shows the presence in the row entry of a
valid bit of data.
Fully associative cache mapping is similar to direct mapping in structure but allows a
memory block to be mapped to any cache location rather than to a prespecified cache
memory location as is the case with direct mapping.
Set associative cache mapping can be viewed as a compromise between direct mapping
and fully associative mapping in which each block is mapped to a subset of cache locations.
It is sometimes called N-way set associative mapping, which provides for a location in main
memory to be cached to any of "N" locations in the L1 cache.
Data writing policies
Data can be written to memory using a variety of techniques, but the two main ones involving
cache memory are:
Write-through. Data is written to both the cache and main memory at the same time.
Write-back. Data is only written to the cache initially. Data may then be written to main
memory, but this does not need to happen and does not inhibit the interaction from taking
place.
The way data is written to the cache impacts data consistency and efficiency. For example, when
using write-through, more writing needs to happen, which causes latency upfront. When using
write-back, operations may be more efficient, but data may not be consistent between the main
and cache memories.
One way a computer determines data consistency is by examining the dirty bit in memory. The
dirty bit is an extra bit included in memory blocks that indicates whether the information has
been modified. If data reaches the processor's register file with an active dirty bit, it means that it
is not up to date and there are more recent versions elsewhere. This scenario is more likely to
happen in a write-back scenario, because the data is written to the two storage areas
asynchronously.
Translation lookaside buffers (TLBs) are also specialized memory caches whose function is to
record virtual address to physical address translations.
Still other caches are not, technically speaking, memory caches at all. Disk caches, for instance,
can use DRAM or flash memory to provide data caching similar to what memory caches do with
CPU instructions. If data is frequently accessed from the disk, it is cached into DRAM or flash-
based silicon storage technology for faster access time and response.
Specialized caches are also available for applications such as web browsers, databases, network
address binding and client-side Network File System protocol support. These types of caches
might be distributed across multiple networked hosts to provide greater scalability or
performance to an application that uses them.
A
depiction of the Pipeline Hazardsy and how it functions
Locality
The ability of cache memory to improve a computer's performance relies on the concept of
locality of reference. Locality describes various situations that make a system more predictable.
Cache memory takes advantage of these situations to create a pattern of memory access that it
can rely upon.
There are several types of locality. Two key ones for cache are:
Temporal locality. This is when the same resources are accessed repeatedly in a short
amount of time.
Spatial locality. This refers to accessing various data or resources that are near each other.
Performance
Cache memory is important because it improves the efficiency of data retrieval. It stores
program instructions and data that are used repeatedly in the operation of programs or
information that the CPU is likely to need next. The computer processor can access this
information more quickly from the cache than from the main memory. Fast access to these
instructions increases the overall speed of the program.
Aside from its main function of improving performance, cache memory is a valuable resource
for evaluating a computer's overall performance. Users can do this by looking at cache's hit-to-
miss ratio. Cache hits are instances in which the system successfully retrieves data from the
cache. A cache miss is when the system looks for the data in the cache, can't find it, and looks
somewhere else instead. In some cases, users can improve the hit-miss ratio by adjusting the
cache memory block size -- the size of data units stored.
Improved performance and ability to monitor performance are not just about improving general
convenience for the user. As technology advances and is increasingly relied upon in mission-
critical scenarios, having speed and reliability becomes crucial. Even a few milliseconds of
latency could potentially lead to enormous expenses, depending on the situation.
A chart
Cache vs. main memory
DRAM serves as a computer's main memory, performing calculations on data retrieved from
storage. Both DRAM and cache memory are volatile memories that lose their contents when the
power is turned off. DRAM is installed on the motherboard, and the CPU accesses it through a
bus connection.
DRAM is usually about half as fast as L1, L2 or L3 cache memory, and much less expensive. It
provides faster data access than flash storage, hard disk drives (HDD) and tape storage. It came
into use in the last few decades to provide a place to store frequently accessed disk data to
improve I/O performance.
DRAM must be refreshed every few milliseconds. Cache memory, which also is a type of
random access memory, does not need to be refreshed. It is built directly into the CPU to give
the processor the fastest possible access to memory locations and provides nanosecond speed
access time to frequently referenced instructions and data. SRAM is faster than DRAM, but
because it's a more complex chip, it's also more expensive to make.
To do this, the OS temporarily transfers inactive data from DRAM to disk storage. This
approach increases virtual address space by using active memory in DRAM and inactive
memory in HDDs to form contiguous addresses that hold both an application and its data.
Virtual memory lets a computer run larger programs or multiple programs simultaneously, and
each program operates as though it has unlimited memory.
In order to copy virtual memory into physical memory, the OS divides memory into page files
or swap files that contain a certain number of addresses. Those pages are stored on a disk and
when they're needed, the OS copies them from the disk to main memory and translates the
virtual memory address into a physical one. These translations are handled by a memory
management unit (MMU).
CACHE SIZE VS BLOCK SIZE
Cache size, Block size, Mapping function, Replacement algorithm, and Write
policy. These are explained as following below.
1. Cache Size:
It seems that moderately tiny caches will have a big impact on performance.
2. Block Size:
Block size is the unit of information changed between cache and main
memory.
As the block size will increase from terribly tiny to larger sizes, the hit
magnitude relation can initially increase as a result of the principle of
[Link] high chance that knowledge within the neck of the woods of a
documented word square measure possible to be documented within the
close to future. As the block size increases, a lot of helpful knowledge square
measure brought into the cache.
The hit magnitude relation can begin to decrease, however, because the
block becomes even larger and also the chance of victimization the new
fetched knowledge becomes but the chance of reusing the information that
ought to be abstracted of the cache to form area for the new block.
3. Mapping Function:
When a replacement block of data is scan into the cache, the mapping
performs determines that cache location the block will occupy. Two
constraints have an effect on the planning of the mapping perform. First,
once one block is scan in, another could be replaced.
We would wish to do that in such the simplest way to minimize the chance
that we are going to replace a block which will be required within the close
to future. A lot of versatile the mapping perform, a lot of scopes we’ve to
style a replacement algorithmic rule to maximize the hit magnitude relation.
Second, a lot of versatile the mapping perform, a lot of advanced is that the
electronic equipment needed to look the cache to see if a given block is
within the cache.
4. Replacement Algorithm:
The replacement algorithmic rule chooses, at intervals, the constraints of the
mapping perform, which block to interchange once a replacement block is to
be loaded into the cache and also the cache already has all slots full of
alternative blocks. We would wish to replace the block that’s least possible
to be required once more within the close to future. Although it’s impossible
to spot such a block, a fairly effective strategy is to interchange the block
that has been within the cache longest with no relevance.
This policy is spoken because of the least-recently-used (LRU) algorithmic
rule. Hardware mechanisms square measure required to spot the least-
recently-used block
5. Write Policy:
If the contents of a block within the cache square measure altered, then it’s
necessary to write down it back to main memory before exchange it. The
written policy dictates once the memory write operation takes place. At one
extreme, the writing will occur whenever the block is updated.
At the opposite extreme, the writing happens only if the block is replaced.
The latter policy minimizes memory write operations however leaves the
main memory in associate obsolete state. This can interfere with the
multiple-processor operation and with direct operation by I/O hardware
modules.
Memory Mapping and Concept of
Virtual Memory
Associative Mapping
Direct Mapping
Set Associative Mapping
Associative Mapping
The associative memory stores both address and data. The address
value of 15 bits is 5 digit octal numbers and data is of 12 bits word in
4 digit octal number. A CPU address of 15 bits is placed
in argument register and the associative memory is searched for
matching address.
Argument Register
Address Data
Match
Register
Output
Direct Mapping
The CPU address of 15 bits is divided into 2 fields. In this the 9 least
significant bits constitute the index field and the remaining 6 bits
constitute the tag field. The number of bits in index field is equal to
the number of address bits required to access cache memory.
TAG INDEX
In this we can store two or more words of memory under the same
index address. Each data word is stored together with its tag and
this forms a set.
Replacement Algorithms
FIFO - First in First out. Oldest item is replaced with the latest
item.
LRU - Least Recently Used. Item which is least recently used by
CPU is removed.
Virtual Memory
Whenever your computer doesn’t have space in the physical memory it writes
what it needs to remember to the hard disk in a swap file as virtual memory.
If a computer running Windows needs more memory/RAM, then installed in the
system, it uses a small portion of the hard drive for this purpose.
So, in that case, instead of preventing pages from entering in the main memory, the OS
searches for the RAM space that are minimum used in the recent times or that are not
referenced into the secondary memory to make the space for the new pages in the
main memory.
For example:
Let’s assume that an OS requires 300 MB of memory to store all the running programs.
However, there’s currently only 50 MB of available physical memory stored on the
RAM.
The OS will then set up 250 MB of virtual memory and use a program called the
Virtual Memory Manager(VMM) to manage that 250 MB.
So, in this case, the VMM will create a file on the hard disk that is 250 MB in size
to store extra memory that is required.
The OS will now proceed to address memory as it considers 300 MB of real
memory stored in the RAM, even if only 50 MB space is available.
It is the job of the VMM to manage 300 MB memory even if just 50 MB of real
memory space is available.
So, when a context switch occurs, the OS never copy any of the old program’s pages
from the disk or any of the new program’s pages into the main memory. Instead, it will
start executing the new program after loading the first page and fetches the program’s
pages, which are referenced.
During the program execution, if the program references a page that may not be
available in the main memory because it was swapped, then the processor considers it
as an invalid memory reference. That’s because the page fault and transfers send
control back from the program to the OS, which demands to store page back into the
memory.
FIFO
Optimal Algorithm
LRU Page Replacement
Optimal Algorithm
The optimal page replacement method selects that page for a replacement for which
the time to the next reference is the longest.
Features:
Optimal algorithm results in the fewest number of page faults. This algorithm is
difficult to implement.
An optimal page-replacement algorithm method has the lowest page-fault rate of
all algorithms. This algorithm exists and which should be called MIN or OPT.
Replace the page which unlike to use for a longer period of time. It only uses the
time when a page needs to be used.
Features:
The LRU replacement method has the highest count. This counter is also called
aging registers, which specify their age and how much their associated pages
should also be referenced.
The page which hasn’t been used for the longest time in the main memory is the
one that should be selected for replacement.
It also keeps a list and replaces pages by looking back into time.
Fault rate
Fault rate is a frequency with which a designed system or component fails. It is
expressed in failures per unit of time. It is denoted by the Greek letter ? (lambda).
Advantages of Virtual Memory
Here, are pros/benefits of using Virtual Memory:
Virtual memory helps to gain speed when only a particular segment of the
program is required for the execution of the program.
It is very helpful in implementing a multiprogramming environment.
It allows you to run more applications at once.
It helps you to fit many large programs into smaller programs.
Common data or code may be shared between memory.
Process may become even larger than all of the physical memory.
Data / code should be read from disk whenever required.
The code can be placed anywhere in physical memory without requiring
relocation.
More processes should be maintained in the main memory, which increases the
effective use of CPU.
Each page is stored on a disk until it is required after that, it will be removed.
It allows more applications to be run at the same time.
There is no specific limit on the degree of multiprogramming.
Large programs should be written, as virtual address space available is more
compared to physical memory.
Memory Management
1
Symbolic addresses
The addresses used in a source code. The variable names, constants, and
instruction labels are the basic elements of the symbolic address space.
2
Relative addresses
At the time of compilation, a compiler converts symbolic addresses into relative
addresses.
3
Physical addresses
The loader generates these addresses at the time when a program is loaded into
main memory.
Virtual and physical addresses are the same in compile-time and load-time address-binding
schemes. Virtual and physical addresses differ in execution-time address-binding scheme.
The set of all logical addresses generated by a program is referred to as a logical address
space. The set of all physical addresses corresponding to these logical addresses is referred to as
a physical address space.
The runtime mapping from virtual to physical address is done by the memory management unit
(MMU) which is a hardware device. MMU uses following mechanism to convert virtual address to
physical address.
The value in the base register is added to every address generated by a user process,
which is treated as offset at the time it is sent to memory. For example, if the base register
value is 10000, then an attempt by the user to use address location 100 will be dynamically
reallocated to location 10100.
The user program deals with virtual addresses; it never sees the real physical addresses.
Swapping
Swapping is a mechanism in which a process can be swapped temporarily out of main memory (or
move) to secondary storage (disk) and make that memory available to other processes. At some
later time, the system swaps back the process from the secondary storage to main memory.
Though performance is usually affected by swapping process but it helps in running multiple and
big processes in parallel and that's the reason Swapping is also known as a technique for
memory compaction.
The total time taken by swapping process includes the time it takes to move the entire process to
a secondary disk and then to copy the process back to memory, as well as the time the process
takes to regain main memory.
Let us assume that the user process is of size 2048KB and on a standard hard disk where
swapping will take place has a data transfer rate around 1 MB per second. The actual transfer of
the 1000K process to or from memory will take
2048KB / 1024KB per second
= 2 seconds
= 2000 milliseconds
Now considering in and out time, it will take complete 4000 milliseconds plus other overhead
where the process competes to regain main memory.
Memory Allocation
Main memory usually has two partitions −
Low Memory − Operating system resides in this memory.
High Memory − User processes are held in high memory.
Operating system uses the following memory allocation mechanism.
S.N Memory Allocation & Description
.
1
Single-partition allocation
In this type of allocation, relocation-register scheme is used to protect user
processes from each other, and from changing operating-system code and data.
Relocation register contains value of smallest physical address whereas limit
register contains range of logical addresses. Each logical address must be less
than the limit register.
2
Multiple-partition allocation
In this type of allocation, main memory is divided into a number of fixed-sized
partitions where each partition should contain only one process. When a partition
is free, a process is selected from the input queue and is loaded into the free
partition. When the process terminates, the partition becomes available for
another process.
Fragmentation
As processes are loaded and removed from memory, the free memory space is broken into little
pieces. It happens after sometimes that processes cannot be allocated to memory blocks
considering their small size and memory blocks remains unused. This problem is known as
Fragmentation.
Fragmentation is of two types −
1
External fragmentation
Total memory space is enough to satisfy a request or to reside a process in it, but
it is not contiguous, so it cannot be used.
2
Internal fragmentation
Memory block assigned to process is bigger. Some portion of memory is left
unused, as it cannot be used by another process.
The following diagram shows how fragmentation can cause waste of memory and a compaction
technique can be used to create more free memory out of fragmented memory −
External fragmentation can be reduced by compaction or shuffle memory contents to place all free
memory together in one large block. To make compaction feasible, relocation should be dynamic.
The internal fragmentation can be reduced by effectively assigning the smallest partition but large
enough for the process.
Paging
A computer can address more memory than the amount physically installed on the system. This
extra memory is actually called virtual memory and it is a section of a hard that's set up to emulate
the computer's RAM. Paging technique plays an important role in implementing virtual memory.
Paging is a memory management technique in which process address space is broken into blocks
of the same size called pages (size is power of 2, between 512 bytes and 8192 bytes). The size of
the process is measured in the number of pages.
Similarly, main memory is divided into small fixed-sized blocks of (physical) memory
called frames and the size of a frame is kept the same as that of a page to have optimum
utilization of the main memory and to avoid external fragmentation.
Address Translation
Page address is called logical address and represented by page number and the offset.
Logical Address = Page number + page offset
Frame address is called physical address and represented by a frame number and the offset.
Physical Address = Frame number + page offset
A data structure called page map table is used to keep track of the relation between a page of a
process to a frame in physical memory.
When the system allocates a frame to any page, it translates this logical address into a physical
address and create entry into the page table to be used throughout execution of the program.
When a process is to be executed, its corresponding pages are loaded into any available memory
frames. Suppose you have a program of 8Kb but your memory can accommodate only 5Kb at a
given point in time, then the paging concept will come into picture. When a computer runs out of
RAM, the operating system (OS) will move idle or unwanted pages of memory to secondary
memory to free up RAM for other processes and brings them back when needed by the program.
This process continues during the whole execution of the program where the OS keeps removing
idle pages from the main memory and write them onto the secondary memory and bring them
back when required by the program.
Advantages and Disadvantages of Paging
Here is a list of advantages and disadvantages of paging −
Paging reduces external fragmentation, but still suffer from internal fragmentation.
Paging is simple to implement and assumed as an efficient memory management
technique.
Due to equal size of the pages and frames, swapping becomes very easy.
Page table requires extra memory space, so may not be good for a system having small
RAM.
Segmentation
Segmentation is a memory management technique in which each job is divided into several
segments of different sizes, one for each module that contains pieces that perform related
functions. Each segment is actually a different logical address space of the program.
When a process is to be executed, its corresponding segmentation are loaded into non-contiguous
memory though every segment is loaded into a contiguous block of available memory.
Segmentation memory management works very similar to paging but here segments are of
variable-length where as in paging pages are of fixed size.
A program segment contains the program's main function, utility functions, data structures, and so
on. The operating system maintains a segment map table for every process and a list of free
memory blocks along with segment numbers, their size and corresponding memory locations in
main memory. For each segment, the table stores the starting address of the segment and the
length of the segment. A reference to a memory location includes a value that identifies a segment
and an offset.