0% found this document useful (0 votes)
19 views

Chapter-V Memory Management

The document discusses memory management techniques. It covers basic memory management concepts like memory partitioning and free space management. It then discusses virtual memory, including demand paging and segmentation. It explains how virtual memory allows for a larger logical address space than physical memory. Page replacement algorithms like FIFO and LRU are also summarized, including examples of how they work.

Uploaded by

shrey6346
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Chapter-V Memory Management

The document discusses memory management techniques. It covers basic memory management concepts like memory partitioning and free space management. It then discusses virtual memory, including demand paging and segmentation. It explains how virtual memory allows for a larger logical address space than physical memory. Page replacement algorithms like FIFO and LRU are also summarized, including examples of how they work.

Uploaded by

shrey6346
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

OPERATING SYSTEMS

OSY - 22516

UNIT-V
MEMORY MANAGEMENT

Mr. Naresh A. Kamble


POINTS TO BE COVERED
• INTRODUCTION
• BASIC MEMORY MANAGEMENT
• VIRTUAL MEMORY
• PAGE REPLACEMENT ALGORITHMS
INTRODUCTION
• Every process needs certain amount of memory for execution.

• Memory management is used to allocate memory space to


the processes and their data at the time of their execution.

• It also focus on
– Upgrading the performance of computer system

– Execution of multiple processes at the same time.

– Sharing same memory same among different processes.


BASICS OF MEMORY MANAGEMENT
• Memory management directly affects the execution time of a
process.

• Execution time of a process depends on the availability of


data in the main memory.

• Memory management ensures


– Accuracy

– Availability

– Consistency

• Of data imported from secondary memory to the main


memory.
MULTISTEP PROCESSING FOR A USER PROGRAM
BASICS OF MEMORY MANAGEMENT
• FUNCTIONS OF MEMORY MANAGEMENT

1. Process Isolation

2. Tracking of memory location

3. Automatic Allocation and management

4. Long Term storage

5. Support of modular programming

6. Protection and access control

7. Keeping status of main memory locations


BASICS OF MEMORY MANAGEMENT
• MEMORY PARTITIONING

• Memory is divided into 2 sections

• One for user and one for resident monitor


BASICS OF MEMORY MANAGEMENT
• STATIC ( FIXED SIZE) MEMORY PARTITIONING
BASICS OF MEMORY MANAGEMENT
• DYNAMIC( VARIABLE SIZE) MEMORY PARTITIONING
BASICS OF MEMORY MANAGEMENT
• FREE SPACE MANAGEMENT TECHNIQUES

• Files are created and deleted frequently.

• It is necessary to reuse the space from deleted files for new


files.

• To keep track of free disk space, the file system maintains a


free space list. It records all disk blocks which are free.
BASICS OF MEMORY MANAGEMENT
• BIT VECTOR
BASICS OF MEMORY MANAGEMENT
• LINKED LIST
BASICS OF MEMORY MANAGEMENT
• GROUPING
BASICS OF MEMORY MANAGEMENT
• COUNTING
VIRTUAL MEMORY
• BACKGROUND
• Virtual memory – separation of user logical memory from physical
memory.

– Only part of the program needs to be in memory for execution.

– Logical address space can therefore be much larger than physical


address space.

– Allows address spaces to be shared by several processes.

– Allows for more efficient process creation.

• Virtual memory can be implemented via:

– Demand paging

– Demand segmentation
Fig: Virtual Memory That is Larger Than Physical Memory
Fig: Virtual Address Space
Fig: Shared Library using Virtual Memory
VIRTUAL MEMORY
• PAGING

• Paging is a memory management technique by which a


computer stores and retrieves data from secondary storage
for use in main memory.

• In paging the operating system retrieves data from secondary


storage in same-size blocks called pages.
VIRTUAL MEMORY
• DEMAND PAGING

• Bring a page into memory only when it is needed


– Less I/O needed

– Less memory needed

– Faster response

– More users

• Page is needed → reference to it


– invalid reference → abort

– not-in-memory → bring to memory


VIRTUAL MEMORY
• With each page table entry a valid–invalid bit is associated

• (1 → in-memory, 0 → not-in-memory)

• Initially valid–invalid but is set to 0 on all entries

• During address translation, if valid–invalid bit in page table entry is


0→page fault

• • Example of a page table snapshot:


VIRTUAL MEMORY
• What happens if the process tries to access a page that was not brought
into memory?

• Access to a page marked invalid causes a page fault.

• The paging hardware, in translating the address through the page table,
will notice that the invalid bit is set, causing a trap to the operating
system.

• This trap is result of the operating system’s failure to bring the desired
page into memory
VIRTUAL MEMORY
• What happens if the process tries to access a page that was not brought
into memory?

• Access to a page marked invalid causes a page fault.

• The paging hardware, in translating the address through the page table,
will notice that the invalid bit is set, causing a trap to the operating
system.

• This trap is result of the operating system’s failure to bring the desired
page into memory
VIRTUAL MEMORY
• The procedure for handling this page fault is as follows.

1. Check an internal table for the process to determine whether the reference was a
valid or an invalid memory access.

2. If the reference was invalid, terminate the process. If it was valid, but page is not
yet brought, the get the page in memory.

3. Find a free frame from the list.

4. Schedule a disk operation to read the desired page into newly allocated frame.

5. When the disk read is complete, modify the internal table kept with the process
& the page table to indicate that the page is now in memory.

6. We restart the instructions that was interrupted by the trap. The process can now
access the page as though it had always been in memory
PAGE REPLACEMENT ALGORITHM
• These algorithms are developed to reduce PAGE FAULT
problem.

• For bringing the required page into main memory, if the space
is not available in memory then we need to remove the page
from the main memory for allocating the space to the new
page which needs to be executed.

