Skip to contentSkip to conversation

unloading drivers and usage counters

DISCUSSION Oliver Neukum 3 participants 4 messages Jan 21, 2001 – Jan 22, 2001

lore
Share & tools
lore
#0 lore raw

Hi,

going through the hotplugging scripts I noticed that there's no good way to unload modules. A time based approach cannot be used due to race conditions. Unloading on device removal requires keeping a usage counter in user space. This seems to be a brittle approach.

Not increasing the module usage counters on connect seems to be the wrong strategy. The desire to keep the modules unloadable has come back to bite us into our behind.
If the usage counters were increased for each connected device unloading would come natural. A patch to disconnect drivers by an ioctl has been posted. It would allow forced unload.

Regards
Oliver

_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
http://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#1 lore raw
Quoted 5 lines

From: Oliver Neukum <[email protected]>
Sent: Sunday, January 21, 2001 1:12 PM

going through the hotplugging scripts I noticed that there's no good way to unload modules. A time based approach cannot be used due to race conditions.

No good way now, true; I'm not sure I'd call the reasons "races" though. More like different models for why "kernel modules" get used.

Quoted 2 lines

Unloading on device removal requires keeping a usage counter in user space. This seems to be a brittle approach.

I can imagine implementing a workable solution in userspace, which may be the best that the 2.4 kernels can handle. Yep, brittle is a good word for that!

Quoted 5 lines

Not increasing the module usage counters on connect seems to be the wrong strategy. The desire to keep the modules unloadable has come back to bite us into our behind.
If the usage counters were increased for each connected device unloading would come natural.

Sounds like a substantial change in the model for what module use counts should be. Maybe the pcmcia_cs tools have a better model?

- Dave

Quoted 2 lines

A patch to disconnect drivers by an ioctl has been posted. It
would allow forced unload.

_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
http://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#2 lore raw
In reply to Oliver Neukum
Quoted 2 lines · David Brownell

Sounds like a substantial change in the model for what module use counts should be. Maybe the pcmcia_cs tools have a better model?

For PCMCIA, module use counts are incremented when a device is opened, and decremented when closed, just like most non-hot-plug modules. Attaching a driver to a newly hot plugged device does not increment its use count.

To decide when to unload a module, the cardmgr daemon keeps track of the number of times a module has been requested in response to new device insertions; this count can indeed get messed up if people manually unload modules, or if cardmgr is killed and restarted. I am not bothered much by this, because the consequences are mostly harmless and the user has to go out of their way to mess up the automatic usage counting. In practice, no one has ever complained to me about it.

The PCMCIA subsystem does provide /proc/bus/pccard/drivers, which lists what drivers are present, which are modules vs. which are static linked, and the actual number of present devices that are associated with each driver. Cardmgr currently only uses the module/static flag from this file, so that it won't bother trying to remove a static driver; it would not be much work to also use the usage information for precise decisions about when to unload modules.

-- Dave

_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
http://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#3 lore raw
In reply to Oliver Neukum
Quoted 11 lines

From: David Hinds <[email protected]>
Sent: Sunday, January 21, 2001 10:04 PM

To decide when to unload a module, the cardmgr daemon keeps track of the number of times a module has been requested in response to new device insertions; this count can indeed get messed up if people manually unload modules, or if cardmgr is killed and restarted. I am not bothered much by this, because the consequences are mostly harmless and the user has to go out of their way to mess up the automatic usage counting. In practice, no one has ever complained to me about it.

Hmm, so maybe a pure user-mode solution isn't so brittle as that. That's been in use how many years now? :-)

This is stuff that could clearly be handled in some /sbin/hotplug policy code, saving state in some file.

Quoted 7 lines

The PCMCIA subsystem does provide /proc/bus/pccard/drivers, which lists what drivers are present, which are modules vs. which are static linked, and the actual number of present devices that are associated with each driver. Cardmgr currently only uses the module/static flag from this file, so that it won't bother trying to remove a static driver; it would not be much work to also use the usage information for precise decisions about when to unload modules.

Sounds like this is something that the "linux hotplug" system should perhaps consider providing in a more general way, for all levels of the driver stacks.

- Dave

_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
http://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel