0% found this document useful (0 votes)
17 views13 pages

OSIMPM4&M5

The document discusses various memory management techniques in operating systems, including swapping, contiguous memory allocation, and memory allocation strategies such as first-fit, best-fit, and worst-fit. It explains paging and segmentation as methods for managing memory, detailing how logical addresses are mapped to physical addresses. Additionally, it covers virtual memory management and demand paging, highlighting the process of handling page faults.

Uploaded by

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

OSIMPM4&M5

The document discusses various memory management techniques in operating systems, including swapping, contiguous memory allocation, and memory allocation strategies such as first-fit, best-fit, and worst-fit. It explains paging and segmentation as methods for managing memory, detailing how logical addresses are mapped to physical addresses. Additionally, it covers virtual memory management and demand paging, highlighting the process of handling page faults.

Uploaded by

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

Unit – IV Operating Systems

Memory Management

1)explain Swapping ?
A process must be in memory to be executed. A process can be swapped temporarily out of memory
to a backing store, and then brought back into memory for continued execution.
Sometimes called “swap space,” “swap partition,” “swap disk”.
. When the higher-priority process finishes, the lower priority process can be swapped back in and
continued. This variant of swapping is sometimes called roll out, roll in.

Fig 2: Schematic View in Swapping

2)ExplainContiguous Memory Allocation?


The main memory is usually divided into two partitions: one for the resident operating system and
one for the user process. The operating system can be either in the low memory or high memory.
We want usually want several user processes to reside in memory at the same time. In contiguous
memory allocation, each process is contained in a single contiguous section of memory.

1|Page MemoryManagement
Unit – IV Operating Systems

Fig 3: Check base first, then validate that within limit

3)Explain Allocation of memory?

First-fit: allocates the first hole that is big enough. Searching can start either at the beginning of
the set of holes or where the previous first-fit search ended. The search stops as soon as it finds a
free hole that is large enough.

Best fit: Allocate a smallest hole that is big enough. This strategy produces the smallest leftover
hole.
Worst fit: Allocate the largest hole. This strategy produces the largest leftover hole, which may be
more useful than the smaller leftover hole from a best-fit approach.

2|Page MemoryManagement
Unit – IV Operating Systems

Fig 9: Example Memory configuration before and after Allocation of 16M Byte block

4)ESSAY :Paging in memory management?:


Paging is a memory-management scheme that permits the physical address of a process to be
noncontiguous. Divide logical memory (programs) into blocks of same size called pages. Divide
physical memory into equal sized partitions called frames (size is power of 2, between ½K and 8K).
The size of the page and frame must be equal.
When a process is to be executed, its pages are loaded into any available memory frames from the
disk. Page table is used to map the page number to corresponding frame number. The page table
contains the base address of the page (frame) in memory. Page number will be used as index for
the page table. Whenever program is loaded into memory the corresponding frame number is
updated to page table. In the fig 11, page 0 is loaded into frame 1, page 1 is loaded into frame 4,
page 2 is loaded into frame 3 and page 3 is loaded into frame 7. The frame numbers are updates to
page table. If a frame is allocated to one process it cannot be allocated to another process.

3|Page MemoryManagement
Unit – IV Operating Systems

CPU generates a logical address; every address generated by the CPU is divided into two parts: a
page number (p) and a page offset (d). The page number is used as index for the page table. The
page number is replaced with corresponding frame number as shown in fig 10. The MMU(memory
management unit) converts logical address into physical address. The base address + offset is sent
to MMU which is mapped to the corresponding physical page.

4|Page MemoryManagement
Unit – IV Operating Systems

In fig 12, the physical memory size is 28 bytes. So, it requires five bits to represent each bit(2 5).
The size of page is 4 bytes. So, it requires 2 bits to represent 4 bytes (2 2). So, d= 2 bits. 25 - 22 = 3
bits required page number.

5|Page MemoryManagement
Unit – IV Operating Systems

6|Page MemoryManagement
Unit – IV Operating Systems

5)ESSAYSegmentation IN Memory management?

Segmentation is a memory-management scheme that supports this user view of memory. A


logical address space is a collection of segments. Each segment has name and offset within
the segment. The segments are numbered and are referred to by a segment number, rather
by a segment name. Thus, a logical address consists of a <segment-number, offset>.
Whenever user compiles a program, it might create the following segments:

Fig 20: User’s view of program

1. The code
2. Global Variables
3. The heap, from which memory is allocated
4. The stacks used by each thread
5. The standard C library Hardware:

The segment table is used to map the two-dimensional logical address into one dimensional
physical address. Each entry in the segment table has a segment base and segment limit.
The segment base contains the starting physical address where the segment resides in
memory, whereas the segment limit specifies the length of the segment.

7|Page MemoryManagement
Unit – IV Operating Systems

Fig 21: Segmentation Hardware


A logical address consists of two parts: a segment number s, and an offset into that segment,
d. The segment number is used as an index to the segment table. The offset d of logical
address must be between 0 and the segment limit. If it is not, we trap to the operating system.
When an offset is legal, it is added to the segment base to produce the address in physical
memory of the desired byte.

Fig 22: Example of Segmentation


8|Page MemoryManagement
Unit – IV Operating Systems

6)ExplainVirtual Memory Management


Virtual Memory:
Virtual memory involves separation of logical memory from physical memory. This
separation allows an extremely large virtual memory to be provided for programmers when
only smaller memory is available (Fig 1). The programmer need not concentrate on the
amount of physical memory.

Fig 1: Diagram showing virtual memory that is larger than physical memory The
part of the program is in main memory and remaining part of memory will be in secondary
memory as shown in Fig 1. The virtual memory allows files and memory to be shared by
two or more processes through page sharing.

9|Page MemoryManagement
Unit – IV Operating Systems

6)Explain Demand Paging?


One option to execute a program is load the entire program into memory. Loading the entire
program into memory results in loading the executable code for all options regardless of
whether an option is ultimately selected by the user or not. An alternative strategy is to
initially load pages only as they are needed. This technique is known as Demand Paging
and is commonly used in virtual memory management.

Fig : Page table when some pages are not in main memory.
With each page table entry a valid–invalid bit is associated. If valid-invalid bit is ‘v’, the
associated page is both legal and in-memory. If the valid-invalid bit is ‘i’, the page is not
valid or is valid but currently on the disk

Fig 3: Address Translation in a paging system


10 | P a g e MemoryManagement
Unit – IV Operating Systems

CPU generates a virtual address and it contains page number and offset. The page number
is used as index of the page table. If its corresponding valid-invalid bit is ‘v’, then physical
address is generated by replacing page number in virtual address with corresponding frame
number. If the corresponding valid-invalid bit is ‘i’ then page fault is generated.
The procedure for handling page fault:
1) Check memory access is valid or invalid.
2) If the reference is invalid terminate the process. If it is valid and valid-invalid bit is
‘i’, page fault is generated and trap to Operating system.
3) Find the free frame in the main memory and requested page on the disk.
4) Load the requested page into free frame.
5) Update page table with the corresponding frame number. 6) Restart the defaulted
instruction.

Fig 4: Steps in handling page faults Performance


of Demand Paging:

11 | P a g e MemoryManagement
Unit – IV Operating Systems

Fig 7: Page Replacement FIFO

12 | P a g e MemoryManagement
Unit – IV Operating Systems

MODOLE 5

ESSAY

1)FILE ACCESS METHODS


2)FILE ALLOCATION METHODS
3)DIRECTORY STRUCTURE

13 | P a g e MemoryManagement

You might also like