logo资料库

Professional Linux Kernel Architecture 原版pdf by Mauerer.pdf

第1页 / 共1361页
第2页 / 共1361页
第3页 / 共1361页
第4页 / 共1361页
第5页 / 共1361页
第6页 / 共1361页
第7页 / 共1361页
第8页 / 共1361页
资料共1361页,剩余部分请下载后查看
Contents
Introduction
What This Book Covers
Chapter 1: Introduction and Overview
1.1 Tasks of the Kernel
1.2 Implementation Strategies
1.3 Elements of the Kernel
1.4 Why the Kernel Is Special
1.5 Some Notes on Presentation
1.6 Summary
Chapter 2: Process Management and Scheduling
2.1 Process Priorities
2.2 Process Life Cycle
2.3 Process Representation
2.4 Process Management System Calls
2.5 Implementation of the Scheduler
2.6 The Completely Fair Scheduling Class
2.7 The Real-Time Scheduling Class
2.8 Scheduler Enhancements
2.9 Summary
Chapter 3: Memory Management
3.1 Overview
3.2 Organization in the (N)UMA Model
3.3 Page Tables
3.4 Initialization of Memory Management
3.5 Management of Physical Memory
3.6 The Slab Allocator
3.7 Processor Cache and TLB Control
3.8 Summary
Chapter 4: Virtual Process Memory
4.1 Introduction
4.2 Virtual Process Address Space
4.3 Principle of Memory Mappings
4.4 Data Structures
4.5 Operations on Regions
4.6 Address Spaces
4.7 Memory Mappings
4.8 Reverse Mapping
4.9 Managing the Heap
4.10 Handling of Page Faults
4.11 Correction of Userspace Page Faults
4.12 Kernel Page Faults
4.13 Copying Data between Kernel and Userspace
4.14 Summary
Chapter 5: Locking and Interprocess Communication
5.1 Control Mechanisms
5.2 Kernel Locking Mechanisms
5.3 System V Interprocess Communication
5.4 Other IPC Mechanisms
5.5 Summary
Chapter 6: Device Drivers
6.1 I/O Architecture
6.2 Access to Devices
6.3 Association with the Filesystem
6.4 Character Device Operations
6.5 Block Device Operations
6.6 Resource Reservation
6.7 Bus Systems
6.8 Summary
Chapter 7: Modules
7.1 Overview
7.2 Using Modules
7.3 Inserting and Deleting Modules
7.4 Automation and Hotplugging
7.5 Version Control
7.6 Summary
Chapter 8: The Virtual Filesystem
8.1 Filesystem Types
8.2 The Common File Model
8.3 Structure of the VFS
8.4 Working with VFS Objects
8.5 Standard Functions
8.6 Summary
Chapter 9: The Extended Filesystem Family
9.1 Introduction
9.2 Second Extended Filesystem
9.3 Third Extended Filesystem
9.4 Summary
Chapter 10: Filesystems without Persistent Storage
10.1 The proc Filesystem
10.2 Simple Filesystems
10.3 Sysfs
10.4 Summary
Chapter 11: Extended Attributes and Access Control Lists
11.1 Extended Attributes
11.2 Access Control Lists
11.3 Summary
Chapter 12: Networks
12.1 Linked Computers
12.2 ISO/OSI and TCP/IP Reference Model
12.3 Communication via Sockets
12.4 The Layer Model of Network Implementation
12.5 Networking Namespaces
12.6 Socket Buffers
12.7 Network Access Layer
12.8 Network Layer
12.9 Transport Layer
12.10 Application Layer
12.11 Networking from within the Kernel
12.12 Summary
Chapter 13: System Calls
13.1 Basics of System Programming
13.2 Available System Calls
13.3 Implementation of System Calls
13.4 Summary
Chapter 14: Kernel Activities
14.1 Interrupts
14.2 Software Interrupts
14.3 Tasklets
14.4 Wait Queues and Completions
14.5 Summary
Chapter 15: Time Management
15.1 Overview
15.2 Implementation of Low-Resolution Timers
15.3 Generic Time Subsystem
15.4 High-Resolution Timers
15.5 Dynamic Ticks
15.6 Broadcast Mode
15.7 Implementing Timer-Related System Calls
15.8 Managing Process Times
15.9 Summary
Chapter 16: Page and Buffer Cache
16.1 Structure of the Page Cache
16.2 Structure of the Buffer Cache
16.3 Address Spaces
16.4 Implementation of the Page Cache
16.5 Implementation of the Buffer Cache
16.6 Summary
Chapter 17: Data Synchronization
17.1 Overview
17.2 The pdflush Mechanism
17.3 Starting a New Thread
17.4 Thread Initialization
17.5 Performing Actual Work
17.6 Periodic Flushing
17.7 Associated Data Structures
17.8 Central Control
17.9 Superblock Synchronization
17.10 Inode Synchronization
17.11 Congestion
17.12 Forced Writeback
17.13 Laptop Mode
17.14 System Calls for Synchronization Control
17.15 Full Synchronization
17.16 Summary
Chapter 18: Page Reclaim and Swapping
18.1 Overview
18.2 Page Reclaim and Swapping in the Linux Kernel
18.3 Managing Swap Areas
18.4 The Swap Cache
18.5 Writing Data Back
18.6 Page Reclaim
18.7 The Swap Token
18.8 Handling Swap-Page Faults
18.9 Initiating Memory Reclaim
18.10 Shrinking Other Caches
18.11 Summary
Chapter 19: Auditing
19.1 Overview
19.2 Audit Rules
19.3 Implementation
19.4 Summary
Appendix A: Architecture Specifics
A.1 Overview
A.2 Data Types
A.3 Alignment
A.4 Memory Pages
A.5 System Calls
A.6 String Processing
A.7 Thread Representation
A.8 Bit Operations and Endianness
A.9 Page Tables
A.10 Miscellaneous
A.11 Summary
Appendix B: Working with the Source Code
B.1 Organization of the Kernel Sources
B.2 Configuration with Kconfig
B.3 Compiling the Kernel with Kbuild
B.4 Useful Tools
B.5 Debugging and Analyzing the Kernel
B.6 User-Mode Linux
B.7 Summary
Appendix C: Notes on C
C.1 How the GNU C Compiler Works
C.2 Standard Data Structures and Techniques of the Kernel
C.3 Summary
Appendix D: System Startup
D.1 Architecture-Specific Setup on IA-32 Systems
D.2 High-Level Initialization
D.3 Summary
Appendix E: The ELF Binary Format
E.1 Layout and Structure
E.2 Data Structures in the Kernel
E.3 Summary
Appendix F: The Kernel Development Process
F.1 Introduction
F.2 Kernel Trees and the Structure of Development
F.3 The Structure of Patches
F.4 Linux and Academia
F.5 Summary
References
Index
Mauerer ffirs.tex V2 - 08/26/2008 3:23am Page iii Professional Linux® Kernel Architecture Wolfgang Mauerer Wiley Publishing, Inc.
Mauerer ffirs.tex V2 - 08/26/2008 3:23am Page iv Professional Linux® Kernel Architecture Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2008 by Wolfgang Mauerer Published by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-0-470-34343-2 Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 Library of Congress Cataloging-in-Publication Data: Mauerer, Wolfgang, 1978- Professional Linux kernel architecture / Wolfgang Mauerer. p. cm. Includes index. ISBN 978-0-470-34343-2 (pbk.) 1. Linux. 2. Computer architecture. 3. Application software. QA76.9.A73M38 2008 005.4’32--dc22 I. Title. 2008028067 No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4355, or online at http://www.wiley.com/go/permissions. Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Website is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Website may provide or recommendations it may make. Further, readers should be aware that Internet Websites listed in this work may have changed or disappeared between when this work was written and when it is read. For general information on our other products and services please contact our Customer Care Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.
Mauerer fauth.tex V2 - 08/22/2008 4:52am Page vi
Mauerer ftoc.tex V4 - 09/03/2008 11:13pm Page xi Contents Introduction xxvii Chapter 1: Introduction and Overview Tasks of the Kernel Implementation Strategies Elements of the Kernel Processes, Task Switching, and Scheduling Unix Processes Address Spaces and Privilege Levels Page Tables Allocation of Physical Memory Timing System Calls Device Drivers, Block and Character Devices Networks Filesystems Modules and Hotplugging Caching List Handling Object Management and Reference Counting Data Types . . . and Beyond the Infinite Why the Kernel Is Special Some Notes on Presentation Summary Chapter 2: Process Management and Scheduling Process Priorities Process Life Cycle Preemptive Multitasking Process Representation Process Types Namespaces 1 2 3 3 4 4 7 11 13 16 17 17 18 18 18 20 20 22 25 27 28 29 33 35 36 38 40 41 47 47
Contents Process Identification Numbers Task Relationships Process Management System Calls Process Duplication Kernel Threads Starting New Programs Exiting Processes Implementation of the Scheduler Overview Data Structures Dealing with Priorities Core Scheduler The Completely Fair Scheduling Class Data Structures CFS Operations Queue Manipulation Selecting the Next Task Handling the Periodic Tick Wake-up Preemption Handling New Tasks The Real-Time Scheduling Class Properties Data Structures Scheduler Operations Scheduler Enhancements SMP Scheduling Scheduling Domains and Control Groups Kernel Preemption and Low Latency Efforts Summary Chapter 3: Memory Management Overview Organization in the (N)UMA Model Overview Data Structures Page Tables Data Structures Creating and Manipulating Entries Initialization of Memory Management Data Structure Setup Architecture-Specific Setup Memory Management during the Boot Process xii Mauerer ftoc.tex V4 - 09/03/2008 11:13pm Page xii 54 62 63 63 77 79 83 83 84 86 93 99 106 106 107 112 113 114 115 116 117 118 118 119 121 121 126 127 132 133 133 136 136 138 153 154 161 161 162 169 191
Management of Physical Memory Structure of the Buddy System Avoiding Fragmentation Initializing the Zone and Node Data Structures Allocator API Reserving Pages Freeing Pages Allocation of Discontiguous Pages in the Kernel Kernel Mappings The Slab Allocator Alternative Allocators Memory Management in the Kernel The Principle of Slab Allocation Implementation General Caches Processor Cache and TLB Control Summary Chapter 4: Virtual Process Memory Introduction Virtual Process Address Space Layout of the Process Address Space Creating the Layout Principle of Memory Mappings Data Structures Trees and Lists Representation of Regions The Priority Search Tree Operations on Regions Associating Virtual Addresses with a Region Merging Regions Inserting Regions Creating Regions Address Spaces Memory Mappings Creating Mappings Removing Mappings Nonlinear Mappings Reverse Mapping Data Structures Creating a Reverse Mapping Using Reverse Mapping Mauerer ftoc.tex V4 - 09/03/2008 11:13pm Page xiii Contents 199 199 201 209 215 222 240 244 251 256 258 259 261 265 283 285 287 289 289 290 290 294 297 298 299 300 302 306 306 308 309 310 312 314 314 317 319 322 323 324 325 xiii
Mauerer ftoc.tex V4 - 09/03/2008 11:13pm Page xiv Contents Managing the Heap Handling of Page Faults Correction of Userspace Page Faults Demand Allocation/Paging Anonymous Pages Copy on Write Getting Nonlinear Mappings Kernel Page Faults Copying Data between Kernel and Userspace Summary Chapter 5: Locking and Interprocess Communication Control Mechanisms Race Conditions Critical Sections Kernel Locking Mechanisms Atomic Operations on Integers Spinlocks Semaphores The Read-Copy-Update Mechanism Memory and Optimization Barriers Reader/Writer Locks The Big Kernel Lock Mutexes Approximate Per-CPU Counters Lock Contention and Fine-Grained Locking System V Interprocess Communication System V Mechanisms Semaphores Message Queues Shared Memory Other IPC Mechanisms Signals Pipes and Sockets Summary Chapter 6: Device Drivers I/O Architecture Expansion Hardware Access to Devices Device Files Character, Block, and Other Devices xiv 327 330 336 337 339 340 341 341 344 345 347 348 348 349 351 352 354 355 357 359 361 361 362 364 365 366 366 367 376 380 381 381 389 390 391 391 392 397 397 397
分享到:
收藏