linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* workqueue - process context
@ 2005-02-19  1:48 Vicente Feito
  2005-02-19  4:57 ` Roland Dreier
  0 siblings, 1 reply; 8+ messages in thread
From: Vicente Feito @ 2005-02-19  1:48 UTC (permalink / raw)
  To: Linux Kernel Mailing List

I've been playing with workqueues, and I've found that once I unload the 
module, if I don't call destroy_workqueue(); then the workqueue I've created 
stays in the process list, [my_wq], I don't know if that's meant to be, or is 
it a bug, cause I believe there can be two options in here:

1) It's meant to be so you can unload your module and let the works run some 
time after you're already gone, that allows you to probe other modules or do 
whatever necesary without the need to wait for the workqueue to be emtpy.

2) It's a bug, cause the module allows to be unloaded, destroying the structs 
but not removing the workqueue from the process context.

Which one is it?I hope I'm being clear with my question.
I was about to try to find a solution to remove the queue but maybe it's meant 
to be, although not likely.

Vicente.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: workqueue - process context
  2005-02-19  4:57 ` Roland Dreier
@ 2005-02-19  2:02   ` Vicente Feito
  2005-02-19  5:03     ` Roland Dreier
  2005-02-19 14:31   ` Rene Herman
  1 sibling, 1 reply; 8+ messages in thread
From: Vicente Feito @ 2005-02-19  2:02 UTC (permalink / raw)
  To: Roland Dreier; +Cc: Linux Kernel Mailing List

On Saturday 19 February 2005 04:57 am, you wrote:
>     Vicente> I've been playing with workqueues, and I've found that
>     Vicente> once I unload the module, if I don't call
>     Vicente> destroy_workqueue(); then the workqueue I've created
>     Vicente> stays in the process list, [my_wq], I don't know if
>     Vicente> that's meant to be, or is it a bug, cause I believe there
>     Vicente> can be two options in here:
>
>     Vicente> 1) It's meant to be so you can unload your module and let
>     Vicente> the works run some time after you're already gone, that
>     Vicente> allows you to probe other modules or do whatever necesary
>     Vicente> without the need to wait for the workqueue to be emtpy.
>
>     Vicente> 2) It's a bug, cause the module allows to be unloaded,
>     Vicente> destroying the structs but not removing the workqueue
>     Vicente> from the process context.
>
> Not destroying its workqueue is a bug in the module just like any
> other resource leak.  It's analogous to a module allocating some
> memory with kmalloc() and not calling kfree() when it's unloaded.  If
> a module creates a workqueue, then it should call destroy_workqueue()
> when it's unloaded.
What if I need the module to be unloaded cause It's mutually exclusive with 
another module to be loaded, and I still need to run the works in a workqueue 
time before that happens? That's completely out of the picture?cause that 
might be useful.
>
> By the way, the module (or any code calling destroy_workqueue()) must
> make sure that it has race conditions that might result in work being
> submitted to the queue while it is being destroyed.
yes, I think flushing is enough, is it?

>
>  -R .
Vicente.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: workqueue - process context
  2005-02-19  1:48 workqueue - process context Vicente Feito
@ 2005-02-19  4:57 ` Roland Dreier
  2005-02-19  2:02   ` Vicente Feito
  2005-02-19 14:31   ` Rene Herman
  0 siblings, 2 replies; 8+ messages in thread
From: Roland Dreier @ 2005-02-19  4:57 UTC (permalink / raw)
  To: Vicente Feito; +Cc: Linux Kernel Mailing List

    Vicente> I've been playing with workqueues, and I've found that
    Vicente> once I unload the module, if I don't call
    Vicente> destroy_workqueue(); then the workqueue I've created
    Vicente> stays in the process list, [my_wq], I don't know if
    Vicente> that's meant to be, or is it a bug, cause I believe there
    Vicente> can be two options in here:

    Vicente> 1) It's meant to be so you can unload your module and let
    Vicente> the works run some time after you're already gone, that
    Vicente> allows you to probe other modules or do whatever necesary
    Vicente> without the need to wait for the workqueue to be emtpy.

    Vicente> 2) It's a bug, cause the module allows to be unloaded,
    Vicente> destroying the structs but not removing the workqueue
    Vicente> from the process context.

Not destroying its workqueue is a bug in the module just like any
other resource leak.  It's analogous to a module allocating some
memory with kmalloc() and not calling kfree() when it's unloaded.  If
a module creates a workqueue, then it should call destroy_workqueue()
when it's unloaded.

By the way, the module (or any code calling destroy_workqueue()) must
make sure that it has race conditions that might result in work being
submitted to the queue while it is being destroyed.

 -R .

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: workqueue - process context
  2005-02-19  2:02   ` Vicente Feito
@ 2005-02-19  5:03     ` Roland Dreier
  0 siblings, 0 replies; 8+ messages in thread
From: Roland Dreier @ 2005-02-19  5:03 UTC (permalink / raw)
  To: Vicente Feito; +Cc: Linux Kernel Mailing List

    Vicente> What if I need the module to be unloaded cause It's
    Vicente> mutually exclusive with another module to be loaded, and
    Vicente> I still need to run the works in a workqueue time before
    Vicente> that happens? That's completely out of the picture?cause
    Vicente> that might be useful.

That doesn't sound like a good idea.  For one thing, how does the
second module get the workqueue pointer from the first module?  The
simplest solution would be for each module to create and destroy its
own workqueue.  However, if you really need a shared workqueue for
some reason, then have a simple third module that can remain loaded
and have it manage the workqueue for both of your other modules.

    Roland> By the way, the module (or any code calling
    Roland> destroy_workqueue()) must make sure that it has race
    Roland> conditions that might result in work being submitted to
    Roland> the queue while it is being destroyed.

    Vicente> yes, I think flushing is enough, is it?

