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

Similar documents
Design Overview of the FreeBSD Kernel CIS 657

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.

UNIX Kernel. UNIX History

CSC209 Review. Yeah! We made it!

History of FreeBSD. FreeBSD Kernel Facilities

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

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

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Mon Sep 17, 2007 Lecture 3: Process Management

Chapter 3: Process Concept

Chapter 3: Process Concept

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

Linux Operating System

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

CS 326: Operating Systems. Process Execution. Lecture 5

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

The Classical OS Model in Unix

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

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

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

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

Processes and Threads

Chapter 3: Process Concept

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

Operating System Labs. Yuanbin Wu

Process Management! Goals of this Lecture!

VEOS high level design. Revision 2.1 NEC

Killing Zombies, Working, Sleeping, and Spawning Children

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

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

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

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

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

CS370 Operating Systems

Introduction. CS3026 Operating Systems Lecture 01

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

Process Management 1

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

Module 12: I/O Systems

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

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

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

UNIX Files. How UNIX Sees and Uses Files

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

Lecture 4: Memory Management & The Programming Interface

Operating Systems. II. Processes

Module 12: I/O Systems

CS 3733 Operating Systems

PROCESS MANAGEMENT Operating Systems Design Euiseong Seo

CS2028 -UNIX INTERNALS

Chapter 13: I/O Systems

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

Processes and Exceptions

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

Chapter 15: The Linux System

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

Address spaces and memory management

(MCQZ-CS604 Operating Systems)

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

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 18

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

CS 5460/6460 Operating Systems

CS 111. Operating Systems Peter Reiher

Operating System Structure

Chapter 21: The Linux System

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Processes and Threads. Processes and Threads. Processes (2) Processes (1)

Operating System Design

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

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

CSE 451: Operating Systems Winter Processes. Gary Kimura

3. Process Management in xv6

Chapter 13: I/O Systems

Chapter 13: I/O Systems. Chapter 13: I/O Systems. Objectives. I/O Hardware. A Typical PC Bus Structure. Device I/O Port Locations on PCs (partial)

Silberschatz and Galvin Chapter 12

www nfsd emacs lpr Process Management CS 537 Lecture 4: Processes Example OS in operation Why Processes? Simplicity + Speed

Module 20: The Linux System

Slide 6-1. Processes. Operating Systems: A Modern Perspective, Chapter 6. Copyright 2004 Pearson Education, Inc.

Assignment 1. Teaching Assistant: Michalis Pachilakis (

Module A: The FreeBSD System

Module A: The FreeBSD System

Pipes and FIFOs. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

CHAPTER 3 - PROCESS CONCEPT

Mid Term from Feb-2005 to Nov 2012 CS604- Operating System

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

Appendix A: FreeBSD. Operating System Concepts 9 th Edition

Processes. Processes (cont d)

Transcription:

Design Overview of the FreeBSD Kernel CIS 657 Organization of the Kernel Machine-independent 86% of the kernel (80% in 4.4BSD) C 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 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 1

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 or I/O changing or mode/state stopping or 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 continues buffer written to disk 2

System Call Implementation Parameters of call, and system call #, pushed on stack Process executes TRAP instruction actual instruction is or 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 is a thread of execution. Process context: user level: address space, run-time environment kernel level: scheduling parameters, resource controls, id information. 3

Process Management II Users can (all through system calls) create es control es execution monitor execution status Each gets a unique 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 by copying context of an existing fork() system call original is the parent new is the child Except for pid,, both user and kernel state is duplicated Process States parent fork() wait() parent child execve() child exit() zombie 4

Process Management System Calls fork(): creates a new child exact copy of parent file descriptors are the same signal handling status memory layout and copy of address space (but not shared memory) Both 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? Process Management System Calls III exit() 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 es have exited, but the parent hasn t t yet called wait() 5

Process Management System Calls IV nice() allows es 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 s s actions, external events, or other es system calls es 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 es may also tell the kernel to ignore (block) all occurrences of a signal can also restore the default action of the kernel almost all uncaught signals cause termination might might cause core dump some signals cannot be caught or ignored (SIGKILL, SIGSTOP) All signals have the same priority (race conditions possible) 6

Process Groups Control access to terminals (job control) an entire pipeline is one group: cat myfile grep foo wc allow signals to be delivered to a set of associated es Process Group ID (pgid( pgid) ) inherited from parent Can be changed by me, for me (or my descendants) Groups of groups are called sessions Primarily to provide daemons with isolated environments Memory Management Each 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 context when necessary with 4.4BSD, the VM subsystem was redesigned from: small, expensive memory; fast disk to: large, cheap memory; slow disk; multiors; shared memory; machine independence 7

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 es 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 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 Solution: zone allocation Useful for a collection of items of identical size zalloc(), zfree() 8

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 es don t t reference I/O streams directly; they use descriptors unsigned integers obtained from open(), pipe(), and socket() syscalls; ; inherited from parent ; 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 inter communication: only exists when a holds descriptor for it generic communication endpoints heavily used for networking 9

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 uses open() for reading one uses open() for writing Descriptor Information Kernel keeps a descriptor table for each map from descriptor (index) to information about the object On 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 10

Pipe ( )( create pipe with pipe() call fork() two new es close() stdout of first dup() write end of pipe onto stdout I/O Redirection myprog grep foo > foofile close() stdin of second 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) 11

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 12