Title: Special Topics on Operating System
1Special Topics on Operating System
2Tentative Topics
- Linux Internal
- Microkernels
- Window CE Internal
- Inferno
- Other Embedded Operating Systems
3Trends of Operating System
- Server UNIX/Linux, Windows/NT
- Desktop Windows 98/NT, UNIX/Linux
- Embedded WIN/CE, Inferno,VxWork, JINI,
4Operating System Structure
- Monolithic Kernel
- UNIX, Windows/98, Linux
- First Generation Microkernel
- Mach, Chorus,
- Second Generation Microkernel
- L4, Exokernel,...
5Linux Internal
- Text Book The Linux Kernel by David A. Rusling,
(Please Download the book from Internet) - Reference Books Linux Kernel Internals (Second
Edition) by M. Beck et al., Addison-Wesley, 1998
6Hardware Basics
7PC Hardware
- PC, SP, PS
- Memory
- D-Cache, I-Cache
- Cache Coherence
- Bus
- ISA, PCI
- Controllers and Peripherals
- IDE, SCSI, NIC,
- Address Space
8Software Basics
- What is an operating system?
- Memory management
- Processes
- ps
- PID TTY STAT TIME COMMAND
- 158 pRe 1 000 -bash
- 174 pRe 1 000 sh /usr/X11R6/bin/startx
- 175 pRe 1 000 xinit /usr/X11R6/lib/X11/xini
t/xinitrc -- - 178 pRe 1 N 000 bowman
- 182 pRe 1 N 001 rxvt -geometry 120x35 -fg
white -bg black - 184 pRe 1 lt 000 xclock -bg grey -geometry
-1500-1500 -padding 0 - 185 pRe 1 lt 000 xload -bg grey -geometry
-0-0 -label xload - 187 pp6 1 926 /bin/bash
- 202 pRe 1 N 000 rxvt -geometry 120x35 -fg
white -bg black - 203 ppc 2 000 /bin/bash
- 1796 pRe 1 N 000 rxvt -geometry 120x35 -fg
white -bg black - 1797 v06 1 000 /bin/bash
- 3056 pp6 3 lt 002 emacs intro/introduction.tex
- 3270 pp6 3 000 ps
9- Device Drivers
- Controller Chips
- NCR810 SCSI
- The Filesystems
- EXT2,CDROM,...
10Kernel Data Structures
- Link Lists
- Hash Tables
- Caches
- Abstract Interfaces
- /proc/filessystems
11Memory Management
- Virtual Memory
- large address space
- protection
- memory mapping
- fair physical memory allocation
- shared virtual memory
12An Abstract Model of VM
13Demand Paging
- Load virtual pages that are currently bein used
by the executing program - Page fault handling
- Linux uses demand paging to load executable
images into a processes virtual memory
14Swapping
- If a process needs to bring a virtual page into
physical memory and there are no free physical
pages available - Clean or read-only pages --gt Disacrd
- Dirty page --gt swapping
- Linux uses a Least Recently Used page aging
technique to choose pages
15Physical and Virtual Addressing Modes
- OS usually runs in physical address model
- Alpha AXP processor does not have a special
physical addressing model. - It divides up the memory space into several areas
and designates two of them as physical address
area - KSEG (0xfffffc000310000)
16Access Control
ASM Address Space Match KRE kernel mode can
read URE user mode can read PFN Page Frame
Number Page_Dirty, Page_ACCESSED
V Valid FOE Fault on Execute FOW
Write FOR Read
17Caches
- Buffer Cache block device drivers(hard disks)
- Page Caches Speed up access to images and data
on disk. - Swap Cache only modified(dirty) pages are saved
in the swap file. - Hardware Caches Data/Instruction, TLB
18Linux Page Tables
Each Platform that Linux runs on must provide
translation macro that allow the kernel to
traverse the page tables for a particular
processor
19Page Allocation and Deallocation
- Physical page mem_map structure
- mem_map_t for each physical page(initialized at
the boot time) - Important fields
- count, age, man_nr (physical frame number)
- free-area vector is used to find free pages
20Free_area data structure
Allocated groups of pages
21Page Allocation/Deallocation
- Buddy algorithm
- Pages are allocated in blocks which are powers of
2 in size - The page deallocation code recombine pages into
large blocks of free pages whenever it can
22Memory Mapping
- Virtual memory is represented by an mm_structure
data structure - vm_area_structure
23Demand Paging
- Page fault
- Search for vm_area_struct (AVL Tree)
- If no (access illegal virtual address)--gt SIGSEGV
- Check for type of access
- Decide the page in swap file or somewhere in disk
- if the page page table entry is invalid but not
empty then it is in swap file - nopage operation(by using page cache)
24The Linux Page Cache
25The Linux Page Cache
- Memory mapped files are read a page at a time and
these pages are stored in the page cache - Search through page_hash_table
- Linux --gt single page read ahead
26Swapping Out and Discarding Pages
- Kernel Swap Daemon(kswapd)
- kernel thread
- keep enough free pages in the system
- started by init process and wait for kernel swap
timer to periodcally expire - if of free pages gt free_page_high do nothing
- otherwise kswapd try to reduce the number of
physical pages being used by the system
27Swap out pages
- Reduce the size of the buffer and page caches
- clock algorithm
- Swapping out System V shared memory pages
- update multiple page table entries
- Swapping out and discarding pages
- clock algorithm
28The Swap Cache
- When swapping pages out, Linux avoids writing
pages if it does not have to - Swap cache --gt a PTE for a swapped out page
- If a swap cache is non-zero, a page in swap file
has not been modified --gt no need to write the
page to the swap file
29Swapping Pages In
- Demand paging
- swapin operation