Skip to content
Advertisement

How to create light weight kernel thread?

When I create a kernel thread (kthread_run), it becomes a new process.(I could see it using top command) . How can I create a light weight kernel thread(like the one we have in user space)?

If I am not wrong, kthread_create will eventually call fork() which will call clone() with appropriate configuration to create a new process/lw process. Is it possible to create lw kernel thread using clone() or similar apis? Thanks so much in advance.

Advertisement

Answer

Kernel threads are always listed in the process table, but this is merely a cosmetical issue. They share the same address space and *-tables, so in this sense they are quite lightweight anyway (i.e. a context-switch isn’t very expensive).

If your 2*16 kernel-threads mainly do the same thing, it might be worthy evaluating if the functionality can be moved into a seperate kernel-module, which exposes an API to be used by all 16 kernel-modules and doing the work in only 1 or 2 threads.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement