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

Os Unit 4 Notes

Uploaded by

Shlok Gaikwad
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)
40 views13 pages

Os Unit 4 Notes

Uploaded by

Shlok Gaikwad
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 4

Memory Management
Q. Explain Memory Management: Memory Management Requirement?

 Memory management keeps track of the status of each memory location, whether it is allocated or
free.
 It allocates the memory dynamically to the programs at their request and frees it for reuse when it
is no longer needed.
 Memory management meant to satisfy some requirements that we should keep in mind.
 These Requirements of memory management are:
1. Relocation –
 The available memory is generally shared among a number of processes in a
multiprogramming system, so it is not possible to know in advance which other programs will be
resident in main memory at the time of execution of this program.
 Swapping the active processes in and out of the main memory enables the operating system to have
a larger pool of ready-to-execute process.
 When a program gets swapped out to a disk memory, then it is not always possible that when it is
swapped back into main memory then it occupies the previous memory location, since the location
may still be occupied by another process.
 We may need to relocate the process to a different area of memory.
 Thus, there is a possibility that program may be moved in main memory due to swapping.

 The figure depicts a process image. The process image is occupying a continuous region of main
memory.
 The operating system will need to know many things including the location of process control
information, the execution stack, and the code entry.
 Within a program, there are memory references in various instructions, and these are called logical
addresses.
 After loading of the program into main memory, the processor and the operating system must be able
to translate logical addresses into physical addresses.

1
 Branch instructions contain the address of the next instruction to be executed. Data reference
instructions contain the address of byte or word of data referenced.
 The figure depicts a process image.
 The process image is occupying a continuous region of main memory.
 The operating system will need to know many things including the location of process control
information, the execution stack, and the code entry.
 Within a program, there are memory references in various instructions, and these are called logical
addresses.
 After loading of the program into main memory, the processor and the operating system must be able
to translate logical addresses into physical addresses.
 Branch instructions contain the address of the next instruction to be executed. Data reference
instructions contain the address of byte or word of data referenced.

2. Protection –
 There is always a danger when we have multiple programs at the same time as one program may
write to the address space of another program.
 So, every process must be protected against unwanted interference when other process tries to write
in a process whether accidental or incidental.
 Between relocation and protection requirement a trade-off occurs as the satisfaction of relocation
requirement increases the difficulty of satisfying the protection requirement.
 Prediction of the location of a program in main memory is not possible, that’s why it is impossible to
check the absolute address at compile time to assure protection.
 Most of the programming language allows the dynamic calculation of address at run time.
 The memory protection requirement must be satisfied by the processor rather than
the operating system because the operating system can hardly control a process when it occupies the
processor.
 Thus, it is possible to check the validity of memory references.

3. Sharing –
 A protection mechanism must have to allow several processes to access the same portion of main
memory.
 Allowing each processes access to the same copy of the program rather than have their own separate
copy has an advantage.
 For example, multiple processes may use the same system file and it is natural to load one copy of
the file in main memory and let it shared by those processes.
 It is the task of Memory management to allow controlled access to the shared areas of memory
without compromising the protection.
 Mechanisms are used to support relocation supported sharing capabilities.

4. Logical Organization –
 Main memory is organized as linear or it can be a one-dimensional address space which consists of
a sequence of bytes or words.
 Most of the programs can be organized into modules, some of those are unmodifiable (read-only,
execute only) and some of those contain data that can be modified.
 To effectively deal with a user program, the operating system and computer hardware must support
a basic module to provide the required protection and sharing.
2
 It has the following advantages:
 Modules are written and compiled independently and all the references from one module to another
