Linux Kernel Architecture Explained: User Space, System Calls and a Worked write() Example

Build a clear map of Linux user space and kernel space, then follow one three-byte write() request through x86-64 registers, VFS, and the return path.

KnowledgeGate Team

Exam prep & CS education

Updated 30 Nov 20266 min read
Linux Kernel Architecture Explained: User Space, System Calls and a Worked write() Example

Linux kernel diagrams often look like neat stacks, but a real request crosses a protection boundary and may involve several cooperating subsystems. That gap between the picture and the execution path causes many wrong answers. Trace write(1, buf, 3) to identify what changes at the user-kernel boundary instead of memorising boxes. The register-level example is for x86-64 Linux. Other Linux architectures use different syscall numbers, registers, and entry instructions.

Linux kernel architecture in one map

The kernel is the privileged core of the operating system. It manages CPU time, memory, devices, and protected access to shared resources. Ordinary applications and most libraries run in user space. Core kernel code and device drivers execute in kernel space with privileges that normal application code does not have.

Linux is commonly described as monolithic but modular. Its major services share kernel address space and can call one another directly. Loadable kernel modules can add features such as drivers at runtime, but module support does not turn Linux into a microkernel.

Keep this request path in mind: application or library call -> architecture-specific system-call entry -> syscall dispatch -> kernel subsystem -> device or other resource -> return to user space. The broader Operating Systems for GATE map places this path alongside processes, scheduling, memory, and filesystems.

Diagram tracing PID 4242 from write() in user space through x86-64 syscall registers, kernel dispatch, VFS, and return value RAX=3.

Kernel subsystems and what each one owns

The architecture becomes easier when each subsystem has a clear responsibility:

  • The syscall interface accepts controlled requests from user space.

  • The scheduler chooses which runnable task gets a CPU.

  • The virtual-memory manager maps virtual pages and enforces protection.

  • VFS gives filesystems and file-like objects a common interface.

  • Networking implements socket and protocol paths.

  • IPC mechanisms coordinate processes.

  • Security hooks check access policy.

  • Device drivers translate generic operations into device-specific work.

These responsibilities cooperate. Opening or writing a file crosses the syscall interface and usually reaches VFS. Choosing another runnable task belongs to the scheduler. If a file operation blocks, the current task can become non-runnable, allowing the scheduler to select another task.

This is therefore a responsibility map, not a rule that every request visits every box. A network packet, page fault, and file write take different paths. Use the GATE category to connect this model with the wider subject and course catalogue.

User mode, kernel mode, and the system-call boundary

Mode is not the same as process identity. When the thread in PID 4242 enters privileged kernel code for a syscall, it remains a thread of PID 4242. A syscall does not necessarily create a process, change the PID, or cause the scheduler to switch tasks.

For a synchronous syscall, user code prepares a syscall number and arguments, then executes its architecture's entry instruction. The CPU transfers control to a configured kernel entry point. Entry code preserves enough user state, dispatches the requested operation, and later restores user execution. The official Linux kernel guide describes syscalls as user-space interaction points and shows that x86 uses architecture-specific syscall tables in Adding a New System Call.

A syscall is deliberate: the running thread requests kernel service. A device interrupt can arrive asynchronously, unrelated to the instruction that was interrupted. An exam-safe distinction is that interrupt context must not sleep. Kernel code running in process context may sleep only where that specific path permits it.

Worked example: trace write(1, buf, 3) end to end

Fix the inputs first. PID 4242 runs on x86-64 Linux. File descriptor 1 usually means standard output, but it can identify a terminal, pipe, or redirected file. Let buf = 0x00007fff10002000. Its first three bytes are 0x4B, 0x47, and 0x0A, representing K, G, and newline. The requested count is 3 bytes.

The raw x86-64 setup is:

Register

Value

Meaning

RAX

1

syscall number for write

RDI

1

fd

RSI

0x00007fff10002000

buf

RDX

3

count

