Sistemas de archivos
Introducido
6:44
Sistemas operativos
An operating system turns one processor into many machines. The first three units build the illusions of the processor: processes, taking turns, and safe…
Narración en inglés · subtítulos en inglés y 中文 que puedes cambiar
En esta lección
| English | Significado |
|---|---|
| inode/ɪˈnəʊd/ | Nodo índice |
| directory/daɪˈrektəri/ | A file-system structure used to organise entries for files and other directories. |
| Journaling/ˈdʒɜːnəlɪŋ/ | writing planned file-system changes to a log first, so the system can recover after a crash |
| bitmap/ˈbɪtmæp/ | An image representation storing information about a grid of individual pixels. |
| fragmentation/ˌfræɡmənˈteɪʃn/ | free space broken into pieces too small or scattered to use well |
| hard link/hɑːd lɪŋk/ | An extra directory entry pointing to the same inode, so the file has several equal names. |
| symbolic link/sɪmˈbɒlɪk lɪŋk/ | A small file that contains the path of another file; it breaks if that path is removed. |
| Shortest seek first/ˈʃɔːtɪst siːk fɜːst/ | disk scheduling that serves the request nearest the current head position next |
Nombres, nodos i y bloques
- El nodo i contiene los metadatos de un archivo y 4 punteros directos más un bloque indirecto (256 punteros en 1 KiB cada uno); el directorio es en sí mismo un archivo de entradas de nombre a nodo i.
- Límite de tamaño: $(4 + 256) \times 1\,\mathrm{KiB} = 260$ KiB. Con bloques de 4 KiB: $(4 + 1024) \times 4\,\mathrm{KiB} = 4112$ KiB, aproximadamente 4 MiB.


With 1 KiB blocks, 4 direct pointers and one 256-pointer indirect block, the max file is —
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
(4 + 256) x 1 KiB = 260 KiB.
El precio del bloque 6
- Leer el bloque 6 de /notes/x: la búsqueda en directorio encuentra el nodo i (en caché); el bloque 6 está más allá de los cuatro punteros directos — leer el bloque indirecto (puntero 2), luego el bloque de datos: dos lecturas de disco para un bloque lógico.
- Leer secuencialmente un archivo de 100 bloques cuesta $100 + 1$ lecturas (el bloque indirecto una vez). La eliminación borra punteros, no datos — los bytes permanecen hasta que se reutilizan.
Reading block 6 (beyond the direct pointers) costs — disk reads
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
The indirect block first (pointer 2), then the data block.
Put the reads for block 6 of a file in order (inode $4$ direct pointers, one indirect block).
Dificultad 3/5 · 200 monedas + un pequeño bono en el primer intento de hoy
Blocks $0$ hasta $3$ use the direct pointers, so block 6 is entry $6 - 4 = 2$ of the indirect block: one extra read before the data.
La pregunta sobre el fallo
- La escritura en modo apéndice escribe los datos, luego el bit de la lista libre y finalmente el tamaño del nodo i. Si ocurre un fallo entre escrituras: escribir datos antes que el nodo i solo pierde espacio (un bloque huérfano); escribir el nodo i antes que los datos miente sobre el tamaño (las lecturas devuelven basura).
- El registro escribe primero la intención y la reinterpreta tras un fallo: es el pequeño costo de escritura que los sistemas de archivos modernos pagan por consistencia ante fallos.
Journaling survives crashes by —
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
The journal records what is about to happen; replay finishes it after the crash.
Esta tarjeta es nueva, por eso aparece en inglés hasta que su traducción esté lista.
Tracking free space
- A bitmap 位图 keeps one bit per block. A 1 TiB disk with 4 KiB blocks has $2^{40} / 2^{12} = 2^{28}$ blocks, so the bitmap is $2^{28}$ bits $= 32$ MiB, small enough to cache.
- Three ways to give a file its blocks, each with a different weak spot. External fragmentation 碎片 means free space broken into gaps too small to use.
| Allocation | Random access | External fragmentation |
|---|---|---|
| contiguous | fast | yes |
| linked | walk the chain | none |
| indexed (inode) | fast | none |
- Indexed allocation pays with the pointer blocks themselves, which is why large files need an indirect block.
A 256 GiB disk uses 4 KiB blocks. How large is its free-space bitmap, in MiB?
Dificultad 2/5 · 140 monedas + un pequeño bono en el primer intento de hoy
2^38 / 2^12 = 2^26 blocks, so 2^26 bits = 2^23 bytes = 8 MiB.
Which allocation gives fast random access and no external fragmentation?
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
Each pointer jumps straight to a block, and blocks can sit anywhere on the disk.
Esta tarjeta es nueva, por eso aparece en inglés hasta que su traducción esté lista.
Hard links and symbolic links
- A hard link 硬链接 is a second directory entry for the same inode. The inode counts its links and frees the blocks only when the count reaches 0. A symbolic link 符号链接 is a small file that holds a path.
- Delete the original name: the hard link still reads the file (the count goes from 2 to 1), but the symbolic link now points at nothing. Hard links cannot cross file systems; symbolic links can.
Deleting a file's original name breaks its hard links.
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
The inode survives while its link count is above zero; symbolic links break.
Esta tarjeta es nueva, por eso aparece en inglés hasta que su traducción esté lista.
Worked example: ordering disk requests
- The head is at cylinder 50, with requests 82, 170, 43, 140, 24, 16, 190. In arrival order (FCFS) it moves 642 cylinders.
- Shortest seek first 最短寻道优先 goes 43, 24, 16, then out to 82, 140, 170, 190: only $\mathbf{208}$, although requests at the far end can wait for a long time. SSDs have no head, so this ordering does not help them.
Head at 50; requests 82, 170, 43, 140, 24, 16, 190. Total seek distance with shortest seek first?
Dificultad 2/5 · 140 monedas + un pequeño bono en el primer intento de hoy
$7 + 19 + 8 + 66 + 58 + 30 + 20 = 208$.
Same requests in arrival order: total seek distance?
Dificultad 2/5 · 140 monedas + un pequeño bono en el primer intento de hoy
$32 + 88 + 127 + 97 + 116 + 8 + 174 = 642$.
Esta tarjeta es nueva, por eso aparece en inglés hasta que su traducción esté lista.
Marks that slip away
- Thinking delete erases. Deletion clears pointers and the free bit; the bytes stay until the block is reused.
- Reading the indirect block every time. A sequential read loads it once: $101$ reads for a 100-block file.
- Writing the inode before the data. A crash between the two leaves an inode 索引节点 that points at garbage. Write the data first, or use a journal.
Esta tarjeta es nueva, por eso aparece en inglés hasta que su traducción esté lista.
Recap
- Inode: metadata, 4 direct pointers, one indirect block; a directory maps names to inodes.
- Largest file: $260$ KiB with 1 KiB blocks, about 4 MiB with 4 KiB blocks.
- Journaling 日志记录 writes the intent first, so a crash replays the change instead of damaging the file system.
¿Qué salió mal? Solo el equipo del sitio ve esta información.