CSC 308
CSC 308
COMPUTER MEMORY
INTRODUCTION
The computer’s memory stores data, instructions required during the processing of data, and
output results. Storage may be required for a limited period of time, instantly, or, for an extended
period of time. Different types of memories, each having its own unique features, are available for
use in a computer. The cache memory, registers, and RAM are fast memories and store the data
and instructions temporarily during the processing of data and instructions. The secondary
memory like magnetic disks and optical disks have large storage capacities and store the data and
instructions permanently but are slow memory devices. The memories are organized in the
computer in a manner to achieve high levels of performance at minimum costs.
MEMORY REPRESENTATION
The computer memory stores different kinds of data like input data, output data, intermediate
results, etc., and the instructions. Binary digit or bit is the basic unit of memory. A bit is a single
binary digit, i.e., 0 or 1. A bit is the smallest unit of representation of data in a computer. However,
the data is handled by the computer as a combination of bits. A group of 8 bits form a byte. One
byte is the smallest unit of data that is handled by the computer. One byte (8 bit) can store 2 8 =
256 different combinations of bits, and thus can be used to represent 256 different symbols. In a
byte, the different combinations of bits fall in the range 00000000 to 11111111. A group of bytes
can be further combined to form a word. A word can be a group of 2, 4 or 8 bytes.
CHARACTERISTICS OF MEMORIES
• Volatility
o Volatile {RAM}
o Non-volatile {ROM, Flash memory}
• Mutability
o Read/Write {RAM, HDD, SSD, RAM, Cache, Registers…}
o Read Only {Optical ROM (CD/DVD…), Semiconductor ROM}
1
• Accessibility
o Random Access {RAM, Cache}
o Direct Access {HDD, Optical Disks}
o Sequential Access {Magnetic Tapes}
IV. MEMORY HIERARCHY
The memory is characterized on the basis of two key factors: capacity and access time. • Capacity
is the amount of information (in bits) that a memory can store.
• Access time is the time interval between the read/ write request and the availability of data. The
lesser the access time, the faster is the speed of memory.
Ideally, we want the memory with fastest speed and largest capacity. However, the cost of fast
memory is very high. The computer uses a hierarchy of memory that is organized in a manner to
enable the fastest speed and largest capacity of memory. The hierarchy of the different memory
types is shown in Figure 1.
The Internal Memory and External Memory are the two broad categories of memory used in
the computer. The Internal Memory consists of the CPU registers, cache memory and primary
memory. The internal memory is used by the CPU to perform the computing tasks. The External
Memory is also called the secondary memory. The secondary memory is used to store the large
amount of data and the software.
In general, referring to the computer memory usually means the internal memory.
• Internal Memory
2
The key features of internal memory are:
1. Limited storage capacity.
2. Temporary storage.
3. Fast access.
4. High cost.
Registers, cache memory, and primary memory constitute the internal memory. The primary
memory is further of two kinds: RAM and ROM. Registers are the fastest and the most expensive
among all the memory types. The registers are located inside the CPU, and are directly accessible
by the CPU. The speed of registers is between 1-2 ns (nanosecond). The sum of the size of registers
is about 200B. Cache memory is next in the hierarchy and is placed between the CPU and the
main memory. The speed of cache is between 2-10 ns. The cache size varies between 32 KB to
4MB. Any program or data that has to be executed must be brought into RAM from the secondary
memory. Primary memory is relatively slower than the cache memory. The speed of RAM is
around 60ns. The RAM size varies from 512KB to 64GB.
• Secondary Memory
The key features of secondary memory storage devices are:
1. Very high storage capacity.
2. Permanent storage (non-volatile), unless erased by user.
3. Relatively slower access.
4. Stores data and instructions that are not currently being used by CPU but may be required later
for processing.
5. Cheapest among all memory.
To get the fastest speed of memory with largest capacity and least cost, the fast memory is located
close to the processor. The secondary memory, which is not as fast, is used to store information
permanently, and is placed farthest from the processor. With respect to CPU, the memory is
organized as follows:
• Registers are placed inside the CPU (small capacity, high cost, very high speed)
• Cache memory is placed next in the hierarchy (inside and outside the CPU)
• Secondary memory is the farthest from CPU (large capacity, low cost, low speed)
3
The registers, cache memory and primary memory are semiconductor memories. They do not have
any moving parts and are fast memories. The secondary memory is magnetic or optical memory,
has moving parts and has slow speed.
CPU REGISTERS
Registers are very high-speed storage areas located inside the CPU. After CPU gets the data and
instructions from the cache or RAM, the data and instructions are moved to the registers for
processing. Registers are manipulated directly by the control unit of CPU during instruction
execution. That is why registers are often referred to as the CPU’s working memory. Since CPU
uses registers for the processing of data, the number of registers in a CPU and the size of each
register affect the power and speed of a CPU. The more the number of registers (ten to hundreds)
and bigger the size of each register (8 bits to 64 bits), the better it is.
CACHE MEMORY
Cache memory is placed in between the CPU and the RAM. Cache memory is a fast memory,
faster than the RAM. When the CPU needs an instruction or data during processing, it first looks
in the cache. If the information is present in the cache, it is called a cache hit, and the data or
instruction is retrieved from the cache. If the information is not present in cache, then it is called
a cache miss, and the information is then retrieved from RAM.
Type of Cache Memory
Cache memory improves the speed of the CPU, but it is expensive. Type of Cache Memory is
divided into different levels that are L1, L2, L3:
Level 1 (L1) cache or Primary Cache
L1 is the primary type cache memory. The Size of the L1 cache very small comparison to others
that is between 2KB to 64KB, it depends on computer processor. It is an embedded register in the
computer microprocessor (CPU). The Instructions that are required by the CPU that are firstly
searched in L1 Cache. Example of registers are accumulator, address register, Program counter
etc.
Level 2 (L2) Cache or Secondary Cache
L2 is secondary type cache memory. The Size of the L2 cache is more capacious than L1 that is
between 256KB to 512KB. L2 cache is located on computer microprocessor. After searching the
Instructions in L1 Cache, if not found then it searched into L2 cache by computer microprocessor.
The high-speed system bus interconnecting the cache to the microprocessor.
Level 3 (L3) Cache or Main Memory
The L3 cache is larger in size but also slower in speed than L1 and L2, its size is between 1MB to
8MB. In Multicore processors, each core may have separate L1 and L2, but all cores share a
common L3 cache. L3 cache has double the speed of the RAM.
4
Fig. 2: Arrangement of Memory
• It stores the program that can be executed within a short period of time.
• It is very expensive.
PRIMARY MEMORY (Main Memory)
Primary memory is the main memory of computer. It is a chip mounted on the motherboard of
computer. Primary memory is categorized into two main types: Random access memory (RAM)
and read only memory (ROM). RAM is used for the temporary storage of input data, output data
and intermediate results. The input data entered into the computer using the input device, is stored
in RAM for processing. After processing, the output data is stored in RAM before being sent to
the output device. Any intermediate results generated during the processing of program are also
stored in RAM. Unlike RAM, the data once stored in ROM either cannot be changed or can only
be changed using some special operations. Therefore, ROM is used to store the data that does not
require a change.
Types of Primary Memory
1. RAM (Random Access Memory)
5
The Word “RAM” stands for “random access memory” or may also refer to short-term memory.
It’s called “random” because you can read store data randomly at any time and from any physical
location. It is a temporal storage memory. RAM is volatile that only retains all the data as long as
the computer powered. It is the fastest type of memory. RAM stores the currently processed data
from the CPU and sends them to the graphics unit.
There are generally two broad subcategories of RAM:
• Static RAM (SRAM): Static RAM is the form of RAM and made with flip-flops and used for
primary storage are volatile. It retains data in latch as long as the computer powered. SRAM is
more expensive and consumes more power than DRAM. It used as Cache Memory in a computer
system. As technically, SRAM uses more transistors as compared to DRAM. It is faster compared
to DRAM due to the latching arrangement, and they use 6 transistors per data bit as compared to
DRAM, which uses one transistor per bit.
• Dynamic Random Access Memory (DRAM): It is another form of RAM used as Main Memory,
it retains information in Capacitors for a short period (a few milliseconds) even though the
computer powered. The Data is Refreshed Periodically to maintain in it. The DRAM is cheaper,
but it can store much more information. Moreover, it is also slower and consumes less power than
SRAM.
2. ROM (Read Only Memory)
ROM is the long-term internal memory. ROM is “Non-Volatile Memory” that retains data even
without the flow of electricity. ROM is an essential chip with permanently written data or
programs. It is similar to the RAM that is accessed by the CPU. ROM comes pre-written by the
computer manufacturer to hold the instructions for booting-up the computer.
There are generally three broad types of ROM
• PROM (Programmable Read Only Memory): PROM stands for programmable ROM. It can be
programmed only be done once and read many. Unlike RAM, PROMs retain their contents
without the flow of electricity. PROM is also nonvolatile memory. The significant difference
between a ROM and a PROM is that a ROM comes with pre-written by the computer manufacturer
whereas PROM manufactured as blank memory. PROM can be programmed by PROM burner
and by blowing internal fuses permanently.
• EPROM (Erasable Programmable Read Only Memory): EPROM is pronounced ee-prom. This
memory type retains its contents until it exposed to intense ultraviolet light that clears its contents,
making it possible to reprogram the memory.
• EEPROM (Electrically Erasable Programmable Read Only Memory): EEPROM can be burned
(programmed) and erased by first electrical waves in a millisecond. A single byte of a data or the
entire contents of device can be erased. To write or erase this memory type, you need a device
called a PROM burner.
6
STORAGE MANAGEMENT STRATEGIES
Expensive resources are managed intensively to achieve better use. Storage management strategies
are geared towards obtaining the best possible use of the main storage resource. Storage management
strategies are divided into the following categories:
1. Fetch strategies
a) Demand fetch strategies
b) Anticipatory fetch strategies
2. Placement strategies
3. Replacement strategies
Fetch strategies are concerned with when to obtain the next piece of program or data for
transfer from main storage to secondary storage. For many years, demand fetch was used, in which
the next piece of program or data is brought into main storage when it is referenced by a running
program. It was believed that since we cannot generally predict where program control will go next,
the overhead involved in making guesses and anticipating the future would by far exceed the expected
benefits. Today, many researchers believe that anticipatory fetch will yield improved system
performance.
Placement strategies are concerned with determining where in main storage to place an
incoming program. We shall consider the first-fit, best-fit and worst-fit storage placement strategies.
Replacement strategies are concerned with determining which piece of program or data to
displace to make room for incoming programs.
CONTIGUOUS VS. NONCONTIGUOUS STORAGE ALLOCATION
The earliest computing systems required contiguous storage allocation – each program had to occupy
a single contiguous block of storage locations. It wasn’t until variable partition multiprogramming
came into existence that it became clear that noncontiguous storage allocation might be useful.
In noncontiguous storage allocation, a program is divided into several blocks or segments that
may be placed throughout main storage in pieces not necessarily adjacent to one another. It is more
difficult for an operating system to control noncontiguous storage allocation. The benefit is that if
main memory has many small holes available instead of a single large hole, the operating system
could often load and execute programs that would otherwise have to wait.
SINGLE USER CONTIGUOUS STORAGE ALLOCATION
In early computers, only one person could use the machine at a time. All the resources were at
the user’s disposal. Billing for resource usage was straightforward and normally based on wall clock
time. A user was given the machine for an interval of time and charged a flat hourly rate.
Originally each user wrote all the code necessary to implement a particular application,
including the highly detailed machine level input/output instructions. Later, input/output control
systems (IOCS) were developed. Subsequently, IOCS routines were called whenever needed to carry
7
out input/output operations. This greatly simplified and speeded up the coding process. The
implementation of input/output control systems may have been the beginning of today’s concept of
operating systems. Figure 3 illustrates the storage organization for a typical single user contiguous
storage allocation system.
Programs are limited in size to the amount of main storage, but it is possible to run programs
larger than main storage by the use of overlays. Figure 4 illustrates this concept. If a particular
program section is not needed for the duration of the program’s execution, then another section of
program may be brought in from secondary storage to occupy the storage used by the program section
that is no longer needed. Overlays give programmers a way to extend limited main storage. Manual
overlay requires careful and time-consuming planning. A program with a sophisticated overlay
structure can be difficult to modify.
0
Operating
system
a
User
Unused
8
Protection in Single User Systems
In single user contiguous storage allocation systems, the user has control over all of main storage.
Storage was divided into a portion holding operating system routines, a portion holding the user’s
program, and an unused portion. The question of protection is simple. How should the operating
system be protected from destruction by the user’s program?
If the user’s program goes astray, it can destroy the operating system. If this destruction is fatal
and the user cannot proceed, then he will realise that something is wrong, terminate the program, fix
the problem, and then retry the job. Here the need for protection may not be apparent. Conversely,
suppose the program destroys the operating system more “gently”. For example, suppose some
input/output routines are accidentally changed. Although the job could still run, all output records
might be truncated. If the results are not examined until it completes, then machine resource could be
wasted. Worse yet, the damage to the operating system may cause output to be produced that cannot
easily be determined to be inaccurate.
It is clear that operating systems should be protected from the user. Protection is implemented
by the use of boundary registers built into the CPU to ensure that the operating system is always
protected from user programs. As illustrated in Fig. 5, each time a user program refers to a storage
address, the boundary register is checked to be certain that the program is not about to cause any
destruction to the operating system. The boundary register contains the highest address used by the
operating system. If the user tries to enter the operating system, the instruction is intercepted, and the
job is terminated with and appropriate error message.
Definitely, users have to enter the operating system from time to time to obtain services such
as input/output. This problem is solved by giving the user specific instruction with which to request
system services (i.e. supervisor call instructions). Using such instructions, user programs summon the
operating system to perform some operations such as input/output operations on behalf of the user
program.
0
Operating
CPU
system
a Boundary
register
User a
Unused
9
Single Stream Batch Processing
Early single-user real storage systems were dedicated to one job for more than the job’s execution
time. Jobs generally required considerable setup time during which the operating system was loaded,
tapes and disk packs were mounted, appropriate forms were placed in the printer, time cards were
“punched in”, etc. during job setup and job teardown, the computer sat idle.
It was then realized by designers that the automation of job-to-job transition could
considerably decrease the amount of time wasted between jobs. This led to the development of batch
processing systems. In single stream batch processing, jobs are grouped in batches by loading them
consecutively onto tape or disk. A job stream processor reads the job control language statements,
and facilitates the setup of the job. It issues directives to the system operator, and performs many
functions automatically that were previously done manually. When a job terminates, the job stream
reader automatically reads in the control language statements for the next job, and performs
appropriate housekeeping chores to facilitate the transition to the next job. Batch processing systems
greatly improved the use of computer systems and demonstrated the real value of operating systems
and intensive resource management. Single stream batch processing systems were the state of the art
in early 1960s.
FIXED PARTITION MULTIPROGRAMMING
Even with batch processing operating systems, single user systems still waste a considerable amount
of computing resource. Fig 6 illustrates this situation. A program consumes the CPU resource until an
output or input is needed. When an I/O request is issued, the job often cannot continue until the
requested data is either sent or received. The input/output speeds are extremely slow compared to
CPU speeds.
Designers saw that they could once again considerably increase the utilization of the CPU by
intensive management. This time, they chose to implement multiprogramming systems, in which
several users simultaneously compete for system resources. The job currently waiting for I/O will
yield the CPU to another job ready to do calculations if, indeed another job is waiting. Thus, both the
input/output and CPU calculations can occur simultaneously. This greatly improved CPU utilization
and system throughput.
To take maximum advantage of multiprogramming, it is necessary for several jobs to reside in
the computer’s main storage at once. Thus when one job requests input/output, the CPU may be
immediately switched to another job that may do calculations without delay. When the job doing
calculations yields the CPU, another job may be ready to use it.
Multiprogramming normally requires considerably more storage than in a single user system.
However, the improved resource use for the CPU and peripheral devices more than justifies the
expense of additional storage.
10
Fig. 6 CPU utilization on a single user system. Note: In many single user jobs, the length of the input/output
waits is much larger relative to the length of periods of CPU utilization than is indicated in this diagram.
0
Operating
Job queue for partition 1 System
These jobs a
may run only .... Partition 1
in Partition 1
b
Job queue for partition 2
These jobs
Partition 2
may run only ....
in Partition 2
c
Job queue for partition 3
These jobs
may run only ....
in Partition 3 Partition 3
11
0
Operating
Job queue for partition 1 System
a
No jobs waiting for Partition 1
Partition 1 (Empty)
b
Job queue for partition 2
Partition 2
No jobs waiting for (Empty)
Partition 2
c
Job queue for partition 3
E D C B A (In Use)
Fig. 8: An extreme example of poor resource utilization in fixed partition multi programming with absolute
translation and loading. Jobs waiting for partition 3 are small and could “fit” in the other partitions. But with
absolute translation and loading, these jobs may run only in partition 3. The other two partitions remain
empty.
12
0
Operating
System
a
Partition 1
b
Job queue
Partition 2
.... Job Job Job Job Job
E D C B A c
0
Operating
CPU
System
a
Partition 1 2 Currently
active user
b
b Low boundary
Partition 2
c High boundary
c
Partition 3
Fig. 10: Storage protection in contiguous allocation multiprogramming systems. While the user in
partition 2 is active, all storage addresses developed by the running program are checked to be sure that
they fall between b and c.
13
In variable partition multiprogramming, we make no assumptions about the relative sizes of
jobs (except that jobs must not be greater than the computers main memory). As jobs arrive, if the
scheduling mechanism decides that they should proceed, they are given as much space in main
memory as they need. There is no waste – a job’s partition is exactly the size of the job.
As in every storage organization scheme, variable partition multiprogramming also involves
some degree of waste. This waste does not become obvious until jobs start to finish and leave holes
in the main storage as in Fig. 12. These holes can be used for other jobs, but as this happens, the holes
get smaller and eventually becoming too small to hold new jobs. This is how waste occurs in variable
partition multiprogramming.
Coalescing Holes
When a job finishes in a variable partition multiprogramming system, we can check whether the
storage being freed borders on other free storage areas (holes). If it does, then we may record in the
free storage list either (1) an additional hole or (2) a single hole reflecting the merger of the existing
hole and the new adjacent hole.
The process of merging adjacent holes to form a single larger hole is known as coalescing and
is illustrated in Fig 13. By coalescing holes, we reclaim the largest possible contiguous blocks of
storage.
Storage Compaction
As holes are coalesced, it is often the case that the separate holes distributed throughout the main
storage collectively constitute a significant amount of storage. Sometimes, a job may request certain
amount of main storage that no individual hole is large enough to provide, even though the sum of all
the holes is larger than the amount of space needed to hold the job.
The technique of storage compaction (Fig. 14) involves moving all occupied areas of storage
to one end or the other of main storage. This leaves a single large free storage hole instead of numerous
small holes common in variable partition multiprogramming. All of the available free storage becomes
contiguous so that a waiting job can run if its memory requirement is met by the single hole that
results from compaction. Storage compaction is sometimes referred to as burping the storage or more
conventionally, garbage collection.
The drawbacks of storage compaction include:
• It consumes system resources that could otherwise be used more productively.
• The system must stop everything while it performs the compaction. This could cause erratic
response times for interactive users and could be devastating in real time systems.
• Compaction involves relocating the jobs that are in storage. In doing this, relocation
information, ordinarily lost when a program is loaded, must now be maintained in readily
accessible form.
• With a normal, rapidly changing job mix, it is necessary to compact frequently. The consumed
system resource might not justify the benefits.
14
User G needs
18K
User F needs
32K
User E needs
14K
User D needs
25K
User C needs
10K
User B needs
20K
User A needs
15K
Free
Free User D 25K
Free
Free
15
Operating Operating Operating
system system system
system
User A User A User A
2K Hole 2K Hole
User A 7K Hole
5K user A finishes 5K user A
Operating
and
system
releases
combines
its
adjacent
Other storage. Other Other
holes to
users users users
form a
single larger
hole.
16
Operating Operating
system system
In use In use
In use
Free
In use
In use
Free
Operating
system places
Free
all “in use”
In use blocks
together
leaving the
Free
free storage as
a single large
hole.
A variation of first-fit, called next-fit strategy begins each search for available hole at the
point where the previous search ended.
17
(a) FIRST-FIT STRATEGY 0
Operating
a system
Place job in first storage hole on 16K Hole
free storage list in which it will fit. b
In use
c
Free Storage List (Kept in address order,
d 14K Hole
or sometimes in random
Start In use
order) Request for e
5K Hole
Address Length 13K
f
a 16K In use
c 14K
g
e 5K
30K Hole
g 30K
…
h
18
Replacement Strategies
There are many approaches to the problem of deciding which page to replace but the object is the same
for all--the policy which selects the page that will not be referenced again for the longest time.
First In First Out (FIFO): This algorithm maintains a space allocation queue. The page to be replaced
is the "oldest" page in the memory, the one which was loaded before all the others. In other words, the
page which resides at the rare end of the queue will be replaced first.
Least Recently Used (LRU): The page to be replaced is the one which has not been referenced since all
the others have been referenced. The simple intuition is that it may not have been referenced because it is
not needed.
Last In First Out (LIFO): The page to be replaced is the one most recently loaded into the memory. Its
basic intuition is that it saves time.
Least Frequently Used (LFU): The page to be replaced is the one used least often of the pages currently
in the memory. The intuition is that the pages most needed are the ones most frequently accessed.
Optimal (OPT or MIN): The page to be replaced is the one that will not be used for the longest period
of time. This algorithm requires future knowledge of the reference string which is not usually available.
Although it cannot be practically implementable but it can be used as a benchmark. Other algorithms are
compared to this in terms of optimality.
VIRTUAL MEMORY
Virtual Memory is a storage allocation scheme in which secondary memory can be addressed as
though it were part of the main memory. The addresses a program may use to reference memory are
distinguished from the addresses the memory system uses to identify physical storage sites and
program-generated addresses are translated automatically to the corresponding machine addresses.
What is Virtual Memory?
Virtual memory is a memory management technique used by operating systems to give the appearance
of a large, continuous block of memory to applications, even if the physical memory (RAM) is limited.
It allows the system to compensate for physical memory shortages, enabling larger applications to run
on systems with less RAM.
A memory hierarchy, consisting of a computer system’s memory and a disk, enables a process to
operate with only some portions of its address space in memory. A virtual memory is what its name
indicates- it is an illusion of a memory that is larger than the real memory. We refer to the software
component of virtual memory as a virtual memory manager. The basis of virtual memory is the
noncontiguous memory allocation model. The virtual memory manager removes some components
from memory to make room for other components.
The size of virtual storage is limited by the addressing scheme of the computer system and the amount
of secondary memory available not by the actual number of main storage locations.
19
Working of Virtual Memory
It is a technique that is implemented using both hardware and software. It maps memory addresses
used by a program, called virtual addresses, into physical addresses in computer memory.
• All memory references within a process are logical addresses that are dynamically translated
into physical addresses at run time. This means that a process can be swapped in and out of
the main memory such that it occupies different places in the main memory at different times
during the course of execution.
• A process may be broken into a number of pieces and these pieces need not be continuously
located in the main memory during execution. The combination of dynamic run-time address
translation and the use of a page or segment table permits this.
If these characteristics are present then, it is not necessary that all the pages or segments are present
in the main memory during execution. This means that the required pages need to be loaded into
memory whenever required. Virtual memory is implemented using Demand Paging or Demand
Segmentation.
Types of Virtual Memory
In a computer, virtual memory is managed by the Memory Management Unit (MMU), which is often
built into the CPU. The CPU generates virtual addresses that the MMU translates into physical
addresses.
There are two main types of virtual memory:
• Paging
• Segmentation
Paging
Paging divides memory into small fixed-size blocks called pages. When the computer runs out of
RAM, pages that aren’t currently in use are moved to the hard drive, into an area called a swap file.
The swap file acts as an extension of RAM. When a page is needed again, it is swapped back into
RAM, a process known as page swapping. This ensures that the operating system (OS) and
applications have enough memory to run.
Demand Paging: The process of loading the page into memory is on demand (whenever a page fault
occurs) is known as demand paging. The process includes the following steps:
20
Fig. 16: Demand Paging Illustrated
Demand Paging
1. If the CPU tries to refer to a page that is currently not available in the main memory, it
generates an interrupt indicating a memory access fault.
2. The OS puts the interrupted process in a blocking state. For the execution to proceed the OS
must bring the required page into the memory.
3. The OS will search for the required page in the logical address space.
4. The required page will be brought from logical address space to physical address space. The
page replacement algorithms are used for the decision-making of replacing the page in physical
address space.
5. The page table will be updated accordingly.
6. The signal will be sent to the CPU to continue the program execution, and it will place the
process back into the ready state.
Hence whenever a page fault occurs these steps are followed by the operating system and the required
page is brought into memory.
What is Page Fault Service Time?
The time taken to service the page fault is called page fault service time. The page fault service time
includes the time taken to perform all the above six steps.
21
Segmentation
Segmentation is another non-contiguous memory allocation scheme like paging. It is a variable-size
partitioning theme. Segmentation divides virtual memory into segments of different sizes. The
partitions of secondary memory area units are known as segments. Segments that aren’t currently
needed can be moved to the hard drive. The system uses a segment table to keep track of each
segment’s status, including whether it’s in memory, if it’s been modified, and its physical address.
Segments are mapped into a process’s address space only when needed. Segment table contains two
main data concerning segment, one is Base, which is the bottom address of the segment, and another
is Limit, which is the length of the segment.
In segmentation, the CPU generates a logical address that contains the segment number and segment
offset. If the segment offset is a smaller amount than the limit, then the address called valid address
otherwise it throws a miscalculation because the address is invalid.
22
Differences Between Paging and Segmentation
Paging Segmentation
In paging, the program is divided into fixed In segmentation, the program is divided into
or mounted size pages. variable size segments.
Page size is determined by hardware. Here, the segment size is given by the user.
In paging, the logical address is split into a Here, the logical address is split into segment
page number and page offset. number and segment offset.
In paging, the operating system must In segmentation, the operating system maintains a
maintain a free frame list. list of holes in the main memory.
23
Paging Segmentation
Paging results in a less efficient system. Segmentation results in a more efficient system.
An abstraction that extends the The actual hardware (RAM) that stores data
Definition available memory by using disk and instructions currently being used by the
storage CPU
Speed Slower (due to disk I/O operations) Faster (accessed directly by the CPU)
24
Feature Virtual Memory Physical Memory (RAM)
Data
Indirect (via paging and swapping) Direct (CPU can access data directly)
Access
Volatility Non-volatile (data persists on disk) Volatile (data is lost when power is off)
What is Swapping?
Swapping is a process or means of removing all pages from memory, or marking them so that they
will be removed by the normal page replacement process. Suspending a process ensures that it is not
runnable while it is swapped out. At some later time, the system swaps back the process from the
secondary storage to the main memory. When a process is busy swapping pages in and out then this
situation is called thrashing.
What is Thrashing?
At any given time, only a few pages of any process are in the main memory, and therefore more
processes can be maintained in memory. Furthermore, time is saved because unused pages are not
swapped in and out of memory. However, the OS must be clever about how it manages this scheme.
In the steady state practically, all of the main memory will be occupied with process pages, so that the
processor and OS have direct access to as many processes as possible. Thus when the OS brings one
page in, it must throw another out. If it throws out a page just before it is used, then it will just have
to get that page again almost immediately. Too much of this leads to a condition called Thrashing.
25
The system spends most of its time swapping pages rather than executing instructions. So, a good
page replacement algorithm is required.
In the given diagram, the initial degree of multiprogramming up to some extent of point(lambda), the
CPU utilization is very high and the system resources are utilized 100%. But if we further increase
the degree of multiprogramming the CPU utilization will drastically fall down and the system will
spend more time only on the page replacement and the time taken to complete the execution of the
process will increase. This situation in the system is called thrashing.
Causes of Thrashing
1. High Degree of Multiprogramming: If the number of processes keeps on increasing in the
memory then the number of frames allocated to each process will be decreased. So, fewer frames will
be available for each process. Due to this, a page fault will occur more frequently and more CPU time
will be wasted in just swapping in and out of pages and the utilization will keep on decreasing.
For example: Let free frames = 400
Case 1: Number of processes = 100
Then, each process will get 4 frames.
Case 2: Number of processes = 400
Each process will get 1 frame.
Case 2 is a condition of thrashing, as the number of processes is increased, frames per process are
decreased. Hence CPU time will be consumed just by swapping pages.
2. Lack of Frames: If a process has fewer frames, then fewer pages of that process will be able to
reside in memory and hence more frequent swapping in and out will be required. This may lead to
thrashing. Hence a sufficient number of frames must be allocated to each process in order to prevent
thrashing.
Recovery of Thrashing
• Do not allow the system to go into thrashing by instructing the long-term scheduler not to
bring the processes into memory after the threshold.
• If the system is already thrashing then instruct the mid-term scheduler to suspend some of the
processes so that we can recover the system from thrashing.
Performance in Virtual Memory
• Let p be the page fault rate(0 <= p <= 1).
• if p = 0 no page faults
• if p =1, every reference is a fault.
26
The performance of a virtual memory management system depends on the total number of page faults,
which depend on “paging policies” and “frame allocation“
Frame Allocation
A number of frames allocated to each process is either static or dynamic.
• Static Allocation: The number of frame allocations to a process is fixed.
• Dynamic Allocation: The number of frames allocated to a process changes.
Paging Policies
• Fetch Policy: It decides when a page should be loaded into memory.
• Replacement Policy: It decides which page in memory should be replaced.
• Placement Policy: It decides where in memory should a page be loaded.
Applications of Virtual memory
Virtual memory has the following important characteristics that increase the capabilities of the
computer system. The following are five significant characteristics of Lean.
• Increased Effective Memory: One major practical application of virtual memory is, virtual
memory enables a computer to have more memory than the physical memory using the disk
space. This allows for the running of larger applications and numerous programs at one time
while not necessarily needing an equivalent amount of DRAM.
• Memory Isolation: Virtual memory allocates a unique address space to each process and that
also plays a role in process segmentation. Such separation increases safety and reliability based
on the fact that one process cannot interact with and or modify another’s memory space
through a mistake, or even a deliberate act of vandalism.
• Efficient Memory Management: Virtual memory also helps in better utilization of the
physical memories through methods that include paging and segmentation. It can transfer
some of the memory pages that are not frequently used to disk allowing RAM to be used by
active processes when required in a way that assists in efficient use of memory as well as
system performance.
27
• Simplified Program Development: For case of programmers, they don’t have to consider
physical memory available in a system in case of having virtual memory. They can program
‘as if’ there is one big block of memory and this makes the programming easier and more
efficient in delivering more complex applications.
How to Manage Virtual Memory?
Here are 5 key points on how to manage virtual memory:
1. Adjust the Page File Size
• Automatic Management: All contemporary operating systems including Windows contain
the auto-configuration option for the size of the empirical page file. But depending on the size
of the RAM, they are set automatically, although the user can manually adjust the page file
size if required.
• Manual Configuration: For tuned up users, the setting of the custom size can sometimes
boost up the performance of the system. The initial size is usually advised to be set to the
minimum value of 1. To set the size of the swap space equal to 5 times the amount of physical
RAM and the maximum size 3 times the physical RAM.
2. Place the Page File on a Fast Drive
• SSD Placement: If this is feasible, the page file should be stored in the SSD instead of the
HDD as a storage device. It has better read and write times, and the virtual memory may prove
beneficial in an SSD.
• Separate Drive: Regarding systems having multiple drives involved, the page file needs to be
placed on a different drive than the os and that shall in turn improve its performance.
3. Monitor and Optimize Usage
• Performance Monitoring: Employ the software tools used in monitoring the performance of
the system in tracking the amounts of virtual memory. High page file usage may signify that
there is a lack of physical RAM or that virtual memory needs a change of settings or addition
in physical RAM.
• Regular Maintenance: Make sure there is no toolbar or other application running in the
background, take time and uninstall all the tool bars to free virtual memory.
4. Disable Virtual Memory for SSDs (with Sufficient RAM)
• Sufficient RAM: If for instance your system has a big physical memory, for example 16GB
and above then it would be advised to freeze the page file in order to minimize SSD usage.
But it should be done, in my opinion, carefully and only if the additional signals that one
decides to feed into his applications should not likely use all the available RAM.
28
5. Optimize System Settings
• System Configuration: Change some general properties of the system concerning virtual
memory efficiency. This also involves enabling additional control options in Windows such as
adjusting additional system setting option on the operating system, or using other options in
different operating systems such as Linux that provides different tools and commands to help
in adjusting how virtual memory is utilized.
• Regular Updates: Ensure that your drivers are run in their newest version because new
releases contain some enhancements and issues regarding memory management.
Advantages of Virtual Memory
• More processes may be maintained in the main memory: Because we are going to load
only some of the pages of any particular process, there is room for more processes. This leads
to more efficient utilization of the processor because it is more likely that at least one of the
more numerous processes will be in the ready state at any particular time.
• A process may be larger than all of the main memory: One of the most fundamental
restrictions in programming is lifted. A process larger than the main memory can be executed
because of demand paging. The OS itself loads pages of a process in the main memory as
required.
• It allows greater multiprogramming levels by using less of the available (primary) memory for
each process.
• It has twice the capacity for addresses as main memory.
• It makes it possible to run more applications at once.
• Users are spared from having to add memory modules when RAM space runs out, and
applications are liberated from shared memory management.
• When only a portion of a program is required for execution, speed has increased.
• Memory isolation has increased security.
• It makes it possible for several larger applications to run at once.
• Memory allocation is comparatively cheap.
• It doesn’t require outside fragmentation.
• It is efficient to manage logical partition workloads using the CPU.
• Automatic data movement is possible.
29
Disadvantages of Virtual Memory
• It can slow down the system performance, as data needs to be constantly transferred between
the physical memory and the hard disk.
• It can increase the risk of data loss or corruption, as data can be lost if the hard disk fails or if
there is a power outage while data is being transferred to or from the hard disk.
• It can increase the complexity of the memory management system, as the operating system
needs to manage both physical and virtual memory.
CONTROL SYSTEMS
A control system is a system, which provides the desired response by controlling the output. The
following figure shows the simple block diagram of a control system.
Here, the control system is represented by a single block. Since, the output is controlled by varying
input, the control system got this name. We will vary this input with some mechanism. In the next
section on open loop and closed loop control systems, we will study in detail about the blocks inside
the control system and how to vary this input in order to get the desired response.
Examples − Traffic lights control system, washing machine
Traffic lights control system is an example of control system. Here, a sequence of input signal is
applied to this control system and the output is one of the three lights that will be on for some duration
of time. During this time, the other two lights will be off. Based on the traffic study at a particular
junction, the on and off times of the lights can be determined. Accordingly, the input signal controls
the output. So, the traffic lights control system operates on time basis.
Classification of Control Systems
Based on some parameters, we can classify the control systems into the following ways.
Continuous time and Discrete-time Control Systems
• Control Systems can be classified as continuous time control systems and discrete time control
systems based on the type of the signal used.
• In continuous time control systems, all the signals are continuous in time. But, in discrete
time control systems, there exists one or more discrete time signals.
SISO and MIMO Control Systems
30
• Control Systems can be classified as SISO control systems and MIMO control systems based
on the number of inputs and outputs present.
• SISO (Single Input and Single Output) control systems have one input and one output.
Whereas, MIMO (Multiple Inputs and Multiple Outputs) control systems have more than one
input and more than one output.
Open Loop and Closed Loop Control Systems
Control Systems can be classified as open loop control systems and closed loop control systems based
on the feedback path.
In open loop control systems, output is not fed-back to the input. So, the control action is independent
of the desired output.
The following figure shows the block diagram of the open loop control system.
Here, an input is applied to a controller and it produces an actuating signal or controlling signal. This
signal is given as an input to a plant or process which is to be controlled. So, the plant produces an
output, which is controlled. The traffic lights control system which we discussed earlier is an example
of an open loop control system.
In closed loop control systems, output is fed back to the input. So, the control action is dependent on
the desired output.
The following figure shows the block diagram of negative feedback closed loop control system.
The error detector produces an error signal, which is the difference between the input and the feedback
signal. This feedback signal is obtained from the block (feedback elements) by considering the output
31
of the overall system as an input to this block. Instead of the direct input, the error signal is applied
as an input to a controller.
So, the controller produces an actuating signal which controls the plant. In this combination, the
output of the control system is adjusted automatically till we get the desired response. Hence, the
closed loop control systems are also called the automatic control systems. Traffic lights control system
having sensor at the input is an example of a closed loop control system.
The differences between the open loop and the closed loop control systems are mentioned in the
following table.
Control action is independent of the desired Control action is dependent of the desired
output. output.
These are also called as non-feedback control These are also called as feedback control
systems. systems.
Inaccurate. Accurate.
32
Fig. 22: Hardwired Control Organisation
The control unit is implemented using hardware (for example: NAND gates, flip-flops, and
counters). We need a special digital circuit that uses , as inputs, the bits from the Opcode field in our
instructions, bits from the flag (or status) register, signals from the bus, and signals from the clock. It
should produce, as outputs, the control signals to drive the various components in the computer.
The advantage of hardwired control is that is very fast. The disadvantage is that the instruction
set and the control logic are directly tied together by special circuits that are complex and difficult to
design or modify. If someone designs a hardwired computer and later decides to extend the instruction
set, the physical components in the computer must be changed. This is prohibitively expensive,
because not only must new chips be fabricated but also the old ones must be located and replaced.
Microprogramming is a second alternative for designing control unit of digital computer (uses
software for control). A control unit whose binary control variables are stored in memory is called a
microprogrammed control unit. The control variables at any given time can be represented by a
string of 1's and 0's called a control word (which can be programmed to perform various operations
on the component of the system). Each word in control memory contains within it a microinstruction.
The microinstruction specifies one or more microoperations for the system. A sequence of
microinstructions constitutes a microprogram. A memory that is part of a control unit is referred to
as a control memory.
A more advanced development known as dynamic microprogramming permits a
microprogram to be loaded initially from an auxiliary memory such as a magnetic disk. Control units
that use dynamic microprogramming employ a writable control memory; this type of memory can be
used for writing (to change the microprogram) but is used mostly for reading.
33
The general configuration of a microprogrammed control unit is demonstrated in the block
diagram of Figure. The control memory is assumed to be a ROM, within which all control information
is permanently stored.
34
Fault Tolerance vs. High Availability
High availability refers to a system’s ability to avoid loss of service by minimizing downtime. It’s
expressed in terms of a system’s uptime, as a percentage of total running time. Five nines, or 99.999%
uptime, is considered the “holy grail” of availability.
In most cases, a business continuity strategy will include both high availability and fault tolerance to
ensure your organization maintains essential functions during minor failures, and in the event of a
disaster.
While both fault tolerance and high availability refer to a system’s functionality over time, there are
differences that highlight their individual importance in your business continuity planning.
Consider the following analogy to better understand the difference between fault tolerance and high
availability. A twin-engine airplane is a fault tolerant system – if one engine fails, the other one kicks
in, allowing the plane to continue flying. Conversely, a car with a spare tire is highly available. A flat
tire will cause the car to stop, but downtime is minimal because the tire can be easily replaced.
Some important considerations when creating fault tolerant and high availability systems in an
organizational setting include:
• Downtime – A highly available system has a minimal allowed level of service interruption.
For example, a system with “five nines” availability is down for approximately 5 minutes per
year. A fault-tolerant system is expected to work continuously with no acceptable service
interruption.
• Scope – High availability builds on a shared set of resources that are used jointly to manage
failures and minimize downtime. Fault tolerance relies on power supply backups, as well as
hardware or software that can detect failures and instantly switch to redundant components.
• Cost – A fault tolerant system can be costly, as it requires the continuous operation and
maintenance of additional, redundant components. High availability typically comes as part of
an overall package through a service provider (e.g., load balancer provider).
Some of your systems may require a fault-tolerant design, while high availability might suffice for
others. You should weigh each system’s tolerance to service interruptions, the cost of such
interruptions, existing SLA agreements with service providers and customers, as well as the cost and
complexity of implementing full fault tolerance.
Load balancing and failover: fault tolerance for web applications
In the context of web application delivery, fault tolerance relates to the use of load balancing and
failover solutions to ensure availability via redundancy and rapid disaster recovery
.
35
Fig. 24: Load Balancing and Failover
Load balancing and failover are both integral aspects of fault tolerance.
Load balancing solutions allow an application to run on multiple network nodes, removing the
concern about a single point of failure. Most load balancers also optimize workload distribution across
multiple computing resources, making them individually more resilient to activity spikes that would
otherwise cause slowdowns and other disruptions.
In addition, load balancing helps cope with partial network failures. For example, a system containing
two production servers can use a load balancer to automatically shift workloads in the event of an
individual server failure.
Failover solutions, on the other hand, are used during the most extreme scenarios that result in a
complete network failure. When these occur, a failover system is charged with auto-activating a
secondary (standby) platform to keep a web application running while the IT team brings the primary
network back online.
For true fault tolerance with zero downtime, you need to implement “hot” failover, which transfers
workloads instantly to a working backup system. If maintaining a constantly active standby system is
not an option, you can use “warm” or “cold” failover, in which a backup system takes time to load
and start running workloads.
36