Difference between revisions of "Operating Systems 2017F Lecture 18"

From Soma-notes
Jump to navigation Jump to search
Line 1: Line 1:
==Video==


== Additional Notes ==
The video from the lecture given on Nov. 16, 2017 [http://homeostasis.scs.carleton.ca/~soma/os-2017f/lectures/comp3000-2017f-lec18-16Nov2017.mp4 is now available].
 
==Notes==
 
===In Class===
<pre>
Lecture 18: Filesystems and such
--------------------------------
* How can you recover a filesystem?
* How do you delete a file?
 
A filesystem is
* persistent data structure
* stored in fixed-sized blocks (at least 512 bytes in size)
* maps hierarchical filenames to file contents
* has metadata about files (somehow)
 
What's in a filesystem?
* data blocks
* metadata blocks
 
How do you organize metadata?
 
First job: identify basic characteristics of the filesystem
 
You need a "summary" block that tells you about everything else
=> this is the "superblock"
 
Normally the superblock is the first block of the filesystem
 
In the superblock
- what kind of filesystem is this?
    - what filesystem magic number is there
- how big is the filesystem?
- how is it organized?
- where can I find the rest of the metadata?
 
for POSIX filesystems
- file metadata is stored in...inodes
- most have pre-reserved inodes
 
So we have
- superblock
- inode blocks
- data blocks
  - data blocks for directories
  - data blocks for files
 
How do you recover from damage?
- filesystems never "reboot", must remain correct over
  the course of years
- but errors will happen
  - bitrot
  - "accidental" corruption
  - computer failure/memory corruption/hard reboot
 
To make filesystems fast, data & metadata is cached in RAM
- bad things happen if this data hasn't been written to disk and you reboot
- even worse things happen if your RAM is bad and corrupts the data
 
Also bad...what if we lose the superblock?
- you could lose EVERYTHING
- so we have backup superblocks
 
Old scandisk/fsck was slow because they had to scan all filesystem metadata
- not to recover data, but to fix metadata
 
Nowadays fsck is very fast and we rarely lose data due to losing power
- we must be writing data to disk all the time
- but isn't writing all the time slow?
 
On magnetic hard disks (not SSDs)
- sequential operations are fast
- random access is slow
  - we have to move the read/write head
 
So, on modern systems we update metadata (and sometimes data) by writing
sequentially to disk...and then later writing randomly
- sequential writes go to the "journal"
 
On fsck on a journaled filesystem
- just check the journal for pending operations (replay the journal)
 
There exist filesystems that are pure journal
- log-based filesystem
 
logs and journal inherently create multiple copies of data and metadata that are hard to track.  This makes deletion nearly impossible (at least to guarantee)
 
Only way to guarantee...encrypt everything
- if every file has its own key, you can delete the key and thus "delete" the data
 
Solid State Disks (SSD) use log-structured storage at a level below blocks.
- writes are coarse-grained (you have to write a lot at once)
- you don't want to write to the same cells too often, they'll die
  - have to do "wear-leveling"
</pre>
 
 
===Additional Notes===
Lec 18 <br>
Lec 18 <br>
* More on filesystems <br>
* More on filesystems <br>

Revision as of 16:08, 16 November 2017

Video

The video from the lecture given on Nov. 16, 2017 is now available.

Notes

In Class

Lecture 18: Filesystems and such
--------------------------------
* How can you recover a filesystem?
* How do you delete a file?

A filesystem is
 * persistent data structure
 * stored in fixed-sized blocks (at least 512 bytes in size)
 * maps hierarchical filenames to file contents
 * has metadata about files (somehow)

What's in a filesystem?
 * data blocks
 * metadata blocks

How do you organize metadata?

First job: identify basic characteristics of the filesystem

You need a "summary" block that tells you about everything else
 => this is the "superblock"

Normally the superblock is the first block of the filesystem

In the superblock
 - what kind of filesystem is this?
    - what filesystem magic number is there
 - how big is the filesystem?
 - how is it organized?
 - where can I find the rest of the metadata?

for POSIX filesystems
 - file metadata is stored in...inodes
 - most have pre-reserved inodes

So we have
 - superblock
 - inode blocks
 - data blocks
   - data blocks for directories
   - data blocks for files

How do you recover from damage?
 - filesystems never "reboot", must remain correct over
   the course of years
 - but errors will happen
   - bitrot
   - "accidental" corruption
   - computer failure/memory corruption/hard reboot

To make filesystems fast, data & metadata is cached in RAM
 - bad things happen if this data hasn't been written to disk and you reboot
 - even worse things happen if your RAM is bad and corrupts the data

Also bad...what if we lose the superblock?
 - you could lose EVERYTHING
 - so we have backup superblocks

Old scandisk/fsck was slow because they had to scan all filesystem metadata
 - not to recover data, but to fix metadata

Nowadays fsck is very fast and we rarely lose data due to losing power
 - we must be writing data to disk all the time
 - but isn't writing all the time slow?

On magnetic hard disks (not SSDs)
 - sequential operations are fast
 - random access is slow
   - we have to move the read/write head

So, on modern systems we update metadata (and sometimes data) by writing
sequentially to disk...and then later writing randomly
 - sequential writes go to the "journal"

On fsck on a journaled filesystem
 - just check the journal for pending operations (replay the journal)

There exist filesystems that are pure journal
 - log-based filesystem

logs and journal inherently create multiple copies of data and metadata that are hard to track.  This makes deletion nearly impossible (at least to guarantee)

Only way to guarantee...encrypt everything
 - if every file has its own key, you can delete the key and thus "delete" the data

Solid State Disks (SSD) use log-structured storage at a level below blocks.
 - writes are coarse-grained (you have to write a lot at once)
 - you don't want to write to the same cells too often, they'll die
   - have to do "wear-leveling"


Additional Notes

Lec 18

  • More on filesystems
  • How can you recover a fs and how do you delete a file?


A filesystem is a:

  • Persistent data structure
  • Stored in fixed size blocks (at least 512 bytes in size)
  • Maps hierarchical filenames to file contents
  • Has metadata about files somehow


What's in a filesystem

  • data blocks
  • metadata blocks, you need someway to find the blocks


How do you organize metadata?

First identify basic characteristics of the filesystem

You need a "superblock" which is a "summary" block that tells you about everything else

Normally the superblock is the first block of the filesystem

In the superblock

  • Type of filesystem
    • What filesystem magic number is there
    • file command to know file type
  • Size of the filesystem
  • How the filesystem is organized
  • Where can I find the rest of the metadata

He opened a .jpg as a binary file to show us the magic number in a file, first several bytes identify type of file. Kernel does not care about file extension. Userspace programs may care about the extension.

POSIX is a standard for UNIX
For POSIX filesystems

  • File metadata is stored in INODES
  • most have pre-reserved inodes

Usenet is a worldwide distribute discussion system that is deprecated now because it could not handle the spam people uploaded into it, lol. Format for usenet was every message stored in individual file. You will have lots of files!
So we have:

  • superblock
  • inode blocks
  • data blocks
    • data blocks for directories
    • data blocks for files


How do you recover from damage?

  • filesystems never "reboot", must remain correct over the course of years
  • Errors will happen: bitrot, accidental corruption, computer failiure/memory corruption/hard reboot


To make filesystems fast, data and meta-data is cached in RAM

  • Bad things happen if this data hasn't been writen to disk and you reboot
  • Even worse things happen if your RAM is bad and corrupts the data
  • FSCK is like scandisk in Windows 98


Also bad...what if you lose the superblock?

  • You could lose EVERYTHING
  • node trunc dd command blew away first bytes of the file system so you could not mount it because you corrupted the superblock. However, fsck fixed this because we have backup superblocks :D


Old scandisk/fsck was slow because we they had to scan all filesystem metadata

  • Not to recover data, but to fix metadata
  • lost+found might have some files that you might recover. It is a part of the filesystem for fsck to use.


Nowadays fsck is very fast and we rarely lose data due to losing power

  • What this means is we must be writing to disk all the time
  • But isn't writing slow? All writes aren't slow particularly on conventional hard disks.


On Magnetic Hard Disks (not SSD's)

  • sequential oeprations are fast
  • random access is slow
    • we have to move the read/write head


So, on modern systems we update metadata (and sometimes data) by writing sequentially to disk...and then later writing randomly

  • Sequential writes go to the journal


On fsck on a journaled filesystem

  • just check the journal for pending operations (replaying the journal)

There exists filesytems for optimizing writes that are pure journal

  • log-based filesystem


Logs and journal inherently create multiple copies of data and metadata that are hard to track. This makes deletion nearly impossible (at least to guarantee)

Only way to garauntee...encrypt everything

  • if every file has its own key, you can delete the key and this "delete" the data


SSD's use log-structured sotrage at a level below blocks

  • Writes are coarse-grained (you have to write a lot at once)
  • You don't want to write to the same cells too often, they will die
    • You have to do "wear-leveling"