Download presentation
Presentation is loading. Please wait.
Published byMatthew Atkins Modified over 9 years ago
1
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.1 Operating System Concepts Operating Systems Lecture 32 Paging Read Ch. 9.4
2
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.2 Operating System Concepts Thinking about implementing SRTN What do you have to change from FCFS?
3
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.3 Operating System Concepts Thinking about implementing SRTN What do will you need to implement the changes?
4
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.4 Operating System Concepts Contiguous Allocation Multiple-partition allocation Initially, all non-OS memory is available for user processes. Hole – block of available memory; When a process arrives, it is allocated memory from a hole large enough to accommodate it. Holes of various size are scattered throughout memory. Operating system maintains information about: a) allocated partitions b) free partitions (hole) OS process 5 process 8 process 2 OS process 5 process 2 OS process 5 process 2 OS process 5 process 9 process 2 process 9 process 10
5
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.5 Operating System Concepts Dynamic Storage-Allocation Problem First-fit: Allocate the first hole that is big enough. Best-fit: Allocate the smallest hole that is big enough; must search entire list, unless ordered by size. Produces the smallest leftover hole. Worst-fit: Allocate the largest hole; must also search entire list. Produces the largest leftover hole. When a process arrives, search for a hole big enough for it. If none available, the process must wait. When a process terminates, memory is freed, creating a hole. This new hole may join with other contiguous holes to create a bigger hole. How to satisfy a request of size n from a list of free holes: First-fit and best-fit better than worst-fit in terms of speed and storage utilization.
6
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.6 Operating System Concepts External Fragmentation As memory is allocated to processes and freed as processes terminate, the free memory space is broken into small pieces. External Fragmentation – total memory space exists to satisfy a request, but it is not contiguous. With the first fit memory allocation rule, given N allocated blocks, another 0.5N blocks may be lost due to fragmentation (50 percent rule). This means 1/3 of memory is unusable!
7
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.7 Operating System Concepts Internal Fragmentation One method of allocating memory is to break memory into fixed sized blocks. Memory is allocated in units of block sizes. The memory allocated may be slightly larger than the size needed by the process. This is Internal Fragmentation. With Internal Fragmentation, the size difference between the process size and the allocated memory is memory internal to a partition, but not being used. Example: Block size 1024 bytes. Process size: 4048 bytes. What is the internal fragmentation size?
8
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.8 Operating System Concepts Compaction One can reduce external fragmentation by compaction. Shuffle memory contents to place all free memory together in one large block. Compaction is possible only if relocation is dynamic, and is done at execution time. I/O problem Latch job in memory while it is involved in I/O. Do I/O only into OS buffers.
9
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.9 Operating System Concepts Paging Paging allows the physical address space of a process to be non-contiguous. Divide physical memory into fixed-sized blocks called frames (size is power of 2, between 512 bytes and 8192 bytes). Divide logical memory into blocks of same size called pages. Each address generated by the CPU consists of a page number, p, and an offset, d. Page number: Index to a page table that contains the base address of the corresponding frame in physical memory. Page offset: Combined with the base address to define the physical memory address that is sent to the memory unit.
10
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.10 Operating System Concepts Address Translation Architecture
11
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.11 Operating System Concepts Paging Example
12
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.12 Operating System Concepts Storing of Addresses Suppose the size of physical address space = 2 m Suppose the page size = 2 n What is the total number of pages? Allocate m bits to specify logical addresses. First m - n bits of the address specify the page number. The n lower order bits indicate the offset.
13
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.13 Operating System Concepts Paging Example Page size = 4 bytes Physical memory = 32 bytes Number of pages = ? Where do the following map? Logical 0: Page 0, offset 0: Logical 3: Page 0, offset 3: Logical 4: Logical 13:
14
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.14 Operating System Concepts Paging and Fragmentation Don't have external fragmentation with paging. Any free frame can be allocated to a process that needs it. May have internal fragmentation with paging. Frames are allocated as units. Last frame may not be completely full.
15
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.15 Operating System Concepts Allocation of Frames The O.S. keeps track of which frames are allocated and which are free in a frame table. If a process requests n frames, there must be n frames available to satisfy the request. If so, they are allocated to the process. As each frame is allocated to each page, the frame number is put in the page table for that process. Note: The user views memory as contiguous space. The program is actually scattered throughout physical memory.
16
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.16 Operating System Concepts Free Frames Before allocation After allocation
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.