19-Memory - Rose

Day 19
Memory Management
Main Memory


Holds user programs and operating system
code
Memory management involves managing
how main memory is shared among the
various processes.


The OS performs this function with support from
hardware.
A program that is running or ready or blocked
exists in main memory.
Requirements of memory
management





Relocation
Protection
Sharing
Logical organization
Physical organization
Assumptions


An entire program exists in main memory.
A program is stored as one contiguous block
in main memory.
Hardware support for memory
management



How to partition memory.
How to keep track of which partition belongs
to which process.
How to prevent a process from accessing a
partition that has not been allocated to it.
Fragmentation

Internal – space within an allocation block is not
completely used



Typical in allocation schemes that have fixed block sizes.
Can be reduced by making the block size small.
External – holes created between blocks that
cannot be used


Typical in allocation schemes where block sizes are not
fixed and are determined by the request.
Compaction must be performed frequently.
Fixed partitioning => fixed size
blocks
Equal sized
 All partitions are the
same size.
Un-equal sized
 Partitions are of un-equal
sizes.
Fixed partitioning disadvantages


Fixed partitioning is simple and very little OS
support is required.
However,


Since number of partitions is fixed, it limits the
degree of multi-programming
It is inefficient with small processes.

If the sizes of processes are known beforehand then a
reasonable size can be decided on.
Dynamic partitioning




Partitions are created dynamically
Sizes are not fixed and are determined
based on the request.
The number of partitions is also not fixed.
Disadvantages:


More external fragmentation
Placement is more complicated
Placement algorithms



First fit – start searching from the beginning
and allocate the first available block.
Next fit – start searching from the last
allocation and allocate the first available
block.
Best fit – start searching from the beginning
and allocate the available block that will result
in the smallest hole
Which do you think will keep the fragmentation to
the minimum?
In the following memory configuration,
where would a 16MB block be placed with
a. First Fit algorithm
b. Next Fit algorithm
c. Best Fit algorithm
Mark your answers on the diagram
Placement Algorithm
Keeping track of memory
From “Operating Systems” by Tannenbaum
Buddy System

Fixed partitioning



Dynamic partitioning



Limits # of active processes
Uses space inefficiently if the sizes of the processes don’t match with that of the
partitions.
More complex to maintain
Includes overhead of compaction
Buddy system

Blocks available are of size 2K, L <= K <=U






2L is the smallest block allocated
2U the largest block allocated and is the size of the entire memory available for allocation.
When a request is made, if the request is 2U-1 <= s <= 2U, then the entire block is
allocated. Else, split into 2U-1 sized buddy blocks
If 2U-2 <= s <= 2U-1, then allocate an entire 2U-1 buddy block. Else, split one of the 2U-1
blocks into 2U-2 sized buddy blocks
And so…
When two buddies become available (after a block is de-allocated), they are coalesced
together into one hole.
Buddy system
Using the Buddy algorithm, show how the memory block will
partitioned after each request/release.
3. Request C=64 K
4. Request D=256K
5. Release B
6. Release A
7. Request E=75K
8. Release C
9. Release E
10. Release D
Relocation






When a process is brought back to memory, it can
be placed anywhere and not its original location.
Address translation is therefore required.
Logical address – Address irrespective of where
the program is currently placed.
Relative address – an example of a logical address
typically relative to a value in a register or the
beginning of a program.
Physical address/absolute address – the actual
address in memory.
Dynamic run-time loading is required.