Overview
- Virtual Memory and Memory Management:
- virtual memory hardware
- segmentation and paging
- Block Devices
- Drivers:
- RAMdisk
- hard disk
- terminal
- display
- Fork, exit, exec, and modules implementations
- Signals and signal handling
- File Systems
Virtual Memory
- each process should have its own address space
- and be unable (except in unusual circumstances) to read or write
other processe's address spaces
- exception: it would be good to share our text (code) segments
- this means program addresses (virtual addresses)
are not the same as machine addresses (physical addresses)
- virtual memory hardware makes this reasonably fast:
- the memory management unit (MMU) does this translation, including
- the translation lookaside buffer (TLB) is an associative
memory that keeps recent translations of virtual to physical addresses
- the TLB may be refilled in hardware or in software
- the memory management hardware also provides page protection, and
page faults for pages that are not mapped
Memory Management
- segmentation vs. paging
- should a process's virtual memory be contiguous in physical memory?
- yes: segmentation. Fewer segment registers are needed, but management
of physical memory is more complex
- no: paging. More page table entries are needed, but management
of blocks is simpler
- what should be swapped to disk?
- entire processes
- unused pages that are not likely to be referred to again soon
- how to find free memory?
- first fit, best fit, etc. Or, move segments around in physical memory
- keep a linked list of free blocks, with the pointers stored in the
nodes themselves
- segmentation also refers to the different parts of a
computer program (on disk) or memory areas of a process (in memory) --
e.g. the stack segment
- paging may refer to bringing in blocks of a memory-mapped file in
from disk, or writing dirty pages out to disk
Block Devices
- floppy, hard disk are physically block oriented
- for convenience, CD-ROM, RAMdisk, Flash storage, etc, which are not
intrinsically block oriented, can be used in a block-oriented fashion
- I/O is done one or more blocks at a time (no transfer is less than
one block)
- in many cases, accessing successive blocks is much faster than accessing
blocks in random order
Device Drivers
- block device drivers all have a lot in common
- open and close the device
- read and write blocks
Fork, exit, exec, modules
- implementation, esp. in Minix
- fork
- copy the address space, perhaps using Copy on Write, CoW
- copy file descriptors, do the right thing with signals
- exit: deallocate resources, inform parent
- zombie processes
- exec
- replace text (code)
- initialize stack, including arguments
- jump to the initial location
- overlays: load and execute parts of a program, under program control
- modules
- load and execute parts of the kernel
- module gets control on interrupt, and when system calls want to do I/O
Signals
- an "interrupt" for user processes
- OS signals a process whenever there is an illegal operation: bad
memory accesses (bad pointers), arithmetic errors (divide by zero), bad
I/O, and illegal instructions
- OS signals a process also when told to: kill, alarm,
^C, ^Z
- a process can tell the OS to ignore (most) signals, use the default
behavior, or call a signal handler
- the default behavior might be to ignore the signal or kill the process,
perhaps with a core dump
File Systems
- Posix API: open, creat, close, fsync, read, write
- also system calls: mmap, munmap
- file system implementation:
- contiguous allocation is a simple strategy and very fast for
sequential access, but deletion requires defragmenting, and only
one file can be growing at any given time
- block allocation is much more common. It is harder to make accesses
fast, but there is no need for defragmentation, and it is very flexible
- block allocation requires keeping track of blocks
- an index node (inode) can directly keep track of the first
few blocks, and indirectly of the remaining blocks as well
- given that the file system uses inodes, that is a good place to
store file attributes as well
- directories are handled like normal files with special content
(and the file system must know they are directories)
- variable length file names in a directory require some form of
storage management of the space in the directory
Projects
- Project 3: create a system call, modify the scheduler to be real-time
- Project 4: create a new RAMdisk
- Project 5: Linux and sbrk
- Project 6: how do you make a file system?
In this class so far
- basics: shells, system calls, user-level I/O
- processes, synchronization, deadlocks, scheduling,
interrupts, context switching
- virtual machines
- operating system structure, Minix organization: message passing,
kernel/drivers/servers/user programs
- virtual memory
- kernel implementation of I/O
- file systems and persistent storage
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License.