Linux Kernel
While it’s generally advisable to keep code in user-space whenever possible, there may be scenarios where kernel-level development becomes necessary. This section will help you determine when it is appropriate to write Linux kernel modules or extend the kernel in any other way and how.
When should you dabble in the Linux Kernel?
A rule of thumb is to exhaustively explore alternatives to kernel code before considering diving into the kernel. This involves dedicating ample time to research and attempting to implement the functionality in user-space. Kernel code can be challenging to debug, and the potential for errors and difficulties in locating them is indeed a valid concern. Therefore, cautious consideration is essential before delving into kernel development.
There are specific conditions to evaluate when contemplating kernel-mode code. For instance, if the code requires access to the low-level resources like interrupts or defines a new interface/driver for hardware that cannot rely on currently available functionality, kernel development may be required. When writing components primarily used by other kernel subsystems, such as schedulers or VM systems, kernel-level implementation may be necessary, although alternatives to keep it in user space should still be explored.
Exploring alternatives
However, it’s important to remember that the reasons to write code in the kernel are limited. For standard applications, it is generally advised to steer clear of kernel involvement. The drawbacks of kernel code are significant, including heightened debugging complexity, increased error frequency, potential compromises to security and stability, and reduced portability across different UNIX operating systems. These factors should be taken into account when considering whether to venture into the kernel.
An alternative worth considering is the use of user-space solutions like FUSE (Filesystem in Userspace). This approach allows developers to implement custom filesystems while remaining in user-space. By leveraging such solutions, one can achieve the desired functionality without the need for direct kernel involvement.
In short, the decision to write code in the kernel or user-space should only be made after careful consideration. Strive to keep code in user-space whenever possible, investing time in researching alternatives and attempting implementation in that domain. However, certain scenarios may warrant kernel-level development. In those cases, evaluating specific conditions and thoroughly weighing the drawbacks becomes crucial. Ultimately, striking a balance between the benefits and challenges of each approach will lead to informed and appropriate architectural decisions.