Unit 3 (1)
Unit 3 (1)
Swapping
Swapping is a memory management technique for swapping data between main memory
and secondary memory for better memory utilization. Swapping is a memory management
technique that can be used to increase the operating system’s performance.
Contiguous memory allocation can be divide the memory into following types of partition.
Fixed-Sized Partitions
Another name for this is static partitioning. In this case, the system gets divided into multiple
fixed-sized partitions. In this type of scheme, every partition may consist of exactly one
process. This very process limits the extent at which multiprogramming would occur, since
the total number of partitions decides the total number of processes. Read more on fixed-
sized partitions here.
Variable-Sized Partitions
Dynamic partitioning is another name for this. The scheme allocation in this type of partition
is done dynamically. Here, the size of every partition isn’t declared initially. Only once we
know the process size, will we know the size of the partitions. But in this case, the size of the
process and the partition is equal; thus, it helps in preventing internal fragmentation.
On the other hand, when a process is smaller than its partition, some size of the partition
gets wasted (internal fragmentation). It occurs in static partitioning, and dynamic
partitioning solves this issue. Read more on dynamic partitions here.
Segmentation
Segmentation method works almost similarly to paging. The only difference between the two
is that segments are of variable-length, whereas, in the paging method, pages are always of
fixed size.
A program segment includes the program's main function, data structures, utility functions,
etc. The OS maintains a segment map table for all the processes. It also includes a list of free
memory blocks along with its size, segment numbers, and its memory locations in the main
memory or virtual memory.
Paging Segmentation
A page is of the fixed block size. A segment is of variable size.
In Paging, the hardware decides the page The segment size is specified by the user.
size.
The paging technique is faster for memory Segmentation is slower than paging
access. method.
Page table stores the page data Segmentation table stores the
segmentation data.
Paging address space is one dimensional In segmentation, there is the availability of
many independent address spaces
A process address space is broken into A process address space Is broken in
fixed-sized blocks, which is called pages. differing sized blocks called sections.
It may lead to internal fragmentation. It may lead to external fragmentation.
Process Creation
1) When a new process is created, the operating system assigns a unique Process Identifier
(PID) to it and inserts a new entry in the primary process table.
2) Then required memory space for all the elements of the process such as program, data,
and stack is allocated including space for its Process Control Block (PCB).
3) Next, the various values in PCB are initialized such as,
The process identification part is filled with PID assigned to it in step (1) and also its
parent’s PID.
The processor register values are mostly filled with zeroes, except for the stack
pointer and program counter. The stack pointer is filled with the address of the stack-
allocated to it in step (ii) and the program counter is filled with the address of its
program entry point.
The process state information would be set to ‘New’.
Priority would be lowest by default, but the user can specify any priority during
creation.
4) Then the operating system will link this process to the scheduling queue and the process
state would be changed from ‘New’ to ‘Ready’. Now the process is competing for the CPU.
5) Additionally, the operating system will create some other data structures such as log files
or accounting files to keep track of processes activity.
Allocation of Frames
The main memory of the system is divided into frames. The OS has to allocate a sufficient
number of frames for each process using various algorithms. The five major ways to allocate
frames are as follows:
Proportional frame allocation
The proportional frame allocation algorithm allocates frames based on the size that is
necessary for the execution and the number of total frames the memory has.
Thrashing
A process is said to be thrashing if the CPU spends more time serving page faults than
executing the pages. This leads to low CPU utilization and the Operating System in return
tries to increase the degree of multiprogramming.
P1 P1 P1 P1 P1 P2 P2 P2 P2 P3 P3 P3
Since P3 doesn’t get the necessary number of pages to run, a page fault is raised. By the
necessary number of pages.
Assuming we use global replacement algorithm(discussed below), one of the pages from P1
gets replaced and following is the new configuration of main memory:
P1 P1 P1 P1 P2 P2 P2 P2 P3 P3 P3 P4
With the current state of memory, P1 now raises a page fault and takes frames from other
processes. These victim processes also start to page fault and take pages from other
processes and this will continue so and so on. This high paging activity is thrashing.