nullChapter 1: Kernel OverviewChapter 1: Kernel OverviewObjectivesObjectivesReview development and history of UNIX and Linux.
Clarify the nature and extent of the kernel within the context of the operating system proper.
Identify operating system design goals and tradeoffs.
Review established architectural approaches for implementing an operating system.
Introduce the notion of the “core” Linux kernel.
Understand the Linux approach to hardware (architecture) abstraction and independence.
Kernel Version
Explore the layout of the Linux source code tree.
Source lines of codeHistoryHistoryUNIX: 1969 Thompson & Ritchie AT&T Bell Labs
BSD: 1978 Berkeley Software Distribution
Commercial Vendors: Sun, HP, IBM, SGI, DEC
GNU: 1984 Richard Stallman, FSF
www.gnu.org gcc gdb emacs
GPL GNU Public License
POSIX: 1986 IEEE Portable Operating System unIX
Minix: 1987 Andy Tannenbaum
SVR4: 1989 AT&T and SunHistoryHistoryLinux: 1991 Linus Torvalds Intel 386 (i386)
Stable version history
Version 1.0 of March 1994 supported only UP i386 machines.
Version 1.2 of March 1995 added support for Alpha, Sparc and MIPS.
Version 2.0 of June 1996 included SMP support and added support for more processors.
Version 2.2 of January 1999
Version 2.4.0 of January 2001
Version 2.6 - current (December 17, 2003 to the present)
Open Source: GPL, LGPL, Cathedral and the Bazaar
Linux FeaturesLinux Features“UNIX-like” operating system
“aims at” standards compliance
“all the features you would expect in a modern UNIX”
preemptive multitasking
virtual memory (protected memory, paging)
shared libraries
demand loading, dynamic kernel modules
shared copy-on-write executables
TCP/IP networking
other features:
free OS
SMP support, large memory, large files
advanced filesystems
efficient, stable, highly portable, supports most device hardware
active development community, support, documentation
GUIs, applications
What’s a Kernel?What’s a Kernel?
aka: executive, system monitor, nucleus
controls and mediates access to hardware
implements and supports fundamental abstractions
processes, files, devices, users, net, etc.
schedules “fair” sharing of system resources
memory, cpu, disk, descriptors, etc.
enforces security and protection
responds to user requests for service (system calls)
performs routine maintenance, system checks, etc.
Kernel Design GoalsKernel Design Goalsperformance: efficiency, speed
utilize resources to capacity, low overhead, code size
stability: robustness, resilience
uptime, graceful degradation
capability: features, flexibility, compatibility
security, protection
protect users from each other, secure system from bad guys
portability
clarity
extensibilityDesign TradeoffsDesign Tradeoffsefficiency vs. protection
more checks, more overhead
clarity vs. compatibility
ugly implementation of “broken” standards (e.g. signals)
flexibility vs. security
the more you can do, the more potential security holes!
not all are antagonistic
portability tends to enhance code clarity
The fundamental architecture of the GNU/LinuxThe fundamental architecture of the GNU/LinuxStephen Tweedie’s DiagramStephen Tweedie’s DiagramSchedulerTrapsVMSyscallsUser ProcessesProcess
ManagerVFSSocket
ManagerMemory
AllocatorMath
SupportNetwork
ProtocolsFile
SystemsIO RequestorPacket RequestorChar DevicesBlock DevicesNet DevicesVahalia’s DiagramVahalia’s Diagramfrom Unix Internals: The New Frontiers
Uresh Vahalia / Prentice-Hall 1996core utilitiesvirtual
memory
frameworkvnode/vfs
interfaceexec
switchblock
device
switchscheduler
frameworkSTREAMSdisktapenetworkttyNFSFFSs5fselfa.outcofffiledeviceanonymoustime-sharingreal-timesystem“Core” Kernel“Core” KernelApplicationsSystem Libraries (libc)System Call InterfaceHardwareArchitecture-Dependent CodeI/O RelatedProcess RelatedSchedulerMemory ManagementIPCFile SystemsNetworkingDevice DriversModulesArchitectural ApproachesArchitectural ApproachesMonolithic
Linux is a modular, UNIX-like monolithic kernel
micro-kernel
virtual machineIsolating Hardware DependenciesIsolating Hardware Dependenciesarchitecture (cpu)
dependent (/arch)
independent (everything else)
abstract dependencies behind functions and macros
example: in schedule(), switch_to(prev,next) was called
link appropriate version at compile-time
device-dependencies isolated in device drivers
provide general abstractions that map to reality
e.g. three-level page tables
tradeoff: exploiting special hardware featuresLinux Kernel Versions
Linux Kernel Versions
Linux kernels come in two flavors: stable or development.
Three numbers, each separated by a dot, represent Linux kernels. The first value is the major release, the second is the minor release, and the third is the revision.
The minor release also determines whether the kernel is a stable or development kernel; an even number is stable, whereas an odd number is development.
example: 2.4.20 2.5.47
Linux Kernel Versions
Linux Kernel Versions
Now, the development of the 2.6 kernel without introducing a 2.7 development series in the near future.
The current 2.6 maintainer system that exists between Linus Torvalds and Andrew Morton is working out exceedingly well.
- As soon as a new kernel is released a two weeks window is open, during this period of time maintainers can submit big diffs to Linus, usually the patches that have already been included in the -mm kernel for a few weeks.
Linux Kernel Versions
Linux Kernel Versions
- After two weeks a -rc1 kernel is released it is now possible to push only patches that do not include new features that could affect the stability of the whole kernel.
A new -rc is released whenever Linus deems the current git tree to be in a reasonably sane state adequate for testing. The goal is to release a new -rc kernel every week.
Process continues until the kernel is considered "ready", the process should last around 6 weeks.
2.6.x.y -stable kernel tree
Kernels with 4 digit versions are -stable kernels. They contain relatively small and critical fixes for security problems or significant regressions discovered in a given 2.6.x kernel. How to get source codeHow to get source codelxr.linux.no is a nice web-based source browser
official home of the Linux kernel
http://www.kernel.org
http://www.kernel.org/pub/linux/kernel/v2.6/
The kernel tarball is distributed in both GNU zip (gzip) and bzip2 format. Bzip2 is the default and preferred format.
The Linux kernel tarball in bzip2 format is named linux-x.y.z.tar.bz2.
After downloading the source, uncompressing and untarring it is simple. For bzip2, run
$ tar xvjf linux-x.y.z.tar.bz2 If it is compressed with GNU zip, run
$ tar xvzf linux-x.y.z.tar.gz
This uncompresses and untars the source to the directory linux-x.y.z
Source Tree LayoutSource Tree Layoutlinux/archlinux/archsubdirectories for each current port , architecture dependent source subtrees.
each contains kernel, lib, mm, boot and other directories whose contents override code stubs in architecture independent code
lib contains highly-optimized common utility routines such as memcpy, checksums, etc.
some architectures of 2.6:
alpha, arm, i386, ia64, m68k, mips, mips64
ppc, s390, sh, sparc, sparc64
linux/driverslinux/driverslargest amount of code in the kernel tree
device, bus, platform and general directories
drivers/char – n_tty.c is the default line discipline
drivers/block – elevator.c, genhd.c, linear.c, ll_rw_blk.c, raidN.c
drivers/net –specific drivers and general routines Space.c and net_init.c
drivers/scsi – scsi_*.c files are generic; sd.c (disk), sr.c (CD-ROM), st.c (tape), sg.c (generic)
general:
cdrom, ide, isdn, parport, pcmcia,
pnp, sound, telephony, video
buses –i2c, nubus, pci, sbus, tc, usb
platforms – acorn, macintosh, s390, sgilinux/fslinux/fscontains:
virtual filesystem (VFS) framework
subdirectories for actual filesystems
vfs-related files:
exec.c, binfmt_*.c - files for mapping new process images
devices.c, blk_dev.c – device registration, block device support
super.c, filesystems.c
inode.c, dcache.c, namei.c, buffer.c, file_table.c
open.c, read_write.c, select.c, pipe.c, fifo.c
fcntl.c, ioctl.c, locks.c, dquot.c, stat.clinux/includelinux/includeinclude/asm-*
architecture-dependent include subdirectories
include/linux
header info needed both by the kernel and user apps
usually linked to /usr/include/linux
kernel-only portions guarded by #ifdefs
#ifdef __KERNEL__
/* kernel stuff */
#endif
other directories:
math-emu
net
pcmcia
scsi
videolinux/ipclinux/ipcSystem V IPC facilities
if disabled at compile-time, util.c exports stubs that simply return –ENOSYS
one file for each facility:
sem.c – semaphores
shm.c – shared memory
msg.c – message queueslinux/kernellinux/kernelthe core kernel code
sched.c – “the main kernel file”
scheduler, wait queues, timers, alarms, task queues
process control
fork.c, exec.c, signal.c, exit.c
acct.c, capability.c, exec_domain.c
kernel module support
kmod.c, ksyms.c, module.c
other operations
time.c, resource.c, dma.c, softirq.c, itimer.c
printk.c, info.c, panic.c, sysctl.c, sys.c
linux/mmlinux/mmpaging and swapping
swap.c, swapfile.c (paging devices), swap_state.c (cache)
vmscan.c – paging policies, kwapd
page_io.c – low-level page transfer
allocation and deallocation
slab.c – slab allocator
page_alloc.c – page-based allocator zone allocator
vmalloc.c – kernel virtual-memory allocator
memory mapping
memory.c – paging, fault-handling, page table code
filemap.c – file mapping
mmap.c, mremap.c, mlock.c, mprotect.clinux/netlinux/netcore sock.c sk_buffer.c dst.c etc.
ipv4
ipv6
x.25
decnet
bluetooth
ethernet
ipx
irda (Infrared Data Association )
Source lines of code
Source lines of code
http://encyclopedia.thefreedictionary.com/source%20lines%20of%20code
This study found that Debian GNU/Linux 2.2 included over 55,000,000 SLOC, and if developed in a conventional proprietary way would have required 14,005 person-years and cost $1.9 billion USD to develop.
nullJanuary 25, 1999 - Linux 2.2.0 was released (1,800,847 lines of code).
January 4, 2001 - Linux 2.4.0 was released (3,377,902 lines of code).
December 17, 2003 - Linux 2.6.0 was released (5,929,913 lines of code).Most active 2.6.35 employers (July 14, 2010 )Most active 2.6.35 employers (July 14, 2010 )TextbookTextbook Understanding the Linux Kernel, 3rd Edition
东南大学出版社
Author : Daniel P.Bovet,Marco Cesati
ISBN 7564102764 Price :98.00
中文译本
深入理解Linux内核(第三版)
【译 者】陈莉君;张琼声;张宏伟
【出 版 社】 中国电力出版社 【
号】 9787508353944
价格 98.00TextbookTextbookLinux内核
与实现(英文影印版)(第2版)
【原 书 名】 Linux Kernel Development (2nd Edition)
【作 者】(美)Robert Love
【出 版 社】 机械工业出版社 【书 号】 7111175751
【出版日期】 2006年1月 市场价 :¥40.00
Linux内核设计与实现(第2版)
【作 者】(美)Robert Love
【译 者】 陈莉君 康华 张波
【出 版 社】 机械工业出版社 【书 号】 7111178653
【出版日期】 2006年1月 市场价 :¥38.00