Skip to contentSkip to conversation

Killing kernel threads

DISCUSSION Super user 2 participants 4 messages Nov 19, 2002 – Dec 2, 2002

lore
Share & tools
lore

Super user

author
#0 lore raw

Hi,

Is there any guaranted way to kill kernel threads started from loadable modules. I've written a kernel module that starts 8 kernel threads and sometimes one of them goes into uninterruptible sleep. Is there anyway to flush away such threads while unloading modules.

I've tried using kill_proc with SIGKILL but it doesn't seem to help.

BTW, I am using the code for handling kernel threads at http://www.scs.ch/~frey/linux/kernelthreads.html

Any pointers regarding the same are highly appreciated.

Thanks,

__________________________________________________
Do you Yahoo!?
Yahoo! Web Hosting - Let the expert host your site
http://webhosting.yahoo.com

#1 lore raw
Quoted 11 lines · Super user

Hi,

Is there any guaranted way to kill kernel threads started from loadable modules. I've written a kernel module that starts 8 kernel threads and sometimes one of them goes into uninterruptible sleep. Is there anyway to flush away such threads while unloading modules.

I've tried using kill_proc with SIGKILL but it doesn't seem to help.

#ifdef NEW_THREAD_EXIT
	struct completion quit;
#else
	struct semaphore quit;

#endif

In the kernel thread, someplace it can be awakened by a signal:

#ifdef NEW_THREAD_EXIT
	complete_and_exit(&quit, 0);
#else
        up_and_exit(&quit, 0);

#endif

In cleanup_module:

#ifdef NEW_THREAD_EXIT
	wait_for_completion(&quit);
#else
	down(&quit);

#endif

You define NEW_THREAD_EXIT based upon the kernel version. 2.4.18 uses the new syntax.

If you have a lot of threads, you need to have one of these constructs for each of the threads and don't forget to initialize the semaphores. Last I knew, this was the way to do it (and it works).

Cheers,
Dick Johnson
Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).
Bush : The Fourth Reich of America

author
#2 lore raw

Size limitation for the module

Hi All,

I have a kernel module which is a huge one. Around 1.5 MB. Is there any known problems in having a such a big module.

The problem is after inserting the module, the box freezes after some time. Some times it crashes.I analyzed the oops message, but it does'nt make much sense, since the trace leads me to some other kernel code. So it looks like my module is corrupting the memory , which leads to this crash.Appreciate if someone can send me a link to fix these types of problems. Also is there any tool which can do a memwatch on the kernel space.

Thanks,
lnxuser2002.

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

#3 lore raw

Re: Size limitation for the module

Quoted 8 lines · Super user

Hi All,

I have a kernel module which is a huge one. Around 1.5 MB. Is there any known problems in having a such a big module.

The problem is after inserting the module, the box freezes after some time.

[SNIPPED...]

There might not be 1.5 MB available from kmalloc() and there may be a bug in kmalloc() when it gets to allocating more memory than it has (these boundary conditions may not have been tested very well, or your module isn't checking returned results).

Normally, if you need lots of memory for a module, you tell the kernel upon boot that there is less memory than there is. IOW, you reserve it. Then, in your module you use ioremap() to allocate it exclusively for your module.

This method has many advantages as well. FYI, the memory is never paged, it's always immediately available for your module.

In principle, you are supposed to use copy/from/to/io and read/b/w/l/write/b/w/l to access it, but on ix86 (only), you can initialize a pointer with the value returned from ioremap().

This, of course is not portable, but a module allocation of 1.5 MB is not portable anyway, so doit2it.

Cheers,
Dick Johnson
Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).
Bush : The Fourth Reich of America