+ All Categories
Home > Documents > Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify...

Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify...

Date post: 04-Jan-2016
Category:
Upload: meredith-shepherd
View: 218 times
Download: 6 times
Share this document with a friend
28
Chapter 1: Kernel Overview
Transcript
Page 1: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

Chapter 1: Kernel Overview

Page 2: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

2

Objectives

• Review 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.• Explore the layout of the Linux source code tree.

Page 3: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

3

History

• UNIX: 1969 Thompson & Ritchie AT&T Bell Labs• BSD: 1978 Berkeley Software Distribution• Commercial Vendors: Sun, HP, IBM, SGI, DEC• GNU: 1984 Richard Stallman, FSF• POSIX: 1986 IEEE Portable Operating System unIX• Minix: 1987 Andy Tannenbaum• SVR4: 1989 AT&T and Sun• Linux: 1991 Linus Torvalds Intel 386 (i386)• Open Source: GPL, LGPL, Cathedral and the Bazaar

Page 4: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

4

Linux 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:– SMP support, large memory, large files– advanced networking, advanced filesystems– efficient, stable, highly portable, supports most device hardware– active development community, support, documentation, open source– GUIs, applications

Page 5: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

5

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.

Page 6: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

6

Kernel Design Goals

• performance: 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• extensibility

Page 7: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

7

Design Tradeoffs

• Butler Lampson: “choose any three design goals” • efficiency 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

Page 8: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

8

Waterloo Diagrams

Conceptual Concrete

fs

sched

mm net

ipc

sched

mm

ipcvfs

net

Page 9: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

9

Stephen Tweedie’s Diagram

Scheduler TrapsVMSyscalls

User Processes

ProcessManager

VFSSocket

ManagerMemoryAllocator

MathSupport

NetworkProtocols

FileSystems

IO RequestorPacket Requestor

Char Devices

Block Devices

Net Devices

Page 10: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

10

Vahalia’s Diagram

from Unix Internals: The New Frontiers

Uresh Vahalia / Prentice-Hall 1996

core utilities

virtualmemory

framework

vnode/vfsinterface

execswitch

blockdeviceswitch

schedulerframework

STREAMS

disk

tapenetwork tty

NFS

FFS

s5fs

elfa.out cofffile

device

anonymous

time-sharing

real-time

system

Page 11: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

11

“Core” KernelApplications

System Libraries (libc)

System Call Interface

Hardware

Architecture-Dependent Code

I/O Related Process RelatedScheduler

Memory Management

IPC

File Systems

Networking

Device Drivers

Mod

ules

Page 12: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

12

Architectural Approaches

• monolithic• layered• modularized• micro-kernel• virtual machine

Page 13: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

13

Isolating Hardware Dependencies

• architecture (cpu)– dependent (/arch)

– independent (everything else)

• abstract dependencies behind functions and macros• 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 features

Page 14: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

14

Source Tree Layout/usr/src/linuxDocumentation

archfs

init kernel

include

ipc

drivers

net

mmlib

scripts

alphaarmi386ia64m68kmipsmips64ppcs390shsparcsparc64

acornatmblockcdromchardiofc4i2ci2oideieee1394isdnmacintoshmiscnet…

adfsaffsautofsautofs4bfscodecramfsdevfsdevptsefsext2fathfshpfs…

asm-alphaasm-armasm-genericasm-i386asm-ia64asm-m68kasm-mipsasm-mips64…linuxmath-emunetpcmciascsivideo

adfsaffsautofsautofs4bfscodecramfsdevfsdevptsefsext2fathfshpfs…

802appletalkatmax25bridgecoredecneteconetethernetipv4ipv6ipxirdakhttpdlapb…

Page 15: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

15

linux/Documentation

• spotty but important collection of developer-generated documentation; you need to read what’s in here!

• recent effort to produce javadoc-style documentation from source header comments using OpenDoc

• an ambitious open-source kernel book effort has begun; see kernelbook.sourceforge.net for details

• some especially interesting entries:– kernel-docs.txt (a bit out of date but good)

– filesystems/ (very extensive)

– networking/ (very extensive)

– kmod.txt

– oops-tracing.txt

– spinlocks.txt (the official story from Linus)

Page 16: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

16

linux/arch

• subdirectories for each current port • 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.

• arch as of 2.4:– alpha, arm, i386, ia64, m68k, mips, mips64

– ppc, s390, sh, sparc, sparc64

Page 17: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

17

linux/drivers• largest amount of code in the kernel tree (~1.5M)• 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 – fc4, i2c, nubus, pci, sbus, tc, usb• platforms – acorn, macintosh, s390, sgi

Page 18: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

18

linux/fs

• contains:– 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.c

Page 19: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

19

linux/include• include/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– video

Page 20: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

20

linux/init

• just two files: version.c, main.c• version.c – contains the version banner that prints at

boot• main.c – architecture-independent boot code• start_kernel is the primary entry point

Page 21: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

21

linux/ipc

• System 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 queues

Page 22: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

22

linux/kernel

• the 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

Page 23: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

23

linux/lib

• kernel code cannot call standard C library routines• files:

– brlock.c – “Big Reader” spinlocks

– cmdline.c – kernel command line parsing routines

– errno.c – global definition of errno

– inflate.c – “gunzip” part of gzip.c used during boot

– string.c – portable string code• usually replaced by optimized, architecture-dependent routines

– vsprintf.c – libc replacement

Page 24: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

24

linux/mm

• paging 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.c

Page 25: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

25

linux/net

• changing too fast!• i haven’t figured it out yet

Page 26: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

26

linux/scripts

• scripts for:– menu-based kernel configuration

– kernel patching

– generating kernel documentation

Page 27: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

27

Sizes (linux-2.4.0-test2)size directory entries files loc90M /usr/src/linux/ 19 7645 2.6M

4.5M Documentation 97 380 na

16.5M arch 12 1685 466K

54M drivers 31 2256 1.5M

5.6M fs 70 489 150K

14.2M include 19 2262 285K

28K init 2 2 1K

120K ipc 6 6 4.5K

332K kernel 25 25 12K

80K lib 8 8 2K

356K mm 19 19 12K

5.8M net 33 453 162K

400K scripts 26 42 12K

Page 28: Chapter 1: Kernel Overview. 2 Objectives Review development and history of UNIX and Linux. Clarify the nature and extent of the kernel within the context.

28

Summary

• Linux is a modular, UNIX-like monolithic kernel• Kernel is the heart of the OS that executes with special

hardware permission (kernel mode)• “Core kernel” provides framework, data structures,

support for drivers, modules, subsystems• Kernel designers must consider many competing goals• Linux source tree mirrors kernel structure• Architecture dependent source subtrees live in /arch• “main” lives in /kernel/init.c• lxr.linux.no is a nice web-based source browser


Recommended