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

OS Concept related to MM

The document discusses memory management concepts, including tracking memory locations, allocation policies, and techniques for allocating and deallocating memory. It covers partitioning methods (fixed and variable), paging, segmentation, and virtual memory, detailing their advantages and disadvantages. Key terms such as page fault, demand paging, working set, and page replacement policy are also explained.

Uploaded by

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

OS Concept related to MM

The document discusses memory management concepts, including tracking memory locations, allocation policies, and techniques for allocating and deallocating memory. It covers partitioning methods (fixed and variable), paging, segmentation, and virtual memory, detailing their advantages and disadvantages. Key terms such as page fault, demand paging, working set, and page replacement policy are also explained.

Uploaded by

doraemonxyz99
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Concept related to memory management

• It performs the following functions:


1. To keep track of all memory locations - free and allocated.
2. To decide memory allocation policy. i.e. which process should get how much
memory.
3. To use various techniques and algorithms to allocate and deallocate memory
locations.
RAM 4 GB
ROM 500 GB
OS App 1 App 2
OS (1.2 GB) (3 MB) (60 MB)
(1 GB)

App 1 App 2 System Call :


(2.3 MB) (52.1 MB)
1. Allocate a chunk of memory to process.
App 3 App 4 2. Free chunk of memory from a process.
(145.3 MB) (6.7 GB)

https://www.youtube.com/c/ComputerScienceAcademy7
A typical memory map for single user computer :
• The operating system like MS-DOS is single user operating system.
• It is also a single tasking system.
• The command interpreter of such operating system is invoked
Free when the computer is started.
Memory
• This operating system loads the program into memory and
Process assigns as much memory as possible.
Command
• It then sets the instruction pointer and executes the program.
Interpreter • If the program is terminated, it is removed from memory.
Kernel • The memory map for single user computer, consist of kernel,
command interpreter, the program to be executed and free
Fig. Memory map of single
user computer available memory.
• Kernel of operating system provides basic operating system
services while command interpreter interprets operating system
commands.
Partitioning
• Certain operating system uses partitioned memory management method, to
allow multiprogramming.
1. Fixed partitioning
• Partitioning means dividing main memory into various sections, these sections
are called partitions.
• These partitions could be of different sizes, but once decided they could not be
changed.
• Hence these partitions are called Fixed partitions.
• These partitions can be allocated to process by operating system.
• For example, a memory of 32 K words might be divided into regions of the
following sizes.
1. Fixed partitioning
• For example, a memory of 32 K words might be divided into regions of the
following sizes.
Resident monitor 10 K • As jobs enter the system, they are put in job
Monitor 10 K
queue.
Very small jobs Small Jobs up
4K to 4 K • The job scheduler takes into account the memory
Average jobs 6K Average Jobs requirement of each job and available regions in
up to 6 K
determining which jobs are allocated memory.
Large jobs 12 K Large Jobs up
to 12 K
• When job is allocated space, it is loaded into
region. It can then compete for CPU.
• When a job terminates, it releases its memory
Job 1 : 3 K
region, which a job scheduler may fill with
Job 2 : 4.5 K
Job 3 : 9.8 K
another job from the job queue.
• The fixed partition suffers from the problem of
X
Job 4 : 1.2 K
internal fragmentation (i.e. wastage of memory
space within partition).
• It also limits the degree of multiprogramming and
CPU utilization.
2. Variable partitioning
• The fixed partition suffers from the problem of internal fragmentation
(i.e. wastage of memory space within partition).
• It also limits the degree of multiprogramming and CPU utilization.
• Variable partitions overcomes these problems.
• In variable partitions the number of partitions and their sizes are
variable.
• They are not defined at the time of system generation.
• At any given time, any partition can be free or allocated to some process.
• In variable partition the starting address of any partition is not fixed.
0 0 0 0
Monitor Monitor Monitor Monitor
(40 K) (40 K) (40 K) (40 K)
40 k 40 k 40 k 40 k
Job 1
Job 1 Job 1 Job 1 Terminates Free
Memory
(60 K) (60 K) (60 K) (60 k)
100 k 100 k Allocate 100 k 100 k
Job 2 Job 4 (70 k) Job 4 Job 4
Job 2 Terminates Free (70 K) (70 K)
Memory
(100 K) (100 k) 170 K 170 K
Free (30 k) Free (30 k)
200 k 200 k 200 k 200 k
Job 3 Job 3 Job 3 Job 3
(30 K) (30 K) (30 K) (30 K)
230 k 230 k 230 k 230 k
Free Free Free Free
Memory Memory Memory Memory
256 K (26 k) 256 K (26 k) 256 K (26 k) 256 K (26 k)

Fig. Variable Partitions