• This procedure is called as page replacement.


PAGE REPLACEMENT ALGORITHM
• Steps in page replacement

• 1. Find the location of the desired page on disk

• 2. Find a free frame:


– If there is a free frame, use it

– If there is no free frame, use a page replacement algorithm to select a


victim frame

• 3. Read the desired page into the (newly) free frame. Update
the page and frame tables.

• 4. Restart the process


PAGE REPLACEMENT ALGORITHM
• FIFO (FIRST IN FIRST OUT) PAGE REPLACEMENT ALGORITHM

• FIFO page replacement algorithm uses the TIME when the


page was brought into memory

• Reference string: 1, 2, 3, 4, 2, 5, 3, 4, 2, 6, 7, 8, 7, 9, 7, 8, 2, 5,
4, 9.

• Page frame size : 3


• Reference string: 1, 2, 3, 4, 2, 5, 3, 4, 2, 6, 7, 8, 7, 9, 7, 8, 2, 5,
4, 9.

• Page frame size : 3

• PAGE FAULT : 14

RS 1 2 3 4 2 5 3 4 2 6 7 8 7 9 7 8 2 5 4 9

1 1 1 1 4 4 4 6 6 6 9 9 9 4 4

2 2 2 2 5 5 5 7 7 7 2 2 2 2

3 3 3 3 2 2 2 8 8 8 5 5 9

PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF
• Reference string: 1, 2, 3, 4, 2, 5, 3, 4, 2, 6, 7, 8, 7, 9, 7, 8, 2, 5,
4, 9.

• Page frame size : 4

• PAGE FAULT : 12

RS 1 2 3 4 2 5 3 4 2 6 7 8 7 9 7 8 2 5 4 9

1 1 1 1 1 5 5 5 5 9 9 9 9

2 2 2 2 2 6 6 6 6 2 2 2

3 3 3 3 3 7 7 7 7 5 5

4 4 4 4 4 8 8 8 8 4

PF PF PF PF PF PF PF PF PF PF PF PF PF
PAGE REPLACEMENT ALGORITHM
• LEAST RECENTLY USED (LRU) ALGORITHM

• LRU uses the TIME of the page that was last used.

• It looks backward in the time rather than forward.

• The LRU algorithm is implemented by making use of two


methods.

• A. COUNTER

• B. STACK
PAGE REPLACEMENT ALGORITHM
• A. COUNTERS

• A time-to-use field is associated with each page-table entry &


add to CPU a logical clock or counter.

• The clock is incremented for every memory reference.

• Whenever a reference to a page is made, the contents of the


clock register are copied to the time-of-use field in the page
table entry for that page.

• In this way we always have “time” of the last reference to


each page.
PAGE REPLACEMENT ALGORITHM
• B. STACK

• Keeps stack of page numbers.

• Whenever a page is referenced, it is removed from the stack


& put on the top of the stack.

• By this, the most recently used page is on the top & least used
page is at bottom.

• It uses a head pointer & a tail pointer.


• Reference string: 1, 2, 3, 4, 2, 5, 3, 4, 2, 6, 7, 8, 7, 9, 7, 8, 2, 5,
4, 9.

• Page frame size : 3

• PAGE FAULT : 16

RS 1 2 3 4 2 5 3 4 2 6 7 8 7 9 7 8 2 5 4 9

1 1 1 1 4 4 3 3 3 6 6 6 9 2 2 2 9

2 2 2 2 2 2 4 4 4 7 7 7 7 5 5 5

3 3 3 5 5 5 2 2 2 8 8 8 8 4 4

PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF
• Reference string: 1, 2, 3, 4, 2, 5, 3, 4, 2, 6, 7, 8, 7, 9, 7, 8, 2, 5,
4, 9.

• Page frame size : 4

• PAGE FAULT : 13

RS 1 2 3 4 2 5 3 4 2 6 7 8 7 9 7 8 2 5 4 9

1 1 1 1 1 5 6 6 6 6 2 2 2 2

2 2 2 2 2 2 2 2 9 9 5 5 5

3 3 3 3 3 7 7 7 7 7 4 4

4 4 4 4 8 8 8 8 8 9

PF PF PF PF PF PF PF PF PF PF PF PF PF PF
PAGE REPLACEMENT ALGORITHM
• OPTIMAL PAGE REPLACEMENT ALGORITHM (OPT)

• Want lowest page-fault rate

• Replace page that will not be used for longest period of time

• It uses the TIME when a page is to be used.


• Reference string: 1, 2, 3, 4, 2, 5, 3, 4, 2, 6, 7, 8, 7, 9, 7, 8, 2, 5,
4, 9.

• Page frame size : 3

• PAGE FAULT : 13

RS 1 2 3 4 2 5 3 4 2 6 7 8 7 9 7 8 2 5 4 9

1 1 1 1 4 4 4 6 7 7 7 2 2 4

2 2 2 2 5 5 5 5 8 8 8 5 5

3 3 3 3 2 2 2 2 9 9 9 9

PF PF PF PF PF PF PF PF PF PF PF PF PF PF
• Reference string: 1, 2, 3, 4, 2, 5, 3, 4, 2, 6, 7, 8, 7, 9, 7, 8, 2, 5,
4, 9.

• Page frame size : 4

• PAGE FAULT : 11

RS 1 2 3 4 2 5 3 4 2 6 7 8 7 9 7 8 2 5 4 9

1 1 1 1 1 5 5 5 5 9 9 9

2 2 2 2 2 2 2 2 2 5 5

3 3 3 3 6 7 7 7 7 4

4 4 4 4 8 8 8 8

PF PF PF PF PF PF PF PF PF PF PF PF

You might also like