Syscall number 1 comes from the x86-64 Linux syscall table. This register assignment is part of the x86-64 ABI, not a portable Linux rule.

Now trace the work:

  1. The syscall instruction crosses into the configured kernel entry path.

  2. Dispatch uses the value 1 in RAX to select write.

  3. The kernel checks fd 1 and safely accesses the three-byte user range. Starting at 0x00007fff10002000, three bytes occupy addresses 0x00007fff10002000 through 0x00007fff10002002 inclusive.

  4. VFS routes the request through the file object behind fd 1 to a terminal, pipe, filesystem, or device implementation. The kernel's VFS documentation defines this common userspace filesystem interface.

  5. If the downstream path accepts all three bytes, the raw return value is RAX = 3.

  6. Execution resumes after syscall in user mode, still in PID 4242.

If fd 1 is invalid, the raw kernel result is -EBADF; the libc wrapper normally returns -1 and sets errno to EBADF. Neither the successful path nor the failure path implies that one syscall equals one context switch.

Eight-step diagram tracing a three-byte write() through x86-64 registers, syscall dispatch, VFS, return RAX=3, and the EBADF failure path.

Process context, interrupts, and scheduling

Consider a teaching timeline, not measured Linux timings. At t=0 ms, PID 4242 runs in user mode. At t=2 ms, it enters the kernel for write. At t=3 ms, suppose the output path blocks. PID 4242 then becomes non-runnable, and the scheduler may select runnable PID 7300. The task switch is a scheduling consequence of blocking, not an automatic property of every syscall.

At t=4 ms, an independent device interrupt may arrive. Its asynchronous arrival does not mean that the interrupted PID requested the device work. Immediate interrupt handling can arrange deferred work for later, without changing the core distinction between interrupt context and process context.

Most importantly, PID 4242 entered the kernel as the same process. That differs from fork() questions about how many processes exist, where successful execution can create a new process.

Architecture traps that produce wrong answers

Correct these common shortcuts before they become exam mistakes:

  • "Monolithic means no modules." Linux can load modules while retaining a monolithic kernel architecture.

  • "Kernel mode means a different process." The same thread can execute kernel code while servicing its request.

  • "A system call equals a context switch." A privilege-mode transition and a scheduler task switch are different events.

  • "All API calls are syscalls." A library call may wrap one syscall, make several, or make none.

The values in the example create two more traps. The 3 in write(1, buf, 3) is the requested byte count, not the syscall number. RAX begins as 1, the x86-64 number for write, and becomes 3 only when this path accepts all three requested bytes.

Finally, do not generalise the worked registers and address. 0x00007fff10002000, RAX, RDI, RSI, RDX, and syscall number 1 belong to this x86-64 example. Another Linux architecture may encode the same request differently.

How exams test Linux kernel architecture

Representative practice questions usually take four forms:

  1. Classify Linux as monolithic, modular, or both in the correct sense.

  2. Match the scheduler, VFS, memory manager, and drivers to their responsibilities.

  3. Put system-call entry, dispatch, subsystem work, and return in order.

  4. Separate a mode switch, process switch, interrupt, and exception.

Use these quick checks:

  • Loading a driver module makes Linux a microkernel: False.

  • After the successful three-byte example, RAX contains: 3.

  • A write request for a regular file reaches the common filesystem abstraction through: VFS.

These are representative patterns, not quotations from past papers. KnowledgeGate has 5+ live practice questions on Linux Kernel Architecture, which is a modest pool for checking this model, not evidence of exam weightage. For any named exam, confirm the current official syllabus and rules from its official source and use previous-year papers to judge the question style.

Short version and next step

Recall one chain: user process -> syscall boundary -> dispatch -> cooperating kernel subsystem -> return. Scheduling may switch tasks if the path blocks or another scheduling condition arises, but a syscall does not guarantee a task switch. For structured subject coverage, continue with GATE Guidance by Sanchit Sir. When you are ready to test this model under practice conditions, use the GATE Test Series. Focus on explaining each boundary and return value, not just naming the boxes.