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

Main Memory

Uploaded by

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

Main Memory

Uploaded by

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

CHAPTER-8

Main Memory
Memory Management

Main memory is a large array of bytes, ranging in size from hundreds of


thousands to billions. Each byte has its own address.

0
1
2
3
4
.
.
n

2
Memory Management

For a program to be executed, it must be mapped to absolute


addresses and loaded into memory.
Eventually, the program terminates, its memory space is declared
available, and the next program can be loaded and executed.

To improve both the utilization of the CPU and the speed of the
computer’s response to its users, general-purpose computers must
keep several programs in memory, creating a need for memory
management.

3
Cont.

Memory management is the functionality of an operating system


which handles or manages primary memory.
Memory management keeps track of each and every memory
location, regardless of either it is allocated to some process or it is
free.
It checks how much memory is to be allocated to processes.
It decides which process will get memory at what time.
It tracks whenever some memory becomes unallocated and
correspondingly it updates the status.

4
8.1.1 Basic Hardware

Memory is divided into two parts.

OS area

User area

5
8.1.1 Basic Hardware

Not only are we concerned with the relative speed of accessing


physical memory, but we also must ensure correct operation.
For proper system operation we must protect the operating system
from access by user processes.
On multiuser systems, we must additionally protect user processes
from one another.
This protection must be provided by the hardware because the
operating system doesn’t usually interfere between the CPU and its
memory accesses.

6
Cont.

We first need to make sure that each process has a separate


memory space.
To separate memory spaces, we need the ability to determine the
range of legal addresses that the process may access and to ensure
that the process can access only these legal addresses.
We can provide this protection by using two registers, usually a
base and a limit.

7
Figure 8.1 A base and a limit register define a
logical address space.
The base register holds the smallest
legal physical memory address.
The limit register specifies the size
of the range.
For example, if the base register holds
30004 and the limit register is 12090,
then the program can legally access all
addresses from 30004 through 42094 .

8
8.1.3 Logical Versus Physical Address Space

Address uniquely identifies a location in the memory. We


have two types of addresses that are logical address and
physical address.
The logical address is generated by CPU during a
programs execution.
The logical address is used like a reference, to access the
physical address.
The physical address refers to a location in the memory
unit.

9
8.1.3 Logical Versus Physical Address Space

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.

10
Figure 8.4 Dynamic relocation using a relocation
register.

Reallocation memory
register
14000
logical Physical
address address
CPU +
346 14346

11
Cont.

The run-time mapping from virtual or logical to physical addresses


is done by a hardware device called the memory-management
unit (MMU).
The base register is now called a relocation register.
The value in the relocation register is added to every address
generated by a user process at the time the address is sent to
memory (see Figure 8.4).
For example, if the base is at 14000, then an attempt by the user to
address location 0 is dynamically relocated to location 14000; an
access to location 346 is mapped to location 14346.

12
8.1.4 Dynamic Loading

In dynamic loading, a routine of a program is not loaded


until it is called by the program.
All routines are kept on disk in a re-locatable load format.
The main program is loaded into memory and is
executed.
Other routines methods or modules are loaded on request.
Dynamic loading makes better memory space utilization
and unused routines are never loaded.

13
Advantages

The advantage of dynamic loading is that an unused


routine is never loaded.
It does not require special support from the operating
system. It is the responsibility of the users to design their
programs to take advantage.

14
8.2 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.

15
8.2 Swapping

Swapping is a mechanism in which a process can be


swapped temporarily out of main memory to a backing
store, and then brought back into memory for continued
execution.
Backing store is a usually a hard disk drive or any other
secondary storage which fast in access and large enough
to accommodate copies of all memory images for all
users. It must be capable of providing direct access to
these memory images.

16
Figure 8.5 Swapping of two processes using a
disk as a backing store.

17
8.2.2 Swapping on Mobile Systems

Although most operating systems for PCs and servers support some modified
version of swapping, mobile systems typically do not support swapping in any
form.

Mobile devices generally use flash memory rather than more spacious hard disks
as their persistent storage. The resulting space constraint is one reason why
mobile operating-system designers avoid swapping.
Other reasons include the poor throughput between main memory and flash
memory in these devices.

18
8.3 Contiguous Memory Allocation

The memory is usually divided into two partitions:


one for the resident operating system and one for the user
processes.
We can place the operating system in either low memory or high
memory.
The major factor affecting this decision is the location of the
interrupt vector. Since the interrupt vector is often in low memory,
programmers usually place the operating system in low memory as
well.
Thus, in this text, we discuss only the situation in which the
operating system resides in low memory.

19
Cont.

Contiguous memory allocation is one of the oldest memory


allocation schemes.
When a process needs to execute, memory is requested by the
process.
The size of the process is compared with the amount of contiguous
main memory available to execute the process.
If sufficient contiguous memory is found, the process is allocated
memory to start its execution.
Otherwise, it is added to a queue of waiting processes until
sufficient free contiguous memory is available.

20
8.3.2 Memory Allocation

There are two types of memory allocation.


1. Fixed-partition scheme
2. Variable-partition scheme

21
Fixed-partition scheme

One of the simplest methods for allocating memory is to divide


memory into several fixed-sized partitions.
Each partition may contain exactly one process.
The degree of multiprogramming is bound by the number of
partitions.
In this multiple partition method, 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.

22
Variable-partition scheme

In the variable-partition scheme, the operating system keeps a table


indicating which parts of memory are available and which are occupied.

As processes enter the system, they are put into an input queue. The operating
system takes into account the memory requirements of each process and the
amount of available memory space in determining which processes are
allocated memory.
When a process is allocated space, it is loaded into memory, and it can then
compete for CPU time.
When a process terminates, it releases its memory, which the operating system
may then fill with another process from the input queue.

23
Cont.

The memory blocks available comprise a set of holes of various sizes


scattered throughout memory.
When a process arrives and needs memory, the system searches the set
for a hole that is large enough for this process.
If the hole is too large, it is split into two parts. One part is allocated to
the arriving process; the other is returned to the set of holes.
When a process terminates, it releases its block of memory, which is then
placed back in the set of holes. If the new hole is adjacent to other holes,
these adjacent holes are merged to form one larger hole.

24
Cont.

This procedure is a particular instance of the general dynamic


storage allocation problem, which concerns how to satisfy a
request of size n from a list of free holes.
There are many solutions to this problem. The first-fit, best-fit,
and worst-fit strategies are the ones most commonly used to select
a free hole from the set of available holes.

25
Best - Fit

Best - Fit - chooses a partition that is smallest and whose size is greater than or
equal to k. It leaves small-sized unusable partitions or holes.

26
First - fit

First - fit - chooses the first partition whose size is greater than or equal to k.

27
Worst - fit

Worst - fit - chooses the largest partition and allocates it to process p. It can
leave bigger unusable partitions.

28
29
30

You might also like