0% found this document useful (0 votes)
24 views15 pages

Understanding Logical vs Physical Memory

Uploaded by

kshitijkumar3108
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)
24 views15 pages

Understanding Logical vs Physical Memory

Uploaded by

kshitijkumar3108
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

SRM Institute of Science and Technology

Delhi – Meerut Road, Sikri Kalan, Ghaziabad, Uttar Pradesh – 201204


Department of Computer Application

Course: MCA 1 Year (Semester-1) Name of Faculty: Aalekh Choudhary


Subject: Operating System (PCA20C02J) +91-9808110243

Logical Address of Memory

It is a virtual address generated by the CPU while a program is running. It is referred to


as a virtual address because it does not exist physically. Using this address, the CPU
access the actual address or physical address inside the memory, and data is fetched from
there.

The hardware device called Memory Management Unit (MMU) is used for mapping
this logical address to the physical address. The set of all logical addresses generated by
the CPU for a program is called the logical address space.

Physical Address of Memory

Physical Address is the actual address of the data inside the memory. The logical address
is a virtual address and the program needs physical memory for its execution. The user
never deals with the Physical Address. The user program generates the logical address
and is mapped to the physical address by the Memory Management Unit(MMU).

The set of all physical addresses corresponding to the logical addresses in the logical
address space is called the physical address space.
Differences between Logical Address and Physical Address :

The Logical Address is generated by the CPU while the program is running and the
Physical Address is the location inside the main memory.

The Logical Address is Virtual and the Physical Address is the actual address of the
memory.

The Logical Address is generated by the CPU and the Physical Address is calculated by
MMU.

Users can't view the Logical Address of a program whereas the Physical Address is
visible to the user.

The set of all logical addresses generated by the CPU in reference to a program is called
the Logical Address Space and the set of all physical addresses corresponding to the
logical addresses in the Logical Address Space is called the Physical Address Space.

Comparison between Logical Address and Physical Address

Logical Address Physical Address


It is a virtual address. It is the actual location in the memory.
It is visible to the user. It is not visible to the user.
It is generated by the CPU. It is computed by the MMU.
It is used by the user to access the It is not accessible directly by the user.
physical address inside the
memory.
The set of all logical addresses The set of all physical addresses corresponding to
generated by the CPU is called the logical addresses in the logical address space is
the logical address space. called the physical address space.
Memory Management
➢ Memory management in an operating system is a crucial function responsible for
efficiently managing the computer's physical memory (RAM) to ensure that
processes can run effectively and without conflicts.
➢ Memory is the important part of the computer that is used to store the data. Its
management is critical to the computer system because the amount of main
memory available in a computer system is very limited. At any time, many
processes are competing for it. Moreover, to increase performance, several
processes are executed simultaneously. For this, we must keep several processes
in the main memory, so it is even more important to manage them effectively.

Why Use Memory Management?


Here, are reasons for using memory management:

• It allows you to check how much memory needs to be allocated to processes that
decide which processor should get memory at what time.
• Tracks whenever inventory gets freed or unallocated. According to it will update
the status.
• It allocates the space to application routines.
• It also make sure that these applications do not interfere with each other.
• Helps protect different processes from each other
• It places the programs in memory so that memory is utilized to its full extent.
Role of Memory management

Following are the important roles of memory management in a computer system:

o Memory manager is used to keep track of the status of memory locations, whether
it is free or allocated. It addresses primary memory by providing abstractions so
that software perceives a large memory is allocated to it.
o Memory manager permits computers with a small amount of main memory to
execute programs larger than the size or amount of available memory. It does this
by moving information back and forth between primary memory and secondary
memory by using the concept of swapping.
o The memory manager is responsible for protecting the memory allocated to each
process from being corrupted by another process. If this is not ensured, then the
system may exhibit unpredictable behavior.
o Memory managers should enable sharing of memory space between processes.
Thus, two programs can reside at the same memory location although at different
times.

Methods Involved in Memory Management

