Thanks for your help. I checked all the interface supported by
IOMemoryDescriptor
but I cannot find one that can work for me. I think I need to give you more
details.
I am writing a filter driver. In the read/write routines, I got a
IOMemoryDescriptor
as input but I really need another buffer of the same size to do some
processing.
So this is what I do roughly:
read(client, byteStart, buffer, completion)
{
IOByteCount n = buffer->getLength();
void *mem = IOMalloc(n);
IOMemoryDescriptor *myBuffer = IOMemoryDescriptor::withAddress(mem, n,
....);
I can understand that IOMalloc can fail so I add some code like this:
if <failed> queue the request ....
Then in the IO completion code, I added:
.....
IOFree(mem);
<process the queue - try IOMalloc again ...>
However, even right after the memory is freed, the IOMalloc still fails (not
100%)!!!
After some time (real quick), I have no more outstanding IO but I still have
some
queued request waiting for memory. The calling process (XTune) is now
hung,
waiting for IO completion. I even add a polling thread to wake up the
request
queue and try IOMalloc but it will still fail. Who is to blame?
I thought about reusing the memory buffer but I cannot assume that the sizes
are all the same
and it will be hard to manage them this way. It is the kernel's job to
manage memory.
I do not know if returning kIOReturnNoMemory immediately (the first failure)
is a good idea?? That might break many things or even panic if the caller
cannot handle IO error.
Please give me you suggestion.
Tony
From: Garth Cummings <email@hidden>
Reply-To: Darwin Drivers Mailing List <email@hidden>
To: Tony Wong <email@hidden>
CC: Darwin Drivers Mailing List <email@hidden>
Subject: Re: IOMalloc question
Date: Tue, 8 May 2007 15:39:44 -0700
Hi Tony,
On Apr 30, 2007, at 11:58 AM, Tony Wong wrote:
I am using IOMalloc in a media filter driver to allocate buffer for each
read, write request.
Data is copied around.
Everything works fine until I ran a heavy read test. After a few fairly
large read requests
(512K size), IOMalloc fails. That's fine. I queue the request up and
then the driver retries
the IOMalloc in the IOCompletion routine when some previous IOMalloc'ed
buffer is freed.
It works a couple times and then it gets stuck. Then I added some
timeout events to
do the IOMalloc periodically but it just fails. The test hangs.
I also have the impression that IOMalloc() will block until memory is
available. When does it
ever return NULL? What does that mean?
Is there other way to allocate memory (I am assuming that IOMalloc has a
limited pool??)?
IOMalloc is only for small temporary allocations. Otherwise try
IOBufferMemoryDescriptor.
--gc
____________________________________________________________________
Garth Cummings email@hidden
Sr. Software Engineer
Apple Developer Technical Support