ebook img

Understanding the Linux Kernel, 3rd Edition: From I/O Ports to Process Management PDF

944 Pages·2005·6.233 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Understanding the Linux Kernel, 3rd Edition: From I/O Ports to Process Management

www.it-ebooks.info www.it-ebooks.info Understanding the LINUX KERNEL www.it-ebooks.info Other Linux resources from O’Reilly Related titles Building Embedded Linux Linux Security Cookbook™ Systems Linux Server Hacks™ Linux Device Drivers Linux Server Security Linux in a Nutshell Running Linux Linux Network SELinux Administrator’s Guide Understanding Linux Linux Pocket Guide Network Internals Linux Books linux.oreilly.com is a complete catalog of O’Reilly’s books on Resource Center Linux and Unix and related technologies, including sample chapters and code examples. ONLamp.com isthe premiersiteforthe opensource web plat- form: Linux, Apache, MySQL, and either Perl, Python, or PHP. Conferences O’Reillybringsdiverseinnovatorstogethertonurturetheideas thatsparkrevolutionaryindustries.Wespecializeindocument- ing the latest tools and systems, translating the innovator’s knowledgeintousefulskillsforthoseinthetrenches.Visitcon- ferences.oreilly.com for our upcoming events. Safari Bookshelf (safari.oreilly.com) is the premier online refer- ence library for programmers and IT professionals. Conduct searchesacrossmorethan1,000books.Subscriberscanzeroin on answers to time-critical questions in a matter of seconds. Read the books on your Bookshelf from cover to cover or sim- ply flip to the page you need. Try it today for free. www.it-ebooks.info Understanding the LINUX KERNEL THIRD EDITION Daniel P. Bovet and Marco Cesati Beijing • Cambridge • Farnham • Köln • Paris • Sebastopol • Taipei • Tokyo www.it-ebooks.info Understanding the Linux Kernel, Third Edition by Daniel P. Bovet and Marco Cesati Copyright © 2006 O’Reilly Media, Inc. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions arealsoavailableformosttitles(safari.oreilly.com).Formoreinformation,contactourcorporate/insti- tutional sales department: (800) 998-9938 [email protected]. Editor: Andy Oram Production Editor: Darren Kelly Production Services: Amy Parker Cover Designer: Edie Freedman Interior Designer: David Futato Printing History: November 2000: First Edition. December 2002: Second Edition. November 2005: Third Edition. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’ReillyMedia,Inc.TheLinuxseriesdesignations,UnderstandingtheLinuxKernel,ThirdEdition,the image of a man with a bubble, and related trade dress are trademarks of O’Reilly Media, Inc. Manyofthedesignationsusedbymanufacturersandsellerstodistinguishtheirproductsareclaimedas trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. ISBN-10: 0-596-00565-2 ISBN-13: 978-0-596-00565-8 [M] [9/07] www.it-ebooks.info Table of Contents Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Linux Versus Other Unix-Like Kernels 2 Hardware Dependency 6 Linux Versions 7 Basic Operating System Concepts 8 An Overview of the Unix Filesystem 12 An Overview of Unix Kernels 19 2. Memory Addressing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Memory Addresses 35 Segmentation in Hardware 36 Segmentation in Linux 41 Paging in Hardware 45 Paging in Linux 57 3. Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 Processes, Lightweight Processes, andThreads 79 Process Descriptor 81 Process Switch 102 Creating Processes 114 Destroying Processes 126 4. Interrupts and Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 The Role of Interrupt Signals 132 Interrupts and Exceptions 133 v www.it-ebooks.info Nested Execution of Exception and Interrupt Handlers 143 Initializing the Interrupt Descriptor Table 145 Exception Handling 148 Interrupt Handling 151 Softirqs and Tasklets 171 Work Queues 180 Returning from Interrupts and Exceptions 183 5. Kernel Synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 How the Kernel Services Requests 189 Synchronization Primitives 194 Synchronizing Accesses to Kernel Data Structures 217 Examples of Race Condition Prevention 222 6. Timing Measurements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 Clock and Timer Circuits 228 The Linux Timekeeping Architecture 232 Updating the Time and Date 240 Updating System Statistics 241 Software Timers and Delay Functions 244 System Calls Related to Timing Measurements 252 7. Process Scheduling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258 Scheduling Policy 258 The Scheduling Algorithm 262 Data Structures Used by the Scheduler 266 Functions Used by the Scheduler 270 Runqueue Balancing in Multiprocessor Systems 284 System Calls Related to Scheduling 290 8. Memory Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294 Page Frame Management 294 Memory Area Management 323 Noncontiguous Memory Area Management 342 9. Process Address Space. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351 The Process’s Address Space 352 The Memory Descriptor 353 Memory Regions 357 vi | Table of Contents www.it-ebooks.info Page Fault Exception Handler 376 Creating and Deleting a Process Address Space 392 Managing the Heap 395 10. System Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398 POSIX APIs and System Calls 398 System Call Handler and Service Routines 399 Entering and Exiting a System Call 401 Parameter Passing 409 Kernel Wrapper Routines 418 11. Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420 The Role of Signals 420 Generating a Signal 433 Delivering a Signal 439 System Calls Related to Signal Handling 450 12. The Virtual Filesystem. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456 The Role of the Virtual Filesystem (VFS) 456 VFS Data Structures 462 Filesystem Types 481 Filesystem Handling 483 Pathname Lookup 495 Implementations of VFS System Calls 505 File Locking 510 13. I/O Architecture and Device Drivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519 I/O Architecture 519 The Device Driver Model 526 Device Files 536 Device Drivers 540 Character Device Drivers 552 14. Block Device Drivers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 560 Block Devices Handling 560 The Generic Block Layer 566 The I/O Scheduler 572 Block Device Drivers 585 Opening a Block Device File 595 Table of Contents | vii www.it-ebooks.info 15. The Page Cache. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599 The Page Cache 600 Storing Blocks in the Page Cache 611 Writing Dirty Pages to Disk 622 The sync(), fsync(), and fdatasync() System Calls 629 16. Accessing Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631 Reading and Writing a File 632 Memory Mapping 657 Direct I/O Transfers 668 Asynchronous I/O 671 17. Page Frame Reclaiming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 676 The Page Frame Reclaiming Algorithm 676 Reverse Mapping 680 Implementing the PFRA 689 Swapping 712 18. The Ext2 and Ext3 Filesystems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 738 General Characteristics of Ext2 738 Ext2 Disk Data Structures 741 Ext2 Memory Data Structures 750 Creating the Ext2 Filesystem 753 Ext2 Methods 755 Managing Ext2 Disk Space 757 The Ext3 Filesystem 766 19. Process Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 775 Pipes 776 FIFOs 787 System V IPC 789 POSIX Message Queues 806 20. Program Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 808 Executable Files 809 Executable Formats 824 Execution Domains 827 The exec Functions 828 viii | Table of Contents www.it-ebooks.info

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.