0% found this document useful (0 votes)
18 views

Lecture 2

Uploaded by

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

Lecture 2

Uploaded by

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

Computer Architecture(CTE214)

by
Engr. B.S. Muhammad(BEng. BUK, MSc. ABU)

Department of Computer Engineering, Kaduna Polytechnic


Lecture Two
Memory Management
Introduction

A memory is just like a human brain. It is used to store data and program
(sequence of instructions). Computer memory is the storage space in the
computer, where data is to be processed and instructions required for
processing are stored.
The memory is divided into large number of small parts called cells. Each
location or cell has a unique address, which varies from zero to memory size
minus one.
Memory is primarily of three types namely;
i. Cache Memory
ii. Primary Memory (Main Memory)
iii. Secondary Memory

Department of Computer Engineering


Cache Memory

Cache memory is a very high speed memory which is very near to the CPU. It acts
as a buffer between the CPU and the main memory. It is used to hold those parts of
data and program which are most frequently used by the CPU. The parts of data
and programs are transferred from the disk to cache memory by the operating
system, from where the CPU can access them.

Figure 2.1: Hierarchy


Department of Computer Engineering
The mode of operation is such that whatever file the User opens will be first stored
in the Main Memory, and whatever program that has to be executed will be sent to
the Cache.
The Cache will then send the program bit by bit to the register, and the register
will then send to the ALU to perform the prescribed operation.

Figure 2.2: Cache Memory

Department of Computer Engineering


Advantages
 Cache memory is faster than main memory.
 It consumes less access time as compared to main memory.
 It stores the program that can be executed within a short period of time.
 It stores data for temporary use.

Disadvantages
 Cache memory has limited capacity.
 It is very expensive.

Department of Computer Engineering


Primary Memory (Main Memory)

Primary memory holds only those data and instructions on which the computer is
currently working. The data and instruction required to be processed resides in the
main memory. This memory is not as fast as cache and registers It is divided into
two subcategories namely;
 Volatile and
 Non Volatile
The volatile memory (also referred to as the RAM) holds the data temporarily and
its erased whenever the system or program is shutdown.
The non-volatile memory (ROM) retains stored data even after the system is
shutdown

Department of Computer Engineering


Characteristics of Main Memory

 These are semiconductor memories.


 Small capacity compared to the secondary memories.
 It is relatively expensive
 Faster than secondary memories.
 A computer cannot run without the primary memory.

Department of Computer Engineering


Secondary Memory

This type of memory is also known as external memory. It is slower than the main
memory. These are used for storing data/information permanently. CPU directly
does not access these memories, instead they are accessed via input-output
routines.
The contents of secondary memories are first transferred to the main memory, and
then the CPU can access it. For example, HDD.

Department of Computer Engineering


Characteristics of Secondary Memory

 These are magnetic and optical memories.


 It is known as the backup memory.
 Cheap
 Large capacity
 Computer may run without the secondary memory.
 Slower than primary memories.

Department of Computer Engineering


Memory Hierarchy

A computer memory should be fast, large, and inexpensive. The memory hierarchy
is to obtain the highest possible access speed while minimizing the total cost of
memory system. The figure below gives the representation of the memory
hierarchy.

Department of Computer Engineering


Now, how do we manage the computer
memory?
What is Memory Management?

Memory Management is the process of controlling and coordinating


computer memory, assigning portions known as blocks to various running
programs to optimize the overall performance of the system.

The Goal of memory management is:


 To provide a convenient abstraction for programming
 To allocate scarce memory resources among competing processes to
maximize performance with minimal overhead.

Department of Computer Engineering


Memory Management Technique

Memory management technique is a way of organizing program in memory. In


multiprogramming, the techniques utilized for managing computer memory are
based on contiguous memory allocation and non-contiguous memory allocation.

Contiguous Memory Allocation


In contiguous memory allocation,
 Programs exist as a single block
 Difficult to find large enough block
 Low overhead
Furthermore, the memory can be contiguously allocated in the form of Fixed
partition or Dynamic partition.

Department of Computer Engineering


Non-Contiguous Memory Allocation
In non-contiguous memory allocation,
 Programs are divided into chunks called Segment
 Each segment can be placed in different parts of the memory
 Easier to find holes in which segment it will fit.

The following are the three key memory management techniques based on non-
contiguous memory allocation:
i. Swapping
ii. Segmentation
iii. Paging

Department of Computer Engineering


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.

Department of Computer Engineering


Department of Computer Engineering
Swapping involves performing two tasks called swapping in and swapping out.
The task of placing the blocks of data from the hard disk to the main memory is
called swapping in. On the other hand, the task of removing blocks of data from
main memory to the hard disk is called swapping out.

The swapping technique is useful when larger program is to be executed or some


operations have to performed on a large file.

Department of Computer Engineering


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, it's corresponding segmentation are loaded into non-
contiguous memory; though every segment is loaded into a contiguous block of
available memory.
The Segmentation technique works very similar to paging; but here segments are
of variable-length where as in paging pages are of fixed size. A program segments
are the program's main function, utility functions, data structures, and so on.

Department of Computer Engineering


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.

Department of Computer Engineering


Department of Computer Engineering
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.

Department of Computer Engineering


Department of Computer Engineering
 Page address is called logical address and represented by page number and the
offset. Therefore, Logical Address = Page number + page offset
 Frame address is called physical address and represented by a frame number
and the offset. Therefore, Physical Address = Frame number + page offset

A data structure called page map table is used to keep track relation between page
of a process to a frame in physical memory.

Department of Computer Engineering


Department of Computer Engineering
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. And when a process is to be executed, it's 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 paging concept will come into picture. When a
computer runs out of RAM, the 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 OS keeps removing idle pages from main memory and write
them on secondary memory and bring them back when required by the program.

Department of Computer Engineering

You might also like