Linux Kernel Versions the Linux Kernel Development Community Before We Begin Chapter 2
Total Page:16
File Type:pdf, Size:1020Kb
Table of Contents Linux Kernel Development Second Edition By Robert Love Publisher: Sams Publishing Pub Date: January 12, 2005 ISBN: 0-672-32720-1 Table of Pages: 432 • Contents • Index Copyright Foreword Preface So Here We Are Kernel Version Audience Book Website Second Edition Acknowledgments About the Author We Want to Hear from You! Reader Services Chapter 1. Introduction to the Linux Kernel Along Came Linus: Introduction to Linux Overview of Operating Systems and Kernels Linux Versus Classic Unix Kernels Linux Kernel Versions The Linux Kernel Development Community Before We Begin Chapter 2. Getting Started with the Kernel Obtaining the Kernel Source The Kernel Source Tree Building the Kernel A Beast of a Different Nature So Here We Are file:///D|/LKD/0672327201/toc.html (1 of 7)2005-5-26 9:47:02 Table of Contents Chapter 3. Process Management Process Descriptor and the Task Structure Process Creation The Linux Implementation of Threads Process Termination Process Wrap Up Chapter 4. Process Scheduling Policy The Linux Scheduling Algorithm Preemption and Context Switching Real-Time Scheduler-Related System Calls Scheduler Finale Chapter 5. System Calls APIs, POSIX, and the C Library Syscalls System Call Handler System Call Implementation System Call Context System Calls in Conclusion Chapter 6. Interrupts and Interrupt Handlers Interrupts Interrupt Handlers Registering an Interrupt Handler Writing an Interrupt Handler Interrupt Context Implementation of Interrupt Handling Interrupt Control Don't Interrupt Me; We're Almost Done! Chapter 7. Bottom Halves and Deferring Work Bottom Halves Softirqs Tasklets Work Queues Which Bottom Half Should I Use? Locking Between the Bottom Halves file:///D|/LKD/0672327201/toc.html (2 of 7)2005-5-26 9:47:02 Table of Contents The Bottom of Bottom-Half Processing Endnotes Chapter 8. Kernel Synchronization Introduction Critical Regions and Race Conditions Locking Deadlocks Contention and Scalability Locking and Your Code Chapter 9. Kernel Synchronization Methods Atomic Operations Spin Locks Reader-Writer Spin Locks Semaphores Reader-Writer Semaphores Spin Locks Versus Semaphores Completion Variables BKL: The Big Kernel Lock Preemption Disabling Ordering and Barriers Synchronization Summarization Chapter 10. Timers and Time Management Kernel Notion of Time The Tick Rate: HZ Jiffies Hardware Clocks and Timers The Timer Interrupt Handler The Time of Day Timers Delaying Execution Out of Time Chapter 11. Memory Management Pages Zones Getting Pages kmalloc() vmalloc() file:///D|/LKD/0672327201/toc.html (3 of 7)2005-5-26 9:47:02 Table of Contents Slab Layer Slab Allocator Interface Statically Allocating on the Stack High Memory Mappings Per-CPU Allocations The New percpu Interface Reasons for Using Per-CPU Data Which Allocation Method Should I Use? Chapter 12. The Virtual Filesystem Common Filesystem Interface Filesystem Abstraction Layer Unix Filesystems VFS Objects and Their Data Structures The Superblock Object The Inode Object The Dentry Object The File Object Data Structures Associated with Filesystems Data Structures Associated with a Process Filesystems in Linux Chapter 13. The Block I/O Layer Anatomy of a Block Device Buffers and Buffer Heads The bio structure Request Queues I/O Schedulers Summary Chapter 14. The Process Address Space The Memory Descriptor Memory Areas Manipulating Memory Areas mmap() and do_mmap(): Creating an Address Interval munmap() and do_munmap(): Removing an Address Interval Page Tables Conclusion Chapter 15. The Page Cache and Page Writeback file:///D|/LKD/0672327201/toc.html (4 of 7)2005-5-26 9:47:02 Table of Contents Page Cache Radix Tree The Buffer Cache The pdflush Daemon To Make a Long Story Short Chapter 16. Modules Hello, World! Building Modules Installing Modules Generating Module Dependencies Loading Modules Managing Configuration Options Module Parameters Exported Symbols Wrapping Up Modules Chapter 17. kobjects and sysfs kobjects ktypes ksets Subsystems Structure Confusion Managing and Manipulating kobjects Reference Counts sysfs The Kernel Events Layer kobjects and sysfs in a Nutshell Chapter 18. Debugging What You Need to Start Bugs in the Kernel printk() Oops Kernel Debugging Options Asserting Bugs and Dumping Information Magic SysRq Key The Saga of a Kernel Debugger Poking and Probing the System file:///D|/LKD/0672327201/toc.html (5 of 7)2005-5-26 9:47:02 Table of Contents Binary Searching to Find the Culprit Change When All Else Fails: The Community Chapter 19. Portability History of Portability in Linux Word Size and Data Types Data Alignment Byte Order Time Page Size Processor Ordering SMP, Kernel Preemption, and High Memory Endnotes Chapter 20. Patches, Hacking, and the Community The Community Linux Coding Style Chain of Command Submitting Bug Reports Generating Patches Submitting Patches Conclusion Appendix A. Linked Lists Circular Linked Lists The Linux Kernel's Implementation Manipulating Linked Lists Traversing Linked Lists Appendix B. Kernel Random Number Generator Design and Implementation Interfaces to Input Entropy Interfaces to Output Entropy Appendix C. Algorithmic Complexity Algorithms Big-O Notation Big Theta Notation Putting It All Together Perils of Time Complexity Bibliography and Reading List file:///D|/LKD/0672327201/toc.html (6 of 7)2005-5-26 9:47:02 Table of Contents Books on Operating System Design Books on Unix Kernels Books on Linux Kernels Books on Other Kernels Books on the Unix API Books on the C Programming Language Other Works Websites Index file:///D|/LKD/0672327201/toc.html (7 of 7)2005-5-26 9:47:02 Copyright Copyright Copyright © 2005 by Pearson Education, Inc. All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Nor is any liability assumed for damages resulting from the use of the information contained herein. Library of Congress Catalog Card Number: 2004095004 Printed in the United States of America First Printing: January 2005 08 07 06 05 4 3 2 1 Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Novell Press cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark. Warning and Disclaimer Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on an "as is" basis. The author and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book. Special and Bulk Sales Pearson offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales. For more information, please contact U.S. Corporate and Government Sales 1-800-382-3419 [email protected] For sales outside of the U.S., please contact International Sales file:///D|/LKD/0672327201/copyrightpg.html (1 of 3)2005-5-26 9:47:24 Copyright [email protected] Credits Senior Editor Scott D. Meyers Managing Editor Charlotte Clapp Project Editor George Nedeff Copy Editor Margo Catts Indexer Chris Barrick Proofreader Tracy Donhardt Technical Editors Adam Belay Martin Pool Chris Rivera Publishing Coordinator Vanessa Evans Book Designer Gary Adair Page Layout file:///D|/LKD/0672327201/copyrightpg.html (2 of 3)2005-5-26 9:47:24 Copyright Michelle Mitchell Dedication To Doris and Helen. file:///D|/LKD/0672327201/copyrightpg.html (3 of 3)2005-5-26 9:47:24 Foreword Foreword As the Linux kernel and the applications that use it become more widely used, we are seeing an increasing number of system software developers who wish to become involved in the development and maintenance of Linux. Some of these engineers are motivated purely by personal interest, some work for Linux companies, some work for hardware manufacturers, and some are involved with in-house development projects. But all face a common problem: The learning curve for the kernel is getting longer and steeper. The system is becoming increasingly complex, and it is very large. And as the years pass, the current members of the kernel development team gain deeper and broader knowledge of the kernel's internals, which widens the gap between them and newcomers. I believe that this declining accessibility of the Linux source base is already a problem for the quality of the kernel, and it will become more serious over time. Those who care for Linux clearly have an interest in increasing the number of developers who can contribute to the kernel. One approach to this problem is to keep the code clean: sensible interfaces, consistent layout, "do one thing, do it well," and so on. This is Linus Torvalds' solution. The approach that I counsel is to liberally apply commentary to the code: words that the reader can use to understand what the coder intended to achieve at the time. (The process of identifying divergences between the intent and the implementation is known as debugging. It is hard to do this if the intent is not known.) But even code commentary does not provide the broad-sweep view of what a major subsystem is intended to do, and how its developers set about doing it. This, the starting point of understanding, is what the written word serves best. Robert Love's contribution provides a means by which experienced developers can gain that essential view of what services the kernel subsystems are supposed to provide, and how they set about providing them. This will be sufficient knowledge for many people: the curious, the application developers, those who wish to evaluate the kernel's design, and others.