Resource usages in Linux drivers
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Thank you!
Quoted 13 lines · Sergei Shtylyov
Hello.
Quoted 8 lines · Jia-Ju Bai
Dear Sir,
I am very sorry to trouble you.
I find that resource management is error-prone when writing Linux drivers, and many problems may occur, such as resource leaks.
Meanwhile, I find that many applied patches in the kernel mailing list focus on releasing allocated resources, especially in error-handling paths.
Quoted 6 lines
Quoted 2 lines
Therefore, I have a question: is it possible to automatically release allocated resources in drivers before unloading and in error-handling paths?
Yes, there's managed device API, look for functions starting with
devm_.
There's one limitation though: it can be used only in the driver'sprobe()method, so can't be used when e.g. network device is being opened.
I think many APIs, such as kmalloc, can also be managed like garbage collection in Java. Maybe the performance is a matter.
Quoted 6 lines
Quoted 2 lines
I am looking forward to your reply, thanks!
Such questions should actually be asked on the mailing lists, not
personally.
I am sorry for that, and I will cc to the mailing lists and other maintainers.
Quoted 26 lines · Jia-Ju Bai
Thank you!
Quoted 13 lines · Sergei Shtylyov
Hello.
Quoted 8 lines · Jia-Ju Bai
Dear Sir,
I am very sorry to trouble you.
I find that resource management is error-prone when writing Linux drivers, and many problems may occur, such as resource leaks.
Meanwhile, I find that many applied patches in the kernel mailing list focus on releasing allocated resources, especially in error-handling paths.Quoted 6 lines
Quoted 2 lines
Therefore, I have a question: is it possible to automatically release allocated resources in drivers before unloading and in error-handling paths?
Yes, there's managed device API, look for functions starting with
devm_.
There's one limitation though: it can be used only in the driver'sprobe()method, so can't be used when e.g. network device is being opened.I think many APIs, such as kmalloc, can also be managed like garbage collection in Java. Maybe the performance is a matter.
Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
I am looking forward to your reply, thanks!
Such questions should actually be asked on the mailing lists, not
personally.I am sorry for that, and I will cc to the mailing lists and other maintainers.
I find that some common APIs are not managed, such as napi_enable and napi_start_queue. Is it possible to provide managed APIs for them? I also find many drivers do not use these managed APIs, especially in ethernet card drivers (like e100, r8169). Is it possible to change them?
Best wishes,
Jia-Ju Bai
Quoted 21 lines · Jia-Ju Bai
Quoted 20 lines
Quoted 8 lines
Quoted 7 lines
I am very sorry to trouble you.
I find that resource management is error-prone when writing Linux drivers, and
many problems may occur, such as resource leaks.
Meanwhile, I find that many applied patches in the kernel mailing list focus on releasing allocated resources, especially in error-handling paths.Quoted 6 lines
Quoted 2 lines
Therefore, I have a question: is it possible to automatically release allocated resources in drivers before unloading and in error-handling paths?
Yes, there's managed device API, look for functions starting with
devm_.
There's one limitation though: it can be used only in the driver'sprobe()method, so can't be used when e.g. network device is being opened.I think many APIs, such as kmalloc, can also be managed like garbage collection in Java.
Maybe the performance is a matter.Quoted 1 line
Quoted 1 line
I am looking forward to your reply, thanks!
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Such questions should actually be asked on the mailing lists, not
personally.I am sorry for that, and I will cc to the mailing lists and other maintainers.
I find that some common APIs are not managed, such as
napi_enableandnapi_start_queue. Is it possible to provide managed APIs for them?
No, they're only called from ndo_open() method IIRC. The device managed
APIs can only be called at the device probing time.
Quoted 2 lines
I also find many drivers do not use these managed APIs, especially in ethernet card drivers (like e100, r8169). Is it possible to change them?
Patches welcome. :-)
Quoted 2 lines
Best wishes,
Jia-Ju Bai
WBR, Sergei
Sergei Shtylyov <[email protected]> :
Quoted 1 line · Jia-Ju Bai
[...]
Quoted 4 lines
Quoted 2 lines
I also find many drivers do not use these managed APIs, especially in ethernet card drivers (like e100, r8169). Is it possible to change them?
Patches welcome. :-)
I respectfully disagree.
If someone believes basic resouce management to be too hard or error-prone to handle, he should imvho seriously rise the bar and reconsider the way he wants to contribute to the kernel.
I may hope he who reads e100.c to think about DMA api, bql or rx ring holes avoidance to quote a few ones. Managed API ? Mildly...
Signature · 1 line
Ueimor
Quoted 9 lines · Francois Romieu
Sergei Shtylyov <[email protected]> :
Quoted 1 line · Jia-Ju Bai
[...]
Quoted 4 lines
Quoted 2 lines
I also find many drivers do not use these managed APIs, especially in ethernet card drivers (like e100, r8169). Is it possible to change them?
Patches welcome. :-)
I respectfully disagree.
Me too, most of the device managed conversions we have seen were bogus because they were done in a semi-automated way without understanding the peculiarities of the network devices, that is the separation between init/open/close that most other device drivers do not have.
A typical example is this:
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=6892b41d9701283085b655c6086fb57a5d63fa47
Quoted 4 lines
If someone believes basic resouce management to be too hard or error-prone to handle, he should imvho seriously rise the bar and reconsider the way he wants to contribute to the kernel.
Well, for one, we could have a device managed register_netdev() which cleans up resources in case of failures and calls free_netdev() automatically, but is that adding much value?
Quoted 4 lines
I may hope he who reads
e100.cto think about DMA api, bql or rx ring holes avoidance to quote a few ones. Managed API ? Mildly...
Signature · 1 line
Florian
David Miller
maintainerFrom: Florian Fainelli <[email protected]>
Date: Thu, 23 Apr 2015 17:40:12 -0700
Quoted 3 lines
Well, for one, we could have a device managed
register_netdev()which cleans up resources in case of failures and callsfree_netdev()automatically, but is that adding much value?
I don't think it's worth it at all.