There are various methods and with their help Memory Management can be done
intelligently by the Operating System:
The memory management techniques can be classified into following main
categories:

o Contiguous memory management schemes


o Non-Contiguous memory management schemes

Contiguous memory management schemes:

In a Contiguous memory management scheme, each program occupies a single


contiguous block of storage locations, i.e., a set of memory locations with consecutive
addresses.

Single contiguous memory management schemes:

The Single contiguous memory management scheme is the simplest memory


management scheme used in the earliest generation of computer systems. In this scheme,
the main memory is divided into two contiguous areas or partitions. The operating
systems reside permanently in one partition, generally at the lower memory, and the user
process is loaded into the other partition.
Advantages of Single contiguous memory management schemes:

o Simple to implement.
o Easy to manage and design.
o In a Single contiguous memory management scheme, once a process is loaded, it
is given full processor's time, and no other processor will interrupt it.

Disadvantages of Single contiguous memory management schemes:

o Wastage of memory space due to unused memory as the process is unlikely to use
all the available memory space.
o The CPU remains idle, waiting for the disk to load the binary image into the main
memory.
o It can not be executed if the program is too large to fit the entire available main
memory space.
o It does not support multiprogramming, i.e., it cannot handle multiple programs
simultaneously.

Multiple Partitioning:

The single Contiguous memory management scheme is inefficient as it limits computers


to execute only one program at a time resulting in wastage in memory space and CPU
time. The problem of inefficient CPU use can be overcome using multiprogramming that
allows more than one program to run concurrently. To switch between two processes,
the operating systems need to load both processes into the main memory. The operating
system needs to divide the available main memory into multiple parts to load multiple
processes into the main memory. Thus multiple processes can reside in the main memory
simultaneously.

The multiple partitioning schemes can be of two types:

o Fixed Partitioning
o Dynamic Partitioning
Fixed Partitioning

The main memory is divided into several fixed-sized partitions in a fixed partition
memory management scheme or static partitioning. These partitions can be of the same
size or different sizes. Each partition can hold a single process. The number of partitions
determines the degree of multiprogramming, i.e., the maximum number of processes in
memory. These partitions are made at the time of system generation and remain fixed
after that.

Dynamic Partitioning

The dynamic partitioning was designed to overcome the problems of a fixed partitioning
scheme. In a dynamic partitioning scheme, each process occupies only as much memory
as they require when loaded for processing. Requested processes are allocated memory
until the entire physical memory is exhausted or the remaining space is insufficient to
hold the requesting process. In this scheme the partitions used are of variable size, and
the number of partitions is not defined at the system generation time.

Difference between contigious and non contigious memory allocation in operating


system

Aspect Contiguous Memory Allocation Non-Contiguous Memory Allocation


Method Allocates memory in a contiguous Allocates memory to a process in non-
block to a process contiguous blocks
Block Size Memory allocated in a single, Memory allocated in noncontiguous
continuous chunk blocks of varying sizes
Management Easy to manage by the operating system Requires additional overhead and can
be more complicated to manage
Memory Usage May result in memory wastage and Efficient use of memory and reduces
external fragmentation fragmentation within memory blocks
Suitable For Systems with limited amounts of Larger memory sizes and systems that
memory and fast access to memory is require more efficient use of memory
important
Advantages Simple and efficient technique for More flexible and efficient technique
memory management for larger memory sizes and systems
that require more efficient use of
memory
Disadvantages Can be inflexible and result in memory Requires additional overhead and can
wastage and fragmentation be more complicated to manage
Non-Contiguous memory management

Non-contiguous memory allocation is a technique that divides a process into blocks, or


pages, that are allocated to different areas of memory. The operating system keeps track
of the blocks allocated to a process. The blocks do not need to be contiguous.
Non-contiguous memory allocation can reduce memory wastage. However, it can also
increase address translation overheads.
In non-contiguous memory allocation, spanning is allowed. This is not possible in other
techniques like dynamic or static contiguous memory allocation.
eFor example, if a process is 4 KB in size and the main memory has two empty slots,
each of 2 KB, the process cannot be accommodated in contiguous memory allocation.

