You are previewing The Art of Linux Kernel Design.
O'Reilly logo
The Art of Linux Kernel Design

Book Description

Uses the Running Operation as the Main Thread

Difficulty in understanding an operating system (OS) lies not in the technical aspects, but in the complex relationships inside the operating systems. The Art of Linux Kernel Design: Illustrating the Operating System Design Principle and Implementation addresses this complexity. Written from the perspective of the designer of an operating system, this book tackles important issues and practical problems on how to understand an operating system completely and systematically. It removes the mystery, revealing operating system design guidelines, explaining the BIOS code directly related to the operating system, and simplifying the relationships and guiding ideology behind it all.

Based on the Source Code of a Real Multi-Process Operating System

Using the 0.11 edition source code as a representation of the Linux basic design, the book illustrates the real states of an operating system in actual operations. It provides a complete, systematic analysis of the operating system source code, as well as a direct and complete understanding of the real operating system run-time structure. The author includes run-time memory structure diagrams, and an accompanying essay to help readers grasp the dynamics behind Linux and similar software systems.

  • Identifies through diagrams the location of the key operating system data structures that lie in the memory
  • Indicates through diagrams the current operating status information which helps users understand the interrupt state, and left time slice of processes
  • Examines the relationship between process and memory, memory and file, file and process, and the kernel
  • Explores the essential association, preparation, and transition, which is the vital part of operating system

Develop a System of Your Own

This text offers an in-depth study on mastering the operating system, and provides an important prerequisite for designing a whole new operating system.

