Design Overview of the FreeBSD Kernel CIS 657

Similar documents
Design Overview of the FreeBSD Kernel. Organization of the Kernel. What Code is Machine Independent?

Unix Processes. What is a Process?

Processes. Dr. Yingwu Zhu

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.

History of FreeBSD. FreeBSD Kernel Facilities

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Process Concepts. CSC400 - Operating Systems. 3. Process Concepts. J. Sumey

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

UNIX Kernel. UNIX History

CSC209 Review. Yeah! We made it!

Linux Operating System

Getting to know you. Anatomy of a Process. Processes. Of Programs and Processes

Chapter 3: Process Concept

The Design and Implementation of the 4.4BSD Operating System. Marshall Kirk McKusick Keith Bostic Michael J. Karels John S.

Chapter 3: Process Concept

Mon Sep 17, 2007 Lecture 3: Process Management

Killing Zombies, Working, Sleeping, and Spawning Children

Chapter 3: Process Concept

CS 326: Operating Systems. Process Execution. Lecture 5

ECE 550D Fundamentals of Computer Systems and Engineering. Fall 2017

CPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu

The Classical OS Model in Unix

Processes COMPSCI 386

Noorul Islam College Of Engineering, Kumaracoil MCA Degree Model Examination (October 2007) 5 th Semester MC1642 UNIX Internals 2 mark Questions

What is a Process? Processes and Process Management Details for running a program

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

Jan 20, 2005 Lecture 2: Multiprogramming OS

Midterm Exam CPS 210: Operating Systems Spring 2013

OS COMPONENTS OVERVIEW OF UNIX FILE I/O. CS124 Operating Systems Fall , Lecture 2

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Computer Science 330 Operating Systems Siena College Spring Lab 5: Unix Systems Programming Due: 4:00 PM, Wednesday, February 29, 2012

Processes and Threads

PROCESS CONTROL: PROCESS CREATION: UNIT-VI PROCESS CONTROL III-II R

CS370 Operating Systems

OS Structure, Processes & Process Management. Don Porter Portions courtesy Emmett Witchel

Operating System Labs. Yuanbin Wu

Process Management! Goals of this Lecture!

ESE 333 Real-Time Operating Systems 2 What is an operating system? Two views: 1. Top-down view: Extended machine ffl Covers the details of the hardwar

* What are the different states for a task in an OS?

UNIX Files. How UNIX Sees and Uses Files

PROCESS VIRTUAL MEMORY PART 2. CS124 Operating Systems Winter , Lecture 19

Chapter 15: The Linux System

Chapter 15: The Linux System. Operating System Concepts Essentials 8 th Edition

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

Inter-Process Communication

Most of the work is done in the context of the process rather than handled separately by the kernel

OS lpr. www. nfsd gcc emacs ls 1/27/09. Process Management. CS 537 Lecture 3: Processes. Example OS in operation. Why Processes? Simplicity + Speed

Lecture 4: Memory Management & The Programming Interface

Chapter 21: The Linux System. Chapter 21: The Linux System. Objectives. History. The Linux Kernel. Linux 2.0

Operating Systems. II. Processes

PROCESS MANAGEMENT Operating Systems Design Euiseong Seo

Chapter 21: The Linux System

CS 355 Operating Systems. Keeping Track of Processes. When are processes created? Process States 1/26/18. Processes, Unix Processes and System Calls

CSC 4320 Test 1 Spring 2017

Introduction. CS3026 Operating Systems Lecture 01

Process Management 1

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

Outline. OS Interface to Devices. System Input/Output. CSCI 4061 Introduction to Operating Systems. System I/O and Files. Instructor: Abhishek Chandra

VEOS high level design. Revision 2.1 NEC

Module 12: I/O Systems

CSE 451: Operating Systems Winter Module 4 Processes. Mark Zbikowski Allen Center 476

Process management. What s in a process? What is a process? The OS s process namespace. A process s address space (idealized)

Operating Systems. Lecture 05

Processes. Process Scheduling, Process Synchronization, and Deadlock will be discussed further in Chapters 5, 6, and 7, respectively.

The control of I/O devices is a major concern for OS designers

Module 12: I/O Systems

Module 20: The Linux System

CS 111. Operating Systems Peter Reiher

CS 3733 Operating Systems

Operating System Design

CS2028 -UNIX INTERNALS

Chapter 13: I/O Systems

Processes and Exceptions

Module 22: The Linux System

Address spaces and memory management

(MCQZ-CS604 Operating Systems)

