0% found this document useful (0 votes)
29 views35 pages

Chapter4-Memory Management

Memory management involves allocating memory efficiently to processes during execution. There are logical and physical addresses that map to memory locations. Memory can be allocated statically at compile time or dynamically during runtime. Dynamic allocation is more flexible but introduces overhead. Memory allocation strategies like first fit, best fit, and worst fit are used to allocate memory from holes efficiently and reduce fragmentation. Paging and swapping are used to virtualize memory.

Uploaded by

Prathamesh
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)
29 views35 pages

Chapter4-Memory Management

Memory management involves allocating memory efficiently to processes during execution. There are logical and physical addresses that map to memory locations. Memory can be allocated statically at compile time or dynamically during runtime. Dynamic allocation is more flexible but introduces overhead. Memory allocation strategies like first fit, best fit, and worst fit are used to allocate memory from holes efficiently and reduce fragmentation. Paging and swapping are used to virtualize memory.

Uploaded by

Prathamesh
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/ 35

Memory Management

By Shital Nalgirkar
RSCOE (COMP)
Memory Management: Basic concept
• Memory is used to store instructions and processed data.
• The memory comprises a large array or group of words or
bytes, each with its own location.
• The primary motive of a computer system is to execute
programs. These programs, along with the information
they access, should be in the main memory during
execution.
• The CPU fetches instructions from memory according to
2 the value of the program counter.
• Logical Address space: An address generated by the CPU is known as
“Logical Address”. It is also known as a Virtual address. Logical address
space can be defined as the size of the process. A logical address can be
changed.
• Physical Address space: An address seen by the memory unit (i.e the one
loaded into the memory address register of the memory) is commonly
known as a “Physical Address”. A Physical address is also known as a Real
address. The set of all physical addresses corresponding to these logical
addresses is known as Physical address space.

3
• Swapping :
• When a process is executed it must have resided in
memory. Swapping is a process of swap a process
temporarily into a secondary memory from the main
memory, which is fast as compared to secondary memory.

4
5
• Memory allocation:
• To gain proper memory utilization, memory must be
allocated efficient manner.
• One of the simplest methods for allocating memory is to
divide memory into several fixed-sized partitions and each
partition contains exactly one process.
• Thus, the degree of multiprogramming is obtained by the
number of partitions.
6
• Multiple partition allocation: In this method, a process is
selected from the input queue and loaded into the free
partition. When the process terminates, the partition
becomes available for other processes.
• Fixed partition allocation: In this method, the operating
system maintains a table that indicates which parts of
memory are available and which are occupied by
processes.

7
• Initially, all memory is available for user processes and is
considered one large block of available memory.
• This available memory is known as “Hole”.
• When the process arrives and needs memory, we search
for a hole that is large enough to store this process.
• If the requirement fulfills then we allocate memory to
process, otherwise keeping the rest available to satisfy
future requests.
8
• While allocating a memory sometimes dynamic storage
allocation problems occur, which concerns how to satisfy a
request of size n from a list of free holes. There are some
solutions to this problem:
First Fit:
• In the first fit, the first available free hole fulfills the
requirement of the process allocated.

9
10
• Here, in this diagram 40 KB memory block is the first
available free hole that can store process A (size of 25 KB),
because the first two blocks did not have sufficient memory
space.
• Best fit:-
• In the best fit, allocate the smallest hole that is big enough to
process requirements. For this, we search the entire list, unless
the list is ordered by size.

11
12
• Worst fit:-In the worst fit, allocate the largest available
hole to process. This method produces the largest leftover
hole.

13
• Fragmentation:
• A Fragmentation is defined as when the process is loaded and removed after
execution from memory, it creates a small free hole.
• These holes can not be assigned to new processes because holes are not
combined or do not fulfill the memory requirement of the process.
• To achieve a degree of multiprogramming, we must reduce the waste of
memory or fragmentation problem. In operating system two types of
fragmentation:
• Internal fragmentation
• External fragmentation

14
• Internal fragmentation:
• Internal fragmentation occurs when memory blocks are allocated to the
process more than their requested size. Due to this some unused space is
leftover and creates an internal fragmentation problem.
• Example: Suppose there is a fixed partitioning is used for memory
allocation and the different size of block 3MB, 6MB, and 7MB space in
memory. Now a new process p4 of size 2MB comes and demand for the
block of memory. It gets a memory block of 3MB but 1MB block memory
is a waste, and it can not be allocated to other processes too. This is called
internal fragmentation.

15
• External fragmentation
• In external fragmentation, we have a free memory block, but we can not
assign it to process because blocks are not contiguous.
• Example: Suppose (consider above example) three process p1, p2, p3
comes with size 2MB, 4MB, and 7MB respectively. Now they get memory
blocks of size 3MB, 6MB, and 7MB allocated respectively. After allocating
process p1 process and p2 process left 1MB and 2MB. Suppose a new
process p4 comes and demands a 3MB block of memory, which is
available, but we can not assign it because free memory space is not
contiguous. This is called external fragmentation.

16
Compaction
• We got to know that the dynamic partitioning suffers from external
fragmentation. However, this can cause some serious problems.
• Compaction is a technique to collect all the free memory present in form of
fragments into one large chunk of free memory, which can be used to run
other processes.
• It does that by moving all the processes towards one end of the memory and
all the available free space towards the other end of the memory so that it
becomes contiguous.

