Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
Mastering Linux Kernel Development
Mastering Linux Kernel Development

Mastering Linux Kernel Development: A kernel developer's reference manual

eBook
$9.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Mastering Linux Kernel Development

Deciphering the Process Scheduler

Process scheduling is one of the most crucial executive jobs of any operating system, Linux being no different. The heuristics and efficiency in scheduling processes is what make any operating system tick and also give it an identity, such as a general-purpose operating system, server, or a real-time system. In this chapter, we will get under the skin of the Linux scheduler, deciphering concepts such as:

  • Linux scheduler design
  • Scheduling classes
  • Scheduling policies and priorities
  • Completely Fair Scheduler
  • Real-Time Scheduler
  • Deadline Scheduler
  • Group scheduling
  • Preemption

Process schedulers

The effectiveness of any operating system is proportional to its ability to fairly schedule all contending processes. The process scheduler is the core component of the kernel, which computes and decides when and for how long a process gets CPU time. Ideally, processes require a timeslice of the CPU to run, so schedulers essentially need to allocate slices of processor time fairly among processes.

A scheduler typically has to:

  • Avoid process starvation
  • Manage priority scheduling
  • Maximize throughput of all processes
  • Ensure low turnaround time
  • Ensure even resource usage
  • Avoid CPU hogging
  • Consider process' behavioral patterns for prioritization
  • Elegantly subsidize under heavy load
  • Handle scheduling on multiple cores efficiently

Linux process scheduler design

Linux, which was primarily developed for desktop systems, has unassumingly evolved into a multi-dimensional operating system with its usage spread across embedded devices, mainframes, and supercomputers to room-sized servers. It has also seamlessly accommodated the ever-evolving diverse computing platforms such as SMP, virtualization, and real-time systems. The diversity of these platforms is brought forth by the kind of processes that run on these systems. For instance, a highly interactive desktop system may run processes that are I/O bound, and a real-time system thrives on deterministic processes. Every kind of process thus calls for a different kind of heuristic when it needs to be fairly scheduled, as a CPU-intensive process may require more CPU time than a normal process, and a real-time process would require deterministic execution. Linux...

Runqueue

Conventionally, the runqueue contains all the processes that are contending for CPU time on a given CPU core (a runqueue is per-CPU). The generic scheduler is designed to look into the runqueue whenever it is invoked to schedule the next best runnable task. Maintaining a common runqueue for all the runnable processes would not be a possible since each scheduling class deals with specific scheduling policies and priorities.

The kernel addresses this by bringing its design principles to the fore. Each scheduling class defined the layout of its runqueue data structure as best suitable for its policies. The generic scheduler layer implements an abstract runqueue structure with common elements that serves as the runqueue interface. This structure is extended with pointers that refer to class-specific runqueues. In other words, all scheduling classes embed their runqueues into...

The scheduler's entry point

The process of scheduling starts with a call to the generic scheduler, that is, the schedule() function, defined in <kernel/sched/core.c>. This is perhaps one of the most invoked routines in the kernel. The functionality of schedule() is to pick the next best runnable task. The pick_next_task() of the schedule() function iterates through all the corresponding functions contained in the scheduler classes and ends up picking the next best task to run. Each scheduler class is linked using a single linked list, which enables the pick_next_task() to iterate through these classes.

