100% found this document useful (1 vote)
143 views10 pages

Memory Management in Operating Systems

Memory management can be divided into hardware, operating system, and application levels. It involves efficiently allocating memory to programs and reusing memory that is no longer needed. There are three main types of memory addresses: compile time, load time, and execution time. Dynamic loading maps executable libraries into a process's memory after it has started. Logical addresses are generated by the CPU while physical addresses are seen by memory.

Uploaded by

Faizal Khan
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
100% found this document useful (1 vote)
143 views10 pages

Memory Management in Operating Systems

Memory management can be divided into hardware, operating system, and application levels. It involves efficiently allocating memory to programs and reusing memory that is no longer needed. There are three main types of memory addresses: compile time, load time, and execution time. Dynamic loading maps executable libraries into a process's memory after it has started. Logical addresses are generated by the CPU while physical addresses are seen by memory.

Uploaded by

Faizal Khan
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

Chapter 5 – Memory Management

Memory management can be defined as a process of utilizing memory in a efficient way.


Memory management can be divided into 3 areas as follows:

1. Hardware memory management:


Memory management at the hardware level is concerned with the electronic devices that actually
store the data. This includes things like RAM and memory caches.

2. Operating system memory management:


In the operating system, memory must be allocated to user programs and re-used by other programs
when it is no-longer required. The operating system can pretend that the computer has more memory
than it actually does, and also that each program has the machines memory to itself, both of these are
features of virtual memory systems.

3. Application memory management:


It involves supplying the memory needed for a program's objects and data structure from the limited
resources available and re-cycling the memory for re-use, when it is no longer required.

1. What are the Responsibilities of main memory management.(functions)

* Status: Keeping the status of each memory location, whether it is allocated or free.
* Policy of allocation: It keeps trace of how much, where and when memory shared be allocated
to the process.
* Memory allocation: When a process require for a memory, specific locations, must be selected
and allocated as per policy above and memory status information is updated correspondingly.
* De-allocation: The allocation memory may be reclaimed by memory management.
This operation is based on the de-allocation policy. After de-allocation the status information
must be updated.

1
Operating System BCA-Department
Chapter 5 – Memory Management
2. Explain various types of memory addresses.

Classically the binding of instructions and data to memory addresses can be done at any of the
following steps:
(1)Compile time: If it is known at compile time, where the process will reside in memory, then absolute
code can be generated if at some later time, the starting location changes, then it will be necessary to
compile this code.
(2) Load time: If it is not known at compile time, where the process will reside in memory, then the compiler
must generate re-locatable code. In this case, final binding is delayed until land time, if the starting
address changes we need only to re-load the user code to incorporate this changed value.
(3)Execution time: Binding delayed until run-time, if the process can be moved during in execution from
one memory segment to another. Needs H/N support for maps (e.g. base and limit registers).

3. what is Dynamic loading

Dynamic loading refers to mapping or less often copying an executable library into a process's
memory after is has started.
*The entire program and all data of a process must be in physical memory for the process to execute.
*The size of a process is thus limited to the size of physical memory.
*To obtain better memory-space utilization, dynamic loading can be used.
*With dynamic loading, routine is not loaded until it is called.
*All routines are stored on the disk in a relocatable load format.

2
Operating System BCA-Department
Chapter 5 – Memory Management

4. What is LOGICAL AND PHYSICAL ADDRESS SPACE.

An address generated by the CPU is commonly referred Logical Address or Virtual Address where as an
address seen by memory unit is commonly referred to as Physical address.

The compile time and load-time address-binding methods generate identical logical and physical addresses.
However, logical (virtual) and physical addresses differ in execution-time based on address-binding scheme.

The set of all the logical addresses generated by a process is called logical address space

The set of all physical addresses corresponding to these logical addresses is physical address space.
These spaces differ in execution-time address-binding.

The Run-time mapping from virtual to physical addresses is done by a hardware device called
Memory Management Unit (MMU). The mapping can be done using different methods.

The physical address space is calculated as follows:


Physical address space = Logical address space + Contents of relocation register

if the base is at 14000, then an attempt by the user to address location 0 is dynamical relocated to location
14000; an access to location 346 is mapped to location 14346

5. What is overlays
Overlay is to keep in memory to only those instruction and data that are needed at given time when
other instruction are needed, they are loaded into space occupied is previously by instruction that are no
longer needed. overlaying means "replacement of a block of stored instructions or data with another".
Overlaying is a programming method that allows programs to be larger than the central processing units
' main memory.
3
Operating System BCA-Department
Chapter 5 – Memory Management
6. Explain SWAPPING
Swapping is a process which helps the CPU utilization, by replacing waiting processes in the main
memory with process, ready to execute, from the disk on the arrival of a new processes of high priority for
which there is no free space available, a memory manager is involved to make memory space available for
the new process. One completion of the higher priority process, the lower priority processes are swapped
In and continued. This type of swapping is known as roll out, roll in.

