0% found this document useful (0 votes)
53 views28 pages

Fixed Dynamic Mem Management DSB

This document discusses different techniques for managing memory in operating systems. It begins by describing fixed/static partitioning where main memory is divided into non-overlapping partitions of equal or unequal sizes. It then describes variable/dynamic partitioning where partitions are of variable lengths and processes are allocated exactly the amount of memory they require, which can lead to external fragmentation over time. The document also introduces the buddy system, which allocates memory in powers of two to reduce fragmentation issues.

Uploaded by

Pranav Kasliwal
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)
53 views28 pages

Fixed Dynamic Mem Management DSB

This document discusses different techniques for managing memory in operating systems. It begins by describing fixed/static partitioning where main memory is divided into non-overlapping partitions of equal or unequal sizes. It then describes variable/dynamic partitioning where partitions are of variable lengths and processes are allocated exactly the amount of memory they require, which can lead to external fragmentation over time. The document also introduces the buddy system, which allocates memory in powers of two to reduce fragmentation issues.

Uploaded by

Pranav Kasliwal
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/ 28

Operating Systems

Fixed/Variable
Partitioning

D S Bais
Real Memory Management
• Background
• Memory Management Requirements
• Fixed/Static Partitioning
• Variable/Dynamic Partitioning
• Simple/Basic Paging
• Simple/Basic Segmentation
• Segmentation with Paging

2
Contiguous Allocation
• An executing process must be loaded entirely in main
memory (if overlays are not used).
• Main memory is usually split into two (Memory split)
or more (Memory division) partitions:
– Resident operating system, usually held in low memory
partition with interrupt vector.
– User processes then held in high memory partitions.
• Relocation registers used to protect user processes
from each other, and from changing OS code and data:
– Base register contains value of smallest physical address.
– Limit register contains range of logical addresses –
each logical address must be less than the limit register.
– MMU maps logical address dynamically.
3
Real Memory Management Techniques

• Although the following simple/basic memory


management techniques are not used in
modern OSs, they lay the ground for a later
proper discussion of virtual memory:
– Fixed/Static Partitioning
– Variable/Dynamic Partitioning
– Simple/Basic Paging
– Simple/Basic Segmentation

4
Fixed Partitioning

• Partition main memory


into a set of non-
overlapping memory
regions called partitions.
• Fixed partitions can be of
equal or unequal sizes.
• Leftover space in
partition, after program
assignment, is called
internal fragmentation.
5
Placement Algorithm with Partitions

• Equal-size partitions:
– If there is an available partition, a process
can be loaded into that partition –
• because all partitions are of equal size, it does
not matter which partition is used.
– If all partitions are occupied by blocked
processes, choose one process to swap out to
make room for the new process.

6
Placement Algorithm with Partitions
• Unequal-size partitions,
use of multiple queues:
– assign each process to the
smallest partition within
which it will fit.
– a queue exists for each
partition size.
– tries to minimize internal
fragmentation.
– problem: some queues
might be empty while
some might be loaded.
7
Placement Algorithm with Partitions

• Unequal-size partitions,
use of a single queue:
– when its time to load a
process into memory,
the smallest available
partition that will hold
the process is selected.
– increases the level of
multiprogramming at
the expense of internal
fragmentation.
8
Dynamics of Fixed Partitioning

• Any process whose size is less than or


equal to a partition size can be loaded
into the partition.
• If all partitions are occupied, the OS can
swap a process out of a partition.
• A program may be too large to fit in a
partition. The programmer must design
the program with overlays.
9
Comments on Fixed Partitioning
• Main memory use is inefficient. Any program,
no matter how small, occupies an entire
partition. This can cause internal fragmentation.
• Unequal-size partitions lessens these problems
but they still remain ...
• Equal-size partitions was used in early IBM’s
OS/MFT (Multiprogramming with a Fixed
number of Tasks).

10
Variable Partitioning
– Degree of multiprogramming limited by number of partitions.
– Variable-partition sizes for efficiency (sized to a given process’ needs).
– Hole – block of available memory; holes of various size are scattered
throughout memory.
– When a process arrives, it is allocated memory from a hole large enough to
accommodate it.
– Process exiting frees its partition, adjacent free partitions combined.
– Operating system maintains information about:
a) allocated partitions b) free partitions (hole)

11
Managing allocated and free partitions
• Example: memory with 5 processes and 3 holes:
– tick marks show memory allocation units.
– shaded regions (0 in the bitmap) are free.

12
Memory Management with Linked Lists

13
Variable Partitioning: example