Table of Contents

    1. 1.1 Loading BIOS, Constructing Interrupt Vector Table, and Activating Interrupt Service Routines in the Real Mode
      1. 1.1.1 Procedure for Starting BIOS
      2. 1.1.2 BIOS Loads the Interrupt Vector Table and Interrupt Service Routines into Memory
    2. 1.2 Loading the OS Kernel and Preparing for the Protected Mode
      1. 1.2.1 Loading Bootsect
      2. 1.2.2 Loading the Second Part of Code— —Setup
      3. 1.2.3 Load the System Module
    3. 1.3 Transfer to 32-Bit Mode and Prepare for the Main Function
      1. 1.3.1 Disable Interrupts and Move System to 0x00000
      2. 1.3.2 Set the Interrupt Descriptor Table and Global Descriptor Table
      3. 1.3.3 Open A20 and Achieve 32-Bit Addressing
      4. 1.3.4 Prepare for the Implementation of head.s in the Protected Mode
      5. 1.3.5 CPU Starts to Execute head.s
    4. 1.4 Summary
    1. 2.1 Set Root Device 2 and Hard Disk
    2. 2.2 Set Up Physical Memory Layout, Buffer Memory, Ramdisk, and Main Memory
    3. 2.3 Ramdisk Setup and Initialization
    4. 2.4 Initialization of the Memory Management Structure mem_map
    5. 2.5 Binding the Interrupt Service Routine
    6. 2.6 Initialize the Request Structure of the Block Device
    7. 2.7 Binding with the Interrupt Service Routine of Peripherals and Establishing the Human–Computer Interaction Interface
      1. 2.7.1 Set the Serial Port
      2. 2.7.2 Set the Display
      3. 2.7.3 Set the Keyboard
    8. 2.8 Time Setting
    9. 2.9 Initialize Process 0
      1. 2.9.1 Initialization of Process 0
      2. 2.9.2 Set the Timer Interrupt
      3. 2.9.3 Set the Entrance of System Call
    10. 2.10 Initialize the Buffer Management Structure
    11. 2.11 Initialize the Hard Disk
    12. 2.12 Initialize the Floppy Disk
    13. 2.13 Enable the Interrupt
    14. 2.14 Process 0 Moves from Privilege Level 0 to 3 and Becomes a Real Process
    1. 3.1 Creation of Process 1
      1. 3.1.1 Preparation for Creating Process 1
      2. 3.1.2 Apply for an Idle Position and a Process Number for Process 1
      3. 3.1.3 Call Copy_process()
      4. 3.1.4 Set the Page Management of Process 1
        1. Set the Code Segment and Data Segment in the Linear Address Space of Process 1
        2. Create the First Page Table for Process 1 and Set the Corresponding Page Directory Entry
      5. 3.1.5 Process 1 Shares Files of Process 0
      6. 3.1.6 Set the Table Item in the GDT of Process 1
      7. 3.1.7 Process 1 Is in Ready State to Complete the Creation of Process 1
    2. 3.2 Kernel Schedules a Process for the First Time
    3. 3.3 Turn to Process 1 to Execute
      1. 3.3.1 Preparing to Install the Hard Disk File System by Process 1
        1. Process 1 Set hd_info of Hard Disk
        2. Read the Hard Disk Boot Blocks to the Buffer
        3. Bind the Buffer Block with Request
        4. Read the Hard Disk
        5. Wait for Hard Disk Reading Data, Process Scheduling, and Switch to Process 0 to Execute
        6. Hard Disk Interruption Occurs during the Execution of Process 0
        7. After Reading the Disk, Switch Process Scheduling to Process 1
      2. 3.3.2 Process 1 Formats the Ramdisk and Replaces the Root Device as the Ramdisk
      3. 3.3.3 Process 1 Loads the Root File System into the Root Device
        1. Copying the Super Block of the Root Device to the super_block[8]
        2. Mount the i node of the Root Device to the Root Device Super Block in super_block[8]
        3. Associate the Root File System with Process 1
    1. 4.1 Open the Terminal Device File and Copy the File Handle
      1. 4.1.1 Open the Standard Input Device File
        1. File_table[0] is Mounted to Filp[0] in Process 1
        2. Determine the Starting Point of Absolute Path
        3. Acquiring the i node of Dev
        4. Determine the i node of Dev as the Topmost i node
        5. Acquire the i node of the tty0 File
        6. Determine tty0 as the Character Device File
        7. Set file_table[0]
      2. 4.1.2 Open the Standard Output and Standard Error Output Device File
    2. 4.2 Fork Process 2 and Switch to Process 2 to Execute
    3. 4.3 Load the Shell Program
      1. 4.3.1 Close the Standard Input File and Open the rc File
      2. 4.3.2 Detect the Shell File
        1. Detect the Attribute of the i node
        2. Test File Header’s Attributes
      3. 4.3.3 Prepare to Execute the Shell Program
        1. Load Parameters and Environment Variables
        2. Adjust the Management Structure of Process 2
        3. Adjust EIP and ESP to Execute Shell
      4. 4.3.4 Execute the Shell Program
        1. Execute the First Page Program Loading by the Shell
        2. Map the Physical Address and Linear Address of the Loading Page
    4. 4.4 The System Gets to the Idle State
      1. 4.4.1 Create the Update Process
      2. 4.4.2 Switch to the Shell Process
      3. 4.4.3 Reconstruction of the Shell
    1. 5.1 Install the File System
      1. 5.1.1 Get the Super Block of Peripherals
      2. 5.1.2 Confirm the Mount Point of the Root File System
      3. 5.1.3 Mount the Super Block with the Root File System
    2. 5.2 Opening a File
      1. 5.2.1 Mount *Filp[20] in the User Process to File_table[64]
      2. 5.2.2 Get the File’s i node
        1. Get the i node of the Directory File
        2. Get the i node of the Target File
      3. 5.2.3 Bind File i node with File_table[64]
    3. 5.3 Reading a File
      1. 5.3.1 Locate the Position of the Data Block in the Peripherals
      2. 5.3.2 Data Block Is Read into the Buffer Block
      3. 5.3.3 Copy Data from the Buffer into the Process Memory
    4. 5.4 Creating a New File
      1. 5.4.1 Searching a File
      2. 5.4.2 Create a New i node for a File
      3. 5.4.3 Create a New Content Item
    5. 5.5 Writing a File
      1. 5.5.1 Locate the Position of the File to Be Written In
      2. 5.5.2 Apply for a Buffer Block
      3. 5.5.3 Copy Specified Data from the Process Memory to the Buffer Block
      4. 5.5.4 Two Ways to Synchronize Data from the Buffer to the Hard Disk
    6. 5.6 Modifying a File
      1. 5.6.1 Reposition the Current Operation Pointer of the File
      2. 5.6.2 Modifying Files
    7. 5.7 Closing a File
      1. 5.7.1 Disconnecting Filp and File_table[64] in the Current Process
      2. 5.7.2 Releasing the Files’ i node
    8. 5.8 Deleting a File
      1. 5.8.1 Checking the Deleting Conditions of Files
      2. 5.8.2 Specific Deleting Work
    1. 6.1 Linear Address Protection
      1. 6.1.1 Patterns of the Process Linear Address Space
      2. 6.1.2 Segment Base Addresses, Segment Limit, GDT, LDT, and Privilege Level
    2. 6.2 Paging
      1. 6.2.1 Linear Address to Physical Address
      2. 6.2.2 Process Execution Paging
      3. 6.2.3 Process Sharing the Page
      4. 6.2.4 Kernel Paging
    3. 6.3 Complete Process of User Process from Creation to Exit
      1. 6.3.1 Create Process str1
      2. 6.3.2 Preparation to Load str1
      3. 6.3.3 Running and Loading of Process str1
      4. 6.3.4 Exiting of Process str1
    4. 6.4 Multiple User Processes Run Concurrently
      1. 6.4.1 Process Scheduling
      2. 6.4.2 Page Protection
    1. 7.1 Function of Buffer
    2. 7.2 Structure of Buffer
    3. 7.3 The Function of b_dev, b_blocknr, and Request
      1. 7.3.1 Ensure the Correctness of the Data Interaction between Processes and Buffer Block
      2. 7.3.2 Let the Data Stay in the Buffer as Long as Possible
    4. 7.4 Function of Uptodate and Dirt
      1. 7.4.1 Function of b_uptodate
      2. 7.4.2 Function of the b_dirt
      3. 7.4.3 Function of the i_update, i_dirt, and s_dirt
    5. 7.5 Function of the Count, Lock, Wait, Request
      1. 7.5.1 Function of b_count
      2. 7.5.2 Function of i_count
      3. 7.5.3 Function of b_lock and *b_wait
      4. 7.5.4 Function of i_lock, i_wait, s_lock, and *s_wait
      5. 7.5.5 Function of Request
    6. 7.6 Example 1: Process Waiting Queue of Buffer Block
    7. 7.7 Overall Look at the Buffer Block and the Request Item
    8. 7.8 Example 2: Comprehensive Examples of Multiprocess Operating File
    1. 8.1 Pipe Mechanism
      1. 8.1.1 The Creation Process of the Pipe
      2. 8.1.2 Operation of Pipe
    2. 8.2 Signal Mechanism
      1. 8.2.1 Use of Signal
      2. 8.2.2 The Influence of Signal on the Process Execution State
    3. 8.3 Summary
    1. 9.1 Run a Simple Program to See What the Operating System Has Done
    2. 9.2 Thoughts on the Design of the Operating System: Master–Slave Mechanism
      1. 9.2.1 Process and Its Creation Mechanism in the Master–Slave Mechanism
        1. Program Boundary and Process
        2. Process Creation
      2. 9.2.2 How Does the Designing of Operating System Display the Master–Slave Mechanism?
        1. Master–Slave Mechanism That the Operating System Reflects in Process Scheduling
        2. Master–Slave Mechanism That the Operating System Adopts in Memory Management
        3. Master–Slave Mechanism Is Reflected by OS File System
    3. 9.3 Three Key Techniques in Realizing the Master–Slave Mechanism
      1. 9.3.1 Protection and Paging
      2. 9.3.2 Privilege Level
      3. 9.3.3 Interrupt
    4. 9.4 Decisive Factor in Establishing the Master–Slave Mechanism: The Initiative
    5. 9.5 Relationship between Software and Hardware
      1. 9.5.1 Nonuser Process: Process 0, Process 1, Shell Process
      2. 9.5.2 Storage of File and Data
        1. Memory, Hard Disk, Buffer: Computing Storage, Storing Storage, Transition State Storage
        2. Guiding Ideology of Designing Buffer
        3. Use the File System to Implement Interprocess Communication: Pipe
    6. 9.6 Parent and Child Processes Sharing Page
    7. 9.7 Operating System’s Global Interrupt and the Process’s Local Interrupt: Signal
    8. 9.8 Summary