Re: Memory Allocation in Interrupt Handlers?
Re: Memory Allocation in Interrupt Handlers?
- Subject: Re: Memory Allocation in Interrupt Handlers?
- From: Michael Smith <email@hidden>
- Date: Thu, 10 May 2007 07:55:45 +1000
On May 9, 2007, at 5:03 AM, email@hidden wrote:
the answer to this is probably easy to find in the right place, but
is there a memory allocation routine that is interrupt safe? From the
documentation for IOMalloc it is clear that it is not, so is there a
function that is?
Or would I have to allocate all my memory prior to going into
interrupt context?
There are two separate things to consider here.
First; you should go to great lengths to avoid allocating memory on
any I/O path. A couple of good ideas:
- Keep a pre-allocated pool of your work structures; consider
subclassing IOCommand and use an IOCommandPool. If the pool is empty
when new work arrives, it's OK to block and better to block up front
than halfway into your setup when an allocation fails and you've run
the kernel out of address space.
- Avoid using buffers for your data. You don't want to copy data
anyway, so this will tend to improve the performance of your driver
as a side effect. Use scatter/gather lists rather.
Second; unless you are using an IOFilterInterruptEventSource, you are
not running any code in interrupt context. IOInterruptEventSource
handlers run in "regular" thread context. You can (but per the
above, should not make a habit of) allocate memory in the latter.
= Mike
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden