0% found this document useful (0 votes)
7 views16 pages

Unit 2

Uploaded by

priyaoza189
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views16 pages

Unit 2

Uploaded by

priyaoza189
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Thursday, 04 July 2024

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

- This demonstrates a significant limiting factors of all


computers. They have only a finite amount of
memory and if a programme does not fit, then
either the size of the main memory must be increase
or the programme must be modify.

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)

Job 1(50k) in partition -1

Internal fragmentation
Job 4(25k) in partition -2

Empty partition
Job 2(50k) in partition -4
(b)

- There are significant consequences if The partition


size are too small, larger jobs will be rejects if they

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.

 Best-Fit Versus Frist-Fit Allocation:-


- For both fix and dynamic memory allocation scheme
the operating system must keep list of each memory
allocation which are free and which are busy then as
new jobs come into the system the free partition
must be allocated.
- This partition may be allocated on the basic of first-
fit memory allocation or Best-fit memory allocation.
- For both scheme the memory manager organized
the memory rest of the free and busy partition
either by size or by location.
- The best-fit allocation method keeps the free/best
list in order by size smallest to largest.
- The first-fit method the free/busy list organized by
memory allocation, low order memory to high order
memory.
- Each has advantages depending on the needs of the
particular allocation scheme best-fit usually may the
best use of memory space.
- “Frist-Fit is faster in making the allocation.”

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.

Note:- Yaad kerne ki trick

9
Frist-FitLocationIgnore Size
Best-FitSizeIgnore Time
 First-Fit:-

- The first-fit algorithm assumes that the memory


manager keep to list one for free memory blocks and
one for busy memory blocks.
- The operation consist of a simple look that compare
the size of each job to the size of each memory block
until a block is found that’s large enough to fit the
job.
- The job is stored into that block memory and the
memory manager move out of the loop to fetch the
next block from the entry queue.
- If the entire list is search then the job is placed into
the waiting queue.

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:-

1. Input memory block and process with a size.


2. Initialize all memory blocks as free.

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”

 Case 1. Joining Two free blocks:-


Before Deallocation

Beginning address Memory block Status


size
6785 600 Free
7560 20 Free
7600 200 Busy
7800 5 Free
10250 4050 Free
After Deallocation

Beginning address Memory block Status

13
size
6785 600 Free
7560 20 Free
7600 205 Free
Null
10250 4050 Free

- Using the DLL location algorithm, the system see


that the memory to be released is next to a free
memory block which start at location 7800 therefore
the least must be changed to reflect.
- 7600 which is combined total of the two free
partition (200 + 5).
 Case 2. Joining three free blocks:-
Before Deallocation

Beginning address Memory block size Status


6785 600 Free
7560 20 Free
7580 20 Busy
7600 205 Free
10250 4050 Free

After Deallocation

Beginning address Memory block size Status


6785 600 Free
7560 245 Free
Null
Null
10250 4050 Free

- Using the deallocation algorithm, the system learns


that the memory to be Do you look at these
14
between two free blocks of memory therefore, the
size of the three free partition (20 + 20 + 205).
Beginning address is 7560.
- The entry at location 7600 has been combined with
the previous entry. We must empty out this entry.
- We do that by changing the status to null entry with
no beginning address and no memory block size.
 Case 3. Deallocating an isolated
block:-
Before Deallocation with free list

Beginning Address Memory Block Size Status


6785 600 Free
7560 245 Free
Null
10250 4050 Free

Before Deallocation with busy list

Beginning Address Memory Size Block Status


7865 1000 Busy
8805 445 Busy
9250 1000 Busy

- To specify matters that’s look at the Busy list for the


memory area between location 7560 and 10250.
- Starting at 7560, that’s a free memory block of 245
so the busy memory area include everything from
location 7805 to 10250.
- Using the deallocation algorithm, the memory block
to be release is not adjacent any free blocks of

15
memory. It is between two others busy area.
Therefore the system must search the table for a null
entry.

After Deallocation Busy memory list

Beginning Address Memory Block Size Status


6780 600 Free
7560 245 Free
8805 445 Free
10250 4050 Free
After Deallocation Free Memory list

Beginning Address Memory Block Size Status


7805 1000 Busy
8805 445 Busy
9250 1000 Busy

16

You might also like