When should I write a Linux kernel module?

后端 未结 10 884
礼貌的吻别
礼貌的吻别 2021-02-02 08:05

Some people want to move code from user space to kernel space in Linux for some reason. A lot of times the reason seems to be that the code should have particularly high priorit

相关标签:
10条回答
  • 2021-02-02 08:36

    If you're asking such a question, then you shouldn't go to the kernel layer. Basically just wondering means you don't need to. The time of the context switch is so negligible that it doesn't matter anyway these days.

    0 讨论(0)
  • 2021-02-02 08:39

    There are very limited reasons to put stuff into the kernel. If you're writing device drivers it's ok. Any standard application: never.

    The drawbacks are huge. Debugging gets harder, errors become more frequent and hard to find. You might compromise security and stability. You might have to adapt to kernel changes more frequently. It becomes impossible to port to other UNIX OSs.

    The closest I've ever come to the kernel was a custom filesystem (with mysql in the background) and even for that we used FUSE (where the U stands for userspace).

    0 讨论(0)
  • 2021-02-02 08:39

    Another reason to not move code into kernel space is that when you use it in production or commercial situations, you will have to publish that code due to the GPL agreement. A situation that many software companies don't want to come into. :)

    0 讨论(0)
  • 2021-02-02 08:40

    Code running in the kernel accesses memory, peripherals, system functions in ways that are different from userspace code and thus has the ability to be more efficient. Not to mention the reduced security restrictions for kernel code. However, all this usually comes at a cost, such as increasing the possibility of opening the kernel up to security threats, locking up the OS, complicating the debugging, and so forth.

    0 讨论(0)
提交回复
热议问题