Non-contiguous memory allocation can be done in two ways

1. Paging
2. Segmentation
3. Swapping
4. Fragmentation
Paging:

What is Paging?

Paging is a memory management technique used in operating systems to manage


physical memory (RAM) and virtual memory. It is designed to overcome some of the
limitations and challenges associated with contiguous memory allocation, where each
process requires a single contiguous block of memory. Paging is a widely used memory
management technique in modern operating systems because it provides a flexible and
efficient way to manage memory. It allows multiple processes to share physical memory
effectively, reduces fragmentation, and simplifies memory allocation and deallocation.
However, it's important to manage page table overhead and ensure efficient page
replacement algorithms for optimal performance. In paging, both physical and virtual
memory are divided into fixed-size blocks or pages. Here's how paging works in memory
management:

1. Page Size: The physical memory and virtual memory are divided into fixed-size
blocks or pages. The page size is typically a power of 2 and is determined by the
operating system. Common page sizes include 4 KB, 8 KB, or 16 KB.

2. Address Translation: Each process operates with its own virtual address space.
When a program references memory, it uses virtual addresses. These virtual addresses
are divided into two parts: a page number and an offset within the page.

- Page Number: Specifies which page in the virtual address space is being accessed.

- Offset: Specifies the location within the page.

3. Page Table: The operating system maintains a data structure called a page table for
each process. The page table maps virtual page numbers to physical page frame
numbers. It helps in translating virtual addresses to physical addresses.

4. Page Faults: When a process tries to access a virtual page that is not currently in
physical memory, a page fault occurs. The operating system must handle this situation
by bringing the required page into memory from secondary storage (e.g., a hard drive
or SSD). This process involves finding a free page frame in physical memory and
swapping out a page if there are no free frames.

5. Page Replacement: If physical memory is full, the operating system needs to decide
which page to evict to make space for the new page. Various page replacement
algorithms, such as LRU (Least Recently Used) or FIFO (First-In-First-Out), help
determine which page to replace.
Advantage/ Benefits of Paging:

Eliminates external fragmentation: Pages can be allocated in any available physical


memory location, reducing external fragmentation.

Simplifies memory allocation and management: The fixed-size pages simplify


memory allocation and deallocation.

Efficient use of physical memory: Paging allows efficient use of available physical
memory as pages can be allocated and freed independently.

Disadvantage / Drawbacks of Paging:

Internal fragmentation: Paging can lead to internal fragmentation because pages may
not be fully utilized.

Page table overhead: Maintaining a page table for each process consumes memory
and introduces overhead in address translation.

Why we use Paging?

A computer system may access and use memory that is larger than the memory that is
built into the computer hardware. Virtual memory is the term used to describe this
additional memory. The computer system employs virtual memory, which is a
component of secondary memory, as its main memory. In order to implement virtual
memory, paging is crucial.

Every process’s code makes use of a collection of logical addresses known as the process
address space. Blocking the process address space is a memory management method
called paging. The units are called "pages," and each block has the same size. A page’s
size is a power of 2, and its value falls between 512 and 8192 bytes. The quantity of
pages in a process is used to determine its size.

A similar division of the main memory is done into blocks of fixed size. These blocks
are known as “frames” and the size of a frame is the same as that of a page to achieve
optimum usage of the primary memory and for avoiding external fragmentation.
Address Translation

Page address is called logical address and represented by page number and the offset.

Logical Address = Page number + page offset

Frame address is called physical address and represented by a frame number and
the offset.

Physical Address = Frame number + page offset

A data structure called page map table is used to keep track of the relation between a
page of a process to a frame in physical memory.

When the system allocates a frame to any page, it translates this logical address into a
physical address and create entry into the page table to be used throughout execution of
the program.

