Download Module 7: Process Synchronization

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Operating Systems
Lecture 32
Paging
Read Ch. 9.4
Operating System Concepts
7.1
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Thinking about implementing SRTN
 What do you have to change from FCFS?
Operating System Concepts
7.2
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Thinking about implementing SRTN
 What do will you need to implement the changes?
Operating System Concepts
7.3
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
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
OS
OS
OS
process 5
process 5
process 5
process 5
process 9
process 9
process 8
process 2
Operating System Concepts
process 10
process 2
process 2
7.4
process 2
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Dynamic Storage-Allocation Problem
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: 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.
First-fit and best-fit better than worst-fit in terms of
speed and storage utilization.
Operating System Concepts
7.5
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
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!
Operating System Concepts
7.6
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
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?
Operating System Concepts
7.7
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
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.
Operating System Concepts
7.8
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
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.
Operating System Concepts
7.9
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Address Translation Architecture
Operating System Concepts
7.10
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Paging Example
Operating System Concepts
7.11
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Storing of Addresses
Suppose the size of physical address space = 2m
Suppose the page size = 2n
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.
Operating System Concepts
7.12
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
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:
Operating System Concepts
7.13
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
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.
Operating System Concepts
7.14
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
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.
Operating System Concepts
7.15
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Free Frames
Before allocation
Operating System Concepts
After allocation
7.16
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005