levels. School will provide equipments f. pfV.rir¡ng the training ...

By
Published by

  • cours - matière potentielle : year
  • cours - matière potentielle : team for competition
  • expression écrite - matière potentielle : club activ¡ty start date
  • cours - matière potentielle : act¡vit¡es
  • cours - matière potentielle : team players
  • exposé
  • cours - matière potentielle : for the beginner
  • cours - matière potentielle : for hkssf
  • expression écrite
  • cours - matière potentielle : events
  • cours - matière potentielle : activity
:: ESF :: GateÌ-,'ay Activ¡ty Enrolment lL/ 12 Term2 esf .ed u,hk/src/moclule/cas/activìty_enrol_print php 2012-0r-t6 2012-03-16 77172 (2) 17/72 (2) 20 AII Covered by act¡vity registration flat fee Day: lu , 15:30:00 To 16:30:OO , Location : C34 It will take the form of a discussion group compar¡ng different worrd views .
  • activity registration
  • activity start date
  • activ ity-enrol-print
  • activity end date
  • dance club
  • flat fee
  • ms
  • php
Published : Wednesday, March 28, 2012
Reading/s : 48
Tags :
Origin : cs.wpi.edu
Number of pages: 10
See more See less
Operating Systems
Memory Management (Ch 8.1  8.6)
Simple Memory Management
One process in memory, using it all – each program needs I/O drivers – until 1960
RAM
User Prog
I/O drivers
Multiprocessing w/Fixed Partitions Simple! Partion 4 Partion 4 900k Partion 3 Partion 3 500k Partion 2 Partion 2 300k Partion 1 Partion 1 200k OS OS
(a) (b) Waste large partition Unequal queues Skip small jobs Hey, processes can be in different memory locations!
Overview
Provide Services – processes – files Manage Devices – processor – memory – disk
(done) (done) (done in cs4513)
(done) (next!)
Simple Memory Management Small, protected OS, drivers – DOS Device OS ROM ROM Drivers
RAM
User Prog
RAM User Prog
User RAM Prog
OS OS “Monoprogramming”  No multiprocessing! Early efforts used “Swapping”, but slooooow
Address Binding Compile Time – maybe absolute binding ( ) .com Link Time – dynamic or static libraries Load Time – relocatable code Run Time – relocatable memory segments – overlays – paging
Source
Object
Compile
Link Load Module Load RAM Binary
Run
1
Logical vs. Physical Addresses CompileTime + Load Time addresses same Run time addresses different
Relocation Logical Physical Register Address Address CPU Memory 14000 346 14346 + MMU User goes from 0 tomax Physical goes from +0 to +max R R
Design Technique: Static vs. Dynamic Static solutions – compute ahead of time – for predictable situations Dynamic solutions – compute when needed – for unpredictable situations Some situations use dynamic because static too restrictive ( ) malloc ex: memory allocation, type checking
VariableSized Partitions
Idea: want to remove “wasted” memory that is not needed in each partition Definition: Hole a block of available memory – scattered throughout physical memory New process allocated memory from hole large enough to fit it
Relocatable Code Basics Allowlogicaladdresses Protect other processes
CPU
Limit Reg
yes < no error
Reloc Reg
+ physical address
Addresses must be contiguous!
Review
Memory
What is a relocation register? What are some of the sections in an object module? What are some of the steps that occur during linking?
ari  ize ions OS OS OS OS process 5 process 5 process 5 process 9 process 9 8 done 9 arrv 10 arrv process 8 process 10 5 done
process 2
process 2
OS keeps track of: – allocated partitions – free partitions (holes) – queues!
process 2
process 2
2
VariableSized Partitions
Given a list of free holes:
100k
140k
110k
25k
How do you satisfy a request of sizes? – 20k, 130k, 70k
VariableSized Partitions
75k
Firstfit: might not search the entire list Bestfit: must search the entire list Worstfit: must search the entire list
Firstfit and Bestft better than Worstfit in terms of speed and storage utilization
Internal Fragmentation Have some “empty” space for each processes A stack Room for growth Allocated to A A data A program OS Internal Fragmentation  allocated memory may be slightly larger than requested memory and not being used.
VariableSized Partitions
100k
140k
110k
25k
75k
Requests: 20k, 130k, 70k – First fit: allocatefirsthole that is big enough – Best fit: allocatesmallesthole that is big enough – Worstfit: allocatelargesthole (say, 120k)
Memory Request?
What if a request for additional memory?
OS
process 3
process 8
process 2
malloc(20k)?
External Fragmentation
External Fragmentation  total memory space exists to satisfy re uest but it is not contiguous OS 50k process 3 125k Process 9? process 8 100k process 2
3
Review
What is the Memory Management Unit? What is external fragmentation? What is internal fragmentation?
Analysis of External Fragmentation
Assume: – system at equilibrium – process in middle – if N processes, 1/2 time process, 1/2 hole ==> 1/2 N holes! – Fifty percent rule – Fundamental: adjacent holes combined adjacent processes not combined
t of Comp process 1 process 1 50k process 3 process 3 90k process 8 process 2 process 8 60k 100k process 2
128 MB RAM, 100 nsec/access è1.5 seconds to compact! Disk much slower!
Where Are We? Memory Management – fixed partitions (done) – linking and loading (done) – variable partitions¬ Paging Misc
Compaction Shuffle memory contents to place all free memory together in one large block Only if relocation dynamic! Same I/O DMA problem (a) (b) OS OS OS 50k process 3 process 3 90k process 8 125k Process 9 process 8 60k process 8 100k process 3 process 2 process 2 process 2
Solution?
Want to minimize external fragmentation – Large Blocks – But internal fragmentation! Tradeoff – Sacrifice some internal fragmentation for reduced external fragmentation Paging
4
100
Pa e 1 4
Physical Memory
00 01 01 11 10 00
111
Logical Memory
Pa e 2
Paging Example Offset
Page size 4 bytes Memory size 32 bytes (8 pages)
note: not losing any bytes!
Paging Hardware
Pa e 0 Pa e 1
m address space 2 n page size 2 mn page offset 2
CPU
Paging Example
Paging Address generated by CPU divided into: Page number (p) index to page table page tablecontains base address of each page in physical memory (frame) Page offset (d) offset into page/frame
101 110
000 001
0 0 1
5
Paging
Page Table
010 011
000
Page
001
0 1
2
3
Page 2
Pa e 0
2 3 3 7
6 7
Page 3
1 4
physical memory
f
Page Table
Logical address space noncontiguous; process gets memory wherever available – Divide physical memory into fixedsize blocks size is a power of 2, between 512 and 8192 bytes calledFrames – Divide logical memory into bocks of same size calledPages
f d
page table
p d
phsical memory m 2 bytes
110 111
101
Logical Memory
Paging Example
11 10
5
0 1 1
0 1
Frame
Page 3
Consider: – Physical memory = 128 bytes – Physical address space = 8 frames How many bits in an address? How many bits for page number? How many bits for page offset? Can a logical address space have only 2 pages? How big would the page table be?
page offset d n
page number p mn
100
011
010
Physical Memory
page table
Page table kept in main memory Page Table Base Register(PTBR)
physical memory
1020% mem time
6
0
Implementation of Page Table
1 4
Associative Registers
Disk
Implementation of Page Table
Page table kept in registers Fast! Only good when number of frames is small Expensive!
Registers Memory
0
2 Page 1 1 4 PTBR 3 Logical Page Table Memory Physical Memory Page Table Length Two memory accesses per data/inst access. – Solution?Associative Registers
f d
f
physical address
logical addressp d
hit
CPU
page frame number number
associative registers miss
1
Another Paging Example
Paging Tradeoffs Advantages – no external fragmentation (no compaction) – relocation (now pages, before were processes) Disadvantages – internal fragmentation consider: 2048 byte pages, 72,766 byte proc – 35 pages + 1086 bytes = 962 bytes avg: 1/2 page per process small pages! – overhead page table / process (context switch + space) lookup (especially if page to disk)
Page Table Example b=7 0 0 3 Page 0 Page 0 1A 1 7 Page 1 2 Page Table Process B Page 0 3B page number page offset Page 1 p d A 4 mn=3 n=4 5 Page 0 0 1 6 Page 1 1 4 Page 1 B 7 Process A Page Table Physical Memory
Consider: – 8 bits in an address – 3 bits for the frame/page number How many bytes (words) of physical memory? How many frames are there? How many bytes is a page? How many bits for page offset? If a process’ page table is 12 bits, how many logical pages does it have?
Associative Register Performance Hit Ratio percentage of times that a page number is found in associative registers Effective access time = hit ratioxhit time + miss ratioxmiss time hit time = reg time + mem time miss time = reg time + mem time * 2 Example: – 80% hit ratio, reg time = 20 nanosec , mem time = 100 nanosec – .80 * 120 + .20 * 220 = 140 nanoseconds
Large Address Spaces
Typical logical address spaces: 32 – 4 Gbytes => 2 address bits (4byte address) Typical page size: 12 – 4 Kbytes = 2 bits Page table may have: 3 2 1 2 2 0 – 2 / 2 = 2 = 1million entries Each entry 3 bytes => 3MB per process! Do not want that all in RAM Solution? Page the page table – Multilevel paging
page n p1
Multilevel Paging Translation
p2
page offset d
p1
outer page table
p2
inner page table
d desired page
Protection Protection bits with each frame Store in page table Protection Bit Expand to more perms 0 1 v 0 Page 1 Page 0 1 0 v 1 Page 0 Page 1 2 3 v 2 Page 2 3 0 i 3 Page 2 Logical Page Table Memory Physical Memory
page nu p1 p2 10 10
Pa e 0 ... ...
Logical Memory
Multilevel Paging page offset d 12
...
Outer Page Table
...
...
...
Page Table
Inverted Page Table Page table maps to physical addresses
CPU
pid
p
pid
p
d
i
i
d
Physical Memory
Still need page per process > backing store Memory accesses longer! (search + swap)
7
Memory View Paging lost users’ view of memory Need “logical” memory units that grow and contract
ex: stack, shared library
Solution? Segmentation!
logical addresss d
CPU
subroutine
main
stack
symbol table
Segmentation
limit base
< no error
yes
+
physical address
main
stack
physical memory
Software Interrupts SendInterrupt(pid, num) – type to process , num pid in Unix – kill() HandleInterrupt(num, handler) – type , use function num handler in Unix – signal() Typical handlers: – ignore – terminate (maybe w/core dump) – userdefined – (Hey, demos!)
Segmentation Logical address: <segment, offset> Segment table  maps two dimensional user defined address into onedimensional physical address – base  starting physical location – limit  length of segment Hardware support – Segment Table Base Register – Segment Table Length Register
Operating Systems
Software Signals
Unreliable Signals Before POSIX.1 standard: signal(SIGINT, sig _int ); ... sig_int() { /* reestablish handler */ signal(SIGINT, sig _int ); } Another signal could come before handler reestablished!
8
Memory Management Outline Basic– Fixed Partitions– Variable PartitionsPaging – Basic– EnhancedSpecific¬ – WinNT – Linux Virtual Memory
Memory Management in WinNT
Each pagetable entry has 32 bits – only 20 needed for address translation – 12 bits “left over” Characteristics – Access: read only, readwrite – States: valid, zeroed, free … Inverted page table – points to page table entries – list of free frames
Memory Management in Linux
Buddyheap Buddyblocks are combined to larger block Linked list of free blocks at each size If not small enough, broken down
16 KB
8 KB
8 KB
8 KB
4 KB
Memory Management in WinNT
32 32 bit addresses 4 GB address space)(2 = – Upper 2GB shared by all processes (kernel mode) – Lower 2GB private per process 12 , so offset is 12 bits)Page size is 4 KB (2 Multilevel paging (2 levels) – 10 bits for outer page table (page directory) – 10 bits for inner page table – 12 bits for offset
Memory Management in Linux
Page size: – Alpha AXP has 8 Kbyte page – Intel x86 has 4 Kbyte page Multilevel paging (3 levels) – Makes code more portable – Even though no hardware support on x86! “middlelayer” defined to be 1
Object Module
Information required to “load” into memory Header Information Machine Code Initialized Data Symbol Table Relocation Information (see SOS sample)
9
Runtime Loader
Executable Code
Initialized Data
Memory
Main.o
Run Time 2 used 0
0
1Mb 1.1s 2.4s
ar
Combines several object modules into load module Resolve external references Relocation  each object module assumes starts at 0. Must change. Linking  modify addresses where one object refers to another (example  external)
Printf.c gcc
Static Library
Dynamic Library
ar
Printf.o
RunTime Dynamic Linking
Initialized Data
Loading an Object Resolve references of object module On Disk In Memory
a.out Loader
Memory
a.out
Loader
Run Time 0 used
0
Memory Linking Performance Comparisons
Uninitialized Data
Main.o
Save disk space. Libraries move? Moving code? Library versions? Load time still the same.
Load Time Dynamic Linking
Main.o
X Window code:  500K minimum  450K libraries
Linking an Object Module
Header
Executable Code
Dynamic Library
Linker
1.2s
Save disk space. Startup fast. Might not need all.
Main.c gcc
LinkinDis Load Run MethodS ace Time Time 4 used 3Mb 3.1s 0
Main.c gcc
Printf.c gcc
Linker
Memory
10
0
0
Printf.o
ar
Normal Linking and Loading Printf.c Main.c gcc gcc
Printf.o
a.out Loader
1Mb 3.1s 0
Linker
Be the first to leave a comment!!

12/1000 maximum characters.