Freebsd
Freebsd
Freebsd
Agenda
History and Goals Kernel Services Process Management Memory Management I/O System Interprocess Communication System Operation Acknowledgments
History of the UNIX System BSD and Other Systems The Transition of BSD to Open Source The FreeBSD Development Model
It was written by C-language It was distributed by source form It can run cheap hardware with advance features Virtual memory, demand paging, page replacement Socket interface for TCP/IP Job control, reliable signals, filesystem interface
Most features from UNIX Terminal drivers from TENEX/TOPS-20 Job control from TOPS and MITs ITS Memory management from Mach The Influence of the User Community
Some packages from other groups comp.bugs.4bsd
The FreeBSD group was formed in 1993 Supporting the PC architecture only Ease of installation Code started base with 4.4BSD-Lite Current version is FreeBSD5.4
Alpha, Space64, X86
www.freebsd.org
Committees
3000 to 4000 developers They are not permitted to change code 300 to 400 committees They are permitted to change code
Kernel Services
FreeBSD Facilities and the Kernel System Calls Traps and Interrupts Clock Interrupts Memory Management Services Timing Services User, Group and Other Identifiers Resource Services System Operation Services
Kernel Provide 4 basic facilities: process, filesystem, communication, system startup Kernel has been organized to the follow:
Basic kernel facilities: timer, system-clock handling, descriptor management, process management Memory management: paging and swapping Generic system interface: the I/O, control, I/O descriptors The filesystem: files, directories, pathname translation, i/O buffer management Interprocess-communication: sockets
Low-level system-startup actions Trap and fault handling Low-level manipulation of the run-time context of a process Configuration and initialization of hardware devices Run-time support for I/O devices
System Calls
System calls provide a layer between the hardware and user-space processes
Syscall handling:
Provides an abstracted hardware interface for user-space Ensure system security and stability A single common layer between user-space and the rest of the system allows the multi-processes Verify the parameter to the system call Call a kernel routine that implements the system call
Clock Interrupts
The system is driven by a clock that interrupts at regular intervals which we call tick. Most system tick for FreeBSD is 10ms. hardclock()
softclock()
Process real-time timer Retransmission of dropped network packets Watchdog timers on peripherals that require monitoring System process-rescheduling event
Demand paging Copy-on-write mmap() interface for share memory sbrk() for heap allocate
Timing Services
Wakeup timer Profiling timer: kernel and user mode Virtual timer: user mode
User identifier (UID) and Group identifier (GID) set-user-identifier and set-groupidentifier, effective uid and effective gid Process Groups and Sessions
Each process in the system is associated with a process group The group of processes is referred to as a job A session is a collection of process groups
Resource Services
amount of user and system time used by process memory utilization of process paging and disk I/O activity of process number of voluntary and involuntary context switches
Accounting
The name of the command that ran The amount of user and system CPU time that was used The average amount of memory used
Process Management
Introduction to Process Management Process State Context Switching Process Scheduling Process Creation and Termination Process Debugging
Process State
Process identification: PID and PPID Scheduling: The process priority, user-mode scheduling priority, recent CPU utilization, and amount of time spent sleeping Process state: SIDL,SRUN,SSLEEP,SSTOP,SZOMB Signal state: Signals pending delivery Tracing Machine state Timers
Context Switching
A process executes for the duration of its time slice A process block for resource The system interrupts the current process
Synchronization
Process Scheduling
Multilevel feedback queue Round robin for same queue Calculations of Process Priority
p_estcpu: an estimate of the recent CPU utilization of this process p_nice: user-settable weighting factor that ranges from -20 to 20
Parent process and child process fork(), vfork() and rfork() Implementation of fork1() Termination exit() OR signal wait4() and SZOMB
Process Debugging
Read and write address space and registers Intercept signals posted to the process Single step and continue the execution of process Terminate the execution of the process
Memory Management
Overview of the FreeBSD VM System Kernel Memory Management Per-Process Resources Shared Memory Process Related Memory Operation The Pager interface Placement and Replacement
Kernel is permanently mapped into up 1G of every process address space Kernel Maps and Submaps kmem_alloc(), kmem_alloc_pageable(), kmem_free() Kernel malloc Kernel Zone Allocator
Per-Process Resources
vmspace Vm_map_entry vm_page Vnode/object vm_page
Start addr
Vm_map End addr Obj offset
Vm_pmap statistics
vm_page
Start addr
Vnode/object End addr Obj offset vm_page Vnode/object vm_page vm_page
Start addr
End addr Obj offset
Shared Memory
mmap(caddr_t address, size_t length, int protection, int flags, int fd, off_t offset) munmap mprotect mlock and munlock msync
copy-on-write page-on-demand
Termination of Process
Vnode Pager
Handles objects that map files in a filesystem Handles objects representing memory-mapped hardware devices Handles nonpagable memory for System V shm Handles object that map anonymous memory Handles shadow object
Device Pager
Physical-Memory Pager
Swap Pager
Page Coloring
L1 Cache Coloring L2 Cache Coloring Global least-recently used page Wired, active, inactive, cache, free
Page Replacement
Swapping
I/O System
Four main kinds of I/Os: filesystem, character-device, block-device, socket interface Devices identified by a major and minor number The Virtual-Filesystem Interface Descriptor Management Services Filesystem-Independent Services
Devices
Static device node under /dev DEVFS for dynamical device management aio_read, aio_write select()
Asynchronous I/O
The Filesystems
Virtual-Filesystem Interface
vnode operation Pathname translation Exported Filesystem Services Name cache and Buffer Management Structure of inode Implementation of Filesystem Services
Physical-Filesystem interface
Interprocess Communication
SYSV Interprocess communication POSIX 1003.1b is not implemented in kernel Socket API Network Communication Network Protocols
sysv ipc
ftok msgget, msgsnd, msgrcv, msgctl semget, semop, semctl shmget, shmat, shmdt, shmctl, shmids
sysv semaphore
System Operation
Bootstrapping Kernel Initialization Kernel Module Initialization User-Level Initialization System Shutdown and Autoreboot Configuration, Build and Debugging
Bootstrapping
Boot loads FreeBSD kernel from BSD filesystem Boot passes the information to kernel Boot need disable mmu and interrupts
Kernel Initialization
Setting up the run-time stack Identifying the type of CPU Calculating the amount of physical memory Initializing MMU hardware and Enable the MMU Crafting the hardware context for process 0 Invoking the initial C-base entry point
Entry point: mi_startup() SYSINIT(name, subsystem,order, function,) Basic services Kernel Thread Initialization Device Module Initialization Kernel Loadable Modules Interprocess Communication Startup Start Kernel Threads
User-Level Initialization
/sbin/init Check consistency of its disk by fsck Single-user mode: /bin/sh and /dev/console Multi-user mode: /etc/rc and /etc/ttys
reboot system call panic() causes system reboot Three phases for shutdown
Shutdown of all services rely to the filesystem Shutdown of the filesystem itself Shutdown other services
make buildkernel KERNCONF=<cfgfile> make installkernel KERNCONF=<cfgfile> Crash dump file /sbin/savecore Using /dev/kmem to talk to kernel
Acknowledgements