You are on page 1of 26

MAIN MEMORY

Primary Memory (Main Memory)

• Primary memory holds only those data and instructions on which the
computer is currently working. It has a limited capacity and data is
lost when power is switched off. It is generally made up of
semiconductor device. These memories are not as fast as registers.
The data and instruction required to be processed resides in the
main memory. It is divided into two subcategories RAM and ROM
RAM vs ROM
Characteristics of Main Memory

These are semiconductor memories.

It is known as the main memory.

Usually volatile memory.

Data is lost in case power is switched off.

It is the working memory of the computer.

Faster than secondary memories.

A computer cannot run without the primary memory.


Swapping

Swapping is a memory management scheme in which any process can


be temporarily swapped from main memory to secondary memory so that
the main memory can be made available for other processes.
It is used to improve main memory utilization. In secondary memory, the
place where the swapped-out process is stored is called swap space.

• Swap-out is a method of removing a process from RAM and adding it to the


hard disk.
• Swap-in is a method of removing a program from a hard disk and putting it
back into the main memory or RAM.
Example
• Suppose the user process's size is 2048KB and is a standard hard disk
where swapping has a data transfer rate of 1Mbps. Now we will
calculate how long it will take to transfer from main memory to
secondary memory.

• Time???
Advantages of Swapping

1. It helps the CPU to manage multiple processes within a single main


memory.
2. It helps to create and use virtual memory.
3. Swapping allows the CPU to perform multiple tasks simultaneously.
Therefore, processes do not have to wait very long before they are
executed.
4. It improves the main memory utilization.
Dis-Advantages of Swapping

1.If the computer system loses power, the user may lose all information
related to the program in case of substantial swapping activity.

2.If the swapping algorithm is not good, the composite method can
increase the number of Page Fault and decrease the overall processing
performance.
WHAT DOES MAIN MEMORY DO?
• Main memory’s job is to hold data that the CPU needs to
access frequently, such as instructions and data currently being
processed. Data can be accessed much more quickly than data
stored on disk Drives or other secondary storage
devices. Instructions are read into the CPU by an instruction
fetch unit, decoded by an instruction decode unit, and executed
by one or more execution units within the CPU.
WHERE DID THE TERM COME FROM?
• The term was coined by IBM engineer George Scalise in 1956 when he
designed RAMAC (Random Access Method of Accounting and Control), the
first commercial computer with a hard disk drive. In early computers, all
processing took place in the main memory because there was no hard disk
drive for long-term storage of programs and data. 

• The word main is used to distinguish it from external mass storage devices


such as Disk Drives. Other terms used to denote this type of memory
include RAM and primary storage.
• Today, most personal computers have both a hard disk drive for permanent
storage and random access memory (RAM) for temporary information that
must be available during program execution.
WHY DOES A COMPUTER NEED MAIN MEMORY?
• The computer can manipulate only data that is in the main memory. Therefore,
every program you execute and every file you access must be copies from
a storage device into the main-memory space. The amount of this space on a
computer is crucial because it determines how many programs can be executed at
one time and how much data can be readily available to a program.

• Because computers often have too little main memory to hold all the data they
need, computer engineers invented a technique called swapping, in which portions
of data are copied into main memory as they are needed. Swapping occurs when
there is no room in memory for needed data. When one portion of data is copied
into memory, an equal-sized portion is copied (swapped) out to make room.
Contiguous Allocation
• Main memory must support both OS and user processes
• Limited resource, must allocate efficiently
• Contiguous allocation is one early method
• Main memory usually into two partitions:
• Resident operating system, usually held in low memory with interrupt vector
• User processes then held in high memory
• Each process contained in single contiguous section of memory
Contiguous Allocation (Cont.)
• Relocation registers used to protect user processes from each
other, and from changing operating-system code and data
• Base register contains value of smallest physical address
• Limit register contains range of logical addresses – each logical address
must be less than the limit register
• MMU maps logical address dynamically
• Can then allow actions such as kernel code being transient and kernel
changing size
Hardware Support for Relocation and Limit Registers
Multiple-partition allocation
• Multiple-partition allocation
• Degree of multiprogramming limited by number of partitions
• Variable-partition sizes for efficiency (sized to a given process’ needs)
• Hole – block of available memory; holes of various size are scattered throughout memory
• When a process arrives, it is allocated memory from a hole large enough to accommodate it
• Process exiting frees its partition, adjacent free partitions combined
• Operating system maintains information about:
a) allocated partitions b) free partitions (hole)
Dynamic Storage-Allocation Problem
How to satisfy a request of size n from a list of free holes?

• First-fit: Allocate the first hole that is big enough

• Best-fit: Allocate the smallest hole that is big enough;


must search entire list, unless ordered by size
• Produces the smallest leftover hole

• Worst-fit: Allocate the largest hole; must also search


entire list
• Produces the largest leftover hole

First-fit and best-fit better than worst-fit in terms of speed and storage
utilization
Fragmentation
• External Fragmentation – total memory space exists to
satisfy a request, but it is not contiguous
• Internal Fragmentation – allocated memory may be slightly
larger than requested memory; this size difference is
memory internal to a partition, but not being used
• First fit analysis reveals that given N blocks allocated, 0.5 N
blocks lost to fragmentation
• 1/3 may be unusable -> 50-percent rule
Fragmentation (Cont.)

• Reduce external fragmentation by compaction


• Shuffle memory contents to place all free memory together in
one large block
• Compaction is possible only if relocation is dynamic, and is done
at execution time
• I/O problem
• Latch job in memory while it is involved in I/O
• Do I/O only into OS buffers
• Now consider that backing store has same fragmentation
problems
Segmentation
• Memory-management scheme that supports user view of memory
• A program is a collection of segments
• A segment is a logical unit such as:
main program
procedure
function
method
object
local variables, global variables
common block
stack
symbol table
arrays
User’s View of a Program
Logical View of Segmentation

4
1

3 2
4

user space physical memory space


Segmentation Architecture
• Logical address consists of a two tuple:
<segment-number, offset>,

• Segment table – maps two-dimensional physical


addresses; each table entry has:
• base – contains the starting physical address where the
segments reside in memory
• limit – specifies the length of the segment

• Segment-table base register (STBR) points to the


segment table’s location in memory

• Segment-table length register (STLR) indicates number


of segments used by a program;
segment number s is legal if s < STLR
Segmentation Architecture (Cont.)
• Protection
• With each entry in segment table associate:
• validation bit = 0  illegal segment
• read/write/execute privileges
• Protection bits associated with segments;
code sharing occurs at segment level
• Since segments vary in length, memory
allocation is a dynamic storage-allocation
problem
• A segmentation example is shown in the
following diagram
Segmentation Hardware
END

You might also like