Unit 2
Unit 2
Unit-2
Memory Management
Single User Contiguous Scheme:-
- Each program to be processed was loaded in its
entirely into memory and allocated as much
continuous space in memory as it needed.
- If the programme was too large and did not fit the
available memory space, it could not be executed.
- Early computers were physically large, they had very
little memory.
Main Memory value is 200k
Job List Main Memory
Job 1 = 30k
Job 2 = 50k(Waiting) Job 1 uses 30k
Job 3 = 30k(Waiting)
Reminder of main
Job 4 = 25k(Waiting)
memory is unused
1
Algorithm to load a job in single
user system:-
1. Store first memory location of programme into base
register(for memory protection).
2. Set programme counter to address of first memory
location.
3. Read first instruction of programme.
4. Increment programme counter by the number of
bits in instruction.
5. Has the last instruction in reached ?
- If yes, then stop loading.
- If no, then continue with step 6.
6. Is programme counter greater than memory size.
- If yes, then stop loading programme.
- If no, then continue with step 7.
7. Load instructions in memory.
8. Read next instruction in programme.
9. Go to STEP 4.
Fixed partition:-
- The first attempt to allow for multi programming use
fixed partition static partitions within the main
memory. Mumbai partition for each job.
- Because the size of each partition was design when
the system was power on, each portion could only
be reconfigure When the computer system was shut
down, reconfigure and restart.
- Once a partition was assigned to a job no other job
to be allowed to enter its boundary.
2
Algorithm load a job fixed
partition:-
1. Determined jobs request memory Size.
2. If job_size > larger size of partitions then reject the job.
- Print appropriate message to operator.
- Go to step one to handle next job in line.
Else
Continue with step 3.
3. Set computer to one.
4. Do while counter <=number of partition in memory
- If job > memory_partition_size(counter)
- Then counter = counter + 1
- Else
If memory_partition_size(counter) = “free”
Then load job into memory_partition(counter)
Change memory_partition_status(counter) to
“busy” go to step 1 to handle next job in line.
Else
Counter = counter + 1
End Do
5. No partitions available at this line, put job in waiting queue.
6. Move to step 1 to handle next job in line.
7. These politicians, kye is more flexible then the single user
scheme because it allowed several programs to be in memory
at the same time.
- It order to allocate memory space to jobs the
memory manager must keep a table, which so each
memory partition size, its Address it, its access
restriction and its current status.
3
Table:-
Partition Memory Access Cartesian
Size Address status
100K 200K Job 1 Busy
25K 300K Job 2 Busy
25K 325K Job 3 Free
50K 350K Job 4 Busy
Main Memory
Job list Partition 1=100k
Job 1 30k ------------------- -------------------------
200K
Job 2 50k < > Partition 2=25k Available
Job 3 30k (Waiting) Partition 3=25k
Job 4 25k < >Partition 4 =50k
(a)
Internal fragmentation
Job 4(25k) in partition -2
Empty partition
Job 2(50k) in partition -4
(b)
4
are too fit into the largest partition, or will wait if the
large partition are busy.
- As a result, large jobs may have a longer turnaround
time as they wait for partition or sufficient size may
never run.
- On the other hand if the partition size are too big,
memory is wasted if a job does not occupied the
entire partition the unused memory in the partition
will remain in active It can be given to another job
because each partition is allocated too only one job
at a time.
- These phenomime partial use of fixed partition the
creation of unused sprays with in the partition is
called internal fragmentation Hindi And is a major
pro back to the fix partition memory allocation
scheme.
Dynamic partition:-
- With dynamic partitions, available memory is still
kept in contiguous blocks but jobs are given only as
much memory as they request when they are loaded
for processing.
- Although this is a significant improvement over fixed
partitions because memory isn’t wasted within the
partition.
- dynamic partition scheme fully utilizes memory
when the first jobs are loaded. But as new jobs enter
the system that are not the same size as those.
- just vacated memory, they are fit into the available
spaces on a priority basis.
5
- demonstrates first-come, first-served-the
subsequent allocation of memory creates fragments
of free memory between blocks of allocated
memory. This problem is called external
fragmentation and, like internal fragmentation, lets
memory go to waste.
6
7
- There are free partition if 5k, 10k & 20k = 35k.
- If all information to execute job 8 which only require
= 30k how ever they are not continuous and because
the jobs are loaded in a continuous manner, this
scheme force to wait.
8
- For Ex.:-Imagen that you have turn your
collection at book into your library. Let’s say
you have books of all shapes and sizes and let’s
also say that their a continuous string optical
taking books out and bringing them that,
someone’s always waiting.
- There are two ways to organize your list.
1. By Size 2. By Location
- If they are organized by size the space for the
smallest book are at the top of the list are largest an
are at the bottom. When they are organized by the
location the space closest to your best at the top of
the of the list and the area far away or at the
bottom.
- Which option is waste ? ---- It dependant on what do
you want to optimise space or speed.
- A fast method of shelving books and if speed is
important it’s the best of two way alternative.
- It is not a good choice, if you have space is limited or
if many large books are return because large books
must wait for the large space. If all of your large
space are fill with small books the customers
returning the large book must wait until a suitable
space become available.
9
Frist-FitLocationIgnore Size
Best-FitSizeIgnore Time
First-Fit:-
10
- The memory manager fetches the next job and
repeat the process.
First-Fit Algorithm:-
1. Input memory blocks with size and processes.
2. Initialize all memory blocks as free.
3. Start by breaking each process and check if it can
be assigned to current block.
4. If sizeoff_job <= sizeoff_block.
If yes then assign and check for next process.
5. If not, then keep checking the further block.
Best-Fit:-
11
3. Start by picking each process and find the minimum
block size that can be assigned to current process.
- Find minimum(blocksize[1], blocksize[2],
blocksize[n]) > Processsize[current]
- if found then a sign into the current process.
4.
- One of the problem best fit algorithm, the entire
table must be searched.
Deallocation:-
- We have considered only the problem of how
memory blocks are allocated. But eventually there
comes a time when memory space must be released
or deallocate.
- For a fix the partition system, the process is quite
straight forward. When the job is completed, the
memory manager reset the status of the memory
blocks where the job was stored to “free”.
- A dynamic partition system uses a more complex
algorithm because the algorithm tries to combine
free areas of memory whenever possible. Therefore,
the system must be prepared for three alternative
situations.
- Case 1. When the block to be deallocated is adjacent
to another free block.
- Case 2. When the block to be deallocated is between
two free blocks.
- Case 3. When the block to be deallocated is isolated
from other free blocks.
Algorithm to deallocate memory
block:-
12
If job_location is adjacent to one or more free blocks
Then
If job_location is between two free blocks
Then merge all three blocks into one block
Memory_size = memory_size + job_size +
memory_size
Set status of memory_size to null entry.
Else
Merge both blocks into one
Memory_size is equal to memory_size + job_size
Else
Search for null entry in free memory list
Enter job_size and beginning_address in the entry slot
Set its status to “free”
13
size
6785 600 Free
7560 20 Free
7600 205 Free
Null
10250 4050 Free
After Deallocation
15
memory. It is between two others busy area.
Therefore the system must search the table for a null
entry.
16