When a process is to be executed, its corresponding pages are loaded into any available
memory frames. Suppose you have a program of 8Kb but your memory can
accommodate only 5Kb at a given point in time, then the paging concept will come into
picture. When a computer runs out of RAM, the operating system (OS) will move idle
or unwanted pages of memory to secondary memory to free up RAM for other
processes and brings them back when needed by the program.

This process continues during the whole execution of the program where the OS keeps
removing idle pages from the main memory and write them onto the secondary
memory and bring them back when required by the program.
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 system having
small RAM.

• Paging reduces external fragmentation.

• Implementing paging is simple.

• Paging improves memory performance.

• Swapping becomes quite easy because the dimensions of the frames and pages
are the same.

• Paging is helpful for quick data access.


Swapping

Swapping is a mechanism in which a process can be swapped temporarily out of main


memory (or move) to secondary storage (disk) and make that memory available to
other processes. At some later time, the system swaps back the process from the
secondary storage to main memory.

Though performance is usually affected by swapping process but it helps in running


multiple and big processes in parallel and that's the reason Swapping is also known as
a technique for memory compaction.

The total time taken by swapping process includes the time it takes to move the entire
process to a secondary disk and then to copy the process back to memory, as well as
the time the process takes to regain main memory.

Let us assume that the user process is of size 2048KB and on a standard hard disk
where swapping will take place has a data transfer rate around 1 MB per second. The
actual transfer of the 1000K process to or from memory will take

2048KB / 1024KB per second


= 2 seconds
= 2000 milliseconds
Now considering in and out time, it will take complete 4000 milliseconds plus other
overhead where the process competes to regain main memory.

What is Fragmentation?

The available free space in primary memory is divided into smaller chunks when
processes are relocated to and from the main memory. This occurs when a process’s
memory requirements are greater than the size of the available memory, preventing
memory from being allocated to the process. Such memory chunks are never used. This
problem is known as Fragmentation.

Fragmentation is of the following two types:

1. External Fragmentation:
Although there is enough free main space to accommodate all processes, it cannot be
used since it is not continuous. By combining or rearranging data in memory’s free
memory blocks to create a single, bigger free memory block, external fragmentation
can be reduced.
2. Internal Fragmentation:
When a process is given a memory block that is bigger than what the process actually
needs, internal fragmentation occurs. A portion of memory is left unused in this case
since no other process will use it. By giving a process access to the lowest free memory
chunk that may be allocated, internal fragmentation can be reduced.
Segmentation

Fragmentation refers to a state where memory blocks remain unutilized, while


segmentation is a methodology that involves dividing a process into multiple
modules or sections.

Segmentation is a memory management technique in which each job is divided into


several segments of different sizes, one for each module that contains pieces that
perform related functions. Each segment is actually a different logical address space of
the program.

When a process is to be executed, its corresponding segmentation are loaded into non-
contiguous memory though every segment is loaded into a contiguous block of
available memory.

Segmentation memory management works very similar to paging but here segments are
of variable-length where as in paging pages are of fixed size.

A program segment contains the program's main function, utility functions, data
structures, and so on. The operating system maintains a segment map table for every
process and a list of free memory blocks along with segment numbers, their size and
corresponding memory locations in main memory. For each segment, the table stores
the starting address of the segment and the length of the segment. A reference to a
memory location includes a value that identifies a segment and an offset.

Common questions

Powered by AI

Paging helps reduce external fragmentation by dividing both physical and virtual memory into fixed-size blocks or pages, ensuring that any available space can be used for loading pages independent of their location. This organization allows for efficient use of memory since pages can be allocated in any available frame, thus eliminating external fragmentation that occurs in contiguous allocation strategies. However, paging introduces internal fragmentation, as the last page of a process may not fully occupy a page frame, resulting in some wasted space within that frame. Additionally, paging requires the management of a page table for each process, which consumes extra memory and introduces overhead in address translation .

