NON CONTIGUOUS MEMORY ALLOCATION: The solution to the external-fragmentation problem is to permit the logical address space of the processes to be noncontiguous, thus allowing a process to be allocated physical memory wherever memory is available. Two complementary techniques achieve this solution: segmentation paging 1. SEGMENTATION: Segmentation is a memory-management scheme that supports the programmer view of memory. A logical address space is a collection of segments. Each segment has a name and a length. The logical addresses specify both the segment name and the offset within the segment. Each address is specified by two quantities: a segment name and an offset Segment-number, offset>. A C compiler might create separate segments for the following: 1. The code 2. Global variables 3. The heap, from which memory is allocated 4. The stacks used by each thread 5. The standard C library SEGMENTATION HARDWARE: The programmer can refer to objects in the program by a two-dimensional address (segment number and offset); the actual physical memory a one dimensional sequence of bytes. The two-dimensional user-defined addresses should be mapped into one-dimensional physical addresses. The mapping of logical address to physical address is done by a table called segment table. Each entry in the segment table has a segment base and a segment limit. The segment base contains the starting physical address where the segment resides in memory The segment limit specifies the length of the segment. A logical address consists of two parts: a segment number, s, and an offset into that segment, d. The segment number is used as an index to the segment table. The offset d of the logical address must be between 0 and the segment limit. If it is not between 0 and limit then hardware trap to the operating system (logical addressing attempt beyond end of segment). When an offset is legal, it is added to the segment base to produce the address in physical memory of the desired byte. The segment table is an array of base–limit register pairs. Segmentation can be combined with paging. 2. PAGING: Paging involves breaking physical memory into fixed-sized blocks called frames and breaking logical memory into blocks of the same size called pages. Paging avoids external fragmentation and the need for compaction, whereas segmentation does not. When a process is to be executed, its pages are loaded into any available memory frames PAGING HARDWARE: Every address generated by the CPU is divided into two parts: a page number (p) and a page offset (d). The page number is used as an index into a page table. The page table contains the base address of each page in physical memory. This base address is combined with the page offset to define the physical memory address that is sent to the memory unit.
Q2Explain virtual memory and its advantage.
Virtual memory is a memory management technique that allows the execution of processes that are not completely in memory. In some cases during the execution of the program the entire program may not be needed, such as error conditions, menu selection options etc. The virtual address space of a process refers to the logical view of how a process is stored in memory. The heap will grow upward in memory as it is used for dynamic memory allocation. The stack will grow downward in memory through successive function calls . The large blank space (or hole) between the heap and the stack is part of the virtual address space but will require actual physical pages only if the heap or stack grows. Virtual address spaces that include holes are known as sparse address spaces. Sparse address space can be filled as the stack or heap segments grow or if we wish to dynamically link libraries Virtual memory allows files and memory to be shared by two or more processes through page sharing ADVANTAGES: One major advantage of this scheme is that programs can be larger than physical memory Virtual memory also allows processes to share files easily and to implement shared memory. Increase in CPU utilization and throughput. Less I/O would be needed to load or swap user programs into memory
Q3.Explain page fault .Procedure to handle page fault.
Q4.Explain pure demand paging and performance of demand paging.PAGE FAULT: If the process tries to access a page that was not brought into memory, then it is called as a page fault. Access to a page marked invalid causes a page fault. The paging hardware, will notice that the invalid bit is set, causing a trap to the operating system. PROCEDURE FOR HANDLING THE PAGE FAULT: 1. Check an internal table (usually kept with the process control block) for this process to determine whether the reference was a valid or an invalid memory access. 2. If the reference was invalid, we terminate the process. If it was valid but we have not yet brought in that page, we now page it in. 3. Find a free frame 4. Schedule a disk operation to read the desired page into the newly allocated frame. 5. When the disk read is complete, we modify the internal table kept with the process and the page table to indicate that the page is now in memory. 6. Restart the instruction that was interrupt. Though it had always been in memory.
Q5.Need of page replacement.PURE DEMANDPAGING: The process of executing a program with no pages in main memory is called as pure demand paging. This never brings a page into memory until it is required. The hardware to support demand paging is the same as the hardware for paging and swapping: Page table. This table has the ability to mark an entry invalid through a valid–invalid bit or a special value of protection bits. Secondary memory. This memory holds those pages that are not present in main memory. The secondary memory is usually a high-speed disk. It is known as the swap device, and the section of disk used for this purpose is known as swap space. PERFORMANCE OF DEMAND PAGING: Demand paging can affect the performance of a computer system. The effective access time for a demand-paged memory is given by effective access time = (1 − p) × ma + p × page fault time. The memory-access time, denoted ma, ranges from 10 to 200 nanoseconds. If there is no page fault then the effective access time is equal to the memory access time. If a page fault occurs, we must first read the relevant page from disk and then access the desired word. There are three major components of the page-fault service time: 1. Service the page-fault interrupt. 2. Read in the page. 3. Restart the process With an average page-fault service time of 8 milliseconds and a memory access time of 200 nanoseconds, the effective access time in nanoseconds is Effective access time = (1 − p) × (200) + p (8 milliseconds) = (1 − p) × 200 + p × 8,000,000 = 200 + 7,999,800 × p. Effective access time is directly proportional to the page-fault rate.
NEED FOR PAGE REPLACEMENT: Page replacement is basic to demand paging If a page requested by a process is in memory, then the process can access it. If the requested page is not in main memory, then it is page fault. When there is a page fault the OS decides to load the pages from the secondary memory to the main memory. It looks for the free frame. If there is no free frame then the pages that are not currently in use will be swapped out of the main memory, and the desired page will be swapped into the main memory. The process of swapping a page out of main memory to the swap space and swapping in the desired page into the main memory for execution is called as Page Replacement.
0 Comments