0% found this document useful (0 votes)
257 views36 pages

Operating Systems: Prof. Navneet Goyal Department of Computer Science & Information Systems BITS, Pilani

The document discusses different memory management techniques used in operating systems. It covers topics like memory partitioning methods including fixed, variable, and dynamic partitioning. Paging and segmentation are introduced as basic building blocks of memory management. Placement algorithms for dynamic partitioning like first fit, best fit, next fit and worst fit are compared. The buddy system for allocating variable sized blocks is also summarized.

Uploaded by

devitosh
Copyright
© Attribution Non-Commercial (BY-NC)
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)
257 views36 pages

Operating Systems: Prof. Navneet Goyal Department of Computer Science & Information Systems BITS, Pilani

The document discusses different memory management techniques used in operating systems. It covers topics like memory partitioning methods including fixed, variable, and dynamic partitioning. Paging and segmentation are introduced as basic building blocks of memory management. Placement algorithms for dynamic partitioning like first fit, best fit, next fit and worst fit are compared. The buddy system for allocating variable sized blocks is also summarized.

Uploaded by

devitosh
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 36

Operating Systems

Prof. Navneet Goyal


Department of Computer Science & Information Systems
BITS, Pilani
Topics for Today
• Memory Management
▫ Requirements
• Partitioning
▫ Fixed
▫ Variable
▫ Dynamic
• Paging
• Segmentation
Memory Management
• Objective – to keep several processes in
memory
• Why we may want to do this?
▫ Increase CPU utilization
▫ Improve response times
• Many memory-management algorithms
• Selection of algorithm/scheme depends on
many factors (specially HW)
• Each algorithm requires its own HW
support
Memory Management
• Subdividing memory to accommodate
multiple processes
• Memory needs to be allocated efficiently
so as to pack as many processes into
memory as possible
Memory Management
• Basic Requirements
• Memory Partitioning
▫ Used only in Kernel Memory Management
• Building blocks of Memory Management
▫ Paging
▫ Segmentation
Virtual Memory
• Universal approach to Memory
Management
• Based on Paging or
• Combination of Paging & Segmentation
• Processes ‘get’ unlimited MM
• Virtual address space on disk
• Hardware support for Paging &
Segmentation
What Is Memory Management?
• Uni-programming System
2 partitions of Main Memory
 For OS
 For user program in execution
• Multiprogramming environment
▫ Many user processes
▫ Limited Main Memory
▫ User part of MM is partitioned by OS
Memory Management Requirements
• Relocation
• Protection
• Sharing
• Logical Organization
• Physical Organization
Relocation
• Programmer does not know where the
program will be placed in memory when it
is executed
• While the program is executing, it may be
swapped to disk and returned to main
memory at a different location (relocated)
• Memory references must be translated in
the code to actual physical memory
address
Protection
• Protecting OS from user processes
• Protecting User processes from one another
• Satisfying Relocation requirement increases
the difficulty of satisfying Protection
requirement
• Location of program in MM is unpredictable
Protection

• Dynamic calculation of addresses at run-time


• Memory references generated by process
must be checked at run time
• Operating system cannot anticipate all of the
memory references a program will make
• Protection is provided by Processor and not
by OS
Protection
Sharing
• Allow several processes to access the
same portion of memory
• Better to allow each process (person)
access to the same copy of the program
rather than have their own separate
copy
Logical Organization
• Programs are written in modules

• Modules can be written and compiled


independently

• Different degrees of protection given to


modules (read-only, execute-only)

• Share modules
Physical Organization
• 2-level organization of memory

• Flow of information between main &


secondary memory is a major concern

• Should programmers be burdened?

• Programmer does not know (at the time of


coding) how much space will be available
and where it will be
Memory Partitioning

• Fixed partitioning
▫ Equal size
▫ Unequal size
• Dynamic Partitioning
Fixed Partitioning
• Equal-size partitions
▫ any process whose size is less than or equal
to the partition size can be loaded into an
available partition
▫ if all partitions are full, the operating
system can swap a process out of a
partition
▫ a program may not fit in a partition. The
programmer must design the program with
overlays*
* Find out what is overlaying
Fixed Partitioning
• Main memory use is inefficient
• Any program, no matter how small,
occupies an entire partition
• This is called internal fragmentation
Placement Algorithm with Partitions
• Equal-size partitions
▫ Placement is trivial
▫ because all partitions are of equal size, it
does not matter which partition is used
• Unequal-size partitions
▫ can assign each process to the smallest
partition within which it will fit
▫ queue for each partition
▫ processes are assigned in such a way as to
minimize wasted memory within a partition
IBM Mainframe
OS – OS/MFT
Dynamic Partitioning
• Partitions are of variable length and
number
• Process is allocated exactly as much
memory as required
• Starts off well!
• Eventually leads to lot of holes in the
memory
• External fragmentation
• Must use compaction to shift processes so
they are contiguous and all free memory is
in one block
IBM Mainframe
OS – OS/MVT
Dynamic Partitioning Placement
Algorithm
• Since compaction is expensive, OS must
judiciously decide how to assign
processes to memory
• Operating system must decide which free
block to allocate to a process
▫ Best-fit algorithm
▫ First-fit algorithm
▫ Next-fit algorithm
▫ Worst-fit algorithm
Dynamic Partitioning Placement
Algorithm
• Best-fit algorithm
▫ Chooses the block that is closest in size to
the request
▫ Worst performer overall
▫ Since smallest block is found for process,
the smallest fragment is left
▫ Memory compaction must be done more
often
Dynamic Partitioning Placement
Algorithm
• First-fit algorithm
▫ Fastest
▫ May have many process loaded in the front
end of memory that must be searched over
when trying to find a free block
Dynamic Partitioning Placement
Algorithm
• Next-fit
▫ Begins to scan the memory from the location of
the last placement & chooses the next available
block that is large enough
▫ More often leads to allocation of a block at the
end of the memory
▫ Results in quick fragmentation of the largest
block of free memory which usually appears at
the end of the memory
▫ Compaction is required to obtain a large block
at the end of memory
Dynamic Partitioning Placement
Algorithm
• Worst-fit
▫ Scans the whole memory to find the biggest
block
▫ Holes are of substantial size
▫ Makes sense?
▫ Compare with Best-fit!
Worst-fit
Comparison of Placement
Algorithms
• First-fit is not only the simplest, but
usually the best and the fastest as well
• Next-fit produces slightly worse results
than First-fit
• Best-fit is usually the worst performer
Replacement Algorithms
• Which process to SWAP out?
▫ FIFO
▫ Optimal pare replacement
▫ LRU
▫ Counting based page replacement
 LFU
 MFU
Buddy System
• Entire space available is treated as a
single block of 2U
• If a request of size s such that 2U-1 < s <=
2U, entire block is allocated
▫ Otherwise block is split into two equal
buddies
▫ Process continues until smallest block
greater than or equal to s is generated

You might also like