Operating Systems 2017F Lecture 7: Difference between revisions
Created page with "==Video== Video from the lecture given on September 28, 2017 [http://homeostasis.scs.carleton.ca/~soma/os-2017f/lectures/comp3000-2017f-lec07-28Sep2017.mp4 is now available]...." |
|||
Line 2: | Line 2: | ||
Video from the lecture given on September 28, 2017 [http://homeostasis.scs.carleton.ca/~soma/os-2017f/lectures/comp3000-2017f-lec07-28Sep2017.mp4 is now available]. | Video from the lecture given on September 28, 2017 [http://homeostasis.scs.carleton.ca/~soma/os-2017f/lectures/comp3000-2017f-lec07-28Sep2017.mp4 is now available]. | ||
3000 Sep28 | |||
Next week: Anil is away from Sunday to Thursday morning. Review section. | |||
Topic today: File system | |||
'''What is a file?''' | |||
It is a key - value pair. | |||
Key: hierarchiacal filename (pathname) | |||
value: arbitrary number of bytes | |||
'''In principle, you can use files to store very small values''' | |||
-most filesystems have a minimum file size of at least 1k, often 4K or more | |||
-one byte of data wastes a lot of space | |||
'''A set of files ‘stored’ together, sharing a common hierarchical root, is a filesystem.''' | |||
Why quote ‘stored’ ? | |||
- Because there is no storage for virtual filesystems (such as /proc and /sys) | |||
when you first start a UNIX system, you start with the ‘root’ filesystem. (have nothing to do with root user.) | |||
-But other filesystems can be put on top by "mount"-ing them. | |||
CODE DEMONSTRATION: | |||
Run ‘mount’ | |||
it shows‘/dev/vda1 on / type ext4 (rw, relatetime,data=ordered) ‘ | |||
- /dev is root filesystem | |||
- / is the top of hierachy | |||
-‘rw’ means read write | |||
-/def/vda1 is a Special file, files in /dev are special files. | |||
(Special files are actual files, it would be stored on disk, nowadays they are not.) | |||
Run ‘df .’ (df is for displaying the amount of available disk space for file systems on which the invoking user has appropriate read access.) | |||
-There is a filesystem called ‘udev’, which is a virtual file system with zero space used, since it is created automatically on run time | |||
Run ‘who’ in another terminal | |||
-it display ‘soma tty7 2017-09-28 12:59 (:0)’ | |||
Run ‘ls /dev’ | |||
-Instead of ''vda'', it shows ''sda''. The ‘v’ in ''vda'' stands for ‘virtual’. The ‘s’ in ''sda'' stands for SCSI (The Small Computer System Interface). | |||
-Any device you want to access on unix system has /dev | |||
Run ‘ls-a’ in /dev | |||
-Looking at the permissions (e.g ‘crw--rw----’), first letter for normal file is blank , directory is ‘d’, ‘c’ is for Character Devices, ‘b’ is for Block Devices | |||
-Character devices example: keyboard, mouse. | |||
-What makes b-disk different?caches. | |||
-Special files are either Character Devices or Block Devices, | |||
-Block divce is for block storage, to cache result. | |||
Traditional filesystems are stored in block devices | |||
-but a filesystem can be anything that provides a filesystem interface. | |||
'''file interface basics:''' | |||
-open, read, write, seek, close | |||
-open directory, read/write directory, close directory | |||
'''Block size issues:''' | |||
-larger blocks, less overhead(fixed overhead for each block access) | |||
-smaller blocks, more efficient space usage(fewer files smaller than one block) | |||
'''filesystem interface basics:''' | |||
-mount and unmount | |||
filesystem blocksize is a multiple of disk blocksize | |||
How do you structure a filesystem? | |||
'''Inode:''' | |||
First, you have to understand inodes. | |||
CODE DEMONSTRATION: | |||
1.Run ‘cp lec07.txt test.txt’ | |||
-There is no different between those files | |||
2.Run ‘ln test.txt duplicate.txt’ | |||
-There is difference between duplicate.txt and test.txt: A number for test.txt changed from ‘1’ to ‘2’. That number is inode count | |||
3. Run ‘ln duplicate.txt alsodup.txt’ | |||
-Inode count number changed ‘2’ from ‘3’ | |||
'''ln' stands for link'' | |||
4.Run ‘ln -s duplicate.txt another.txt’ | |||
-There is no different between another.txt lec07.txt | |||
5.Run ‘ls -la has diffrence’ | |||
-It shows another.txt -> duplicate.txt (symbolic link pointing one to the other | |||
6.Run ‘rm duplicate.txt’ | |||
-The arrow is still pointing, but inode count number goes down. (From ‘3’ to ‘2’) | |||
7.Run ‘cat another.txt’ | |||
-It shows there is such file, because the file that pointing to is not exist | |||
-‘ln’ creates hard links to an item by default. | |||
-File name is a pointer to an inodes. | |||
-‘rm’ is not remove, just unlink, which reduces the link count for inode | |||
-When you clear storage, when inode inbound number go to 0, is not link to other file,system will remove it. | |||
-When the user open a file, referece count is incremented. | |||
A file sys doesn’t have to be a block device? It can store anywhere as long as you provide the api. | |||
A file system can be made in a file (the basic of virtual machine) | |||
One other file api: mmap | |||
Inode store permision | |||
mmap, munmap: map or unmap files or devices into memory, this is the piece that unify the file sys with process memory. | |||
What ‘read’ does: read directly into RAM | |||
Run ‘top’ | |||
-There are ‘VIRT’, ‘RES’ and ‘SHR’ | |||
VIRT stands for the virtual size of a process | |||
RES stands for the resident size, which is an accurate representation of how much actual physical memory a process is consuming. | |||
SHR indicates how much of the VIRT size is actually sharable (memory or libraries). | |||
==Code== | ==Code== | ||
Code and files from the lecture (captured as they were at the end) are available [http://homeostasis.scs.carleton.ca/~soma/os-2017f/code/lec07/ here]. | Code and files from the lecture (captured as they were at the end) are available [http://homeostasis.scs.carleton.ca/~soma/os-2017f/code/lec07/ here]. |
Revision as of 20:19, 3 October 2017
Video
Video from the lecture given on September 28, 2017 is now available.
3000 Sep28 Next week: Anil is away from Sunday to Thursday morning. Review section.
Topic today: File system
What is a file? It is a key - value pair.
Key: hierarchiacal filename (pathname)
value: arbitrary number of bytes
In principle, you can use files to store very small values
-most filesystems have a minimum file size of at least 1k, often 4K or more
-one byte of data wastes a lot of space
A set of files ‘stored’ together, sharing a common hierarchical root, is a filesystem.
Why quote ‘stored’ ?
- Because there is no storage for virtual filesystems (such as /proc and /sys)
when you first start a UNIX system, you start with the ‘root’ filesystem. (have nothing to do with root user.)
-But other filesystems can be put on top by "mount"-ing them.
CODE DEMONSTRATION:
Run ‘mount’
it shows‘/dev/vda1 on / type ext4 (rw, relatetime,data=ordered) ‘
- /dev is root filesystem
- / is the top of hierachy
-‘rw’ means read write
-/def/vda1 is a Special file, files in /dev are special files.
(Special files are actual files, it would be stored on disk, nowadays they are not.)
Run ‘df .’ (df is for displaying the amount of available disk space for file systems on which the invoking user has appropriate read access.)
-There is a filesystem called ‘udev’, which is a virtual file system with zero space used, since it is created automatically on run time
Run ‘who’ in another terminal
-it display ‘soma tty7 2017-09-28 12:59 (:0)’
Run ‘ls /dev’
-Instead of vda, it shows sda. The ‘v’ in vda stands for ‘virtual’. The ‘s’ in sda stands for SCSI (The Small Computer System Interface).
-Any device you want to access on unix system has /dev
Run ‘ls-a’ in /dev
-Looking at the permissions (e.g ‘crw--rw----’), first letter for normal file is blank , directory is ‘d’, ‘c’ is for Character Devices, ‘b’ is for Block Devices
-Character devices example: keyboard, mouse.
-What makes b-disk different?caches.
-Special files are either Character Devices or Block Devices,
-Block divce is for block storage, to cache result.
Traditional filesystems are stored in block devices
-but a filesystem can be anything that provides a filesystem interface.
file interface basics:
-open, read, write, seek, close
-open directory, read/write directory, close directory
Block size issues:
-larger blocks, less overhead(fixed overhead for each block access)
-smaller blocks, more efficient space usage(fewer files smaller than one block)
filesystem interface basics:
-mount and unmount
filesystem blocksize is a multiple of disk blocksize
How do you structure a filesystem?
Inode:
First, you have to understand inodes.
CODE DEMONSTRATION:
1.Run ‘cp lec07.txt test.txt’
-There is no different between those files
2.Run ‘ln test.txt duplicate.txt’
-There is difference between duplicate.txt and test.txt: A number for test.txt changed from ‘1’ to ‘2’. That number is inode count
3. Run ‘ln duplicate.txt alsodup.txt’
-Inode count number changed ‘2’ from ‘3’
'ln' stands for link
4.Run ‘ln -s duplicate.txt another.txt’
-There is no different between another.txt lec07.txt
5.Run ‘ls -la has diffrence’
-It shows another.txt -> duplicate.txt (symbolic link pointing one to the other
6.Run ‘rm duplicate.txt’
-The arrow is still pointing, but inode count number goes down. (From ‘3’ to ‘2’)
7.Run ‘cat another.txt’
-It shows there is such file, because the file that pointing to is not exist
-‘ln’ creates hard links to an item by default.
-File name is a pointer to an inodes.
-‘rm’ is not remove, just unlink, which reduces the link count for inode
-When you clear storage, when inode inbound number go to 0, is not link to other file,system will remove it.
-When the user open a file, referece count is incremented.
A file sys doesn’t have to be a block device? It can store anywhere as long as you provide the api.
A file system can be made in a file (the basic of virtual machine)
One other file api: mmap
Inode store permision
mmap, munmap: map or unmap files or devices into memory, this is the piece that unify the file sys with process memory.
What ‘read’ does: read directly into RAM
Run ‘top’
-There are ‘VIRT’, ‘RES’ and ‘SHR’
VIRT stands for the virtual size of a process RES stands for the resident size, which is an accurate representation of how much actual physical memory a process is consuming. SHR indicates how much of the VIRT size is actually sharable (memory or libraries).
Code
Code and files from the lecture (captured as they were at the end) are available here.