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

Chapter Three Memory Management (Main Memory)

The document discusses various memory management techniques used in computer systems. It begins by introducing memory management and its purposes such as dynamically allocating memory to running processes. It then describes logical and physical address spaces and how the memory management unit maps between them. The rest of the document discusses specific memory management techniques like swapping, paging, segmentation and their advantages/disadvantages as well as differences between paging and segmentation. It also briefly covers direct memory access.

Uploaded by

Riyad Tamam
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
94 views

Chapter Three Memory Management (Main Memory)

The document discusses various memory management techniques used in computer systems. It begins by introducing memory management and its purposes such as dynamically allocating memory to running processes. It then describes logical and physical address spaces and how the memory management unit maps between them. The rest of the document discusses specific memory management techniques like swapping, paging, segmentation and their advantages/disadvantages as well as differences between paging and segmentation. It also briefly covers direct memory access.

Uploaded by

Riyad Tamam
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 33

Chapter Three

Memory management (Main memory)


Introduction
• The main purpose of a computer system is to execute programs.

• Program must be brought into memory and placed within a process for it to be run.

• Input queue or job queue :- collection of processes on the disk(storage) that are
waiting to be brought into memory to run the program.

• Memory management is a broad term that incorporates all processes and


methodologies for the effective use, allocation, monitoring and management of
computer memory.
Cont..
• Memory management allows an operating system (OS) to dynamically
distribute memory across all running processes, while ensuring optimal
performance.

• Memory management is the process of controlling and coordinating computer


memory, assigning portions called blocks to various running programs to
optimize overall system performance.

• Memory management resides in hardware, OS, programs and applications.


Address Space
Address uniquely identifies a location in the memory.

We have two types of addresses that are :-

Logical Address and


Physical Address.
.
Logical Address Space
The address generated by CPU is called logical (or virtual) address space.

 Processes are always uses virtual address space and they do not see physical
address.

The logical address is a virtual address and can be viewed by the user.

The user can’t view the physical address directly.

The logical address is used like a reference, to access the physical address.
Physical Address Space
The physical address is address that seen by memory unit and used to access
memory units.

Virtual addresses are mapped with physical addresses by memory management


unit.

It refers to a location in the memory unit.


Cont..
Identical logical address and physical address are generated by Compile-time
and Load time address binding methods.

The logical and physical address generated while run-time address binding
method differs from each other.

The logical address is generated by the CPU while program is running whereas,
the physical addres is computed by the MMU (Memory Management Unit).
Cont..
Memory-Management Unit (MMU)
Hardware device that maps virtual(Logical) to physical address.

In MMU scheme, the value in the relocation register is added to every address
generated by a user process at the time it is sent to memory.

The user program deals with logical addresses; it never sees the real physical
addresses.
Swapping
• For execution, each process must be placed in the main memory.

• Swapping is a mechanism in which a process can be swapped/moved


temporarily out of main memory to a backing store , and then brought back into
memory for continued execution.

• Swapping is a simple memory management technique used by the operating


system to increase the utilization of the processor by moving some blocked
process from the main memory to the secondary memory(hard disk).
Cont..
• Backing store is typically part of a hard disk that is used by a paging or
swapping system to store information not currently in main memory.

• Backing store is slower and cheaper than main memory.

• This technique uses Address binding which is the process of mapping the
program's logical addresses to corresponding physical or main memory
addresses.
Cont..
• Due to address binding methods, the process that is swapped out of main
memory occupies same address space.

• When it is swapped back to the main memory ,the binding is done at the
assembly or load time.
Advantage of swaps
 Swap is generally cheaper. There is no upfront premium and it reduces transactions costs.

Swap can be used to border risk, and long time period border is possible.

It provides flexible and maintains informational.

It has longer term than futures or options. Swaps will run for years, however forwards and
futures are for the relatively short term.

 Using swaps can give companies a better match between their liabilities and revenues.
Disadvantages of swaps
Early termination of swap before maturity may acquire a breakage cost.

Lack of liquidity.

It is subject to default risk


Paging
• Paging is a memory management scheme, which assigns a noncontiguous
address space to a process.

• Paging is implemented by breaking the main memory into fixed-sized blocks


that are called frames.

• The logical memory of a process is broken into the same fixed-sized blocks
called pages.

• The page size and frame size is defined by the hardware.


Cont..
• As we know, the process is to be placed in main memory for execution.

• So, when a process is to be executed, the pages of the process from the source
i.e. back store are loaded into any available frames in main memory.