• The fixed partition suffers from the problem of internal fragmentation i.e.
wastage of memory space within partition.
• If there is partition of 4 K size executing a job of 2 K size then there is wastage
of 2 K size.
• Variable partition suffers from external fragmentation.
• Suppose a job of size 7 K is terminated. A job of 2 K size may be loaded and
partition of 5 K remains unused. This causes memory wastage, called external
fragmentation.
• This problem can be solved by two techniques - 1. Compaction 2. Paging
1. Compaction
• Compaction changes allocation of memory to make free space contiguous, and
hence useful.
2. Paging
• Paging permits program's memory to be noncontiguous and thus allowing a
program to be allocated physical memory wherever it is available.
Paging
• The logical or virtual address space of a program is divided into equal sized pages,
and the physical main memory is also divided into equal sized page frames.
• The size of page is the same as that of page frame, so that a page can exactly fit into
a page frame, and therefore, it can be assigned to any page frame, which is free.
Frame Number
0 • When a computer program is to be
Page 0
executed, its pages are loaded into any
1
Page 0
1 available frames and
0
Page 1 1 4
2 • page table is defined to translate from
2 3 3 Page 2 user pages to memory frames.
Page 2
3 7 4 Page 1 • The page size is defined by hardware.
Page 3 • It is typically a power of 2.
Page table
5
Logical Memory • For example, it can be 1024 words or 2048
6 words per page.
App / Job / Process
(4 KB) 7 Page 3

Fig. Paging Model Physical Memory


Frame Number
0 • For example, for 1 MB (1024 KB) of
Page 0
memory,
1
Page 0
1
• and page size - 2 KB,
0
Page 1 2 • we will require 1024/2 = 512 page frames
1 4
2 3 3 Page 2 • numbering from 0 to 511 or
Page 2
3 7 4 Page 1
• from 000000000 to 111111111 in binary.
Page 3
Page table • Hence 9 high order bits of the address can
Logical Memory 5 be reserved to denote the page frame
App / Job / Process
6 number.
(8 KB) 7 Page 3
• Each page has 2 KB (2048) locations
numbering from 0 to 2047 (00000000000 to
Physical Memory
Fig. Paging Model 11111111111 ), thus requiring 11 bits for
displacement D.
• Thus the total address would be made up of
9 bits for page number + 11 bits for
displacement = 20 bits.
Frame Number
0 • 512 requires 9 bits, 1024 would require 10
1 Page 0 and 2048 would require 11 bits.
Page 0
0 1
Page 1 2 • For 2 MB of memory having page size 2 KB,
1 4
3 Page 2 we require 2048/2 = 1024 page frames.
Page 2 2 3
• Thus requiring 10 bits per page number +11
3 7 4 Page 1
Page 3 bits for displacement - 21 bits.
Page table
Logical Memory 5
6
App / Job / Process
(8 KB) 7 Page 3

Fig. Paging Model Physical Memory


Segmentation
• Segmentation is similar to that of paging.
• Pages are physical in nature and are of fixed size, whereas segments are logical
divisions of program, and they are of variable sizes.
• For instance, each program in executable form can be considered as consisting
of segments: code, data and stack.
• Each of the these can be further divided into further segments.
• In a program, normally we have a main program and some subprograms.
These can various functions such as "SQRT", it is prewritten and precompiled.
This is another segment.
Main
SQRT
Program
Segment 1 1400
Segment 0
Segment Limit Base Segment 0
2400
Sub 0 1000 1400
Data area 1 400 6300
Program
Segment 3 2 400 4300
Segment 2 3200
3 1100 3200 Segment 3
4 1000 4700 4300
Stack area Segment 2
Program Segment Table 4700
Segment 4
Segment 4
5700

• The segment table has a separate entry for each


segment, giving beginning address of segment in
physical memory and length of that segment. 6300
Segment 1
6700
Physical memory
Virtual memory
• The memory management techniques discussed so far, keeps many processes in
memory simultaneously to allow multiprogramming.
• However, they require the entire process to be in memory before the process can
execute.
• Virtual memory is a technique which allows the execution of processes that may not
completely in memory. Some part of it can be on disk. The main advantages of this is
that the user programs can be larger than physical memory.
• Virtual memory is difficult to implement and it decreases performance. They can be
implemented by paging, segmentation or combined schemes.
RAM 4 GB
OS App 1 App 2
(1.2 GB) (3 MB) (60 MB)
Virtual memory
• A program is divided into pages and some pages are loaded in memory while
rest remain on disk. Whenever they are required they are loaded in memory.

RAM 4 GB
OS App 1 App 2
(1.2 GB) (3 MB) (60 MB)

• following terms are commonly used with virtual memory


1. Locality of reference
• This is basic principle behind the virtual memory.
• In locality of reference, we forecast whether a page is likely to be referenced in
the near future, based on its past behavior and hence may be removed from
memory.
2. Page fault
• When process is executing with only a few pages in memory, and when an instruction
is encountered which refers to page outside main memory, a page fault occurs.
• At this stage, the operating system must bring the required page
3. Demand Paging
• In demand paging, a page is brought in only when demanded.
• When page fault result, then only page is loaded in memory.
• In this scheme, lots of pages remains in memory.
4. Working set
• At any time, a process has a number of pages in physical memory.
• Not all of these are actively referred.
• The set of pages which are actively referred is called working set.
• Working set decides the policy of bringing in pages from disk to main memory.
5. Page replacement policy
• As number of processes and number of pages in main memory increases, all
the page frames may get occupied.
• At this time, if a new page is to be brought in the operating system has to
overwrite some existing page in memory.
• The page chosen is selected by page replacement policy.

6. Dirty page / Dirty bit


• If the page in memory has been modified after it was loaded from the disk, is
called 'dirty page’.
• Now a days one bit is used to calculate modification of page.
• This bit is called dirty bit.
• If a page it dirty, it cannot be blindly overwritten, otherwise updates will be lost.

You might also like