# Operating System (CH 3)
# Operating System (CH 3)
By
Fikadu M.
[email protected]
Chapter Three
Memory Management
🠶 Introduction
🠶 Basic memory management
🠶 Multiprogramming with variable partitions - swapping
🠶 Virtual memory
🠶 Shared pages
🠶 segmentation
🠶 Over the years, people discovered the concept of a memory hierarchy, in which
computers have:
a few megabytes of very fast, expensive, volatile cache memory,
a few gigabytes of medium-speed, medium priced, volatile main memory,
and a few terabytes of slow, cheap, non-volatile disk storage, not to mention removable
storage, such as DVDs and USB sticks.
🠶 It is the job of the operating system to abstract this hierarchy into a useful model
and then manage the abstraction.
mechanism
keep track of which parts of memory are in use,
Keep track of unused (“free”) memory
Protect memory space
allocate memory to processes when they need
it,
de-allocate it when they are done.
Swap processes: memory <–> disk
Every program simply saw the physical memory. When a program executed
an instruction like
🠶 Thus the model of memory presented to the programmer was simply physical
memory,
🠶 Under these conditions, it was not possible to have two running programs in
memory at the same time.
🠶 If the first program wrote a new value to, say, location 2000, this would erase
whatever value the second program was storing there.
🠶 Nothing would work and both programs would crash almost immediately.
🠶 When the system is organized in this way, generally only one process at a
time can be running.
Backing store – fast disk large enough to accommodate copies of all memory images
for all users;
Roll out, roll in – swapping variant used for priority-based scheduling algorithms;
lower-priority process is swapped out so higher-priority process can be loaded and
executed.
🠶 Major part of swap time is transfer time; total transfer time is directly
proportional to the amount of memory swapped.
🠶 In Fig. 3-4(d) A is swapped out to disk. Then D comes in and B goes out.
1. Fixed partitioning
2. Dynamic partitioning
🠶 if all partitions are occupied, the operating system can swap a process out
of
a partition
🠶 a program may be too large to fit in a partition. The programmer must then
design the program with overlays
🠶 A hole of 64K is left after loading 3 processes: not enough room for another process
🠶 Eventually each process is blocked. The OS swaps out process 2 to bring in process
4
🠶 First-fit algorithm
Scans memory form the beginning and chooses the first available block that is large
enough
Fastest
🠶 Next-fit
Scans memory from the location of the last placement
🠶 worst fit
Allocate the largest hole; must also search entire list. Produces the largest leftover hole
🠶 it may be swapped to disk and return to main memory at a different location (relocated)
🠶 Thus, it avoids reading into memory pages that will not be used
in anyway, decreasing the swap time and the amount of
physical memory needed.
🠶 Reference String
The string of memory references is called reference string.
🠶 Want lowest page-fault rate.
🠶 Easy to implement, keep a list, replace pages from the tail and
add new pages at the head.
Lecture 3: Memory Management 3/ 3/ 202
39 Cont’d
…