14
Internal/External Fragmentation
• There are really two types of fragmentation:
1. Internal Fragmentation –
allocated memory may be slightly larger than
requested memory; this size difference is
memory internal to a partition, but not being
used.
2. External Fragmentation –
total memory space exists to satisfy a size n
request, but that memory is not contiguous.

15
Reducing External Fragmentation
• Reduce external fragmentation by doing
compaction:
– Shuffle memory contents to place all free
memory together in one large block (or
possibly a few large ones).
– Compaction is possible only if relocation is
dynamic, and is done at execution time.
– I/O problem:
• Lock job in memory while it is involved in I/O.
• Do I/O only into OS buffers.
16
Comments on Variable Partitioning
• Partitions are of variable length and number.
• Each process is allocated exactly as much
memory as it requires.
• Eventually holes are formed in main memory.
This can cause external fragmentation.
• Must use compaction to shift processes so they
are contiguous; all free memory is in one block.
• Used in IBM’s OS/MVT (Multiprogramming
with a Variable number of Tasks).
17
Dynamic Storage-Allocation Problem

• Satisfy request of size n from list of free


holes – four basic methods:
– First-fit: Allocate the first hole that is big enough.
– Next-fit: Same logic as first-fit but starts search
always from the last allocated hole (need to keep a
pointer to this) in a wraparound fashion.
– Best-fit: Allocate the smallest hole that is big
enough; must search entire list, unless ordered by
size. Produces the smallest leftover hole.
– Worst-fit: Allocate the largest hole; must also
search entire list. Produces the largest leftover hole.
18
Placement Algorithms
• Used to decide which
free block to allocate to
a process of 16MB.
• Goal: reduce usage of
compaction procedure
(its time consuming).
• Example algorithms:
– First-fit
– Next-fit
– Best-fit
– Worst-fit (to imagine)
19
Comments on Placement Algorithms
• First-fit favors allocation near the beginning: tends to
create less fragmentation then Next-fit.
• Next-fit often leads to allocation of the largest block at
the end of memory.
• Best-fit searches for smallest block: the fragment left
behind is small as possible –
– main memory quickly forms holes too small to hold any
process: compaction generally needs to be done more often.

• First/Next-fit and Best-fit better than Worst-fit (name


is fitting) in terms of speed and storage utilization.
20
Replacement Algorithm
• When all processes in main memory are
blocked, the OS must choose which
process to replace:
– A process must be swapped out (to a
Blocked-Suspend state) and be replaced by
a process from the Ready-Suspend queue or
a new process.

21
Knuth’s Buddy System
• A reasonable compromise to overcome disadvantages
of both fixed and variable partitioning schemes.
• Memory allocated using power-of-2 allocation;
Satisfies requests in units sized as power of 2.
• Memory blocks are available in size of 2^{K} where L
<= K <= U and where:
– 2^{L} = smallest size of block allocatable.
– 2^{U} = largest size of block allocatable
(generally, the entire memory available).
• A modified form is used in Unix SVR4 for kernel
memory allocation.
22
Buddy System Allocation

23
Example of Buddy System

24
Tree Representation of Buddy System

25
Dynamics of Buddy System (1)
• We start with the entire block of size 2^{U}.
• When a request of size S is made:
– If 2^{U-1} < S <= 2^{U} then allocate the entire block of size
2^{U}.
– Else, split this block into two buddies, each of size 2^{U-1}.
– If 2^{U-2} < S <= 2^{U-1} then allocate one of the 2 buddies.
– Otherwise one of the 2 buddies is split again.
• This process is repeated until the smallest block greater or equal
to S is generated.
• Two buddies are coalesced whenever both of them become
unallocated.
26
Dynamics of Buddy System (2)
• The OS maintains several lists of holes:
– the i-list is the list of holes of size 2^{i}.
– whenever a pair of buddies in the i-list occur, they
are removed from that list and coalesced into a
single hole in the (i+1)-list.
• Presented with a request for an allocation of
size k such that 2^{i-1} < k <= 2^{i}:
– the i-list is first examined.
– if the i-list is empty, the (i+1)-list is then
examined ...
27
Comments on Buddy System
• Mostly efficient when the size M of memory
used by the Buddy System is a power of 2:
– M = 2^{U} “bytes” where U is an integer.
– then the size of each block is a power of 2.
– the smallest block is of size 1.
• On average, internal fragmentation is 25%
– each memory block is at least 50% occupied.
• Programs are not moved in memory:
– simplifies memory management.

28

You might also like