Usually, but you have to be extra-careful if you have any work
functions that might resubmit themselves.

 - Roland


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: workqueue - process context
  2005-02-19  4:57 ` Roland Dreier
  2005-02-19  2:02   ` Vicente Feito
@ 2005-02-19 14:31   ` Rene Herman
  2005-02-19 16:19     ` Roland Dreier
  1 sibling, 1 reply; 8+ messages in thread
From: Rene Herman @ 2005-02-19 14:31 UTC (permalink / raw)
  To: Roland Dreier; +Cc: Vicente Feito, Linux Kernel Mailing List

Roland Dreier wrote:

> Not destroying its workqueue is a bug in the module just like any
> other resource leak.  It's analogous to a module allocating some
> memory with kmalloc() and not calling kfree() when it's unloaded.

Except though that with kmalloc() it's indeed just a leak while in this 
case things might blow up violently if run_workqueue() later accesses a 
workqueue_struct (or work_struct) which is already gone as part of the 
modules' datasection, for example. That's to say, if I'm reading this 
right...

I have no idea about the module refcounting stuff. Is there a chance 
that create_workqueue() could increase a reference somewhere so that the 
module wouldn't be allowed to unload untill after a destroy_workqueue()?

Rene.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: workqueue - process context
  2005-02-19 14:31   ` Rene Herman
@ 2005-02-19 16:19     ` Roland Dreier
  2005-02-19 16:52       ` Rene Herman
  0 siblings, 1 reply; 8+ messages in thread
From: Roland Dreier @ 2005-02-19 16:19 UTC (permalink / raw)
  To: Rene Herman; +Cc: Vicente Feito, Linux Kernel Mailing List

    Rene> I have no idea about the module refcounting stuff. Is there
    Rene> a chance that create_workqueue() could increase a reference
    Rene> somewhere so that the module wouldn't be allowed to unload
    Rene> untill after a destroy_workqueue()?

There's no point to doing this, since it's adding complexity to try
and avoid a very obvious and easy to find bug.  Other types of
resource leaks are harder to find, but a module not destroying a
workqueue is going to be trivial to spot and fix.

(There are technical issues as well -- if create_workqueue()
increments the module reference count, then you would never be able to
unload the module if the destroy_workqueue() was in the module_exit
function, because you can never even start to unload a module with a
non-zero ref count).

 - R.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: workqueue - process context
  2005-02-19 16:19     ` Roland Dreier
@ 2005-02-19 16:52       ` Rene Herman
  0 siblings, 0 replies; 8+ messages in thread
From: Rene Herman @ 2005-02-19 16:52 UTC (permalink / raw)
  To: Roland Dreier; +Cc: Vicente Feito, Linux Kernel Mailing List

Roland Dreier wrote:

>     Rene> I have no idea about the module refcounting stuff. Is there
>     Rene> a chance that create_workqueue() could increase a reference
>     Rene> somewhere so that the module wouldn't be allowed to unload
>     Rene> untill after a destroy_workqueue()?
> 
> There's no point to doing this, since it's adding complexity to try
> and avoid a very obvious and easy to find bug.  Other types of
> resource leaks are harder to find, but a module not destroying a
> workqueue is going to be trivial to spot and fix.

Yes, fair enough. Thank you.

Rene.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: workqueue - process context
@ 2005-02-19  2:38 Vicente Feito
  0 siblings, 0 replies; 8+ messages in thread
From: Vicente Feito @ 2005-02-19  2:38 UTC (permalink / raw)
  To: Linux Kernel Mailing List

On Saturday 19 February 2005 04:57 am, you wrote:
>     Vicente> I've been playing with workqueues, and I've found that
>     Vicente> once I unload the module, if I don't call
>     Vicente> destroy_workqueue(); then the workqueue I've created
>     Vicente> stays in the process list, [my_wq], I don't know if
>     Vicente> that's meant to be, or is it a bug, cause I believe there
>     Vicente> can be two options in here:
>
>     Vicente> 1) It's meant to be so you can unload your module and let
>     Vicente> the works run some time after you're already gone, that
>     Vicente> allows you to probe other modules or do whatever necesary
>     Vicente> without the need to wait for the workqueue to be emtpy.
>
>     Vicente> 2) It's a bug, cause the module allows to be unloaded,
>     Vicente> destroying the structs but not removing the workqueue
>     Vicente> from the process context.
>
> Not destroying its workqueue is a bug in the module just like any
> other resource leak.  It's analogous to a module allocating some
> memory with kmalloc() and not calling kfree() when it's unloaded.  If
> a module creates a workqueue, then it should call destroy_workqueue()
> when it's unloaded.
What if I need the module to be unloaded cause It's mutually exclusive with 
another module to be loaded, and I still need to run the works in a workqueue 
time before that happens? That's completely out of the picture?cause that 
might be useful.
>
> By the way, the module (or any code calling destroy_workqueue()) must
> make sure that it has race conditions that might result in work being
> submitted to the queue while it is being destroyed.
yes, I think flushing is enough, is it?

>
>  -R .
Vicente.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2005-02-19 16:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-19  1:48 workqueue - process context Vicente Feito
2005-02-19  4:57 ` Roland Dreier
2005-02-19  2:02   ` Vicente Feito
2005-02-19  5:03     ` Roland Dreier
2005-02-19 14:31   ` Rene Herman
2005-02-19 16:19     ` Roland Dreier
2005-02-19 16:52       ` Rene Herman
2005-02-19  2:38 Vicente Feito

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).