Os Unit 5 Part 1
Os Unit 5 Part 1
Management
Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013
Memory
Memory
•Size (More)
•Access Time(Less)
•Per unit cost(Less)
Operating System Concepts – 9th Edition 8.2 Silberschatz, Galvin and Gagne ©2013
Memory
Operating System Concepts – 9th Edition 8.3 Silberschatz, Galvin and Gagne ©2013
Memory Management Strategies
Operating System Concepts – 9th Edition 8.4 Silberschatz, Galvin and Gagne ©2013
Logical vs. Physical Address Space
● The concept of a logical address space that is bound to a
separate physical address space is central to proper memory
management
● Logical address – generated by the CPU; also referred to as
virtual address
● Physical address – address seen by the memory unit
● Logical address space is the set of all logical addresses
generated by a program
● Physical address space is the set of all physical addresses
generated by a program
Operating System Concepts – 9th Edition 8.5 Silberschatz, Galvin and Gagne ©2013
Memory-Management Unit (MMU)
● Hardware device that at run time maps virtual to physical address
Is called memory management unit(MMU)
● Base register now called relocation register
● The value in relocation register is added to every address
generated by the user process(ie CPU)
● The user program deals with logical addresses; it never sees the
real physical addresses
● Execution-time
binding occurs
when reference is made
to location in memory
● Logical address bound
to physical addresses Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition 8.6
Background
● Program must be brought (from disk) into memory and placed within a
Main Memory for it to be run
● Main memory and registers are only storage CPU can access directly
● Protection of memory required to ensure correct operation
● A pair of base and limit registers define the logical address space
● CPU must check every memory access generated in user mode to be
sure it is between base and limit for that user
Operating System Concepts – 9th Edition 8.7 Silberschatz, Galvin and Gagne ©2013
Hardware Address Protection
Operating System Concepts – 9th Edition 8.8 Silberschatz, Galvin and Gagne ©2013
Hardware Support for Relocation and Limit Registers
Operating System Concepts – 9th Edition 8.9 Silberschatz, Galvin and Gagne ©2013
Swapping
● A process can be swapped temporarily out of memory to a
backing store(secondary memory), and then brought back into
memory(MM) for continued execution
● Roll out, roll in – swapping variant used for priority-based
scheduling algorithms; lower-priority process is swapped out so
higher-priority process can be loaded and executed
● Major part of swap time is transfer time; total transfer time is
directly proportional to the amount of memory swapped
● If next processes to be put on CPU is not in memory, need to
swap out a process and swap in target process
● Context switch time can then be very high
Operating System Concepts – 9th Edition 8.10 Silberschatz, Galvin and Gagne ©2013
Schematic View of Swapping
Operating System Concepts – 9th Edition 8.11 Silberschatz, Galvin and Gagne ©2013
Non-Contiguous
Static
Dynamic
Operating System Concepts – 9th Edition 8.12 Silberschatz, Galvin and Gagne ©2013
Contiguous Allocation
● The main memory must accommodate both the operating system
and the various user processes. Limited resource, must allocate
efficiently
● In contiguous memory allocation, each process is contained in a
single contiguous section of memory.
● Contiguous allocation is one early method
● Main memory usually into two partitions:
● Resident operating system, usually held in low memory
● User processes then held in high memory
● Each process contained in single contiguous section of
memory
Operating System Concepts – 9th Edition 8.13 Silberschatz, Galvin and Gagne ©2013
Continues Memory Allocation
Operating System Concepts – 9th Edition 8.14 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition 8.15 Silberschatz, Galvin and Gagne ©2013
Advantage and Disadvantage of Fixed
Memory partition
● Advantage
This scheme is simple and is easy to implement
It supports multiprogramming as multiple processes can be
stored inside the main memory.
Management is easy using this scheme
● Disadvantage
Internal Fragmentation
Limitation on the size of the process
External Fragmentation
Degree of multiprogramming is less
Operating System Concepts – 9th Edition 8.16 Silberschatz, Galvin and Gagne ©2013
Variable Partitioning
Operating System Concepts – 9th Edition 8.17 Silberschatz, Galvin and Gagne ©2013
Advantage and Disadvantage of Variable
size Memory partition
● Advantage
No Internal Fragmentation
Degree of Multiprogramming is Dynamic
No Limitation on the Size of Process
● Disadvantage
External Fragmentation
Difficult Implementation
Operating System Concepts – 9th Edition 8.18 Silberschatz, Galvin and Gagne ©2013
Contigues Allocation Algorithm
● First fit-
• Allocate the first hole that is big enough.
• Searching can start either at the beginning of the set of holes
or at the location where the previous first-fit search ended.
• We can stop searching as soon as we find a free hole that is
large enough.
● Best fit.-
• Allocate the smallest hole that is big enough.
• We must search the entire list, unless the list is ordered by
size.
• This strategy produces the smallest leftover hole.
Operating System Concepts – 9th Edition 8.19 Silberschatz, Galvin and Gagne ©2013
● Worst fit.-
• Allocate the largest hole. Again, we must search the entire
list, unless it is sorted by size.
• This strategy produces the largest leftover hole, which may be
more useful than the smaller leftover hole from a best-fit
approach.
Operating System Concepts – 9th Edition 8.20 Silberschatz, Galvin and Gagne ©2013
Dynamic Storage-Allocation Problem
How to satisfy a request of size n from a list of free holes?
● 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 – 9th Edition 8.21 Silberschatz, Galvin and Gagne ©2013
Fragmentation
● External Fragmentation – total memory space exists to satisfy a
request, but it is not contiguous
Operating System Concepts – 9th Edition 8.22 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition 8.23 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition 8.24 Silberschatz, Galvin and Gagne ©2013
Paging
● Paging is a memory-management scheme that permits Physical
address space of a process can be noncontiguous;
● process is allocated physical memory whenever the space is available
● Avoids external fragmentation
● Avoids problem of varying sized memory chunks
● Divide physical memory into fixed-sized blocks called frames
● Size is power of 2, between 512 bytes and 16 Mbytes
● Divide logical memory(Process) into blocks of same size called pages
● Keep track of all free frames
● To run a program of size N pages, need to find N free frames and load
program
● Set up a page table to translate logical to physical addresses
Operating System Concepts – 9th Edition 8.25 Silberschatz, Galvin and Gagne ©2013
Address Translation Scheme
Operating System Concepts – 9th Edition 8.26 Silberschatz, Galvin and Gagne ©2013
Paging Hardware
Operating System Concepts – 9th Edition 8.27 Silberschatz, Galvin and Gagne ©2013
Paging Model of Logical and Physical Memory
Operating System Concepts – 9th Edition 8.28 Silberschatz, Galvin and Gagne ©2013
Paging Example
Operating System Concepts – 9th Edition 8.29 Silberschatz, Galvin and Gagne ©2013
Paging (Cont.)
Operating System Concepts – 9th Edition 8.30 Silberschatz, Galvin and Gagne ©2013
Free Frames
Operating System Concepts – 9th Edition 8.31 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition 8.32 Silberschatz, Galvin and Gagne ©2013
Implementation of Page Table
● Page table is kept in main memory
● Page-table base register (PTBR) points to the page table
● Page-table length register (PTLR) indicates size of the page
table
● In this scheme every data/instruction access requires two
memory accesses
● One for the page table and one for the data / instruction
● The two memory access problem can be solved by the use of
a special fast-lookup hardware cache called associative
memory or translation look-aside buffers (TLBs)
Operating System Concepts – 9th Edition 8.33 Silberschatz, Galvin and Gagne ©2013
Associative Memory
Operating System Concepts – 9th Edition 8.34 Silberschatz, Galvin and Gagne ©2013
Paging Hardware With TLB
Operating System Concepts – 9th Edition 8.35 Silberschatz, Galvin and Gagne ©2013
Effective Access Time
● Paging scheme using TLB. TLB access time 10 ns and
memory access time takes 50ns . What is effective
memory access time (in ns) if TLB hit ratio is 90% and
there is no page fault
=90%(10+50) + 10%(10+50+50)
=
Operating System Concepts – 9th Edition 8.36 Silberschatz, Galvin and Gagne ©2013
Memory Protection
Operating System Concepts – 9th Edition 8.37 Silberschatz, Galvin and Gagne ©2013
Valid (v) or Invalid (i) Bit In A Page Table
Operating System Concepts – 9th Edition 8.38 Silberschatz, Galvin and Gagne ©2013
Segmentation
Operating System Concepts – 9th Edition 8.39 Silberschatz, Galvin and Gagne ©2013
User’s View of a Program
Operating System Concepts – 9th Edition 8.40 Silberschatz, Galvin and Gagne ©2013
Segmentation Architecture
● Logical address consists of a two tuple:
<segment-number, offset>,
● Segment table – maps two-dimensional physical addresses; each
table entry has:
● base – contains the starting physical address where the
segments reside in memory
● limit – specifies the length of the segment
Operating System Concepts – 9th Edition 8.41 Silberschatz, Galvin and Gagne ©2013
Logical View of Segmentation
4
1
3 2
4
Operating System Concepts – 9th Edition 8.42 Silberschatz, Galvin and Gagne ©2013
Segmentation Hardware
Operating System Concepts – 9th Edition 8.43 Silberschatz, Galvin and Gagne ©2013
End of Chapter 8
Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013