Freebsd

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 47

Introduction on FreeBSD Operating System

Agenda

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 MITs ITS Memory management from Mach The Influence of the User Community
Some packages from other groups comp.bugs.4bsd

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.4BSD-Lite Current version is FreeBSD5.4
Alpha, Space64, X86

JUNOS is based on FreeBSD4.10

The FreeBSD Development Model

Publicly readable source-code control system Developers groups


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

Core team can do everything

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

FreeBSD Facilities and the Kernel

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

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

Traps and Interrupts

Traps occur synchronously for process

Divide by zero, illegal instruction, page fault

I/O device Interrupts occur asynchronously

Clocks, Console, Ethernet

Software Interrupts is doing lowerpriority processing for I/O interrupts

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()

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

User, Group and Other Identifiers

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

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

Process State

The proc structure


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

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, spl0, splsoftclock, splnet, , splhigh

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

Process Creation and Termination


Parent process and child process fork(), vfork() and rfork() Implementation of fork1() Termination exit() OR signal wait4() and SZOMB

Process Debugging

ptrace system call


1. 2. 3. 4.

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

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

Shared Memory

mmap(caddr_t address, size_t length, int protection, int flags, int fd, off_t offset) munmap mprotect mlock and munlock msync

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, active, inactive, cache, free

Page Replacement

Swapping

I/O System

I/O System Overview Devices The Filesystems

I/O System Overview

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

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

SYSV Interprocess communication

sysv ipc

ftok msgget, msgsnd, msgrcv, msgctl semget, semop, semctl shmget, shmat, shmdt, shmctl, shmids

sysv message queue

sysv semaphore

sysv shared memory

System Operation

Bootstrapping Kernel Initialization Kernel Module Initialization User-Level Initialization System Shutdown and Autoreboot Configuration, Build and Debugging

Bootstrapping

BIOS loads boot Commands for boot


boot, autoboot, help, load

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

Kernel Module Initialization


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

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

Configuration, Build and Debugging


make buildkernel KERNCONF=<cfgfile> make installkernel KERNCONF=<cfgfile> Crash dump file /sbin/savecore Using /dev/kmem to talk to kernel

Acknowledgements

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

You might also like