Systems and Networking · 16 min · free with an account

Syscalls and Buffering

Lesson preview · about 30%

A syscall is a controlled trip into the kernel, and it is not free.

Core idea

Batch at the boundary: syscalls cost orders of magnitude more than calls.

Start with the idea

Reading a file, opening a socket, or spawning a thread all cross a privilege boundary that costs far more than a function call. That is why buffering and batching can help when per-call overhead matters, while event loops can handle many mostly idle connections efficiently. Interviewers ask this to see whether you know where the cost of IO actually is.

A system call crosses from user code into the kernel to request a privileged operation. The transition and work on the other side have cost, but there is no single fixed ratio to a function call: data size, caching, contention, device latency, and kernel path all matter. Buffered I/O can combine many small writes into fewer requests. Scatter/gather I/O can send several buffers in one call. Batching is valuable when per-call overhead is a measurable part of the workload, not as a rule to apply blindly.

Keep learning, for free

The rest of this lesson is waiting for you.

Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.

No payment details. Your account opens the complete Academy.

← All lessons in Rust Interview Prep