Last time: introduction. Networks and Operating Systems ( ) Chapter 2: Processes. This time. General OS structure. The kernel is a program!

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 18

CHAPTER 3 - PROCESS CONCEPT

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Processes and More. CSCI 315 Operating Systems Design Department of Computer Science

Assignment 1. Teaching Assistant: Michalis Pachilakis (

Processes. Processes (cont d)

CS 5460/6460 Operating Systems

Process. Program Vs. process. During execution, the process may be in one of the following states

Process Time. Steven M. Bellovin January 25,

Operating System Structure

Module A: The FreeBSD System

Module A: The FreeBSD System

UNIT I Linux Utilities

Appendix A: FreeBSD. Operating System Concepts 9 th Edition

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

CS370 Operating Systems

Fall 2017 :: CSE 306. Process Abstraction. Nima Honarmand

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

Processes in linux. What s s a process? process? A dynamically executing instance of a program. David Morgan. David Morgan

W4118 Operating Systems. Junfeng Yang

CSE 451: Operating Systems Winter Processes. Gary Kimura

Transcription:

Design Overview of the FreeBSD Kernel CIS 657

Organization of the Kernel Machine-independent 86% of the kernel (80% in 4.4BSD) C code Machine-dependent 14% of kernel Only 0.6% of kernel in assembler (2% in 4.4BSD)

What Code is Machine Independent? Basic kernel facilities: timer and clock handling, descriptor and process mgmt. Memory mgmt: paging & swapping Generic system interfaces: I/O, control, multiplexing performed on descriptors Filesystem Terminal-handling support Inter-Process communication (sockets) Network communication (protocols, routing) Linux compatability

What Code is Machine Dependent? PCI and ISA bus support Virtual memory (hardware-specific) Assembly language (trap handling, context switching ) Linux compatability other machine dependent Header files for specific hardware

Kernel Services Kernel runs in separate address space Kernel runs privileged instructions in system mode of processor I/O changing processor mode/state stopping processor Boundary is crossed with system calls System calls perform complex actions in kernel space All system calls appear synchronous to applications (example: write)

Write Appears Synchronous Process Timeline Kernel Timeline write() Time copy buffer process continues buffer written to disk

System Call Implementation Parameters of call, and system call #, pushed on process stack Process executes TRAP instruction actual instruction is processor dependent CPU microcode changes privelege level to system mode and page tables executes system call indicated by call # (lookup table)

System Call Implementation II Arguments copied to kernel space and verified. Kernel returns results in registers or copies them to user-level memory On error, return -1 and set global variable errno All kernel data structures stored in kernel address space why?

Process Management Multitasking environment what does this mean? A process is a thread of execution. Process context: user level: address space, run-time environment kernel level: scheduling parameters, resource controls, id information.

Process Management II Users can (all through system calls) create processes control processes execution monitor execution status Each process gets a unique process identifier (pid( pid) user references pid in system call kernel uses it for internal table lookup (directly?) and to report status to user

Process Management III Kernel creates new process by copying context of an existing process fork() system call original process is the parent new process is the child Except for pid,, both user and kernel state is duplicated

Process States parent process wait() parent process fork() child process execve() child process exit() zombie process

Process Management System Calls fork(): creates a new child process exact copy of parent file descriptors are the same signal handling status memory layout and copy of address space (but not shared memory) Both process return from fork() child receives 0 parent receives pid of child

Process Management System Calls II execve() an entire family of calls (execl( execl, execve,, etc.) we generically refer to as exec overlays the current address space with the memory image of a program keeps old context information closely linked to fork() the vast majority of fork() calls are almost immediately followed by exec() calls. How could we optimize this?

exit() Process Management System Calls III process terminates cleanly (a dirty termination could be the result of a bug) returns an 8-bit status code to the parent (more requires use of IPC) wait()/wait4() suspend the caller until a child exits find out what the little bugger was up to zombie processes have exited, but the parent hasn t t yet called wait()

Process Management System Calls IV nice() allows processes to influence the scheduling algorithm can only decrease one s s own priority (hence the name: you can be nice to others) this has only minor overall influence on the basic algorithm

Signals software interrupts generated by kernel, in response to a process s s actions, external events, or other processes system calls processes may specify handler functions that catch the signal a signal X that has been raised is blocked while the handler for X is running.

Signals II processes may also tell the kernel to ignore (block) all occurrences of a signal process can also restore the default action of the kernel almost all uncaught signals cause process termination might might cause core dump some signals cannot be caught or ignored (SIGKILL, SIGSTOP) All signals have the same priority (race conditions possible)

Process Groups Control access to terminals (job control) an entire pipeline is one process group: cat myfile grep foo wc allow signals to be delivered to a set of associated processes Process Group ID (pgid( pgid) ) inherited from parent Can be changed by me, for me (or my descendants) Groups of process groups are called sessions Primarily to provide daemons with isolated environments

Memory Management Each process has its own address space Three logical segments: text -- program code (rx( rx), size only changes on exec() data -- the heap (rw( rw), grow/shrink through system calls stack -- stack for procedure calls (rw( rw), grow/shrink automatically by the kernel

Memory Management II demand paged virtual memory swapping of entire process context when necessary with 4.4BSD, the VM subsystem was redesigned from: small, expensive memory; fast disk to: large, cheap memory; slow disk; multiprocessors; shared memory; machine independence

Memory Management III: Copying vs. Memory Mapping 4.4BSD has mmap(), so why copy into the kernel? Discuss: alignment copy-on-write overhead address translation cache effects Result: mmap() is used to access large files and to share data between processes without copying, but not for passing system call parameters

Memory Management in the Kernel Kernel needs to allocate memory to service system calls short short term need Kernel has limited stack; can t t just allocate memory there as we would with a user process Kernel has its own memory allocator (like malloc()/free() for user programs) Requires extremely careful programming why?

Zone Allocation Some large, persistent allocations don t work well with kernel malloc E.g., structure tracking information about process Solution: zone allocation Useful for a collection of items of identical size zalloc(), zfree()

I/O Powerful fundamental model: sequence, or stream, of bytes, with either random or sequential access No access methods, no control blocks, etc. User-level libraries can build structure on this, but the kernel only sees sequences of bytes Amish files: no bells, no whistles, no shiny objects Simplicity begets efficiency

Descriptors and I/O Unix processes don t t reference I/O streams directly; they use descriptors unsigned integers obtained from open(), pipe(), and socket() syscalls; ; inherited from parent process; or received via socket IPC read(), write() transfer data to/from descriptors close() deallocates a descriptor

Three Things Descriptors Can Reference Files: linear array of bytes, at least one name exists until all names are deleted, and no open descriptors I/O devices look like files open() system call Sockets transient object used for interprocess communication: only exists when a process holds descriptor for it generic communication endpoints heavily used for networking

Three Things II Pipes: linear array of bytes used only as I/O stream unidirectional accessed through pair of descriptors one for writing one for reading pipe() system call FIFO special kind of pipe, appears in file space one process uses open() for reading one process uses open() for writing

Descriptor Information Kernel keeps a descriptor table for each process map from descriptor (index) to information about the object On process exit, kernel reclaims open descrip- tors; ; might then delete object kernel keeps a file offset associated with each descriptor updated on each read(), write(), or lseek() can t lseek() on a pipe or socket

Descriptor Management Three standard descriptors: 0 : standard input 1 : standard output 2 : standard error inherited via fork() and persist across exec() start out associated with terminal for a login session I/O redirection changes this

I/O Redirection myprog grep foo > foofile Pipe ( )( create pipe with pipe() call fork() two new processes close() stdout of first process dup() write end of pipe onto stdout close() stdin of second process dup() read end of pipe onto stdin Output ( > )( close() stdout open() output file for writing dup() file descriptor onto stdout

Descriptor Management Review open(), pipe(), socket() calls allocate descriptors allocate lowest available descriptor dup(), dup2() clone descriptors dup() picks lowest available close() deallocates and makes the table slot available

Devices Appear in the file space (except networks) filenames (typically /dev/ ) can be accessed with regular file syscalls Two kinds of devices: structured (block) unstructured (character) Device drivers sit below some of the system calls (read,( write, ioctl)

Special Device System Calls mknod() creates device special files (those things that live in /dev) to be associated with device drivers ioctl() the kitchen sink I/O call. Everything that doesn t t map onto standard calls some devices have most of their interface here

Sockets Remember that network devices don t have device special files They use sockets: generic communications endpoints Can be mapped to multiple protocols (e.g., IPX, TCP/IP, etc.) Create the endpoints, then connect.

Filesystems & Filestores All the usual stuff (tree-structured, directories, links, protection ) Split the filesystem into two parts: naming, locking, protection (common to all filesystems) layout of storage on the physical medium (the filestore) Berkeley FFS, Sprite LFS, VM-based