A processes needs to be in memory to be executed. A process how ever swapped out of memory temporarily
to a Backing store and again swapped-in into in memory for continued execution.
For example, assume a multiprogramming environment with a round robin CPU scheduling algorithm.
When a quantum expires, the memory manager will swap-out the process that just finished and swap in
another process to the memory space.

The concept of swapping has divided into two more concepts: Swap-in and Swap-out.
*Swap-out is a method of removing a process from RAM and adding it to the hard disk.
*Swap-in is a method of removing a program from a hard disk and putting it back into the main memory
or RAM.

7. Discuss partitioned memory management or Describe multiprogramming with fixed-size partitions


This is the simple technique of memory management technique. This partition technique allows
multiprogramming. Here the main memory is divided into smaller memory regions, called as partition.
Each partition can hold different user job.

We can divide partition memory allocation into as follows:


Single partition allocation:
If the operating system is low memory and the user processes are executing in high memory thus there
is necessary to save the OS code and data from change by the user processes and to protect the user
processes from one another.

4
Operating System BCA-Department
Chapter 5 – Memory Management
Multiple partition allocation:
In this technique, when there is several processes residing in memory at the same time, and various
processes are in the 1/p queue waiting to be brought into memory, memory allocation is divided into no. of
fixed size partitions. Each partition may contuing exactly one process. Thus the degree of multiprogramming
is bound by no. of partitions. When the partition is free a process is selected from the I/P queue, and loaded
into the free partition, when the process terminates, partition is avoidable to other processes.

8. Explain best fit, first fit and worst fit. or Dynamic Storage-Allocation Problem Compare first-fit, best-fit and
worst-fit allocation of memory.
Memory allocation is the process of assigning blocks of memory on request

First Fit: Another strategy is first fit, which simply scans the free list until a large enough hole is found.
In the first fit approach is to allocate the first free partition or hole large enough which can
accommodate the process. It finishes after finding the first suitable free partition.
Best Fit : The allocator places a process in the smallest block of unallocated memory in which it will fit.
The best fit deals with allocating the smallest free partition which meets the requirement of the
requesting process. This algorithm first searches the entire list of free partitions and considers the
smallest hole that is adequate. It then tries to find a hole which is close to actual process size needed.
Worst Fit: The memory manager places process in the largest block of unallocated memory available.
In worst fit approach is to locate largest available free portion so that the portion left will be big
enough to be useful. It is the reverse of best fit.

Working with example

5
Operating System BCA-Department
Chapter 5 – Memory Management

9. What is fragmentation? Explain their types with examples. What is fragmentation?


Explain their types with examples. Define internal and external fragmentation
Fragmentation refers to a situation when memory that is internal to a partition is not being used or when
enough total memory space exists to satisfy a request, but it is not contiguous; storage is fragmented into a
large number of holes.
The different types of memory fragmentation are:
Internal fragmentation
External fragmentation

Fragmentation can be reduced by the following three methods


* Compaction
* Paging
* Segmentation

6
Operating System BCA-Department
Chapter 5 – Memory Management
10 Define Compaction
One solution to a problem of external fragmentation is COMPACTION. The goal of compaction is to
shuffle memory contents to place all free memory together in one large block. It combines all the free areas
into one contiguous area.
Compaction is possible only if relocation is dynamic, and is done at execution time.

When swapping creates multiple holes in memory, it is possible to combine them all in one big hole by
moving all the processes downward as far as possible. This techniques is known as memory compaction.
It requires lot of CPU time.

[Link] is Virtual Memory


Memory is hardware that your computer uses to load the operating system and run programs.
* Computer consists of one or more RAM chips that each have several memory modules.
* The amount of real memory in a computer is limited to the amount of RAM installed.
Common memory sizes are 1GB, 2GB, and 4GB.
* Because your computer has a finite amount of RAM, it is possible to run out of memory when too many
programs are running at one time.
* This is where virtual memory comes in.
* Virtual memory increases the available memory of your computer by enlarging the "address space," or
places in memory where data can be stored.
* It does this by using hard disk space for additional memory allocation.

7
Operating System BCA-Department
Chapter 5 – Memory Management
12. Explain paging.
In the paging scheme, physical memory is broken into fixed sized blocks called frames. The logical memory
is broken into blocks of same size called pages. When the process is to be executed, its pages are loaded
into any available memory frames from the backing store. The backing store is divided into fixed size
blocks that are of the same size as the memory frames.

13. Explain shared pages.

8
Operating System BCA-Department
Chapter 5 – Memory Management
14. What is the hit ratio with respect to memory management

Hit ratio is a concept defined for any two adjacent level of memory hierarchy .
The hit ratios at successive levels are function of memory capacities, management policies and program
behavior. Hit ratios always lies between 0 to 1.
The percentage of times that a particular page number is found in the TLB is called hit ratio.
A 80% hit ratio means that we find the desired page number in the TLS 80 percent of time.

15 Explain Segmentation (short note )


