Dischi e file system

Transcript

Dischi e file system
Struttura fisica di un disco
Un disco è fatto di piatti coassiali in grado di ruotare attorno all’asse.
I dati sono memorizzati su ciascun lato o superficie di ogni piatto;
ogni lato ha una testina R/W che può muoversi rispetto al centro:
superficie 1
superficie 0
testine R/W (solidali)
traccia (corona circolare)
cilindro=
{
tracce corrispondenti
sulle diverse superfici
braccio oscillante
con testina
settore
Questo complesso di organi elettromeccanici si dice disk drive.
Tecnologie (dischi magnetici):
HD
piatti di Al o vetro-ceramica 3.5-5”, ricoperti di ossidi di ferro;
densità di informazione p.es. 50kbit/inch; 2000 tracks/inch;
in rotazione continua (3600-7200 rpm), sigillati (Winchester)
per produrre un cuscino d’aria (1-10µ) tra testina e superficie
FD
disco plastico 3.5”; ruota solo durante l’accesso;
le testine toccano la superficie
Dischi e file system- 03/16/06 11:57 PM
1/11
Dischi: caratteristiche
Dimensioni tipiche (esempi)
Cilindri (o Superfici
tracce/sup) (o testine)
HD 2000
20
HD 500
10
FD 80
2
Settori/traccia Byte/sect Totale
100
20
18
512
512
512
2G
50M
1.4M
512 byte/sector è lo standard per i PC.
Prestazioni (HD)
• tempo di accesso a un settore (non sotto la testina) consta di:
seek time (la testina va sulla traccia del settore desiderato);
p.es. track-to-track=4ms, max=20-100 ms
+ latency time (il settore ruota fin sotto la testina)
(p.es., max 16.67ms a 3600 rpm)
• throughput (velocità di trasferimento dell’informazione in bit/s):
1. teorica, dal supporto fisico = (n. byte per traccia) × (rpm)/60;
2. di picco (burst) all’interfaccia drive-controller;
3. medio, all’interfaccia drive-controller
4. sul bus di sistema (interfaccia controller-CPU)
Per vari fattori, (2) > (3) > (4); p.es. 9, 4, 1 Mbyte/s;
p.es. (2) > (3) perché la media su più tracce include il seek time e
(3) > (4) a causa del bus (p.es. ISA) o del controller tra drive e bus
Dischi e file system- 03/16/06 11:57 PM
2/11
Indirizzamento/geometria del disco
Un settore può individuarsi con l’indirizzo (detto CHS) <c,h,s>, dove:
• c=n.cilindro (0...), h=n.head (0...), s=n.settore (nella traccia, 1...)
(cilindro 0=più esterno, in FD settore 1 dopo foro di riferimento)
Si usa pure il sector number o LBA (Linear Block Addressing) (28 bit):
posizione di <c,h,s> da <0,0,1> contata incrementando s poi h poi c:
sup 0
...
sup h
...
sup 12
0
63
...
...
Cil 0
...
...
sec 1
...
...
...
...
...
62
125
...
sec 63
Cil c
sec 1
...
sec s
...
sec 63
Quindi il sector number LBA di <c,h,s> è dato da:
• c×(n. settori per cilindro) + h×(n. settori per traccia) + s - 1
• (n. settori per cilindro) = (n. superfici) × (n. settori per traccia)
Ciò rispecchia la strategia di allocazione di settori consecutivi:
1. nella stessa traccia finché possibile, poi
2. nella traccia omologa della superficie successiva (stesso cilindro)
3. esaurito il cilindro, nei cilindri successivi.
2→3 è meno efficiente di 1→2 (seek time 0, testine già su traccia).
A volte il numero di settore LBA si calcola da un riferimento ≠ <0,0,1>
(per es., nel PC, in un HD suddiviso in partizioni o unità logiche);
si parla allora di numero di settore relativo.
Dischi e file system- 03/16/06 11:57 PM
3/11
Controller
I disk drive sono collegati al bus via un’interfaccia detta controller
(convenzione: drive = elettro-meccanica, controller = elettronica):
Controller
Drive 1
Drive 2
CR
SR
SCR
SNR
HND
DR
CNH
CNL
DOR
Buffer
Bus
CR:
SR:
SNR:
HND:
CNH:
CNL:
SCR:
DR:
DOR:
Control Register
Status Register
Sector Number Register
Head Number/Drive R.
Cylinder Number High R.
Cylinder Number Low R.
Sector Count Register
Data Register (16 bit)
Digital Output Register
Il buffer (min 1 sect) accoppia le diverse velocità di drive e bus;
un buffer di dimensioni ragguardevoli (p.es. 2MB) si dice cache.
Il controller presuppone il disco formattato “a basso livello”:
• tracce delimitate da sequenze di bit (preambolo e postambolo)
• il settore “geometrico” (area di disco coinvolta in un accesso)
memorizza dati e informazione di controllo in particolari formati;
p.es. “soft-sector” FD:
1. identificatore: n.traccia e n.settore del settore + CRC
2. 0,5K dati (settore “logico” visto dal sw via controller) + CRC
3. postambolo
4. sequenza di delay gap (separa da settore successivo)
(1), (3), (4) permettono al controller di sincronizzarsi col disco e
riconoscerne la struttura.
Dischi e file system- 03/16/06 11:57 PM
4/11
Dischi e PC
Driver: parte di SO che pilota un controller (int 13 BIOS/DOS).
Il BIOS controlla l’interfaccia fisica drive/controller
programmando i registri del controller:
Drive
Cavo
Interf. ATAn
Interazioni
logiche (SW)
Interazioni fisiche
Bus
Controller
Drive/
Controller
CPU
Register
level I/O
BIOS
Int 13
DOS or
Application
Drive EIDE. In genere, drive elettromeccanico/controller elettronico;
ma EIDE integra elettronica/processore/firmware, per due ragioni.
1. Un disco EIDE contiene un buffer/cache interno (p.es. 256KB)
per incrementare le prestazioni massimizzando il cache hit ratio
(accessi cache / accessi totali) con varie strategie di caching:
• read-only detto anche read-ahead, look-ahead, write-through:
read anticipato settori successivi a quelli richiesti,
write immediato su disco, non passando da cache
• read/write o write-behind: anche il write passa dalla cache
• segmentazione cache per coprire più aree del disco
• auto-adattamento: scelta dinamica numero/dimensione dei
segmenti
2. Un disco EIDE adatta le caratteristiche interne del drive a:
1. interfaccia standard drive-controller (ATA), e quindi anche
2. al BIOS che controlla (1) programmando il controller
→
evoluzione tecnologia drive non ha impatto su architettura PC
Esempio: traduzione geometria interna/esterna (vedi pag. 6).
Dischi e file system- 03/16/06 11:57 PM
5/11
Dischi e PC: traduzioni
Il firmware su EIDE traduce la geometria interna del drive
(tipicamente indirizzo CHS con più settori nelle tracce più esterne),
nella geometria “esterna” vista da controller e BIOS
(p.es. LBA o CHS con n.settori/traccia costante)
EIDE
Internal CHS
geometry
Controller
Translation
EBIOS
CHS int 13
geometry
DOS or
Applications
Translation
LBA or extended CHS geometry
Il BIOS può introdurre un altro livello di traduzione di indirizzi di disco:
gli HD odierni hanno più cilindri del max previsto dal BIOS int 13:
quindi un moderno EBIOS simula meno cilindri e più testine.
DOS
View
Cylinder: 10 bits
Head: 8 bits
Sector: 6 bits
int 13
Translating BIOS (EBIOS)
Controller/
Disk View
ATA
(con CHS)
Cylinder: 16 bits
Hd:4 b.
Sector: 8 bits
Max capacità gestibile:
• int 13: max 210×28×63 ≈ 210+8+6 settori = 223 K = 8G
• ATA: max 228 settori = 227 K = 128G
Ma se EBIOS non traducesse (come BIOS obsoleti):
• max 210×24×63 ≈ 210+4+6 settori = 219 K = 0.5G
Esempio: caratteristiche disco fisico/logico
valore fisico
valore logico
testine
4
11
Dischi e file system- 03/16/06 11:57 PM
cilindri
1704
723
settori/traccia
54-92 (esterno)
63
6/11
SCSI vs. EIDE
Non-issues
SCSI/IDE HD cost about the same for the same size/speed.
Advantages of IDE
• faster response time (low request overhead)
• HD drive interface compatible with RLL/MFM/ESDI:
any driver for one (including system BIOS) will run the other.
• IDE controllers integrated on motherboard unlike
SCSI host adapters.
• Will always be the boot device when mixed with SCSI.
Advantages of SCSI
• Supports up to 7 devices per host adapter.
Saves slots IRQ's, DMA channels &, as you add devices, money
• Supports different types of devices sharing same host adapter
(hard drives, tape drives, CDROMs, scanners, etc).
• SCSI devices will work in other systems as well (Mac, etc.)
• Automatically configures device type, geometry (size), speed
and even manufacturer/model number(SCSI-2).
No need to look up CMOS settings.
• Busmastering DMA (available in all but a few cheap adapters)
decreases amount of CPU time required to do I/O,
leaving more time to work on other tasks (multitasking OS only).
• SW portability – a driver:
• is written for host adapter, not specific device.
• drives any brand/speed SCSI CD drive attached to adapter
Dischi e file system- 03/16/06 11:57 PM
7/11
• Coexists with any other type of controller (IDE/RLL/MFM/ESDI)
or host adapter (other SCSI cards) without any special tricks.
SCSI host adapters do not take up one of the two available HD
controller port addresses.
• higher bandwidth utilization (throughput) with multiple devices.
Supports pending requests, which allows the system to overlap
requests to multiple devices so that one device can be seeking
while the second is returning data.
• Ability to "share" devices between machines by connecting
them to the same SCSI bus. (note: this is considerably more
difficult to do than it sounds).
Warnings
• With otherwise equal drives, IDE will perform better in DOS due
to low command overhead.
SCSI will perform better in multitasking OS's (OS/2, Unix, NT...).
• Most benchmarks only test one aspect of your system at a time,
not the effect various aspects have on each other.
For instance, an IDE drive may get faster throughput but hurt
CPU performance during the transfer, so your system may
actually run slower.
• When comparing two systems, keep in mind that CPU, memory,
cache, and bus speed/type will all effect disk performance.
• If someone gets great I/O performance with a particular
controller/drive combination on his Pentium, you should not
expect your 386SX-25 to get such I/O performance even with
the exact same controller/drive combination.
Dischi e file system- 03/16/06 11:57 PM
8/11
ATA drives/controllers do not offer a key SCSI feature:
• Command Queuing: allows multiple requests to "queue" and
remain pending on the SCSI subsystem as opposed to ATA's
serial approach where one request must be finished before
another is started.
• This parallel execution allows SCSI to reorder requests into a
sequence that minimizes head/actuator seek motions.
• SCSI's advanced features should result in less degradation in
multitasking and multithreaded environments.
Dischi e file system- 03/16/06 11:57 PM
9/11
Accesso diretto al disk controller
Il software potrebbe pilotare il controller scavalcando il BIOS. P.es.:
call
call
call
spec_sect_r
wait_read
; attende completamento read
do_read
; trasferisce dati controller a sistema
spec_sect_r specifica al controller il settore da leggere:
spec_sect_r
proc
; n. settori da leggere = 1
; scr = sector count register del controller
mov
mov
out
al,1
dx,scr
dx,al
mov
mov
out
al,sect_n ; sect_n = n.settore da leggere
dx,snr
; snr = sector number register del controller
dx,al
mov
mov
out
mov
mov
out
ax,cyl_n
dx,cnl
dx,al
dx,cnh
al,ah
dx,al
mov
mov
out
al,head_n ; head_n = n.testina e drive settore da leggere
dx,hnd
; hnd = head number / drive register controller
dx,al
mov
mov
out
dx,dor
al,0
dx,al
; bit 1 di dor controlla gli interrupt dal controller
; 0 per disabilitare gli interrupt
mov
mov
out
dx,cr
al,21H
dx,al
; cr = command register controller
; 21H = comando read per il controller
; cyl_n = n.cilindro settore da leggere
; cnl = cylinder number low register controller
; cnh = cylinder number high register controller
ret
spec_sect_r
endp
Costanti registri controller:
dr
scr
snr
cnl
cnh
hnd
sr
cr
dor
equ
equ
equ
equ
equ
equ
equ
equ
equ
01f0h
01f2h
01f3h
01f4h
01f5h
01f6h
01f7h
01f7h
03f6h
Dischi e file system- 03/16/06 11:57 PM
; come sr, ma usato in lettura
10/11
Esempio: accesso diretto al controller / 2
Il sw attende in un loop il completamento del comando read
(cioè che i dati passino dal disco al controller).
Il loop usa lo status register del controller sr, in particolare i bit:
• bit 7: busy, il controller lo pone a 1 mentre esegue un comando
• bit 3: data request, a 1 se il controller può trasferire dati
• bit 0: se 1 error sul precedente comando
wait_read
proc
check:
mov
in
dx,sr
al,dx
test
jz
al,08H
check
; polling registro sr
ret
wait_read
endp
All’uscita da wait_read:
• il buffer contiene (almeno) il settore richiesto,
• il data register dr del controller contiene la 1a word del settore
• ogni in da dr lo ricarica automaticamente con la prossima
word del buffer
do_read legge un settore (via dr) e lo visualizza:
do_read
proc
display:
mov
mov
in
call
loop
dx,dr
cx,100H
ax,dx
display_ax
display
; dr=01f0, indirizzo I/O data register controller
; cx = n.word da visualizzare (512 byte)
; ax:= data register controller
ret
do_read
endp
Dischi e file system- 03/16/06 11:57 PM
11/11