Kahibaro
Discord Login Register

7.5 Linux Internals

Overview: Why Study Linux Internals?

Linux internals are the mechanisms beneath the familiar commands and configuration files: how the kernel represents processes, memory, files, and resources; how it isolates workloads; how it enforces limits and performs scheduling.

This chapter gives you a conceptual map of the major internal subsystems you’ll explore in the following Linux Internals chapters:

You’ll see how these pieces fit together at a high level, with enough detail to recognize what belongs to which subsystem and how to investigate behavior on a running system. Deep dives into each topic are in the dedicated child chapters.

User space vs Kernel space

Linux is structurally split into two privilege domains:

Transitions between user space and kernel space are tightly controlled:

  1. A user-space program invokes a system call (e.g. read, write, fork, execve, clone).
  2. The CPU switches from user mode to kernel mode.
  3. The kernel performs the requested operation, enforcing permissions and limits.
  4. Control returns to user space, usually with a return value in a CPU register.

Being able to think in terms of user vs kernel space is essential when debugging performance or strange behavior: is the issue in your application code, in how it calls the kernel, or in how the kernel handles the request?

System Calls and the API Surface

From user space, Linux is mainly experienced through:

Typical relationships:

You can inspect which syscalls a program uses:

  strace -f -o trace.log ./your_program

In later internals chapters, you’ll see that almost every key concept (process creation, memory mapping, IPC, namespaces, cgroups) is expressed via specific syscalls.

Core Kernel Abstractions

Linux provides a relatively small set of powerful abstractions:

Understanding these abstractions helps you reason about behavior across many tools and subsystems.

Tasks: Processes and Threads

Internally, Linux represents everything that executes as a task (often referred to as a task_struct in kernel code).

From a user-space perspective:

Linux exposes tasks via:

In the Process lifecycle chapter you’ll see how these tasks are created, scheduled, and destroyed, and how they move through states like running, sleeping, and zombie.

Address Spaces and Virtual Memory

Each process sees its own virtual address space:

Conceptually:

The Memory management chapter explores:

File Descriptors and the Unified I/O Model

Linux uses a unified model for I/O: “everything is a file” is not literally true, but everything looks like a file descriptor:

In user space, these show up as integers: 0, 1, 2 (stdin, stdout, stderr), and higher numbers for additional descriptors.

Key internals points:

This abstraction is central when later chapters talk about signals and IPC (pipes, sockets, eventfd) and performance.

Virtual Filesystems: `/proc` and `/sys` as Views Into the Kernel

Two special pseudo-filesystems expose internal kernel state:

These are not stored on disk. Instead:

Internals-wise, virtual filesystems allow the kernel to expose state and controls uniformly as files and directories, making it easy for tooling and scripting.

Scheduling, Latency, and Preemption

Linux uses preemptive multitasking:

Important notions for internals:

The scheduler interacts with almost every internal subsystem:

Tools often used when exploring these internals include schedstat, perf sched, and tracing frameworks like ftrace or bpftrace.

Resource Limits, Capabilities, and Security Hooks

Linux enforces safety and isolation via:

While the detailed configuration is covered elsewhere in the course, from an internals perspective:

Understanding that these checks are centralized in the kernel helps explain why many operations “fail” with EPERM or EACCES even when they look legal from an application’s perspective.

Namespaces: Multiple Views of the Same Kernel

Namespaces let the kernel provide isolated views of global resources to different sets of tasks:

Key internal idea:

Namespaces are crucial for containers. The Namespaces chapter will cover:

cgroups: Controlling and Accounting Resources

Control groups (cgroups) are how Linux:

They are arranged hierarchically:

From an internals perspective:

The cgroups chapter will explain:

Signals and IPC in the Kernel

Linux supports several inter-process communication (IPC) mechanisms:

At the internals level:

The Signals and IPC chapter will explain:

Observability: Looking Inside Without Crashing the System

Linux offers rich observability mechanisms to inspect internals without modifying kernel code:

From an internals perspective, these mechanisms use:

Being comfortable with these tools is essential when you start exploring process lifecycle, memory behavior, and resource isolation in depth.

How the Internals Topics Connect

The remaining chapters in this Linux Internals section zoom in on specific subsystems:

Together, these topics form a coherent picture:

As you go through the child chapters, try to always tie the details back to these core abstractions: tasks, address spaces, file descriptors, namespaces, and cgroups, all under the control of a single running kernel.

Views: 80

Comments

Please login to add a comment.

Don't have an account? Register now!