How many kernel system calls do runtimes make?
Summary
TLDRThis video explores the number of system calls made by different applications to perform a simple task: reading a file and printing it to the screen. The presenter uses strace to capture system calls for various languages and runtimes, including Python, Node.js, Bun, and C. The goal is to demystify the 'under the carpet' operations and understand the performance implications of system calls. The video concludes with a discussion on the efficiency of system calls and the potential for batch processing to reduce kernel mode switches.
Takeaways
- 🔍 The script explores the number of system calls made by different applications to perform a simple file read operation.
- 🛠️ It uses the `strace` tool to capture every system call made by a process, which helps understand the interaction between user space and kernel space.
- 📚 A system call acts as a bridge between user space applications and the kernel, often switching processes into kernel mode to access elevated permissions.
- 💡 The script discusses the cost of system calls, noting that while individual calls are not significant, frequent calls can add up and affect performance.
- 🌐 The presenter compares system calls to web page loading, where a large number of calls can slow down the process.
- 🔧 The script examines system calls made by different programming languages and frameworks: Python, Node.js, Bun, and C.
- 📈 It finds that Python makes 762 system calls, taking about 7 milliseconds, while Node.js makes 800 calls in about 13 milliseconds.
- 🚀 The script reveals that Bun, a JavaScript runtime, makes 952 system calls in 24 milliseconds, which is significantly higher than the others.
- 🏎️ C, with no interpreter overhead, makes the fewest system calls and is the fastest, with the time being less than a microsecond.
- 💡 The presenter suggests the idea of batching system calls to reduce the number of kernel mode switches, which could potentially improve performance.
Q & A
What is the main purpose of the tool 'strace' mentioned in the script?
-The main purpose of 'strace' is to trace system calls made by a process. It captures every system call made by the specified process, providing insight into how the process interacts with the kernel.
What is a system call and why are they significant?
-A system call is a bridge that connects user space (normal applications) to kernel space (where operations with elevated permissions are performed). They are significant because they allow applications to perform tasks that require higher privileges, such as reading from a disk, writing to files, or interacting with hardware.
What is the cost associated with making a system call?
-Making a system call involves a small cost as it switches the process from user mode to kernel mode, which involves flushing some registers to memory and reading some data. While not significant for a single call, frequent system calls can add up and slow down performance.
Why might minimizing system calls be beneficial?
-Minimizing system calls can be beneficial because each call involves a transition between user and kernel mode, which has an associated cost. Reducing the number of calls can lead to performance improvements, especially in applications that make frequent system calls.
What is the difference between a context switch and a kernel mode switch?
-A context switch occurs when the CPU stops executing one process and starts executing another, while a kernel mode switch is a transition from user mode to kernel mode, which happens when a system call is made. The latter is a smaller operation than a full context switch.
What is the significance of the 'drop_caches' command used in the script?
-The 'drop_caches' command is used to clear the file system page cache, ensuring that the system calls being traced are not influenced by cached data. This allows for a more accurate measurement of system calls when reading from a file.
Why does the script mention that Python and Node.js might be making additional system calls beyond just reading the file?
-Python and Node.js are higher-level languages that perform additional operations in the background, such as reading configuration files and managing packages. These operations require system calls, which is why the number of system calls can be higher than expected for a simple file read operation.
What does the script suggest about the performance of C compared to Python and Node.js for reading a file?
-The script suggests that C, being a lower-level language, likely makes fewer system calls and is faster for the task of reading a file compared to higher-level languages like Python and Node.js, which have more overhead.
What is the role of 'bun' in the context of the script?
-'Bun' is mentioned as a JavaScript framework/runtime similar to Node.js. The script compares the number of system calls made by Bun to those made by Node.js and Python to demonstrate the differences in performance and system call overhead.
What is the significance of the 'read.out' program mentioned in the script?
-The 'read.out' program is a compiled C program that reads from a file. It is used to demonstrate the minimal number of system calls and high performance that can be achieved by a lower-level, compiled language compared to interpreted languages or higher-level frameworks.
What is the potential downside of making many system calls in a loop?
-Making many system calls in a loop can lead to frequent mode switches between user and kernel mode, which can negatively impact performance due to the overhead associated with each switch.
Outlines
Esta sección está disponible solo para usuarios con suscripción. Por favor, mejora tu plan para acceder a esta parte.
Mejorar ahoraMindmap
Esta sección está disponible solo para usuarios con suscripción. Por favor, mejora tu plan para acceder a esta parte.
Mejorar ahoraKeywords
Esta sección está disponible solo para usuarios con suscripción. Por favor, mejora tu plan para acceder a esta parte.
Mejorar ahoraHighlights
Esta sección está disponible solo para usuarios con suscripción. Por favor, mejora tu plan para acceder a esta parte.
Mejorar ahoraTranscripts
Esta sección está disponible solo para usuarios con suscripción. Por favor, mejora tu plan para acceder a esta parte.
Mejorar ahoraVer Más Videos Relacionados
System Calls
L-1.10: User mode and Kernel mode in operating system in hindi
L-1.7: System Calls in Operating system and its types in Hindi
GHIDRA for Reverse Engineering (PicoCTF 2022 #42 'bbbloat')
fork() and exec() System Calls
L-1.1: Introduction to Operating System and its Functions with English Subtitles
5.0 / 5 (0 votes)