This is not the current version of the class.

Storage 1: OS input/output, memory hierarchy

Overview

In this bridge lecture to the storage unit, we discuss how files are read and written, starting with a WeensyOS example and transitioning to Linux.

Full lecture notes on storageTextbook readings

System calls for reading and writing

WeensyOS reading

Example reader

int readc() {
    unsigned char ch;
    ssize_t r = -1;

    while (r < 0) {
        r = sys_read(&ch, 1);
    }

    assert(r == 1);
    return ch;
}

WeensyOS writing

Example writer

int writec(unsigned char ch) {
    ssize_t r = -1;

    while (r < 0) {
        r = sys_write(&ch, 1);
    }

    assert(r == 1);
    return ch;
}

Relationship to Unix

WeensyOS p-reader and p-writer

Speed?

Moving to Unix

Write a file one byte at a time using system calls

    size_t n = 0;
    while (n < size) {
        ssize_t r = write(fd, buf, 1);
        if (r != 1) {
            perror("write");
            exit(1);
        }
        ++n;
    }

Write a file one byte at a time using the stdio library

    size_t n = 0;
    while (n < size) {
        int ch = fputc(buf[0], f);
        if (ch == EOF) {
            perror("write");
            exit(1);
        }
        ++n;
    }

Question 1

Storage hierarchy

Storage hierarchy

Expense of storage

Question 2

Historical costs of storage

Absolute costs ($/MB):

Year Memory (DRAM) Flash/SSD Hard disk
~1955 $411,000,000 $6,230
1970 $734,000 $260.00
1990 $148.20 $5.45
2003 $0.09 $0.305 $0.00132
2010 $0.019 $0.00244 $0.000073
2022 $0.0027 $0.000073 $0.000016

Relative costs (relative to hard disk storage in 2022):

Year Memory Flash/SSD Hard disk
~1955 25,700,000,000,000 389,000,000
1970 45,900,000,000 16,300,000
1990 9,260,000 340,000
2003 5,600 19,100 82.5
2010 1,190 153 4.6
2022 168 4.6 1

(Processor speed has also increased a lot—from 0.002 MIPS in 1951 to 750,000 MIPS now—but this is “only” 375,000,000x.)