module are resolved by `the system at run time.
 Different modules are provided with different degrees of protection.
 There are mechanisms by which modules can be shared among processes.
 Sharing can be provided on a module level that lets the user specify the sharing that is desired.

5. Physical organization –
 The structure of computer memory has two levels referred to as main memory and secondary
memory.
 Main memory is relatively very fast and costly as compared to the secondary memory. Main
memory is volatile.
 Thus, secondary memory is provided for storage of data on a long-term basis while the main
memory holds currently used programs.
 The major system concern between main memory and secondary memory is the flow of information
and it is impractical for programmers to understand this for two reasons:
 The programmer may engage in a practice known as overlaying when the main memory
available for a program and its data may be insufficient.
 It allows different modules to be assigned to the same region of memory. One disadvantage is that it
is time-consuming for the programmer.
 In a multiprogramming environment, the programmer does not know how much space will be
available at the time of coding and where that space will be located inside the memory.

Q. Explain Memory Partitioning: Fixed Partitioning, Dynamic Partitioning?

 In operating systems, Memory Management is the function responsible for allocating and managing
a computer’s main memory.
 Memory Management function keeps track of the status of each memory location, either allocated
or free to ensure effective and efficient use of Primary Memory.
 There are two Memory Management Techniques: Contiguous, and Non-Contiguous.
 In Contiguous Technique, executing process must be loaded entirely in the main memory.
Contiguous Technique can be divided into:
Fixed (or static) partitioning
Variable (or dynamic) partitioning

 Fixed Partitioning:

 This is the oldest and simplest technique used to put more than one process in the main memory.
 In this partitioning, the number of partitions (non-overlapping) in RAM is fixed but the size of each
partition may or may not be the same.
 As it is a contiguous allocation, hence no spanning is allowed. Here partitions are made before
execution or during system configure.

3
 As illustrated in above figure, first process is only consuming 1MB out of 4MB in the main
memory.
 Hence, Internal Fragmentation in first block is (4-1) = 3MB.
 Sum of Internal Fragmentation in every block = (4-1)+(8-7)+(8-7)+(16-14)= 3+1+1+2 = 7MB.
 Suppose process P5 of size 7MB comes. But this process cannot be accommodated in spite of
available free space because of contiguous allocation (as spanning is not allowed). Hence, 7MB
becomes part of External Fragmentation.
There are some advantages and disadvantages of fixed partitioning.

Advantages of Fixed Partitioning –


1. Easy to implement:
 Algorithms needed to implement Fixed Partitioning are easy to implement.
 It simply requires putting a process into a certain partition without focusing on the emergence
of Internal and External Fragmentation.
2. Little OS overhead:
 Processing of Fixed Partitioning requires lesser excess and indirect computational power.

Disadvantages of Fixed Partitioning –


1. Internal Fragmentation:
 Main memory use is inefficient. Any program, no matter how small, occupies an entire partition.
This can cause internal fragmentation.

2. External Fragmentation:
 The total unused space (as stated above) of various partitions cannot be used to load the
processes even though there is space available but not in the contiguous form (as spanning is not
allowed).

3. Limit process size:


 Process of size greater than the size of the partition in Main Memory cannot be accommodated.
 The partition size cannot be varied according to the size of the incoming process size.
 Hence, the process size of 32MB in the above-stated example is invalid.
4
4.Limitation on Degree of Multiprogramming:
 Partitions in Main Memory are made before execution or during system configure.
 Main Memory is divided into a fixed number of partitions.
 Suppose if there are n1 partitions in RAM and n2 are the number of processes, then n2 <=
n1 condition must be fulfilled.
 Number of processes greater than the number of partitions in RAM is invalid in Fixed
Partitioning.

Dynamic Partitioning or Variable Partitioning –


 It is a part of Contiguous allocation technique.
 It is used to alleviate the problem faced by Fixed Partitioning.
 In contrast with fixed partitioning, partitions are not made before the execution or
during system configure.
 Various features associated with variable Partitioning-
 Initially RAM is empty and partitions are made during the run-time according to process’s
need instead of partitioning during system configure.
 The size of partition will be equal to incoming process.
 The partition size varies according to the need of the process so that the internal
fragmentation can be avoided to ensure efficient utilization of RAM.
 Number of partitions in RAM is not fixed and depends on the number of incoming process
and Main Memory’s size.

 There are some advantages and disadvantages of variable partitioning over fixed partitioning as
given below.
 Advantages of Variable Partitioning –
1. No Internal Fragmentation:
 In variable Partitioning, space in main memory is allocated strictly according to the need of
process.
 Hence there is no case of internal fragmentation.
 There will be no unused space left in the partition.
2. No restriction on Degree of Multiprogramming:
 More number of processes can be accommodated due to absence of internal fragmentation.

5
 A process can be loaded until the memory is empty.
3. No Limitation on the size of the process:
 In Fixed partitioning, the process with the size greater than the size of the largest partition could
not be loaded and process cannot be divided as it is invalid in contiguous allocation technique.
 Here, In variable partitioning, the process size can’t be restricted since the partition size is
decided according to the process size.

Disadvantages of Variable Partitioning –


1. Difficult Implementation:
 Implementing variable Partitioning is difficult as compared to Fixed Partitioning as it involves
allocation of memory during run-time rather than during system configure.
2. External Fragmentation:
 There will be external fragmentation inspite of absence of internal fragmentation.
 For example, suppose in above example- process P1(2MB) and process P3(1MB) completed
their execution.
 Hence two spaces are left i.e. 2MB and 1MB. Let’s suppose process P5 of size 3MB comes.
 The empty space in memory cannot be allocated as no spanning is allowed in contiguous
allocation.
 The rule says that process must be contiguously present in main memory to get executed.
 Hence it results in External Fragmentation.

Q. Explain Buddy System in detail?

 Buddy allocation system is an algorithm in which a larger memory block is divided into small
parts to satisfy the request.
 This algorithm is used to give best fit. The two smaller parts of block are of equal size and called
as buddies.
 The buddy memory allocation technique is a memory allocation algorithm that divides memory
into partitions to try to satisfy a memory request as suitably as possible.
 This system makes use of splitting memory into halves to try to give a best fit.
 Static partition schemes suffer from the limitation of having the fixed number of active processes
and the usage of space may also not be optimal.
 The buddy system is a memory allocation and management algorithm that manages memory in
power of two increments.
 Assume the memory size is 2U, suppose a size of S is required.
 If 2U-1<S<=2U: Allocate the whole block
 Else: Recursively divide the block equally and test the condition at each time, when it satisfies,
allocate the block and get out the loop.
 System also keep the record of all the unallocated blocks each and can merge these different size
blocks to make one big chunk.

Advantage –
 Easy to implement a buddy system
 Allocates block of correct size
 It is easy to merge adjacent holes

6
 Fast to allocate memory and de-allocating memory

Disadvantage –
 It requires all allocation unit to be powers of two
 It leads to internal fragmentation
 Example –
Consider a system having buddy system with physical address space 128 KB.
 Calculate the size of partition for 18 KB process.
 So, size of partition for 18 KB process = 32 KB. It divides by 2, till possible to get minimum block
to fit 18 KB.

Q. Explain Relocation in detail with diagram?

 Relocation is the process of assigning load addresses for position-dependent code and data of
a program and adjusting the code and data to reflect the assigned addresses.
 Relocation problem. Having multiple partitions presents a problem:
 This means that references to particular memory addresses within the program won't be the
same every time the program runs.
 For example, the program might call a particular function that begins 1024 bytes into the
program.
 Memory management keeps track of the status of each memory location, whether it is
allocated or free.
 It allocates the memory dynamically to the programs at their request and frees it for reuse
when it is no longer needed.
 Memory management meant to satisfy some requirements that we should keep in mind.
These Requirements of memory management are:
 Relocation – The available memory is generally shared among a number of processes in a
multiprogramming system, so it is not possible to know in advance which other programs will
be resident in main memory at the time of execution of this program.
 Swapping the active processes in and out of the main memory enables the operating system to
have a larger pool of ready-to-execute process.
 When a program gets swapped out to a disk memory, then it is not always possible that when it is
swapped back into main memory then it occupies the previous memory location, since the location
may still be occupied by another process.
7
 We may need to relocate the process to a different area of memory.
 Thus, there is a possibility that program may be moved in main memory due to swapping.
 The figure depicts a process image.
 The process image is occupying a continuous region of main memory.
 The operating system will need to know many things including the location of process control
information, the execution stack, and the code entry.
 Within a program, there are memory references in various instructions and these are called logical
addresses.
 After loading of the program into main memory, the processor and the operating system must be
able to translate logical addresses into physical addresses.
 Branch instructions contain the address of the next instruction to be executed. Data reference
instructions contain the address of byte or word of data referenced.

Q. Explain Paging in detail?

 Paging is a fixed size partitioning scheme.


 In paging, secondary memory and main memory are divided into equal fixed
size partitions.
 The partitions of secondary memory are called as pages.
 The partitions of main memory are called as frames.
 Each process is divided into parts where size of each part is same as page size.

8
 The size of the last part may be less than the page size.
 The pages of process are stored in the frames of main memory depending upon
their availability.

Example
 Consider a process is divided into 4 pages P0, P1, P2 and P3.
 Depending upon the availability, these pages may be stored in the main memory
frames in a non-contiguous fashion as shown

Translating Logical Address into Physical Address-

 CPU always generates a logical address.


 A physical address is needed to access the main memory.

Following steps are followed to translate logical address into physical address-

Step-01:

CPU generates a logical address consisting of two parts-


1. Page Number
2. Page Offset

 Page Number specifies the specific page of the process from which CPU wants
to read the data.
 Page Offset specifies the specific word on the page that CPU wants to read.

9
Step-02:
For the page number generated by the CPU,
 Page Table provides the corresponding frame number (base address of the
frame) where that page is stored in the main memory.

Step-03:

 The frame number combined with the page offset forms the required physical
address.

 Framenumber specifies the specific frame where the required page is stored.
 Page Offset specifies the specific word that has to be read from that page .
Diagram-
The following diagram illustrates the above steps of translating logical address into
physical address-

Advantages-
The advantages of paging are-
 It allows to store parts of a single process in a non-contiguous fashion.
 It solves the problem of external fragmentation.

10
Disadvantages-
The disadvantages of paging are-
 It suffers from internal fragmentation.
 There is an overhead of maintaining a page table for each process.
 The time taken to fetch the instruction increases since now two memory accesses are required.

Q. Write a note on Segmentation in detail?

 A process is divided into Segments.


 The chunks that a program is divided into which are not necessarily all of the same sizes are
called segments.
 Segmentation gives the user’s view of the process which paging does not give.
 Here the user’s view is mapped to physical memory.
 Segmentation is another non-contiguous memory allocation technique.
 In segmentation, process is not divided blindly into fixed size pages.
 Rather, the process is divided into modules for better visualization.
Characteristics of Segmentation-
 Segmentation is a variable size partitioning scheme.
 In segmentation, secondary memory and main memory are divided into partitions of unequal size.
 The size of partitions depend on the length of modules.
 The partitions of secondary memory are called as segments.

There are types of segmentation:

 Virtual memory segmentation – Each process is divided into a number of segments, not all of
which are resident at any one point in time.
 Simple segmentation – Each process is divided into a number of segments, all of which are
loaded into memory at run time, though not necessarily contiguously.
11
 There is no simple relationship between logical addresses and physical addresses in segmentation.
 A table stores the information about all such segments and is called Segment Table.
 Segment Table – It maps two-dimensional Logical address into one-dimensional Physical
address. It’s each table entry has:
 Base Address: It contains the starting physical address where the segments reside in memory.
Limit: It specifies the length of the segment.
 Segment number (s): Number of bits required to represent the segment.
 Segment offset (d): Number of bits required to represent the size of the segment.

 Advantages of Segmentation –
1. No Internal fragmentation.
2. Segment Table consumes less space in comparison to Page table in paging.
3. As a complete module is loaded all at once, segmentation improves CPU utilization.
4 The user’s perception of physical memory is quite similar to segmentation.
5. Users can divide user programmes into modules via segmentation.
6. These modules are nothing more than the separate processes’ codes.
7. The user specifies the segment size, whereas in paging, the hardware determines the page size.
8. Segmentation is a method that can be used to segregate data from security operations.

 Disadvantage of Segmentation –
1. As processes are loaded and removed from the memory, the free memory space is broken into
little pieces, causing External fragmentation.
2. Overhead is associated with keeping a segment table for each activity.
3. Due to the need for two memory accesses, one for the segment table and the other for main
memory, access time to retrieve the instruction increases.

Q. Explain Virtual Memory: Hardware and Control Structures in detail?

 With virtual memory based on paging or segmentation, that job is left to the operating system and
the hardware.
 As far as the programmer is concerned, they are dealing with a huge memory associated with disk
storage.
 The operating system automatically loads pieces into main memory as required.
 Memory references are dynamically translated into physical addresses at run time.
 A process may be swapped in and out of main memory such that it occupies different regions.
 A process may be broken up into pieces that do not need to be located contiguously in main
memory.
 All pieces of a process do not need to be loaded in main memory during execution.
 Memory references are dynamically translated into physical addresses at run time.
 A process may be swapped in and out of main memory such that it occupies different regions.

Q. Explain in detail Operating System Software?

 The operating system (OS) manages all of the software and hardware on the computer.
 It performs basic tasks such as file, memory and process management, handling input and output,
and controlling peripheral devices such as disk drives and printers.
12
 System software is the software that manages the resources and allows a user to interact with
the system.
 It controls a computer's internal working, mostly through an operating system.
 It also manages peripherals, including printers, storage devices, and monitors.
 The data and programs that make up the computer's operating system are known
as system software.
 Printers, hardware drivers, function libraries, system services, system preferences, and other
configuration files are included in system files.
 System software programs examples are file management tools, system utilities, assemblers,
debuggers, and compilers.
 When you installed the operating system on the computer, the system software is installed.
You may also update the software by executing programs like "Windows Update" for Windows
and "Software Update" for Mac OS X.

Advantages and Disadvantages of System Software


There are various advantages and disadvantages of System Software. These are as follows:

Advantages

 There are various advantages of System Software.


 Some of them are as follows:
 It should be written in the computer language that the CPU and other computer hardware may
read.
 It should be interface with both specialized hardware and higher-level application software. It
is typically hardware-agnostic and has no direct link to the hardware on which it works.
 Other programs that rely on system software must also be supported as they evolve and
change.
 It connects directly to the hardware that allows the system to run.
 It often needs a programming language, which is more difficult to learn than a user interface
that is more intuitive.

Disadvantages
 There are various disadvantages of System Software. Some of them are as follows:
 System software developers must have full knowledge of low-level languages and machine
activities.
 It does not meet all of the user's requirements.
 System software development and updates take longer.
 If you choose a licensed and reputable organization's system software, it will be more
expensive.

13

You might also like