You are on page 1of 47

Introduction on FreeBSD Operating System

       

History and Goals Kernel Services Process Management Memory Management I/O System Interprocess Communication System Operation Acknowledgments

History and Goals
  

History of the UNIX System BSD and Other Systems The Transition of BSD to Open Source The FreeBSD Development Model

History of the UNIX System

Bell Lab invented UNIX in 1969
  

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

CSRG at Berkeley invented BSD in 1979

BSD and Other Systems      Most features from UNIX Terminal drivers from TENEX/TOPS-20 Job control from TOPS and MIT’s ITS Memory management from Mach The Influence of the User Community Some packages from other groups comp.bugs.4bsd .

4 Alpha.4BSD-Lite Current version is FreeBSD5.10 . Space64. X86  JUNOS is based on FreeBSD4.The Transition of BSD to Open Source      The FreeBSD group was formed in 1993 Supporting the PC architecture only Ease of installation Code started base with 4.

org   Committees    3000 to 4000 developers They are not permitted to change code 300 to 400 committees They are permitted to change code  Core team can do everything .freebsd.The FreeBSD Development Model  Publicly readable source-code control system Developers groups   www.

Group and Other Identifiers Resource Services System Operation Services .Kernel Services          FreeBSD Facilities and the Kernel System Calls Traps and Interrupts Clock Interrupts Memory Management Services Timing Services User.

communication. process management Memory management: paging and swapping Generic system interface: the I/O. system-clock handling. filesystem.FreeBSD Facilities and the Kernel   Kernel Provide 4 basic facilities: process. system startup Kernel has been organized to the follow:      Basic kernel facilities: timer. control. pathname translation. I/O descriptors The filesystem: files. i/O buffer management Interprocess-communication: sockets . directories. descriptor management.

FreeBSD Facilities and the Kernel      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  Result handling: errno .

Ethernet  Software Interrupts is doing lowerpriority processing for I/O interrupts . Console. page fault  I/O device Interrupts occur asynchronously  Clocks.Traps and Interrupts  Traps occur synchronously for process  Divide by zero. illegal instruction.

Most system tick for FreeBSD is 10ms.Clock Interrupts    The system is driven by a clock that interrupts at regular intervals which we call tick. hardclock()    softclock()     Increment the current time of day Call softclock() if necessary Process real-time timer Retransmission of dropped network packets Watchdog timers on peripherals that require monitoring System process-rescheduling event .

Memory Management Services     Demand paging Copy-on-write mmap() interface for share memory sbrk() for heap allocate .

Timing Services   System Real Time Interval Time for each process    Wakeup timer Profiling timer: kernel and user mode Virtual timer: user mode .

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 . Group and Other Identifiers    User identifier (UID) and Group identifier (GID) set-user-identifier and set-groupidentifier.User.

Resource Services   Process Priorities: nice value Resource Utilization     The The The The 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   Resource Limits Filesystem Quotas .

System Operation Services  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 …    Bootstrapping Shutdown Debugging .

Process Management       Introduction to Process Management Process State Context Switching Process Scheduling Process Creation and Termination Process Debugging .

Introduction to Process Management   The definition of Process Design goal for FreeBSD Process management     Multiprogramming Fair Scheduling Communication Easy management and debugging .

user-mode scheduling priority. recent CPU utilization.SZOMB Signal state: Signals pending delivery Tracing Machine state Timers .Process State  The proc structure        Process identification: PID and PPID Scheduling: The process priority.SSLEEP.SRUN.SSTOP. and amount of time spent sleeping Process state: SIDL.

spl0. splhigh . splsoftclock. splnet. ….Context Switching  Cause of context switching    A process executes for the duration of its time slice A process block for resource The system interrupts the current process  Voluntary Context Switching  sleep() and wakeup()  Synchronization  Set-priority-level.

Process Scheduling    I/O-Bound Versus Processor-Bound   Multilevel feedback queue Round robin for same queue Calculations of Process Priority   FreeBSD favors I/O bound p_estcpu: an estimate of the recent CPU utilization of this process p_nice: user-settable weighting factor that ranges from -20 to 20 .

vfork() and rfork() Implementation of fork1() Termination exit() OR signal wait4() and SZOMB .Process Creation and Termination      Parent process and child process fork().

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   Inefficient of ptrace /proc file system . 4. 3.Process Debugging  ptrace system call 1. 2.

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 .

Overview of the FreeBSD VM System   FreeBSD VM is paging system Three important policies:    The fetch policy The placement policy The replacement policy   Swapping mmap system call for shared memory .

Kernel Memory Management      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 .

int fd. size_t length. int flags. off_t offset) munmap mprotect mlock and munlock msync . int protection.Shared Memory      mmap(caddr_t address.

Process Related Memory Operation  Create of a New Process  copy-on-write page-on-demand  Load a execute file   Process manipulation of its address space  sbrk. mmap. mprotect  Termination of Process .

The Pager interface  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   .

Placement and Replacement  Page Coloring   L1 Cache Coloring L2 Cache Coloring Global least-recently used page Wired. inactive. active. cache. free  Page Replacement    Swapping .

I/O System    I/O System Overview Devices The Filesystems .

character-device. block-device.I/O System Overview      Four main kinds of I/Os: filesystem. socket interface Devices identified by a major and minor number The Virtual-Filesystem Interface Descriptor Management Services Filesystem-Independent Services  Name cache. Buffer management .

Devices  Device Naming and Access   Static device node under /dev DEVFS for dynamical device management aio_read. aio_write select()  Asynchronous I/O   Mutliplexing I/O on Descriptors  .

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 .

msgsnd. msgrcv. shmctl.SYSV Interprocess communication  sysv ipc  ftok msgget. shmdt. shmat. semctl shmget. semop. shmids  sysv message queue   sysv semaphore   sysv shared memory  . msgctl semget.

System Operation       Bootstrapping Kernel Initialization Kernel Module Initialization User-Level Initialization System Shutdown and Autoreboot Configuration. Build and Debugging .

help. autoboot. load …    Boot loads FreeBSD kernel from BSD filesystem Boot passes the information to kernel Boot need disable mmu and interrupts .Bootstrapping   BIOS loads boot Commands for boot boot.

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 .

function.…) Basic services Kernel Thread Initialization Device Module Initialization Kernel Loadable Modules Interprocess Communication Startup Start Kernel Threads .Kernel Module Initialization         Entry point: mi_startup() SYSINIT(name.order. subsystem.

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 .

System Shutdown and Autoreboot    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 .

Build and Debugging     make buildkernel KERNCONF=<cfgfile> make installkernel KERNCONF=<cfgfile> Crash dump file /sbin/savecore Using /dev/kmem to talk to kernel .Configuration.

org The Design and Implementation of FreeBSD .freebsd.Acknowledgements   http://www.