February 19, 2019
For today:
1) Project proposal
2) Read Think OS Chapter 4 and do the reading quiz
3) Start Homework 3
4) Read the HFC 3 notes in Lecture 7
Today:
1) Leftovers from Lecture 7
2) Binary flags
3) Hard drive performance
4) Think OS Chapter 4
For next time:
1) Read Head First C Chapter 4
2) Finish Homework 3
3) Work on your project.
I will review proposals over the next few days, but also let me know if you have questions.
You saw one use of binary flags in Homework 2.5, the arguments to regcomp
ret = regcomp(®ex, pattern, REG_EXTENDED | REG_NOSUB);
1) To find header files, try this
gcc -H find_track.c
2) Read regex.h. What are the values of REG_EXTENDED and REG_NOSUB?
3) Read about bitwise OR at https://en.wikipedia.org/wiki/Bitwise_operations_in_C#Bitwise_OR_|
What do you get if you OR together REG_EXTENDED and REG_NOSUB?
Another use of binary flag is UNIX file permissions.
0) Read Julia's cartoon intro to UNIX permissions (above).
1) Read about setuid/setgid at https://en.wikipedia.org/wiki/Setuid
What are the three unrelated things setgid does for different file type?
2) Read about the sticky bit at https://en.wikipedia.org/wiki/Sticky_bit
3) What is the 4-digit octal code for a file that is sticky but not setuid or setgid, can be read, written, and executed by user, read and executed by group, and read-only by other?
4) Read about chmod at https://en.wikipedia.org/wiki/Chmod#Symbolic_modes
What is the symbolic command to create the permissions specified above, starting from unknown permissions?
Time to read a block =
1) Seek time: track to track, less than 1 ms; full stroke, hard to get good numbers; average about 10 ms.
2) Rotational latency: 0-8 ms at 7200 RPM, 4ms on average.
3) Data transfer time: Might be limited by data going past the head, or by a bottleneck in the disk controller or host bus adapter.
Disk-to-buffer transfer might be 1 Gbit/s
Buffer-to-computer might be 3 Gbit/s
0) Read https://en.wikipedia.org/wiki/Data-rate_units
1) What the total time to seek a random track, read a random block, and transfer 8 KiB to the computer at 1 Gbps?
2) How much additional time would it take to transfer 800 KiB?
A file system is basically a key-value database, optimized for particular access patterns.
For example, if you know the distribution of file sizes, you could use it to optimize the size of indirection blocks. In my misspent youth, I wrote a paper on this topic .
The file system as an abstraction:
1) A file is a stream of bytes (although random access is also possible).
2) Actual layout is handled by the OS and/or device hardware. For HDD, layout has a BIG effect on performance.
Disks are slow, so we need tricks:
1) Block transfers. If you have to go to China, buy a lot of tea.
2) Prefetching. And get some other things while you're there.
3) Buffering: You will need a tea warehouse.
4) Caching: We need a different metaphor for caching.
The design of UNIX inodes is an exercise in (1) workload-based optimization, and (2) games with powers of 2.
Block allocation is a perpetual area of design, especially for HDD, where contiguity is so important.
For more, see https://en.wikipedia.org/wiki/Journaling_file_system
From Wikipedia
Exercise:
1) In a file system with 48-bit block addresses, how many blocks can be addressed? Express your answer in base 10 scientific notation.
2) If each block is 8 KiB, what is the total size of all addressable blocks? Express your answer in power of two units of bytes.
3) How many block addresses can fit in a block?
4) If the system uses UNIX-style inodes that contains 12 direct block pointers, what is the biggest file we can address using only the direct pointers?
5) What is the biggest file we can address using the direct pointers and the singly indirect pointer?
6) Bonus question: what is the biggest file we can address using the inode, the singly indirect pointer, and the doubly indirect pointer?