Memory management facilitates multi-programming by dividing memory into partitions or pages that can be dynamically allocated to different processes, enabling them to run concurrently. By swapping processes in and out of main memory, operating systems can maximize CPU utilization and maintain process execution even in limited memory conditions. The benefits include improved throughput, efficient memory usage, and better resource allocation, which enhance overall system productivity. The challenges include managing increased complexity of memory allocation, handling address translation overheads, dealing with potential fragmentation, and ensuring that processes do not corrupt each other's memory spaces .

In a paging system, a page fault occurs when a process attempts to access a page that is not currently loaded in physical memory. The operating system handles page faults by interrupting the process, locating the needed page on secondary storage, such as a hard drive, and loading it into a free frame in physical memory. If no frames are free, a page replacement algorithm, like LRU or FIFO, determines which page to swap out to free up space. Although essential for managing large programs, frequent page faults can significantly degrade performance due to the time spent loading pages from disk, affecting the overall system responsiveness and efficiency .

The primary function of the Memory Management Unit (MMU) is to map logical addresses generated by the CPU to physical addresses in memory. This process allows the CPU to access the actual physical memory location to fetch or store data. The MMU is involved in translating the virtual addresses into physical addresses to enable program execution without the user needing to handle or even seeing the actual physical addresses .

Contiguous memory allocation involves allocating a single continuous block of memory to a process, which is simpler to manage due to its straightforward nature but can lead to severe external fragmentation and inefficient memory utilization. It is suitable for systems where quick access to memory is crucial but struggles with flexibility and the ability to accommodate multiple processes efficiently . Non-contiguous memory allocation, in contrast, assigns memory in separate blocks that may not be adjacent, reducing the risk of fragmentation and allowing for flexible process allocation. However, it requires more complex management due to address translation overhead, and it still suffers from some internal fragmentation since block sizes might not perfectly fit process size requirements .

Swapping is considered useful for memory compaction because it allows the operating system to temporarily move processes out of main memory to secondary storage, freeing up space for other processes. This process enables larger and multiple processes to run simultaneously by optimizing the usage of RAM and facilitating the reallocation of memory as needed. Although this introduces some delay due to the time required to move processes back and forth, swapping helps to better utilize system resources by ensuring that memory is efficiently allocated and reorganized as workloads change .

A fixed partition memory management scheme may become inefficient when the size of the process frequently varies, leading to memory underutilization or wastage. Fixed partitions allocate a set memory size for processes, meaning if a process does not use the entire partition, the remaining memory within the partition is wasted, which is especially inefficient for small processes or when processes sizes vary significantly. Additionally, if a process requires more memory than what is allocated for a fixed partition, it cannot be accommodated, potentially leading to insufficient system performance and an inability to utilize full memory capacity efficiently .

A page table is necessary in a system using paging because it maps virtual page numbers to physical page frame numbers, facilitating the translation of virtual addresses generated by processes into corresponding physical addresses. This mechanism allows processes to operate within their own virtual address space while effectively sharing physical memory. However, maintaining these tables introduces extra memory usage and computational overhead, as each process requires its own page table, which increases the memory management complexity and system resource consumption .

The main roles of memory management in ensuring efficient process execution include tracking the status of memory locations to ascertain whether they are free or allocated, and managing primary memory by providing abstractions, so that larger memory is perceived by software. It allows concurrent processes by swapping processes between primary and secondary memory, protects processes' allocated memory from corruption by other processes, and shares memory space between processes, thus optimizing memory utilization and preventing processes from interfering with each other .

Dynamic partitioning improves system efficiency compared to fixed partitioning by allowing each process to occupy only as much memory as they require at runtime, rather than being allocated a fixed-size partition. This reduces memory wastage as processes do not have to fit into pre-determined partitions, thereby utilizing available memory more effectively and potentially fitting more processes into memory simultaneously. As partitions are variable and created as needed, this technique adapts more flexibly to varying process memory requirements, unlike fixed partitions which may remain partially unused, leading to better overall memory usage .

You might also like