Considering that Linux was primarily designed to cater to highly interactive systems, the function first looks for the next best runnable task in the CFS class if there are no higher-priority runnable tasks in any of the other classes (this is done by checking whether...

Process priorities

The decision of which process to run depends on the priority of the process. Every process is labelled with a priority value, giving it an immediate position in terms of when it will be given CPU time. Priorities are fundamentally classified into dynamic and static priorities on *nix systems. Dynamic priorities are basically applied to normal processes dynamically by the kernel, considering various factors such as the nice value of the process, its historic behavior (I/O bound or processor bound), lapsed execution, and waiting time. Static priorities are applied to real-time processes by the user and the kernel does not change their priorities dynamically. Processes with static priorities are thus given higher priority when scheduling.

I/O bound process: When the execution of a process is heavily punctuated with I/O operations (waiting for a resource or an event...

Process schedulers


The effectiveness of any operating system is proportional to its ability to fairly schedule all contending processes. The process scheduler is the core component of the kernel, which computes and decides when and for how long a process gets CPU time. Ideally, processes require a timeslice of the CPU to run, so schedulers essentially need to allocate slices of processor time fairly among processes.

A scheduler typically has to:

  • Avoid process starvation
  • Manage priority scheduling
  • Maximize throughput of all processes
  • Ensure low turnaround time
  • Ensure even resource usage
  • Avoid CPU hogging
  • Consider process' behavioral patterns for prioritization
  • Elegantly subsidize under heavy load
  • Handle scheduling on multiple cores efficiently

Linux process scheduler design


Linux, which was primarily developed for desktop systems, has unassumingly evolved into a multi-dimensional operating system with its usage spread across embedded devices, mainframes, and supercomputers to room-sized servers. It has also seamlessly accommodated the ever-evolving diverse computing platforms such as SMP, virtualization, and real-time systems. The diversity of these platforms is brought forth by the kind of processes that run on these systems. For instance, a highly interactive desktop system may run processes that are I/O bound, and a real-time system thrives on deterministic processes. Every kind of process thus calls for a different kind of heuristic when it needs to be fairly scheduled, as a CPU-intensive process may require more CPU time than a normal process, and a real-time process would require deterministic execution. Linux, which caters to a wide spectrum of systems, is thus confronted with addressing the varying scheduling challenges...

Runqueue


Conventionally, the runqueue contains all the processes that are contending for CPU time on a given CPU core (a runqueue is per-CPU). The generic scheduler is designed to look into the runqueue whenever it is invoked to schedule the next best runnable task. Maintaining a common runqueue for all the runnable processes would not be a possible since each scheduling class deals with specific scheduling policies and priorities.

The kernel addresses this by bringing its design principles to the fore. Each scheduling class defined the layout of its runqueue data structure as best suitable for its policies. The generic scheduler layer implements an abstract runqueue structure with common elements that serves as the runqueue interface. This structure is extended with pointers that refer to class-specific runqueues. In other words, all scheduling classes embed their runqueues into the main runqueue structure. This is a classic design hack, which lets every scheduler class choose an appropriate...

The scheduler's entry point


The process of scheduling starts with a call to the generic scheduler, that is, the schedule() function, defined in <kernel/sched/core.c>. This is perhaps one of the most invoked routines in the kernel. The functionality of schedule() is to pick the next best runnable task. The pick_next_task() of the schedule() function iterates through all the corresponding functions contained in the scheduler classes and ends up picking the next best task to run. Each scheduler class is linked using a single linked list, which enables the pick_next_task() to iterate through these classes.

Considering that Linux was primarily designed to cater to highly interactive systems, the function first looks for the next best runnable task in the CFS class if there are no higher-priority runnable tasks in any of the other classes (this is done by checking whether the total number of runnable tasks (nr_running) in the runqueue is equal to the total number of runnable tasks in the...

Process priorities


The decision of which process to run depends on the priority of the process. Every process is labelled with a priority value, giving it an immediate position in terms of when it will be given CPU time. Priorities are fundamentally classified into dynamic and static priorities on *nix systems. Dynamic priorities are basically applied to normal processes dynamically by the kernel, considering various factors such as the nice value of the process, its historic behavior (I/O bound or processor bound), lapsed execution, and waiting time. Static priorities are applied to real-time processes by the user and the kernel does not change their priorities dynamically. Processes with static priorities are thus given higher priority when scheduling.

Note

I/O bound process: When the execution of a process is heavily punctuated with I/O operations (waiting for a resource or an event), for instance a text editor, which almost alternates between running and waiting for a key press, such processes...

Scheduler classes


Let's now go deeper into each scheduling class and understand the operations, policies, and heuristics it engages in managing scheduling operations adeptly and elegantly for its processes. As mentioned earlier, an instance of struct sched_class must be provided by each scheduling class; let's look at some of the key elements from that structure:

  • enqueue_task: Basically adds a new process to the run queue
  • dequeue_task: When the process is taken off the runqueue
  • yield_task: When the process wants to relinquish CPU voluntarily
  • pick_next_task: The corresponding function of the pick_next_task called by schedule(). It picks up the next best runnable task from its class.
Left arrow icon Right arrow icon

Key benefits

  • ? Master the design, components, and structures of core kernel subsystems
  • ? Explore kernel programming interfaces and related algorithms under the hood
  • ? Completely updated material for the 4.12.10 kernel

Description

Mastering Linux Kernel Development looks at the Linux kernel, its internal arrangement and design, and various core subsystems, helping you to gain significant understanding of this open source marvel. You will look at how the Linux kernel, which possesses a kind of collective intelligence thanks to its scores of contributors, remains so elegant owing to its great design. This book also looks at all the key kernel code, core data structures, functions, and macros, giving you a comprehensive foundation of the implementation details of the kernel’s core services and mechanisms. You will also look at the Linux kernel as well-designed software, which gives us insights into software design in general that are easily scalable yet fundamentally strong and safe. By the end of this book, you will have considerable understanding of and appreciation for the Linux kernel.

Who is this book for?

If you are a kernel programmer with a knowledge of kernel APIs and are looking to build a comprehensive understanding, and eager to explore the implementation, of kernel subsystems, this book is for you. It sets out to unravel the underlying details of kernel APIs and data structures, piercing through the complex kernel layers and gives you the edge you need to take your skills to the next level.

What you will learn

  • • Comprehend processes and files—the core abstraction mechanisms of the Linux kernel that promote effective simplification and dynamism
  • • Decipher process scheduling and understand effective capacity utilization under general and real-time dispositions
  • • Simplify and learn more about process communication techniques through signals and IPC mechanisms
  • • Capture the rudiments of memory by grasping the key concepts and principles of physical and virtual memory management
  • • Take a sharp and precise look at all the key aspects of interrupt management and the clock subsystem
  • • Understand concurrent execution on SMP platforms through kernel synchronization and locking techniques

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 11, 2017
Length: 354 pages
Edition : 1st
Language : English
ISBN-13 : 9781785886133
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Oct 11, 2017
Length: 354 pages
Edition : 1st
Language : English
ISBN-13 : 9781785886133
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 158.97
Mastering Linux Kernel Development
$54.99
Linux Device Drivers Development
$48.99
Mastering Embedded Linux Programming
$54.99
Total $ 158.97 Stars icon
Banner background image

Table of Contents

11 Chapters
Comprehending Processes, Address Space, and Threads Chevron down icon Chevron up icon
Deciphering the Process Scheduler Chevron down icon Chevron up icon
Signal Management Chevron down icon Chevron up icon
Memory Management and Allocators Chevron down icon Chevron up icon
Filesystems and File I/O Chevron down icon Chevron up icon
Interprocess Communication Chevron down icon Chevron up icon
Virtual Memory Management Chevron down icon Chevron up icon
Kernel Synchronization and Locking Chevron down icon Chevron up icon
Interrupts and Deferred Work Chevron down icon Chevron up icon
Clock and Time Management Chevron down icon Chevron up icon
Module Management Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.9
(10 Ratings)
5 star 30%
4 star 10%
3 star 20%
2 star 0%
1 star 40%
Filter icon Filter
Top Reviews

Filter reviews by




Sachin Ahirkar Nov 13, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The best thing about this book is the language used. Any person having some prior knowledge of Linux can use this book for exploring kernel in a deep way. Well explained topics with their structural information and by using diagrams so that it makes easy to get a picture of everything. Big thanks to the author.
Amazon Verified review Amazon
Sarfaraz Nov 29, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
If you understand a topic then you will be able to explain it to others in a simplest way, this is true for the book”Mastering Linux Kernel Development”. The most important thing is that this book covers kernel 4.12, so this is one of the books that cover latest version of the kernel. Similarly topics like synchronization, IPC, DFC, memory management are covered properly in this book and explained with examples. This book does not cover the concept of LDD, and can be understood from the fact that it is kernel book and not a device driver book. And concept presented in this book will help in designing the LDD more effectively. All together I am satisfied with this book and recommend other to buy one.This is one of the excellent book on linux kernel.
Amazon Verified review Amazon
Stergios Papadimitriou Aug 30, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Although I have excellent books for the Linux kernel, as the "Linux kernel Development" of Robert Love,"Understanding the Linux kernel" of Daniel P. Bovet and Marco Cesati,these refer to rather old Linux kernel versions.The present book covers the new Linux kernel version, and recent improvements as e.g. the Completely Fair Schedulerare described very well.The book succeeds in covering essential material for the Linux kernel, avoiding to drift away in not so important details,the level of presentation detail is about similar to the rather classic "Linux Kernel Development" book of Robert Love.Although the style and quality of presentation is very good, there are a few grammatical and syntactical errors.However, the technical English text of the book is already very readable, and all the explanations and descriptions that the author supplies are quite understandable.Personally, although I have long experience with the Linux kernel,I gained new insights and knowledge for the Linux kernel from the book,and I continue to improve my expertise by studying it.Therefore, I think the book will be very useful and instructive and for other readers,this is way I rated it finally with 5 stars!
Amazon Verified review Amazon
Amazon Customer Feb 12, 2018
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
The book gives a nice insight of the linux kernel. The main edge of this book is that it covers 4.1 kernel which is almost the latest version
Amazon Verified review Amazon
Izzy Apr 16, 2018
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
Kindle formatting is very poor. I hope printed version is better. Returned for a refund.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.