300 likes | 599 Views
Special Topics on Operating System. R. C. Chang. Tentative Topics. Linux Internal Microkernels Window CE Internal Inferno Other Embedded Operating Systems. Trends of Operating System. Server : UNIX/Linux, Windows/NT Desktop : Windows 98/NT, UNIX/Linux
E N D
Special Topics on Operating System R. C. Chang
Tentative Topics • Linux Internal • Microkernels • Window CE Internal • Inferno • Other Embedded Operating Systems
Trends of Operating System • Server : UNIX/Linux, Windows/NT • Desktop : Windows 98/NT, UNIX/Linux • Embedded : WIN/CE, Inferno,VxWork, JINI,…
Operating System Structure • Monolithic Kernel • UNIX, Windows/98, Linux • First Generation Microkernel • Mach, Chorus,… • Second Generation Microkernel • L4, Exokernel,...
Linux 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
Hardware Basics • A typical PC Motherboard
PC Hardware • PC, SP, PS • Memory • D-Cache, I-Cache • Cache Coherence • Bus • ISA, PCI • Controllers and Peripherals • IDE, SCSI, NIC,… • Address Space
Software Basics • What is an operating system? • Memory management • Processes • $ ps • PID TTY STAT TIME COMMAND • 158 pRe 1 0:00 -bash • 174 pRe 1 0:00 sh /usr/X11R6/bin/startx • 175 pRe 1 0:00 xinit /usr/X11R6/lib/X11/xinit/xinitrc -- • 178 pRe 1 N 0:00 bowman • 182 pRe 1 N 0:01 rxvt -geometry 120x35 -fg white -bg black • 184 pRe 1 < 0:00 xclock -bg grey -geometry -1500-1500 -padding 0 • 185 pRe 1 < 0:00 xload -bg grey -geometry -0-0 -label xload • 187 pp6 1 9:26 /bin/bash • 202 pRe 1 N 0:00 rxvt -geometry 120x35 -fg white -bg black • 203 ppc 2 0:00 /bin/bash • 1796 pRe 1 N 0:00 rxvt -geometry 120x35 -fg white -bg black • 1797 v06 1 0:00 /bin/bash • 3056 pp6 3 < 0:02 emacs intro/introduction.tex • 3270 pp6 3 0:00 ps • $
Device Drivers • Controller Chips • NCR810 SCSI • The Filesystems • EXT2,CDROM,...
Kernel Data Structures • Link Lists • Hash Tables • Caches • Abstract Interfaces • /proc/filessystems
Memory Management • Virtual Memory • large address space • protection • memory mapping • fair physical memory allocation • shared virtual memory
Demand 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
Swapping • 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 --> Disacrd • Dirty page --> swapping • Linux uses a Least Recently Used page aging technique to choose pages
Physical 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)
Access 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
Caches • 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
Linux 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
Page 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
Free_area data structure Allocated groups of pages
Page 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
Memory Mapping • Virtual memory is represented by an mm_structure data structure • vm_area_structure
Demand Paging • Page fault • Search for vm_area_struct (AVL Tree) • If no (access illegal virtual address)--> 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)
The 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 --> single page read ahead
Swapping 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 > free_page_high do nothing • otherwise kswapd try to reduce the number of physical pages being used by the system:
Swap 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
The Swap Cache • When swapping pages out, Linux avoids writing pages if it does not have to • Swap cache --> a PTE for a swapped out page • If a swap cache is non-zero, a page in swap file has not been modified --> no need to write the page to the swap file
Swapping Pages In • Demand paging • swapin operation