Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Mastering Linux Kernel Development
Mastering Linux Kernel Development

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

Arrow left icon
Profile Icon CH Raghav Maruthi
Arrow right icon
$19.99 per month
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.9 (10 Ratings)
Paperback Oct 2017 354 pages 1st Edition
eBook
$29.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon CH Raghav Maruthi
Arrow right icon
$19.99 per month
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.9 (10 Ratings)
Paperback Oct 2017 354 pages 1st Edition
eBook
$29.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$29.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781785883057
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Oct 11, 2017
Length: 354 pages
Edition : 1st
Language : English
ISBN-13 : 9781785883057
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

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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.