0% found this document useful (0 votes)
47 views10 pages

Os 8

Uploaded by

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

Os 8

Uploaded by

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

Memory management

- For several processes to be in memory, memory needs to be shared


- Memory management is the planned organization of programs & data in memory
- Goals of memory management:
To make it as simple as possible to find space, be loaded, execute
To maximize the usage of memory & reduce waste

A memory manager is responsible to keep track of which parts of the memory are in use and which
parts are not, so that they can be deallocated

Memory is divided into: Logical addresses & Physical addresses

• Logical Address

Think of it like a label or a name for a piece of data or instruction within a program's memory
space.

It's a unique identifier generated by the CPU for each piece of data or instruction, making it easy
for the program to locate them.

Logical addresses are virtual and exist within the program's address space. They are independent
of the physical memory's layout.

• Physical Address

Address seen by the memory unit

Loaded into the memory address register


This is the actual location in physical memory (RAM) where the data or instruction
resides.
Unlike logical addresses, physical addresses directly correspond to the physical memory cells
in hardware.

During program execution, the CPU generates logical address

When the CPU generates a logical address, it sends it to the Memory Management Unit (MMU).

The MMU translates the logical address into a corresponding physical address.

Once the MMU has translated the logical address to a physical address, the CPU can access the data
or instruction stored at that physical location in memory.

The CPU then performs the required operation on the data or executes the instruction.

Memory Management Techniques


• Single Tasking With Overlay

• Fixed Memory Partitioning

• Variable Memory Partitioning

#1 Single Tasking With Overlay

• A technique to allow for a process to be larger than the size of physical memory (Virtual
Memory)

• Keeps in memory only instructions and data that are needed at any given time

• When instructions are needed, they are loaded into the space which was previously
occupied by instructions that are no longer needed (overlay area)

• The concept of overlaying involves dividing a program into smaller sections or overlays that
can be loaded into memory as needed, rather than loading the entire program at once.

• Only load required data or code into memory without swap out anything. But for the next
overlays, the previous portions or data that are not currently needed will be swapped out in
order to make a space for require overlays.
Execution

1. Main program (100 bytes)

2. Data Area (50 bytes)

3. Overlay 1(100 bytes)

4. Overlay 2 (50 bytes)

5. Overlay 3 (25 bytes)


#2 Memory Partitioning – Fixed

• Dividing the memory space into multiple partitions (predetermined), each partition can be
assigned to a specific process or task. This isolation ensures that processes do not interfere
with each other's memory space and can run concurrently.

• simplest form of memory management.

Fixed partitioning: dividing the memory into fixed spaces

• Each partition may contain exactly one process, and processes are loaded into partitions based
on their size.

• The degree of multiprogramming is bound by the number of partitions

• When a partition is free, a process is selected from the input queue and is loaded into the free
partition

• When a process terminates, the partition becomes available for another process

• Fixed Sizes: The size of each partition is predetermined and remains constant. Processes must
fit within the size of a partition; otherwise, they cannot be loaded into memory.

• Simplicity: Fixed partitioning is relatively simple to implement and manage compared to


other memory allocation schemes. However, it may lead to inefficient memory usage if
processes vary widely in size, as smaller processes may waste space in larger partitions.
#3 Memory Partitioning – Variable

• allows partitions to adjust dynamically based on the memory requirements of processes.

• When a process arrives and needs memory, we search for a large enough space for this
process. Loads the process wherever the memory space is available using first fit, best fit or
worst fit algorithms

• First fit – allocates the first space available to fit the process

• Best fit – allocates the smallest space that will fit the process

• Worst fit – allocates the largest space available


Fragmentation

• Fragmentation happens when memory spaces are used in such a way that there are small
pieces of memory available left unused

• Fragmentation occurs naturally when you use a disk frequently creating, deleting, and
modifying files

#1 External Fragmentation

• Too many small sized free space

• These small spaces cannot be used for anything as they are not contiguous

• Although enough total space exist but because they are not contiguous, they cannot be
allocated

• Variable partitioning leads to external fragmentation

• To resolve external fragmentation a technique called compaction is used

• Compaction shuffles all free memory spaces together to form a large block
#2 Internal Fragmentation

• When extra spaces are allocated to a process, the difference between the two numbers results
in internal fragmentation

• Fixed partitioning leads to internal fragmentation as extra memory allocated to a program


which is not used cannot be used else where
Virtual Memory

Virtual memory is a memory management technique used by operating systems to provide the illusion
to applications that they have access to a large, contiguous, and dedicated block of memory, when in
reality the physical memory (RAM) may be limited.

- is the separation of user logical memory from physical memory

- allows for large virtual memory to be provided to processes even though physical memory is small

- offloads programmers of having to worry about writing overlay codes

- is implemented using demand paging or demand segmentation

Pagers and Swappers

pager: is concerned with individual pages of a process

swapper: manipulates the entire process

Demand Paging
Demand paging involves the process of bringing data (in the form of pages) from disk to RAM as
needed. When a program attempts to access a page of memory that is not currently in RAM, a page
fault occurs. The operating system then responds to this page fault by loading the required page from
disk into RAM. This swapping of pages between disk and RAM, triggered by the demand for specific
memory pages by the program, is indeed called demand paging.

So, in summary:

- Data is initially stored on disk.


- When the system needs data that is not currently in RAM, the operating system brings it into
RAM from disk.
- This process of bringing data into RAM on demand is known as demand paging.
- Demand paging is a key mechanism used by operating systems to efficiently manage memory
resources and provide the illusion of a larger RAM size through the use of virtual memory.

• process resides in secondary storage usually a disk


• when a process needs to be executed, it is paged into memory
• the whole process is not paged, only pages that are needed are brought in; this is done by a
lazy swapper
• a pager decides which pages to bring into memory
• when a process is to be swapped the pager guesses which page will be used before the process
is swapped out again
• needs hardware support to distinguish between pages that are in memory and on disk

• Uses the valid-invalid scheme


- a technique used in demand-paged virtual memory systems to track whether a page of memory
is currently valid (resident in RAM) or invalid (not resident in RAM).
- helps the operating system efficiently manage memory and handle page faults and page
replacement.
- valid – the page is in memory and is legal
- invalid – the page is not valid, it is not in the logical address space OR the page is valid but on
the disk

• advantages:
- avoids reading pages that will not be used
- decreases paging time
- decreases the need for physical memory
Demand Segmentation

- address spaces are divided into segments


- each segment has a linear sequence of addresses from 0 to a maximum value
- segment lengths may change during execution
- each segment has different addresses
- each segment can shrink and grow without effecting other segments
- supports the user view of memory; uses segment tables to keep track of segments

in summary,

demand segmentation divides the logical address into variable-sized segments. This division is done
at the logical level, which is organized based on the needs and structure of the program. It make it
easier for the operating system to manage and allocate memory resources effectively.

Once the logical address space is divided into segments, the memory management unit(MMU), will
translate the logical addresses into corresponding physical addresses. When page fault happen, the
operating system will decide which page will be swap out from physical memory(RAM) into disk.
(based on page replacement algorithms like Least Recently Used (LRU), (FIFO).

The swapped-out page will be stored on the disk, in a dedicated area called swap space or page file.

Page Fault: When a program attempts to access a page of memory that is not currently in RAM, a
page fault occurs.

You might also like