• CPU generates the logical address for a process which consists of two parts that
are page number and the page offset.

• The page number is used as an index in the page table.


Cont..
• The page table contains the base address of each page that loaded in main
memory.

• This base address is combined with page offset to generate the address of the
page in main memory.
Advantages
•Allocating memory is easy and cheap
•Eliminates external fragmentation
•Data (page frames) can be scattered all over PM
•Pages are mapped appropriately anyway
•Allows demand paging and prepaging
•More efficient swapping
•No need for considerations about fragmentation
•Just swap out page least likely to be used
Disadvantages
•Longer memory access times (page table lookup)
•Defended page tables
•Inverted page tables
•Memory requirements (one entry per VM page)
•Internal fragmentation
Paging Vs Swapping
• Paging allows the memory address space of a process to be noncontiguous.

• Swapping allows multiple programs to run parallels in the operating system.

• Paging is more flexible as only pages of a process are moved.

• Swapping is less flexible as it moves entire process back and forth between
main memory and back store.

• Paging allows more processes to reside in main memory.

• Compared to paging swapping allows less processes to reside in main memory.


Segmentation
• Segmentation is one of the most common ways to achieve memory protection.

• Because internal fragmentation of pages takes place, the user’s view of memory
is lost.

• The user will view the memory as a combination of segments.

• In this type, memory addresses are not contiguous.

• Each memory segment is associated with a specific length and a set of


permissions.
Cont..
• When a process tries to access the memory it is first checked to see whether it
has the required permission to access the particular memory segment and
whether it is within the length specified by that particular memory segment.

• Memory segmentation is the division of a computer's primary memory into


segments or sections.

• Segments or sections are also used in object files of compiled programs when
they are linked together into a program image and when the image is loaded into
memory.
Cont..
Advantages of segmentation
• Allow the use of separate memory areas for the program code and data
• Permit a program to be placed into different areas of memory whenever the program
is end.
• Multitasking becomes easy
• The advantage of having separate code and data segments is that one program can
work on different sets of data.
• The reference logical addressed can be loaded into the instruction pointer (IP) and
run the program anywhere in the segment memory
• Programs are re-locatable so that programs can be run at any location in the memory
Disadvantages of segmentation
•External fragmentation is present
•Costly memory management algorithms.
•Segmentation finds free memory area big enough. .
•Segments of unequal size not suited as well for swapping
Paging Vs. Segmentation
Segmentation Paging

Program is divided into variable size segments Program is divided into fixed size pages

User or compiler is responsible for dividing the program into Division into pages is performed by the Operating System
segments

Segmentation is slower than paging Paging is faster than segmentation

Segmentation is visible to the user Paging is invisible to the user

Segmentation eliminates internal fragmentation Paging suffers from internal fragmentation

Segmentation suffers from external fragmentation There is no external fragmentation

Processor uses segment number, offset to calculate absolute Processor uses page number, offset to calculate absolute
address address

Operating System maintains a list of free holes in main Operating System maintains a free frame list
DMA
• Stands for "Direct Memory Access."

• DMA is a method of transferring data from the computer's RAM to another part
of the computer without processing or using the CPU.

• While most data that is input or output from your computer is processed by the
CPU, some data does not require processing, or can be processed by another
device.

• In these situations, DMA can save processing time and is a more efficient way
to move data from the computer's memory to other devices
Cont..
• DMA channels are used by high speed devices and they allow them to
communicate directly with the main memory (RAM) on our system.

• When DMA channels are used, CPU is not involved in the communication.
Contiguous Memory Allocation
• The main memory must accommodate both the operating system and the various user
processes.
• Therefore need to allocate different parts of the main memory in the most efficient
way possible.
• The memory is usually divided into two partitions: one for the resident operating
system, and one for the user processes.
• We may place the operating system in either low memory or high memory.
• With this approach each process is contained in a single contiguous section of
memory.
Cont..
• One of the simplest methods for memory allocation is to divide memory into
several fixed-sized partitions.

• Each partition may contain exactly one process.

• In this multiple-partition method, when a partition is free, a process is selected


from the input queue and loaded into the free partition.

• When the process terminates, the partition becomes available for another
process.
Cont..
• The contiguous memory allocation scheme can be implemented in operating
systems with the help of two registers, known as the base and limit registers.
Cont..
• The operating system keeps a table indicating which parts of memory are
available and which are occupied.

• Finally, when a process arrives and needs memory, a memory section large
enough for this process is delivered.

You might also like