Segmentation is a memory management scheme in which the physical memory allocated to the process
is non-contiguous.
In segmentation logical address space is divided into number of small blocks known as segment.
Segments are of variable (unequal size) and each segment is allocated memory independently.
The responsibility for dividing the program into segments lies with the user (or compiler).
The operating system is uninvolved. Thus, segmentation supports user's view of memory.
Each segment has a name and a length. The address specify both the name and the offset within the
segment.
In segmentation, a logical address consists of two parts : segment number and offset.
An offset is the location in a distinct segment in main memory.

9
Operating System BCA-Department
Chapter 5 – Memory Management

16. Explain how segments are shared?

10
Operating System BCA-Department

Common questions

Powered by AI

Overlays allow a program to exceed the size of available physical memory by keeping only essential instructions and data in memory at any time. Other parts are loaded as needed, replacing currently-resident sections that are no longer required. This technique is beneficial for executing large programs on systems with limited memory, as it minimizes memory usage and avoids the need for additional hardware. Overlays require careful division of the program into manageable segments, often managed manually, enabling efficient execution without physical memory constraints .

Dynamic loading improves memory utilization by loading a routine only when it is called, rather than having all routines loaded into memory at the start of process execution. This approach means that a smaller amount of physical memory is needed because only the required routines are loaded at any given time, allowing for more efficient use of available memory space. It also allows larger programs to run in systems with smaller physical memory, thus optimizing resource usage and improving system performance .

Logical address space, also known as virtual address space, is generated by the CPU, whereas physical address space refers to the actual addresses in memory hardware. During compile time and load-time, logical and physical addresses are identical because the binding is done at load-time when the starting address is known. However, during execution-time, they differ as logical addresses are mapped to physical addresses using a Memory Management Unit (MMU). This mapping allows the system to support virtual memory, enabling processes to perceive they have space beyond the actual physical memory. This differentiation is crucial for efficient memory management and enables features such as swapping and paging, facilitating better utilization of physical memory .

First-fit allocates the first available memory block that is large enough, leading to quick allocations but can result in external fragmentation. Best-fit searches for the smallest sufficient block, minimizing leftover space but typically requires more time to scan the list. Worst-fit uses the largest available block, ensuring the remainder is large enough for future use but may increase fragmentation. Each strategy has its trade-offs: first-fit is faster but can lead to more fragmentation, best-fit reduces fragmentation at the expense of time, and worst-fit aims to minimize wasted space at the expense of searching time .

Segmentation is a memory management scheme where a program is divided into segments that are allocated memory independently. Each segment is of variable size, reflecting logical units such as functions or arrays, and may lead to non-contiguous memory allocation. Unlike paging, which divides memory into fixed-size blocks (pages and frames) without regard for logical distinctions, segmentation aligns more with the way a programmer structures a program. While segmentation supports a user's view of program organization, paging simplifies memory management but may lead to internal fragmentation due to fixed block sizes. Segmentation can share segments, which encourages modularized and re-usable program components .

Memory fragmentation occurs when free memory is split into small blocks and is unable to cater to memory allocation requests due to lack of contiguous space. Internal fragmentation arises when allocated memory to a process is larger than necessary, leaving unused space within the partition. External fragmentation happens when free memory is divided into unconnected small blocks despite having sufficient total space. Compaction, segmentation, and paging are strategies that help alleviate external fragmentation by reorganizing memory to make larger contiguous free blocks available .

Swapping is a memory management technique where processes are temporarily moved from main memory to a backing store like a hard disk, allowing space for other processes. It is especially useful when a high-priority process needs to be executed but there is insufficient memory. Swapping temporarily frees space in RAM, enabling the CPU to switch to other processes, effectively improving CPU utilization. When the needed process completes execution, previously swapped-out processes can be brought back into memory (swap-in) and continue execution, thus maintaining a balance between memory availability and CPU load .

Relocation registers are used to support execution-time binding, allowing a process to move in memory during execution. They enable dynamic address translation by holding base and limit values; the base register holds the start address of the process in memory, facilitating the translation of logical addresses to physical addresses efficiently. This mechanism ensures correct execution even if a program is transferred from one memory location to another during operation, providing flexibility and allowing better memory utilization and process management .

Memory compaction is used to address external fragmentation by rearranging memory contents. The purpose is to consolidate all free memory into a single contiguous block, thus making large blocks available for allocation to new or existing processes. This technique is particularly effective when dynamic allocation and deallocation of memory create numerous small free sections across memory. Compaction is viable only if dynamic relocation is supported, as it involves shifting processes within memory, which requires significant CPU resources .

Virtual memory extends the available memory in a computer by utilizing a portion of the hard disk as additional RAM, enabling the system to handle larger processes or more processes simultaneously than would be possible with just physical RAM. It enlarges the address space, thus allowing programs to simulate having more memory than is physically available. This technique helps prevent system slowdowns by managing over-commitment of memory resources, facilitating short-term memory shortages, and enabling efficient multitasking by swapping parts of programs or data in and out of physical memory as needed .

You might also like