Os 8
Os 8
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
• 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
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.
• 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
• 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.
• Each partition may contain exactly one process, and processes are loaded into partitions based
on their size.
• 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.
• 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
•
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
• 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
• 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
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.
- allows for large virtual memory to be provided to processes even though physical memory is small
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:
• advantages:
- avoids reading pages that will not be used
- decreases paging time
- decreases the need for physical memory
Demand Segmentation
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.