17
Paging
• In Operating Systems, Paging is a storage mechanism used
to retrieve processes from the secondary storage into the
main memory in the form of pages.
• One page of the process is to be stored in one of the frames
of the memory. The pages can be stored at the different
locations of the memory but the priority is always to find
the contiguous frames or holes.

18
Memory allocation

19
• Static Memory Allocation
• Static memory allocation is performed when the compiler compiles the
program and generate object files, linker merges all these object files and
creates a single executable file, and loader loads this single executable file
in main memory, for execution.
• In static memory allocation, the size of the data required by the process
must be known before the execution of the process initiates.
• wastage of memory.
• efficiency

20
• Dynamic Memory Allocation
• Dynamic memory allocation is performed while the program is in
execution. Here, the memory is allocated to the entities of the program
when they are to be used for the first time while the program is running.
• If the program is large enough then a dynamic memory allocation is
performed on the different parts of the program, which is to be used
currently. This reduces memory wastage and improves the performance of
the system.
• Allocating memory dynamically creates an overhead over the system. Some
allocation operations are performed repeatedly during the program
execution creating more overheads, leading in slow execution of the
21 program.
Advantages and Disadvantages
• Advantages of static allocation
• efficient
• no overheads
• faster execution
• Dynamic allocation advantages:
• flexible way of assigning the memory
• reduces the memory wastage
• improves system performance.
22
• Disadvantage's:
• Static:
• memory wastage
• Dynamic:
• overhead of assigning the memory to a process during the
time of its execution.

23
Memory allocation
• Contiguous Memory Allocation
• Taking into account the future growth of the file and its
request for memory, the operating system allocates
sufficient contiguous memory blocks to that file.
• Considering this future expansion and the file’s request for
memory, the operating system will allocate those many
contiguous blocks of memory to that file.

24
• In Contiguous memory allocation, when the process
arrives to the main memory for execution, the contiguous
memory blocks are allocated to the process according to its
requirement.
• Now, to allocate the contiguous space to user processes,
the memory can be divide either in the fixed-sized partition
or in the variable-sized partition.

25
• In the variable size partition method, the operating system analyses the
memory requirement of the process and see whether it has a memory block
of the required size. If it finds the match, then it allocates that memory
block to the process. If not, then it searches the ready queue for the process
that has a smaller memory requirement.
• If the memory block (hole) is too large for the process it gets spilt into two
parts. One part of the memory block is allocated to the arrived process and
the other part is returned to the set of holes. When a process terminates and
releases the memory allocated to it, the released memory is then placed
back to the set of holes. The two holes that are adjacent to each other, in
the set of holes, are merged to form one large hole.
26
• In the above section, we have seen, how the operating
system allocates the contiguous memory to the processes.
Here, we will see how the operating system selects a free
hole from the set of holes?
• The operating system uses either the block allocation list
or the bit map to select the hole from the set of holes.

27
• Block allocation list maintains two tables. One table
contains the entries of the blocks that are allocated to the
various files. The other table contains the entries of the
holes that are free and can be allocated to the process in the
waiting queue.
• Now, as we have entries of free blocks which one must be
chosen can be decided using either of these strategies:
first-fit, best-fit, worst-fit strategies.

28
• Bit Map
• The bit map method only keeps track of the free or
allocated block. One block is represented by one bit, bit 0
resembles the free block and bit 1 resembles that the block
is allocated to a file or a process.

29
Paging
• In Operating Systems, Paging is a storage mechanism used to retrieve
processes from the secondary storage into the main memory in the form of
pages.
• The main idea behind the paging is to divide each process in the form of
pages. The main memory will also be divided in the form of frames.
• One page of the process is to be stored in one of the frames of the memory.
The pages can be stored at the different locations of the memory but the
priority is always to find the contiguous frames or holes.
• Pages of the process are brought into the main memory only when they are
required otherwise they reside in the secondary storage.

30
• Advantages and Disadvantages of Paging
• Here is a list of advantages and disadvantages of paging −
• Paging reduces external fragmentation, but still suffer from
internal fragmentation.
• Paging is simple to implement and assumed as an efficient
memory management technique.
• Due to equal size of the pages and frames, swapping becomes
very easy.
• Page table requires extra memory space, so may not be good for a
31 system having small RAM.
Virtual memory
• A computer can address more memory than the amount physically installed
on the system. This extra memory is actually called virtual memory and it
is a section of a hard disk that's set up to emulate the computer's RAM.
• Virtual memory serves two purposes.
• First, it allows us to extend the use of physical memory by using disk.
• Second, it allows us to have memory protection, because each virtual
address is translated to a physical address.

32
• Demand Paging:
• A demand paging system is quite similar to a paging system with swapping
where processes reside in secondary memory and pages are loaded only on
demand, not in advance.
• When a context switch occurs, the operating system does not copy any of
the old program’s pages out to the disk or any of the new program’s pages
into the main memory Instead, it just begins executing the new program
after loading the first page and fetches that program’s pages as they are
referenced.

33
• While executing a program, if the program references a
page which is not available in the main memory because it
was swapped out a little ago, the processor treats this
invalid memory reference as a page fault and transfers
control from the program to the operating system to
demand the page back into the memory.

34
• Advantages
• Following are the advantages of Demand Paging −
• Large virtual memory.
• More efficient use of memory.
• There is no limit on degree of multiprogramming.
• Disadvantages
• Number of tables and the amount of processor overhead for
handling page interrupts are greater than in the case of the simple
paged management techniques.
35

You might also like